diff --git a/core/src/mindustry/logic/LogicDialog.java b/core/src/mindustry/logic/LogicDialog.java index ee6ef6fa735e..022087c76836 100644 --- a/core/src/mindustry/logic/LogicDialog.java +++ b/core/src/mindustry/logic/LogicDialog.java @@ -30,10 +30,9 @@ public class LogicDialog extends BaseDialog{ public LCanvas canvas; Cons consumer = s -> {}; boolean privileged; - public static float period = 15f; + private static float period = 15f; Table varTable = new Table(); - public static boolean refreshing = true; - private static boolean doRefresh, noSave; + private static boolean refreshing = true, doRefresh, noSave; @Nullable LExecutor executor; GlobalVarsDialog globalsDialog = new GlobalVarsDialog(); diff --git a/core/src/mindustry/world/blocks/logic/LogicBlock.java b/core/src/mindustry/world/blocks/logic/LogicBlock.java index 87349da6becb..b34e84904c0d 100644 --- a/core/src/mindustry/world/blocks/logic/LogicBlock.java +++ b/core/src/mindustry/world/blocks/logic/LogicBlock.java @@ -8,7 +8,6 @@ import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; -import arc.scene.ui.Label; import arc.scene.ui.layout.*; import arc.struct.Bits; import arc.struct.*; @@ -34,7 +33,6 @@ import java.util.zip.*; import static mindustry.Vars.*; -import static mindustry.logic.LogicDialog.*; public class LogicBlock extends Block{ @MindustryXApi @@ -263,13 +261,7 @@ public class LogicBuild extends Building implements Ranged{ public @Nullable String tag; public char iconTag; - Table settingTable = new Table(); - boolean showSettingTable = false; - boolean showContent = false; - - float counter = 0f; - - boolean linkSimplify = false; + private static boolean showVars = false; /** Block of code to run after load. */ public @Nullable Runnable loadBlock; @@ -599,7 +591,7 @@ public void drawConfigure(){ for(LogicLink l : links){ Building build = world.build(l.x, l.y); if(l.active && validLink(build)){ - build.block.drawPlaceText(linkSimplify ? i++ + "" : l.name + "[" + i++ + "]", build.tileX(), build.tileY(), true); + build.block.drawPlaceText(l.name + "[" + i++ + "]", build.tileX(), build.tileY(), true); } } } @@ -651,17 +643,17 @@ public boolean validLink(Building other){ return other != null && other.isValid() && (privileged || (!other.block.privileged && other.team == team && other.within(this, range + other.block.size*tilesize/2f))) && !(other instanceof ConstructBuild); } - private void rebuildSettingTable() { - settingTable.clear(); - if (!showSettingTable) return; - settingTable.setColor(Color.lightGray); - settingTable.update(() -> { - counter += Time.delta; - if (counter > period && refreshing) { - counter = 0; - } - }); - settingTable.table(t -> { + @Override + public boolean shouldShowConfigure(Player player){ + return accessible(); + } + + @Override + public void buildConfiguration(Table table){ + table.setBackground(Styles.black3); + Table vars = new Table(); + table.table(t -> { + t.button(Icon.pencil, Styles.cleari, this::showEditDialog).size(40); t.button(Icon.copy, Styles.cleari, () -> { Core.app.setClipboardText(code); UIExt.announce("已复制逻辑"); @@ -670,63 +662,32 @@ private void rebuildSettingTable() { updateCode(Core.app.getClipboardText().replace("\r\n", "\n")); UIExt.announce("已导入逻辑(仅单机生效)"); }).size(40); - t.button(Icon.trash, Styles.cleari, () -> { - code = ""; - updateCode(code); - UIExt.announce("已清除逻辑(仅单机生效)"); - }).size(40); - t.button(Icon.chatSmall, Styles.cleari, () -> { - linkSimplify = !linkSimplify; - UIExt.announce(linkSimplify ? "仅显示linkindex" : "显示方块名和linkindex"); - }).size(40); t.button(Icon.info, Styles.cleari, () -> { - showContent = !showContent; - rebuildSettingTable(); + showVars = !showVars; + vars.clear(); + if(showVars) buildVarsTable(vars); + table.pack(); }).size(40); }); - if (showContent && !code.isEmpty()) { - settingTable.row(); - settingTable.pane(t -> { - for (var s : executor.vars) { - if(s.name.startsWith("___")) continue; - String text = arcVarsText(s); - t.table(tt -> { - tt.labelWrap(s.name + "").color(arcVarsColor(s)).width(100f); - Label label = tt.labelWrap(" : " + text).width(200f).get(); - tt.update(() -> { - if (counter + Time.delta > period && refreshing) { - label.setText(arcVarsText(s)); - } - }); - }); - t.row(); - } - }).maxHeight(400f); - - } + table.row().pane(vars).pad(4).maxHeight(400f); + if(showVars) buildVarsTable(vars); } - @Override - public boolean shouldShowConfigure(Player player){ - return accessible(); - } + private void buildVarsTable(Table table){ + final var vars = executor.vars; + table.update(() -> { + if(vars != executor.vars){ + table.clear(); + buildVarsTable(table); + } + }); - @Override - public void buildConfiguration(Table table){ - if (Core.settings.getBool("logicSupport")){ - table.table(t -> { - t.button(Icon.pencil, Styles.cleari, () -> { - ui.logic.show(code, executor, privileged, code -> configure(compress(code, relativeConnections()))); - }).size(40); - t.button(Icon.settings, Styles.cleari, () -> { - showSettingTable = !showSettingTable; - rebuildSettingTable(); - }).size(40); - }); + table.setColor(Color.lightGray); + for(var s : vars){ + if(s.name.startsWith("___")) continue; + table.add(s.name).color(LogicDialog.arcVarsColor(s)).align(Align.left); + table.label(() -> LogicDialog.arcVarsText(s)).align(Align.right); table.row(); - table.add(settingTable); - }else{ - table.button(Icon.pencil, Styles.cleari, this::showEditDialog).size(40); } }