Skip to content

Commit

Permalink
fixup! UI&ARC: logic Support 处理器编辑增强
Browse files Browse the repository at this point in the history
重制处理器快捷显示
  • Loading branch information
way-zer committed Jul 14, 2024
1 parent 074cf4d commit e0bb6be
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 74 deletions.
5 changes: 2 additions & 3 deletions core/src/mindustry/logic/LogicDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public class LogicDialog extends BaseDialog{
public LCanvas canvas;
Cons<String> 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();
Expand Down
103 changes: 32 additions & 71 deletions core/src/mindustry/world/blocks/logic/LogicBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -34,7 +33,6 @@
import java.util.zip.*;

import static mindustry.Vars.*;
import static mindustry.logic.LogicDialog.*;

public class LogicBlock extends Block{
@MindustryXApi
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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("已复制逻辑");
Expand All @@ -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);
}
}

Expand Down

0 comments on commit e0bb6be

Please sign in to comment.