Skip to content

Commit 10695aa

Browse files
wip
1 parent 3893196 commit 10695aa

31 files changed

Lines changed: 976 additions & 173 deletions

1.18.2/core/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ repositories {
1111

1212
dependencies {
1313
// coreで必要な依存関係のみ
14-
implementation 'net.java.dev.jna:jna:5.13.0'
15-
implementation 'net.java.dev.jna:jna-platform:5.13.0'
14+
compileOnly 'net.java.dev.jna:jna:5.13.0'
15+
compileOnly 'net.java.dev.jna:jna-platform:5.13.0'
16+
compileOnly 'commons-io:commons-io:2.11.0'
1617
compileOnly 'org.apache.logging.log4j:log4j-core:2.25.3'
1718
// TODO(kisaragi): 妥協しているがバージョンが違うと容易にスライドするのでMinecraft側ソースに責務を押し付けるべき
1819
compileOnly 'org.lwjgl:lwjgl-glfw:3.2.3'

1.18.2/core/src/main/java/jp/axer/cocoainput/CocoaInput.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919

2020
public class CocoaInput {
2121
private static CocoaInputController controller;
22-
// TODO(kisaragi): この辺怪しいのでインターフェース切るべきっぽい
23-
public static String zipsource;
2422
// TODO(kisargi): あとで直す
2523
// public static ConfigPack config = ConfigPack.defaultConfig;
2624
private static SimpleLogger logger;
2725

28-
public CocoaInput(String loader, String zipfile, SimpleLogger logger, MinecraftRawWindowIdAccessor w, NativeLibraryLoader n, ScreenScaleFactorGetter s) {
26+
public CocoaInput(String loader, SimpleLogger logger, MinecraftRawWindowIdAccessor w, NativeLibraryLoader n, ScreenScaleFactorGetter s) {
2927
logger.log("Modloader:" + loader);
30-
CocoaInput.zipsource = zipfile;
3128
try {
3229
if (Platform.isMac()) {
3330
CocoaInput.applyController(new DarwinController(n, logger, s));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package jp.axer.cocoainput.config;
2+
3+
public interface ConfigPack {
4+
boolean isAdvancedPreeditDraw();
5+
boolean isNativeCharTyped();
6+
}

1.18.2/fabric/src/fabric/java/jp/axer/cocoainput/LibraryCopyImpl.java renamed to 1.18.2/core/src/main/java/jp/axer/cocoainput/domain/LibraryCopyImpl.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jp.axer.cocoainput;
1+
package jp.axer.cocoainput.domain;
22

33
import java.io.File;
44
import java.io.FileNotFoundException;
@@ -8,25 +8,20 @@
88
import java.util.zip.ZipEntry;
99
import java.util.zip.ZipFile;
1010

11+
import jp.axer.cocoainput.CocoaInput;
1112
import org.apache.commons.io.IOUtils;
1213

13-
import com.sun.jna.Platform;
14-
15-
import jp.axer.cocoainput.arch.darwin.DarwinController;
16-
import jp.axer.cocoainput.arch.dummy.DummyController;
17-
import jp.axer.cocoainput.arch.win.WinController;
18-
import jp.axer.cocoainput.arch.x11.X11Controller;
1914
import jp.axer.cocoainput.domain.*;
20-
import jp.axer.cocoainput.plugin.CocoaInputController;
21-
import jp.axer.cocoainput.config.ConfigPack;
22-
import net.minecraft.client.Minecraft;
23-
import net.minecraft.client.gui.screens.Screen;
2415

2516
public class LibraryCopyImpl implements NativeLibraryLoader {
2617
private SimpleLogger logger;
18+
private String zipsource;
19+
private final MinecraftNativeFolderAccessor minecraftNativeFolderAccessor;
2720

28-
public LibraryCopyImpl(SimpleLogger logger) {
21+
public LibraryCopyImpl(SimpleLogger logger, String zipsource, MinecraftNativeFolderAccessor minecraftNativeFolderAccessor) {
2922
this.logger = logger;
23+
this.zipsource = zipsource;
24+
this.minecraftNativeFolderAccessor = minecraftNativeFolderAccessor;
3025
}
3126

3227
public void copyFrom(String libraryName, String libraryPath) throws IOException {
@@ -35,16 +30,16 @@ public void copyFrom(String libraryName, String libraryPath) throws IOException
3530
libFile = CocoaInput.class.getResourceAsStream("/" + libraryPath);
3631
} else {
3732
try {//Modファイルを検出し、jar内からライブラリを取り出す
38-
ZipFile jarfile = new ZipFile(CocoaInput.zipsource);
33+
ZipFile jarfile = new ZipFile(zipsource);
3934
libFile = jarfile.getInputStream(new ZipEntry(libraryPath));
4035
} catch (FileNotFoundException e) {//存在しない場合はデバッグモードであるのでクラスパスからライブラリを取り出す
4136
logger.log("Couldn't get library path. Is this debug mode?'");
4237
libFile = ClassLoader.getSystemResourceAsStream(libraryPath);
4338
}
4439
}
45-
File nativeDir = new File(Minecraft.getInstance().gameDirectory.getAbsolutePath().concat("/native"));
40+
File nativeDir = new File(minecraftNativeFolderAccessor.getRoot().concat("/native"));
4641
File copyLibFile = new File(
47-
Minecraft.getInstance().gameDirectory.getAbsolutePath().concat("/native/" + libraryName));
42+
minecraftNativeFolderAccessor.getRoot().concat("/native/" + libraryName));
4843
try {
4944
nativeDir.mkdir();
5045
FileOutputStream fos = new FileOutputStream(copyLibFile);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package jp.axer.cocoainput.domain;
2+
3+
public interface MinecraftNativeFolderAccessor {
4+
String getRoot();
5+
}

1.18.2/fabric/src/fabric/java/jp/axer/cocoainput/config/ConfigPack.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

1.18.2/fabric/src/fabric/java/jp/axer/cocoainput/config/TinyConfig.java renamed to 1.18.2/fabric/src/fabric/java/jp/axer/cocoainput/config/fabric/FabricConfigImpl.java

Lines changed: 12 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jp.axer.cocoainput.config;
1+
package jp.axer.cocoainput.config.fabric;
22
import java.lang.annotation.ElementType;
33
import java.lang.annotation.Retention;
44
import java.lang.annotation.RetentionPolicy;
@@ -20,7 +20,6 @@
2020

2121
import com.google.gson.Gson;
2222
import com.google.gson.GsonBuilder;
23-
import com.mojang.blaze3d.vertex.PoseStack;
2423

2524
import net.minecraft.client.gui.screens.Screen;
2625
import net.minecraft.client.gui.components.EditBox;
@@ -29,12 +28,12 @@
2928
import net.minecraft.network.chat.TextComponent;
3029
import net.minecraft.network.chat.TranslatableComponent;
3130

32-
public class TinyConfig {
31+
public class FabricConfigImpl {
3332

3433
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
3534
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
3635

37-
private static final List<EntryInfo> entries = new ArrayList<>();
36+
final List<EntryInfo> entries = new ArrayList<>();
3837

3938
protected static class EntryInfo {
4039
Field field;
@@ -49,20 +48,20 @@ protected static class EntryInfo {
4948
boolean inLimits = true;
5049
}
5150

52-
private static Class configClass;
53-
private static String translationPrefix;
54-
private static Path path;
51+
private final Class<?> configClass;
52+
private final String translationPrefix;
53+
private final Path path;
5554

5655
private static final Gson gson = new GsonBuilder()
5756
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
5857
.excludeFieldsWithModifiers(Modifier.PRIVATE)
5958
.setPrettyPrinting()
6059
.create();
6160

62-
public static void init(String modid,Path apath, Class<?> config) {
61+
public FabricConfigImpl(String modid, Path apath, Class<?> config) {
6362
translationPrefix = modid + ".tinyconfig.";
6463
configClass = config;
65-
path=apath;
64+
path = apath;
6665

6766
for (Field field : config.getFields()) {
6867
Entry e;
@@ -121,7 +120,7 @@ else if (type.isEnum()) {
121120

122121
}
123122

124-
private static void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
123+
private void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
125124
boolean isNumber = pattern != null;
126125
info.widget = (BiFunction<EditBox, Button, Predicate<String>>) (t, b) -> s -> {
127126
s = s.trim();
@@ -153,99 +152,18 @@ private static void textField(EntryInfo info, Function<String,Number> f, Pattern
153152
};
154153
}
155154

156-
public static void write() {
155+
public void write() {
157156
try {
158157
if (!Files.exists(path)) Files.createFile(path);
159-
Files.write(path, gson.toJson(configClass.newInstance()).getBytes());
158+
Files.write(path, gson.toJson(this).getBytes());
160159
} catch (Exception e) {
161160
e.printStackTrace();
162161
}
163162

164163
}
165164

166165
public Screen getScreen(Screen parent) {
167-
return new TinyConfigScreen(parent);
168-
}
169-
170-
private static class TinyConfigScreen extends Screen {
171-
protected TinyConfigScreen(Screen parent) {
172-
super(new TextComponent("CocoaInput config"));
173-
this.parent = parent;
174-
}
175-
private final Screen parent;
176-
177-
@Override
178-
protected void init() {
179-
super.init();
180-
181-
Button done = this.addRenderableWidget(new Button(this.width/2 - 100,this.height - 28,200,20,
182-
new TranslatableComponent("gui.done"), (button) -> {
183-
for (EntryInfo info : entries)
184-
try { info.field.set(null, info.value); }
185-
catch (IllegalAccessException ignore) {}
186-
write();
187-
minecraft.setScreen(parent);
188-
}));
189-
190-
int y = 45;
191-
for (EntryInfo info : entries) {
192-
if (info.widget instanceof Map.Entry) {
193-
Map.Entry<Button.OnPress,Function<Object,BaseComponent>> widget = (Map.Entry<Button.OnPress, Function<Object, BaseComponent>>) info.widget;
194-
addRenderableWidget(new Button(width-85,y,info.width,20, widget.getValue().apply(info.value), widget.getKey()));
195-
}
196-
else {
197-
EditBox widget = addWidget(new EditBox(font, width-85, y, info.width, 20, null));
198-
widget.setValue(info.tempValue);
199-
200-
Predicate<String> processor = ((BiFunction<EditBox, Button, Predicate<String>>) info.widget).apply(widget,done);
201-
widget.setFilter(processor);
202-
processor.test(info.tempValue);
203-
204-
addWidget(widget);
205-
}
206-
y += 30;
207-
}
208-
209-
}
210-
211-
@Override
212-
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
213-
this.renderBackground(matrices);
214-
215-
if (mouseY >= 40 && mouseY <= 39 + entries.size()*30) {
216-
int low = ((mouseY-10)/30)*30 + 10 + 2;
217-
fill(matrices, 0, low, width, low+30-4, 0x33FFFFFF);
218-
}
219-
220-
super.render(matrices, mouseX, mouseY, delta);
221-
drawCenteredString(matrices, font, title, width/2, 15, 0xFFFFFF);
222-
223-
int y = 40;
224-
for (EntryInfo info : entries) {
225-
drawString(matrices, font, new TextComponent(info.comment), 12, y + 10, 0xFFFFFF);
226-
/*
227-
if (info.error != null && info.error.getKey().isMouseOver(mouseX,mouseY))
228-
renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
229-
else if (mouseY >= y && mouseY < (y + 30)) {
230-
if (info.dynamicTooltip != null) {
231-
try {
232-
renderComponentTooltip(matrices, (List<ITextComponent>) info.dynamicTooltip.invoke(null, entries), mouseX, mouseY);
233-
y += 30;
234-
continue;
235-
} catch (Exception e) { e.printStackTrace(); }
236-
}
237-
String key = translationPrefix + info.field.getName() + ".tooltip";
238-
239-
List<ITextComponent> list = new ArrayList<>();
240-
for (String str : I18n.get(key).split("\n"))
241-
list.add(new TextComponent(str));
242-
renderComponentTooltip(matrices, list, mouseX, mouseY);
243-
244-
}
245-
*/
246-
y += 30;
247-
}
248-
}
166+
return new FabricConfigScreen(parent, this);
249167
}
250168

251169
@Retention(RetentionPolicy.RUNTIME)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package jp.axer.cocoainput.config.fabric;
2+
3+
import com.mojang.blaze3d.vertex.PoseStack;
4+
import net.minecraft.client.gui.components.Button;
5+
import net.minecraft.client.gui.components.EditBox;
6+
import net.minecraft.client.gui.screens.Screen;
7+
import net.minecraft.network.chat.BaseComponent;
8+
import net.minecraft.network.chat.TextComponent;
9+
import net.minecraft.network.chat.TranslatableComponent;
10+
11+
import java.util.Map;
12+
import java.util.function.BiFunction;
13+
import java.util.function.Function;
14+
import java.util.function.Predicate;
15+
16+
public class FabricConfigScreen extends Screen {
17+
private final FabricConfigImpl config;
18+
19+
public FabricConfigScreen(Screen parent, FabricConfigImpl config) {
20+
super(new TextComponent("CocoaInput config"));
21+
this.parent = parent;
22+
this.config = config;
23+
}
24+
private final Screen parent;
25+
26+
@Override
27+
protected void init() {
28+
super.init();
29+
30+
Button done = this.addRenderableWidget(new Button(this.width/2 - 100,this.height - 28,200,20,
31+
new TranslatableComponent("gui.done"), (button) -> {
32+
for (FabricConfigImpl.EntryInfo info : config.entries)
33+
try { info.field.set(null, info.value); }
34+
catch (IllegalAccessException ignore) {}
35+
config.write();
36+
minecraft.setScreen(parent);
37+
}));
38+
39+
int y = 45;
40+
for (FabricConfigImpl.EntryInfo info : config.entries) {
41+
if (info.widget instanceof Map.Entry) {
42+
Map.Entry<Button.OnPress, Function<Object, BaseComponent>> widget = (Map.Entry<Button.OnPress, Function<Object, BaseComponent>>) info.widget;
43+
addRenderableWidget(new Button(width-85,y,info.width,20, widget.getValue().apply(info.value), widget.getKey()));
44+
}
45+
else {
46+
EditBox widget = addWidget(new EditBox(font, width-85, y, info.width, 20, null));
47+
widget.setValue(info.tempValue);
48+
49+
Predicate<String> processor = ((BiFunction<EditBox, Button, Predicate<String>>) info.widget).apply(widget,done);
50+
widget.setFilter(processor);
51+
processor.test(info.tempValue);
52+
53+
addWidget(widget);
54+
}
55+
y += 30;
56+
}
57+
58+
}
59+
60+
@Override
61+
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
62+
this.renderBackground(matrices);
63+
64+
if (mouseY >= 40 && mouseY <= 39 + config.entries.size()*30) {
65+
int low = ((mouseY-10)/30)*30 + 10 + 2;
66+
fill(matrices, 0, low, width, low+30-4, 0x33FFFFFF);
67+
}
68+
69+
super.render(matrices, mouseX, mouseY, delta);
70+
drawCenteredString(matrices, font, title, width/2, 15, 0xFFFFFF);
71+
72+
int y = 40;
73+
for (FabricConfigImpl.EntryInfo info : config.entries) {
74+
drawString(matrices, font, new TextComponent(info.comment), 12, y + 10, 0xFFFFFF);
75+
/*
76+
if (info.error != null && info.error.getKey().isMouseOver(mouseX,mouseY))
77+
renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
78+
else if (mouseY >= y && mouseY < (y + 30)) {
79+
if (info.dynamicTooltip != null) {
80+
try {
81+
renderComponentTooltip(matrices, (List<ITextComponent>) info.dynamicTooltip.invoke(null, entries), mouseX, mouseY);
82+
y += 30;
83+
continue;
84+
} catch (Exception e) { e.printStackTrace(); }
85+
}
86+
String key = translationPrefix + info.field.getName() + ".tooltip";
87+
88+
List<ITextComponent> list = new ArrayList<>();
89+
for (String str : I18n.get(key).split("\n"))
90+
list.add(new TextComponent(str));
91+
renderComponentTooltip(matrices, list, mouseX, mouseY);
92+
93+
}
94+
*/
95+
y += 30;
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)