In-game rule edit dialog
This commit is contained in:
@@ -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;
|
||||
}),
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -30,16 +30,24 @@ public class CustomRulesDialog extends BaseDialog{
|
||||
private Table main;
|
||||
private Prov<Rules> resetter;
|
||||
private LoadoutDialog loadoutDialog;
|
||||
|
||||
public boolean showRuleEditRule;
|
||||
public Seq<Table> categories;
|
||||
public Table current;
|
||||
public Seq<String> categoryNames;
|
||||
public String currentName;
|
||||
public String currentName = "";
|
||||
public String ruleSearch = "";
|
||||
public Seq<Runnable> 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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user