From 400db1b1e888059e04c7288cf2c9ff885cb88db4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 24 Jun 2024 14:11:56 -0400 Subject: [PATCH] In-game rule edit dialog --- core/assets/bundles/bundle.properties | 2 ++ core/src/mindustry/game/Gamemode.java | 1 + core/src/mindustry/game/Rules.java | 2 ++ .../ui/dialogs/CustomRulesDialog.java | 17 ++++++++++---- .../mindustry/ui/dialogs/MapPlayDialog.java | 2 +- .../mindustry/ui/dialogs/PausedDialog.java | 23 +++++++++++++++++-- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 0290485044..5b08e098ac 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -1335,6 +1335,8 @@ rules.disableworldprocessors = Disable World Processors rules.schematic = Schematics Allowed rules.wavetimer = Wave Timer rules.wavesending = Wave Sending +rules.allowedit = Allow Editing Rules +rules.allowedit.info = When enabled, the player can edit rules in-game via the button in the bottom left corner of the Pause menu. rules.waves = Waves rules.airUseSpawns = Air units use spawn points rules.attack = Attack Mode diff --git a/core/src/mindustry/game/Gamemode.java b/core/src/mindustry/game/Gamemode.java index 86e94966fa..4c2512e9ca 100644 --- a/core/src/mindustry/game/Gamemode.java +++ b/core/src/mindustry/game/Gamemode.java @@ -13,6 +13,7 @@ public enum Gamemode{ }, map -> map.spawns > 0), sandbox(rules -> { rules.infiniteResources = true; + rules.allowEditRules = true; rules.waves = true; rules.waveTimer = false; }), diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index b0f7c7275b..e2850f0124 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -19,6 +19,8 @@ import mindustry.world.blocks.*; * Does not store game state, just configuration. */ public class Rules{ + /** Allows editing the rules in-game. Essentially a cheat mode toggle. */ + public boolean allowEditRules = false; /** Sandbox mode: Enables infinite resources, build range and build speed. */ public boolean infiniteResources; /** Team-specific rules. */ diff --git a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java index 56d22c553d..a277593dd3 100644 --- a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java +++ b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java @@ -30,16 +30,24 @@ public class CustomRulesDialog extends BaseDialog{ private Table main; private Prov resetter; private LoadoutDialog loadoutDialog; + + public boolean showRuleEditRule; public Seq categories; public Table current; public Seq categoryNames; - public String currentName; + public String currentName = ""; public String ruleSearch = ""; public Seq additionalSetup; // for modding to easily add new rules public CustomRulesDialog(){ + this(false); + } + + public CustomRulesDialog(boolean showRuleEditRule){ super("@mode.custom"); + this.showRuleEditRule = showRuleEditRule; + loadoutDialog = new LoadoutDialog(); setFillParent(true); @@ -49,8 +57,6 @@ public class CustomRulesDialog extends BaseDialog{ additionalSetup = new Seq<>(); categories = new Seq<>(); categoryNames = new Seq<>(); - currentName = ""; - ruleSearch = ""; buttons.button("@edit", Icon.pencil, () -> { BaseDialog dialog = new BaseDialog("@waves.edit"); @@ -209,7 +215,6 @@ public class CustomRulesDialog extends BaseDialog{ main.left().defaults().fillX().left(); main.row(); - category("waves"); check("@rules.waves", b -> rules.waves = b, () -> rules.waves); check("@rules.wavesending", b -> rules.waveSending = b, () -> rules.waveSending, () -> rules.waves); @@ -352,6 +357,10 @@ public class CustomRulesDialog extends BaseDialog{ category("teams"); + //not sure where else to put this + if(showRuleEditRule){ + check("@rules.allowedit", b -> rules.allowEditRules = b, () -> rules.allowEditRules); + } team("@rules.playerteam", t -> rules.defaultTeam = t, () -> rules.defaultTeam); team("@rules.enemyteam", t -> rules.waveTeam = t, () -> rules.waveTeam); diff --git a/core/src/mindustry/ui/dialogs/MapPlayDialog.java b/core/src/mindustry/ui/dialogs/MapPlayDialog.java index db72034f0b..b2f31971b4 100644 --- a/core/src/mindustry/ui/dialogs/MapPlayDialog.java +++ b/core/src/mindustry/ui/dialogs/MapPlayDialog.java @@ -14,7 +14,7 @@ import static mindustry.Vars.*; public class MapPlayDialog extends BaseDialog{ public @Nullable Runnable playListener; - CustomRulesDialog dialog = new CustomRulesDialog(); + CustomRulesDialog dialog = new CustomRulesDialog(true); Rules rules; Gamemode selectedGamemode = Gamemode.survival; Map lastMap; diff --git a/core/src/mindustry/ui/dialogs/PausedDialog.java b/core/src/mindustry/ui/dialogs/PausedDialog.java index b854aa1eb9..677b3d53ed 100644 --- a/core/src/mindustry/ui/dialogs/PausedDialog.java +++ b/core/src/mindustry/ui/dialogs/PausedDialog.java @@ -1,7 +1,10 @@ package mindustry.ui.dialogs; import arc.*; +import arc.scene.ui.layout.*; +import mindustry.*; import mindustry.editor.*; +import mindustry.game.*; import mindustry.gen.*; import static mindustry.Vars.*; @@ -10,12 +13,28 @@ public class PausedDialog extends BaseDialog{ private MapProcessorsDialog processors = new MapProcessorsDialog(); private SaveDialog save = new SaveDialog(); private LoadDialog load = new LoadDialog(); - private boolean wasClient = false; + private CustomRulesDialog rulesDialog = new CustomRulesDialog(); public PausedDialog(){ super("@menu"); shouldPause = true; + clearChildren(); + add(titleTable).growX().row(); + + stack(cont, new Table(t -> { + t.bottom().left(); + t.button(Icon.book, () -> { + Rules toEdit = Vars.state.rules.copy(); + rulesDialog.show(toEdit, () -> state.rules.copy()); + rulesDialog.hidden(() -> { + //apply rule changes only once it is hidden + Vars.state.rules = toEdit; + Call.setRules(toEdit); + }); + }).size(70f).tooltip("@customize").visible(() -> state.rules.allowEditRules && (net.server() || !net.active())); + })).grow().row(); + shown(this::rebuild); addCloseListener(); @@ -130,7 +149,7 @@ public class PausedDialog extends BaseDialog{ } public void runExitSave(){ - wasClient = net.client(); + boolean wasClient = net.client(); if(net.client()) netClient.disconnectQuietly(); if(state.isEditor() && !wasClient){