Skip to content

Commit 5ab5668

Browse files
build: update ui branch explorer
1 parent 5e70d89 commit 5ab5668

1 file changed

Lines changed: 87 additions & 20 deletions

File tree

src/mi2u/ui/IslandOverlayManager.java

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package mi2u.ui;
22

33
import arc.*;
4-
import arc.scene.*;
4+
import arc.func.*;
55
import arc.scene.event.*;
66
import arc.scene.ui.layout.*;
77
import arc.struct.*;
@@ -21,13 +21,17 @@ public class IslandOverlayManager {
2121

2222
public Table widgetShop = new Table();
2323

24-
public Table islandConfigureTable = new Table();
24+
/** 当前选中的island设置一级菜单 */
25+
protected Table islandConfigureTable = new Table();
26+
27+
/** 当前选中的island设置二级菜单 */
28+
protected Table islandConfigureSubTable = new Table();
2529

2630
public IslandOverlayManager(){}
2731

2832
public void onClientLoad(){
2933
rebuildWidgetShop();
30-
rebuildIslandConfigureTableFor(null);
34+
rebuildIslandConfigureTableFor(selectedIsland);
3135
rebuildOverlay();
3236
root.setFillParent(true);
3337
root.touchable = Touchable.childrenOnly;
@@ -78,22 +82,80 @@ public void rebuildWidgetShop(){
7882
public void rebuildIslandConfigureTableFor(Island island){
7983
var table = islandConfigureTable;
8084
table.clear();
85+
table.defaults().growY();
8186

82-
// 面包屑布局路径
87+
// 面包屑布局分支
8388
// 选中方式:父子路径label,子级下拉菜单labels,短按是展开下拉菜单,长按是确认选中
8489
// 编辑方式:拖拽摇杆在root位移,同级调序上下键,父级更换模式开启键
8590
// 进入父级更换模式后,面包屑label长按效果变为确认更换
8691

87-
// 构建面包屑
92+
// 左侧面包屑
93+
var branchTable = new IslandBranchTable();
94+
branchTable.build();
95+
branchTable.onConfirm = isle -> setSelectedIsland(isle);
96+
branchTable.setTarget(island);
97+
table.add(branchTable);
98+
99+
// 中间主菜单
88100
table.table(t -> {
101+
t.top();
102+
t.add(getIslandName(island));
103+
});
104+
105+
// 右侧信息菜单
106+
}
89107

90-
t.button("root", () -> {
91-
setSelectedIsland(null);
108+
/**
109+
* 第一列:从root到target的分支列表
110+
* 第二列:点击某个父级显示所有子级,折叠列表
111+
* 底部:确认按钮
112+
*/
113+
public class IslandBranchTable extends Table{
114+
public Island target;
115+
public Cons<Island> onConfirm;
116+
public Func<Island, String> confirmTextProvider = island -> "切换到[accent]" + getIslandName(island);
117+
118+
Table mainColumn = new Table();
119+
Table subColumn = new Table();
120+
121+
public void build(){
122+
clear();
123+
124+
table(t -> {
125+
t.defaults().top().growY();
126+
t.pane(mainColumn);
127+
t.pane(subColumn);
92128
});
93129

94-
if(island == null) return;
130+
row();
131+
132+
button("", textb, () -> {
133+
if(onConfirm != null) onConfirm.get(target);
134+
}).with(funcSetTextb).update(b -> b.setText(confirmTextProvider.get(target)));
135+
}
136+
137+
public void setTarget(Island island){
138+
target = island;
139+
rebuildMainColumn(mainColumn);
140+
if(island != null && island.content instanceof ChildrenContent cc){
141+
rebuildSubColumnFor(subColumn, cc.children);
142+
}else if(island == null){
143+
rebuildSubColumnFor(subColumn, rootIslands);
144+
}else{
145+
rebuildSubColumnFor(subColumn, null);
146+
}
147+
}
148+
149+
public void rebuildMainColumn(Table t){
150+
t.clear();
151+
t.defaults().growX().width(100f).left();
152+
153+
//root
154+
t.button(getIslandName(null), textb, () -> setTarget(null)).with(funcSetTextb).with(b -> b.getLabel().setAlignment(Align.left));
155+
156+
if(target == null) return;
95157
var seq = new Seq<Island>();
96-
Island elem = island;
158+
Island elem = target;
97159
do{
98160
seq.add(elem);
99161
elem = elem.parent instanceof Island isle ? isle : null;
@@ -102,20 +164,25 @@ public void rebuildIslandConfigureTableFor(Island island){
102164
for(int i = seq.size - 1; i >= 0; i--){
103165
var isle = seq.get(i);
104166
t.add(">");
105-
t.button(isle.name, () -> setSelectedIsland(isle))
106-
.disabled(selectedIsland == isle);
167+
t.row();
168+
t.button(getIslandName(isle), textb, () -> setTarget(isle)).with(funcSetTextb).with(b -> b.getLabel().setAlignment(Align.left));
107169
}
108-
});
109-
110-
table.row();
111-
112-
if(island == null){
113-
table.add("未选中");
114-
}else{
115-
table.add("已选中"+island.name);
116170
}
117171

172+
public void rebuildSubColumnFor(Table t, Seq<Island> seq){
173+
t.clear();
174+
if(seq == null) return;
175+
t.defaults().growX().width(80f);
176+
for(var isle : seq){
177+
t.button(getIslandName(isle), textb, () -> {
178+
setTarget(isle);
179+
}).with(funcSetTextb).with(b -> b.getLabel().setAlignment(Align.left));
180+
t.row();
181+
}
182+
}
183+
}
118184

119-
// 二级设置入口
185+
public static String getIslandName(Island island){
186+
return island == null ? "root" : island.name == null || island.name.isEmpty() ? "<No Name>" : island.name;
120187
}
121188
}

0 commit comments

Comments
 (0)