diff --git a/src/informatis/Informatis.java b/src/informatis/Informatis.java index f3ba671..7a52a34 100644 --- a/src/informatis/Informatis.java +++ b/src/informatis/Informatis.java @@ -1,5 +1,6 @@ package informatis; +import informatis.core.setting.SharSettingUI; import informatis.core.UpdateChecker; import informatis.ui.fragments.sidebar.windows.tools.draws.OverDrawManager; import informatis.ui.fragments.sidebar.windows.tools.tools.ToolManager; @@ -7,7 +8,6 @@ import informatis.ui.fragments.sidebar.windows.*; import informatis.ui.fragments.FragmentManager; import informatis.core.ModMetadata; -import informatis.core.Setting; import mindustry.game.EventType.*; import mindustry.mod.*; @@ -18,7 +18,7 @@ public class Informatis extends Mod { public void init(){ Events.on(ClientLoadEvent.class, e -> { ModMetadata.init(); - Setting.init(); + SharSettingUI.init(); WindowManager.init(); DialogManager.init(); FragmentManager.init(); diff --git a/src/informatis/core/Setting.java b/src/informatis/core/Setting.java deleted file mode 100644 index 997011d..0000000 --- a/src/informatis/core/Setting.java +++ /dev/null @@ -1,176 +0,0 @@ -package informatis.core; - -import arc.*; -import arc.func.*; -import arc.graphics.*; -import arc.scene.Group; -import arc.scene.event.*; -import arc.scene.ui.*; -import arc.scene.ui.layout.*; -import arc.struct.*; -import arc.util.*; -import informatis.ui.fragments.FragmentManager; -import mindustry.ui.*; -import mindustry.ui.dialogs.*; - -import static arc.Core.*; -import static mindustry.Vars.*; - -abstract class SharSetting extends SettingsMenuDialog.SettingsTable.Setting { - - public SharSetting(String name) { - super(name); - } - - public SharSetting(String name, Object def) { - this(name); - Core.settings.defaults(name, def); - } - - public void add(Table table) { } - public void add(SettingsMenuDialog.SettingsTable table) { } -} - -public class Setting { - public static SettingsMenuDialog.SettingsTable sharset; - - public static void addGraphicCheckSetting(String key, boolean def, Seq list) { - addGraphicCheckSetting(key, def, list, () -> {}); - } - public static void addGraphicCheckSetting(String key, boolean def, Seq list, Runnable onSetted) { - list.add(new SharSetting(key, def) { - - @Override - public void add(Table table) { - CheckBox box = new CheckBox(title); - box.update(() -> box.setChecked(settings.getBool(name))); - box.changed(() -> { - settings.put(name, box.isChecked()); - onSetted.run(); - }); - - box.left(); - addDesc(table.add(box).left().padTop(3f).get()); - table.row(); - } - }); - } - - public static void addGraphicSlideSetting(String key, int def, int min, int max, int step, SettingsMenuDialog.StringProcessor sp, Seq list){ - list.add(new SharSetting(key, def) { - - @Override - public void add(Table table){ - - Label value = new Label("", Styles.outlineLabel); - Table content = new Table(); - content.add(title, Styles.outlineLabel).left().growX().wrap(); - content.add(value).padLeft(10f).right(); - content.margin(3f, 33f, 3f, 33f); - content.touchable = Touchable.disabled; - - Slider slider = new Slider(min, max, step, false); - slider.setValue(settings.getInt(name)); - slider.changed(() -> { - settings.put(name, (int)slider.getValue()); - value.setText(sp.get((int)slider.getValue())); - }); - slider.change(); - - addDesc(table.stack(slider, content).width(Math.min(Core.graphics.getWidth() / 1.2f, 460f)).left().padTop(4f).get()); - table.row(); - } - }); - } - - public static void addGraphicTypeSetting(String key, float min, float max, int def, boolean integer, Boolp condition, Func h, Seq list){ - list.add(new SharSetting(key, def) { - - @Override - public void add(Table table) { - final String[] str = {""}; - Table table1 = new Table(t -> { - final float[] value = {def}; - t.add(new Label(title + ": ")).left().padRight(5) - .update(a -> a.setColor(condition.get() ? Color.white : Color.gray)); - - t.field((integer ? String.valueOf(value[0]).split("[.]")[0] : value[0]) + str[0], s -> { - str[0] = h.get(s); - value[0] = s.isEmpty() ? def : Strings.parseFloat(s); - - if(integer) settings.put(key, (int)value[0]); - else settings.put(key, value[0]); - - }).update(a -> a.setDisabled(!condition.get())) - .valid(f -> Strings.canParsePositiveFloat(f) && Strings.parseFloat(f) >= min && Strings.parseFloat(f) <= max).width(120f).left(); - }); - - addDesc(table.add(table1).left().padTop(4f).get()); - table.row(); - } - }); - } - - public static void init(){ - Seq> settingSeq = new Seq<>(); - Seq tapSeq = new Seq<>(); - addGraphicCheckSetting("tileinfo", true, tapSeq, () -> FragmentManager.tileInfoFragment.rebuildTileInfoTable()); - addGraphicCheckSetting("schem", !mobile, tapSeq, () -> FragmentManager.quickSchemFragment.rebuildBody()); - addGraphicCheckSetting("sidebar", !mobile, tapSeq, () -> FragmentManager.sidebarSwitcherFragment.rebuildSidebarTable()); - addGraphicCheckSetting("elementdebug", false, tapSeq); - addGraphicCheckSetting("hiddenElem", false, tapSeq); - addGraphicCheckSetting("serverfilter", false, tapSeq, () -> {}); - - //TODO: remove all drawing settings - Seq drawSeq = new Seq<>(); - addGraphicSlideSetting("selectopacity", 50, 0, 100, 5, s -> s + "%", drawSeq); - addGraphicSlideSetting("baropacity", 50, 0, 100, 5, s -> s + "%", drawSeq); - addGraphicCheckSetting("rangeShader", false, drawSeq); - addGraphicCheckSetting("select", false, drawSeq); - addGraphicCheckSetting("distanceLine", false, drawSeq); - addGraphicCheckSetting("spawnerarrow", false, drawSeq); - - settingSeq.add(tapSeq, drawSeq); - - sharset = new SettingsMenuDialog.SettingsTable(); - sharset.table(t -> { - Seq buttons = new Seq<>(); - buttons.add(new TextButton(bundle.get("setting.shar-ui"), Styles.cleart)); - buttons.add(new TextButton(bundle.get("setting.shar-draw"), Styles.cleart)); - buttons.each(b -> b.clicked(() -> buttons.each(b1 -> b1.setChecked(b1 == b)))); - t.table(Styles.black8, bt -> { - bt.top().align(Align.top); - buttons.each(b -> { - b.getLabel().setFontScale(0.85f); - bt.add(b).minHeight(60f * 0.85f).minWidth(150f * 0.85f).top(); - }); - }).grow().row(); - - Stack stack = new Stack(); - for(int i = 0; i < settingSeq.size; i++){ - int finalI = i; - stack.add(new Table(st -> { - for(SharSetting setting : settingSeq.get(finalI)) - st.table(setting::add).left().row(); - - st.button(Core.bundle.get("settings.reset", "Reset to Defaults"), () -> { - settingSeq.get(finalI).each(s -> Core.settings.put(s.name, Core.settings.getDefault(s.name))); - }).margin(14.0f).width(240.0f).pad(6.0f); - st.visibility = () -> buttons.get(finalI).isChecked(); - st.pack(); - })); - } - t.add(stack); - t.fillParent = true; - }); - - BaseDialog dialog = new BaseDialog(bundle.get("setting.shar-title")); - dialog.addCloseButton(); - dialog.cont.center().add(new Table(t -> t.pane(sharset).grow().row())); - ui.settings.shown(() -> { - Table settingUi = (Table)((Group)((Group)(ui.settings.getChildren().get(1))).getChildren().get(0)).getChildren().get(0); //This looks so stupid lol - settingUi.row(); - settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show); - }); - } -} \ No newline at end of file diff --git a/src/informatis/core/setting/SettingHelper.java b/src/informatis/core/setting/SettingHelper.java new file mode 100644 index 0000000..e36a885 --- /dev/null +++ b/src/informatis/core/setting/SettingHelper.java @@ -0,0 +1,99 @@ +package informatis.core.setting; + +import arc.Core; +import arc.func.Boolp; +import arc.func.Func; +import arc.graphics.Color; +import arc.scene.event.Touchable; +import arc.scene.ui.CheckBox; +import arc.scene.ui.Label; +import arc.scene.ui.Slider; +import arc.scene.ui.layout.Table; +import arc.struct.Seq; +import arc.util.Strings; +import mindustry.ui.Styles; +import mindustry.ui.dialogs.SettingsMenuDialog; + +import static arc.Core.settings; + +public class SettingHelper { + public static void addGraphicCheckSetting(String key, boolean def, Seq list) { + addGraphicCheckSetting(key, def, list, () -> { + }); + } + + public static void addGraphicCheckSetting(String key, boolean def, Seq list, Runnable onSetted) { + list.add(new SharSetting(key, def) { + + @Override + public void add(Table table) { + CheckBox box = new CheckBox(title); + box.update(() -> box.setChecked(settings.getBool(name))); + box.changed(() -> { + settings.put(name, box.isChecked()); + onSetted.run(); + }); + + box.left(); + addDesc(table.add(box).left().padTop(3f).get()); + table.row(); + } + }); + } + + public static void addGraphicSlideSetting(String key, int def, int min, int max, int step, SettingsMenuDialog.StringProcessor sp, Seq list) { + list.add(new SharSetting(key, def) { + + @Override + public void add(Table table) { + + Label value = new Label("", Styles.outlineLabel); + Table content = new Table(); + content.add(title, Styles.outlineLabel).left().growX().wrap(); + content.add(value).padLeft(10f).right(); + content.margin(3f, 33f, 3f, 33f); + content.touchable = Touchable.disabled; + + Slider slider = new Slider(min, max, step, false); + slider.setValue(settings.getInt(name)); + slider.changed(() -> { + settings.put(name, (int) slider.getValue()); + value.setText(sp.get((int) slider.getValue())); + }); + slider.change(); + + addDesc(table.stack(slider, content).width(Math.min(Core.graphics.getWidth() / 1.2f, 460f)).left().padTop(4f).get()); + table.row(); + } + }); + } + + public static void addGraphicTypeSetting(String key, float min, float max, int def, boolean integer, Boolp condition, Func h, Seq list) { + list.add(new SharSetting(key, def) { + + @Override + public void add(Table table) { + final String[] str = {""}; + Table table1 = new Table(t -> { + final float[] value = {def}; + t.add(new Label(title + ": ")).left().padRight(5) + .update(a -> a.setColor(condition.get() ? Color.white : Color.gray)); + + t.field((integer ? String.valueOf(value[0]).split("[.]")[0] : value[0]) + str[0], s -> { + str[0] = h.get(s); + value[0] = s.isEmpty() ? def : Strings.parseFloat(s); + + if (integer) settings.put(key, (int) value[0]); + else settings.put(key, value[0]); + + }).update(a -> a.setDisabled(!condition.get())) + .valid(f -> Strings.canParsePositiveFloat(f) && Strings.parseFloat(f) >= min && Strings.parseFloat(f) <= max).width(120f).left(); + }); + + addDesc(table.add(table1).left().padTop(4f).get()); + table.row(); + } + }); + } + +} \ No newline at end of file diff --git a/src/informatis/core/setting/SharSetting.java b/src/informatis/core/setting/SharSetting.java new file mode 100644 index 0000000..5c346aa --- /dev/null +++ b/src/informatis/core/setting/SharSetting.java @@ -0,0 +1,20 @@ +package informatis.core.setting; + +import arc.Core; +import arc.scene.ui.layout.Table; +import mindustry.ui.dialogs.SettingsMenuDialog; + +abstract class SharSetting extends SettingsMenuDialog.SettingsTable.Setting { + + public SharSetting(String name) { + super(name); + } + + public SharSetting(String name, Object def) { + this(name); + Core.settings.defaults(name, def); + } + + public void add(Table table) { } + public void add(SettingsMenuDialog.SettingsTable table) { } +} diff --git a/src/informatis/core/setting/SharSettingUI.java b/src/informatis/core/setting/SharSettingUI.java new file mode 100644 index 0000000..55319f4 --- /dev/null +++ b/src/informatis/core/setting/SharSettingUI.java @@ -0,0 +1,85 @@ +package informatis.core.setting; + +import arc.*; +import arc.scene.Group; +import arc.scene.ui.TextButton; +import arc.scene.ui.layout.*; +import arc.struct.*; +import arc.util.Align; +import informatis.ui.fragments.FragmentManager; +import mindustry.ui.*; +import mindustry.ui.dialogs.*; + +import static arc.Core.*; +import static informatis.core.setting.SettingHelper.*; +import static mindustry.Vars.*; + +public class SharSettingUI { + public static void init(){ + Seq> settingSeq = new Seq<>(); + Seq tapSeq = new Seq<>(); + addGraphicCheckSetting("tileinfo", true, tapSeq, () -> FragmentManager.tileInfoFragment.rebuildTileInfoTable()); + addGraphicCheckSetting("schem", !mobile, tapSeq, () -> FragmentManager.quickSchemFragment.rebuildBody()); + addGraphicCheckSetting("sidebar", !mobile, tapSeq, () -> FragmentManager.sidebarSwitcherFragment.rebuildSidebarTable()); + addGraphicCheckSetting("elementdebug", false, tapSeq); + addGraphicCheckSetting("hiddenElem", false, tapSeq); + addGraphicCheckSetting("serverfilter", false, tapSeq, () -> {}); + + //TODO: remove all drawing settings + Seq drawSeq = new Seq<>(); + addGraphicSlideSetting("selectopacity", 50, 0, 100, 5, s -> s + "%", drawSeq); + addGraphicSlideSetting("baropacity", 50, 0, 100, 5, s -> s + "%", drawSeq); + addGraphicCheckSetting("rangeShader", false, drawSeq); + addGraphicCheckSetting("select", false, drawSeq); + addGraphicCheckSetting("distanceLine", false, drawSeq); + addGraphicCheckSetting("spawnerarrow", false, drawSeq); + + settingSeq.add(tapSeq, drawSeq); + + SettingsMenuDialog.SettingsTable sharset = buildSharSettingTable(settingSeq); + + BaseDialog dialog = new BaseDialog(bundle.get("setting.shar-title")); + dialog.addCloseButton(); + dialog.cont.center().add(new Table(t -> t.pane(sharset).grow().row())); + ui.settings.shown(() -> { + Table settingUi = (Table)((Group)((Group)(ui.settings.getChildren().get(1))).getChildren().get(0)).getChildren().get(0); //This looks so stupid lol + settingUi.row(); + settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show); + }); + } + + private static SettingsMenuDialog.SettingsTable buildSharSettingTable(Seq> settingSeq) { + SettingsMenuDialog.SettingsTable sharset = new SettingsMenuDialog.SettingsTable(); + sharset.table(t -> { + Seq buttons = new Seq<>(); + buttons.add(new TextButton(bundle.get("setting.shar-ui"), Styles.cleart)); + buttons.add(new TextButton(bundle.get("setting.shar-draw"), Styles.cleart)); + buttons.each(b -> b.clicked(() -> buttons.each(b1 -> b1.setChecked(b1 == b)))); + t.table(Styles.black8, bt -> { + bt.top().align(Align.top); + buttons.each(b -> { + b.getLabel().setFontScale(0.85f); + bt.add(b).minHeight(60f * 0.85f).minWidth(150f * 0.85f).top(); + }); + }).grow().row(); + + Stack stack = new Stack(); + for (int i = 0; i < settingSeq.size; i++) { + int finalI = i; + stack.add(new Table(st -> { + for (SharSetting setting : settingSeq.get(finalI)) + st.table(setting::add).left().row(); + + st.button(Core.bundle.get("settings.reset", "Reset to Defaults"), () -> { + settingSeq.get(finalI).each(s -> Core.settings.put(s.name, Core.settings.getDefault(s.name))); + }).margin(14.0f).width(240.0f).pad(6.0f); + st.visibility = () -> buttons.get(finalI).isChecked(); + st.pack(); + })); + } + t.add(stack); + t.fillParent = true; + }); + return sharset; + } +}