Skip to content

Commit

Permalink
refactor: split structures from Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Dec 6, 2023
1 parent 708490a commit bb6bfb9
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 178 deletions.
4 changes: 2 additions & 2 deletions src/informatis/Informatis.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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;
import informatis.ui.fragments.sidebar.dialogs.DialogManager;
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.*;
Expand All @@ -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();
Expand Down
176 changes: 0 additions & 176 deletions src/informatis/core/Setting.java

This file was deleted.

99 changes: 99 additions & 0 deletions src/informatis/core/setting/SettingHelper.java
Original file line number Diff line number Diff line change
@@ -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<SharSetting> list) {
addGraphicCheckSetting(key, def, list, () -> {
});
}

public static void addGraphicCheckSetting(String key, boolean def, Seq<SharSetting> 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<SharSetting> 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<String, String> h, Seq<SharSetting> 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();
}
});
}

}
20 changes: 20 additions & 0 deletions src/informatis/core/setting/SharSetting.java
Original file line number Diff line number Diff line change
@@ -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) { }
}
Loading

0 comments on commit bb6bfb9

Please sign in to comment.