Skip to content

Commit

Permalink
feat: add tool manager and fog remover #84
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Aug 27, 2023
1 parent a8b4d07 commit 98b51c7
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 25 deletions.
4 changes: 4 additions & 0 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ window.player.name = Player Display
window.tool.name = Tool Display [red](WIP)[]
window.editor.name = Map Editor Display [red](WIP)[]

#ToolWindow - Tool
setting.fogremover.name = Fog Remover
setting.fogremover.description = remove every fog in the world!

#Other
default-bar = default bar
th-bar = th bar
Expand Down
4 changes: 4 additions & 0 deletions assets/bundles/bundle_ko.properties
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ window.player.name = 플레이어 디스플레이
window.tool.name = 도구 디스플레이 [red](WIP)[]
window.editor.name = 맵 편집 디스플레이 [red](WIP)[]

#ToolWindow - Tool
setting.fogremover.name = 안개 제거하기
setting.fogremover.description = 맵에 있는 모든 안개를 제거합니다!

#Other
default-bar = 기본 바
th-bar = 번째 바
Expand Down
2 changes: 2 additions & 0 deletions src/informatis/Informatis.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import informatis.ui.fragments.sidebar.dialogs.DialogManager;
import informatis.ui.fragments.sidebar.windows.*;
import arc.*;
import informatis.ui.fragments.sidebar.windows.tools.tools.ToolManager;
import mindustry.*;
import mindustry.game.EventType.*;
import mindustry.mod.*;
Expand All @@ -29,6 +30,7 @@ public void init(){
DialogManager.init();
FragmentManager.init();
OverDrawManager.init();
ToolManager.init();
OverDrawer.init();
SVars.init();
});
Expand Down
66 changes: 41 additions & 25 deletions src/informatis/ui/fragments/sidebar/windows/ToolWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import arc.scene.ui.layout.*;
import arc.util.*;
import informatis.ui.components.PageTabsFragment;
import informatis.ui.fragments.sidebar.windows.tools.tools.ToolManager;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
Expand Down Expand Up @@ -54,8 +55,8 @@ private Table buildOverDrawTable() {
sidebarTable.row();
}
}).padRight(2 * 8f);
bodyScroll[0] = mainTable.pane(Styles.smallPane, bodyTable -> {
bodyTable.top().left().margin(12).defaults().growX();
bodyScroll[0] = mainTable.pane(Styles.smallPane, bodyTable -> {
bodyTable.top().left().margin(12).defaults().growX();
for (int i = 0; i < categories.length; i++) {
final OverDrawCategory category = categories[i];

Expand All @@ -66,29 +67,11 @@ private Table buildOverDrawTable() {
categoryTable.row();
categoryTable.image().color(Color.gray).height(2f).pad(8, 0, 8, 0);
categoryTable.row();
categoryTable.table(configTable -> {
configTable.top().left().defaults().left().grow();
categoryTable.table(configListTable -> {
configListTable.top().left().defaults().left().grow();
for (ToolConfigable toolConfigable : OverDrawManager.draws.get(category)) {
configTable.button(bundle.get("setting." + toolConfigable.getName() + ".name"), Styles.flatToggleMenut, () -> toolConfigable.setEnabled(!toolConfigable.isEnabled()))
.tooltip(t -> {
t.background(Styles.black8).add(bundle.get("setting." + toolConfigable.getName() + ".description"));
}).checked(toolConfigable.isEnabled()).padBottom(4).get().getLabelCell().labelAlign(Align.left).pad(8, 16, 8, 8).get().setFontScale(0.9f);
configTable.row();
if(toolConfigable.getSubConfigs().length == 0) continue;;
configTable.table(subConfigTable -> {
subConfigTable.left().defaults().left().padBottom(4).labelAlign(Align.left);

for (ToolConfigable subConfigable : toolConfigable.getSubConfigs()) {
CheckBox checkBox = subConfigTable.check(bundle.get("setting." + subConfigable.getName() + ".name"), subConfigable.isEnabled(), subConfigable::setEnabled)
.tooltip(t -> {
t.background(Styles.black8).add(bundle.get("setting." + subConfigable.getName() + ".description"));
}).disabled(x -> !toolConfigable.isEnabled()).get();
checkBox.getLabel().setFontScale(0.8f);
checkBox.getImage().setScale(0.7f);
subConfigTable.row();
}
}).pad(4, 24, 16, 4);
configTable.row();
configListTable.add(buildConfigTable(toolConfigable));
configListTable.row();
}
});
}).marginBottom(32f).prefHeight();
Expand All @@ -99,6 +82,39 @@ private Table buildOverDrawTable() {
}

private Table rebuildToolsTable() {
return new Table();
return new Table(mainTable -> {
mainTable.pane(Styles.smallPane, bodyTable -> {
bodyTable.top().left().defaults().top().left().grow();
for (ToolConfigable toolConfigable : ToolManager.tools) {
bodyTable.add(buildConfigTable(toolConfigable));
bodyTable.row();
}
}).grow();
});
}

private Table buildConfigTable(ToolConfigable toolConfigable) {
return new Table(configTable -> {
configTable.top().left().defaults().left().grow();
configTable.button(bundle.get("setting." + toolConfigable.getName() + ".name"), Styles.flatToggleMenut, () -> toolConfigable.setEnabled(!toolConfigable.isEnabled()))
.tooltip(t -> {
t.background(Styles.black8).add(bundle.get("setting." + toolConfigable.getName() + ".description"));
}).checked(toolConfigable.isEnabled()).padBottom(4).get().getLabelCell().labelAlign(Align.left).pad(8, 16, 8, 8).get().setFontScale(0.9f);
configTable.row();
if(toolConfigable.getSubConfigs().length == 0) return;
configTable.table(subConfigTable -> {
subConfigTable.left().defaults().left().padBottom(4).labelAlign(Align.left);

for (ToolConfigable subConfigable : toolConfigable.getSubConfigs()) {
CheckBox checkBox = subConfigTable.check(bundle.get("setting." + subConfigable.getName() + ".name"), subConfigable.isEnabled(), subConfigable::setEnabled)
.tooltip(t -> {
t.background(Styles.black8).add(bundle.get("setting." + subConfigable.getName() + ".description"));
}).disabled(x -> !toolConfigable.isEnabled()).get();
checkBox.getLabel().setFontScale(0.8f);
checkBox.getImage().setScale(0.7f);
subConfigTable.row();
}
}).pad(4, 24, 16, 4);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package informatis.ui.fragments.sidebar.windows.tools.tools;

import arc.graphics.Color;
import mindustry.Vars;

public class FogRemover extends Tool {
Color lastStaticColor, lastDynamicColor;

public FogRemover() {
super("fogremover");
}

@Override
public void setEnabled(boolean value) {
super.setEnabled(value);
if(value) {
lastStaticColor = Vars.state.rules.staticColor;
lastDynamicColor = Vars.state.rules.dynamicColor;
Vars.state.rules.staticColor = Color.clear;
Vars.state.rules.dynamicColor = Color.clear;
} else {
Vars.state.rules.staticColor = lastStaticColor;
Vars.state.rules.dynamicColor = lastDynamicColor;
}
}
}
11 changes: 11 additions & 0 deletions src/informatis/ui/fragments/sidebar/windows/tools/tools/Tool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package informatis.ui.fragments.sidebar.windows.tools.tools;

import informatis.ui.fragments.sidebar.windows.SettingConfiger;

public class Tool extends SettingConfiger {
public Tool(String name) {
super(name);
}

public void onUpdate() {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package informatis.ui.fragments.sidebar.windows.tools.tools;

import arc.Events;
import mindustry.game.EventType;

public class ToolManager {
public static Tool[] tools = new Tool[] { new FogRemover() };

public static void init() {
Events.run(EventType.Trigger.update, () -> {
for (Tool tool : tools) {
tool.onUpdate();
}
});
}
}

0 comments on commit 98b51c7

Please sign in to comment.