Layout improvements

This commit is contained in:
Anuken
2020-01-20 20:21:04 -05:00
parent 200e85d970
commit 2642c3c8b8
6 changed files with 75 additions and 17 deletions
+25 -11
View File
@@ -1,6 +1,7 @@
package mindustry.ui; package mindustry.ui;
import arc.graphics.*; import arc.graphics.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import mindustry.core.GameState.*; import mindustry.core.GameState.*;
import mindustry.gen.*; import mindustry.gen.*;
@@ -21,18 +22,31 @@ public class ItemsDisplay extends Table{
top().left(); top().left();
margin(0); margin(0);
table(Tex.button,t -> { table(Tex.button, c -> {
t.margin(10).marginLeft(15).marginTop(15f); c.margin(10).marginLeft(12).marginTop(15f);
t.label(() -> state.is(State.menu) ? "$launcheditems" : "$launchinfo").colspan(3).padBottom(4).left().colspan(3).width(210f).wrap(); c.marginRight(12f);
t.row(); c.left();
for(Item item : content.items()){
if(item.type == ItemType.material && data.isUnlocked(item)){ Collapser col = new Collapser(base -> base.pane(t -> {
t.label(() -> format(item)).left(); t.marginRight(30f);
t.addImage(item.icon(Cicon.small)).size(8 * 3).padLeft(4).padRight(4); t.left();
t.add(item.localizedName).color(Color.lightGray).left(); for(Item item : content.items()){
t.row(); if(item.type == ItemType.material && data.isUnlocked(item)){
t.label(() -> format(item)).left();
t.addImage(item.icon(Cicon.small)).size(8 * 3).padLeft(4).padRight(4);
t.add(item.localizedName).color(Color.lightGray).left();
t.row();
}
} }
} }).get().setScrollingDisabled(true, false), false).setDuration(0.3f);
c.addImageTextButton("$launcheditems", Icon.downOpen, Styles.clearTogglet, col::toggle).update(t -> {
t.setText(state.is(State.menu) ? "$launcheditems" : "$launchinfo");
t.setChecked(col.isCollapsed());
((Image)t.getChildren().get(1)).setDrawable(col.isCollapsed() ? Icon.upOpen : Icon.downOpen);
}).padBottom(4).left().fillX().margin(12f);
c.row();
c.add(col);
}); });
} }
@@ -110,7 +110,7 @@ public class TechTreeDialog extends FloatingDialog{
} }
void treeLayout(){ void treeLayout(){
RadialTreeLayout layout = new RadialTreeLayout(); TreeLayout layout = new RadialTreeLayout();
LayoutNode node = new LayoutNode(root, null); LayoutNode node = new LayoutNode(root, null);
layout.layout(node); layout.layout(node);
float minx = 0f, miny = 0f, maxx = 0f, maxy = 0f; float minx = 0f, miny = 0f, maxx = 0f, maxy = 0f;
@@ -31,11 +31,13 @@ public class PlacementFragment extends Fragment{
Array<Block> returnArray = new Array<>(); Array<Block> returnArray = new Array<>();
Array<Category> returnCatArray = new Array<>(); Array<Category> returnCatArray = new Array<>();
boolean[] categoryEmpty = new boolean[Category.all.length]; boolean[] categoryEmpty = new boolean[Category.all.length];
ObjectMap<Category,Block> selectedBlocks = new ObjectMap<Category,Block>(); ObjectMap<Category,Block> selectedBlocks = new ObjectMap<>();
ObjectFloatMap<Category> scrollPositions = new ObjectFloatMap<>();
Block hovered, lastDisplay; Block hovered, lastDisplay;
Tile lastHover; Tile lastHover;
Tile hoverTile; Tile hoverTile;
Table blockTable, toggler, topTable; Table blockTable, toggler, topTable;
ScrollPane blockPane;
boolean lastGround; boolean lastGround;
boolean blockSelectEnd; boolean blockSelectEnd;
int blockSelectSeq; int blockSelectSeq;
@@ -86,6 +88,8 @@ public class PlacementFragment extends Fragment{
} }
boolean gridUpdate(InputHandler input){ boolean gridUpdate(InputHandler input){
scrollPositions.put(currentCategory, blockPane.getScrollY());
if(Core.input.keyDown(Binding.pick)){ //mouse eyedropper select if(Core.input.keyDown(Binding.pick)){ //mouse eyedropper select
Tile tile = world.ltileWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y); Tile tile = world.ltileWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);
Block tryRecipe = tile == null ? null : tile.block(); Block tryRecipe = tile == null ? null : tile.block();
@@ -240,6 +244,9 @@ public class PlacementFragment extends Fragment{
} }
} }
blockTable.act(0f); blockTable.act(0f);
blockPane.act(0f);
blockPane.setScrollYForce(scrollPositions.get(currentCategory, 0));
Core.app.post(() -> blockPane.setScrollYForce(scrollPositions.get(currentCategory, 0)));
}; };
//top table with hover info //top table with hover info
@@ -343,14 +350,15 @@ public class PlacementFragment extends Fragment{
frame.row(); frame.row();
frame.table(Tex.pane2, blocksSelect -> { frame.table(Tex.pane2, blocksSelect -> {
blocksSelect.margin(4).marginTop(0); blocksSelect.margin(4).marginTop(0);
blocksSelect.pane(blocks -> blockTable = blocks).height(194f).update(pane -> { blockPane = blocksSelect.pane(blocks -> blockTable = blocks).height(194f).update(pane -> {
if(pane.hasScroll()){ if(pane.hasScroll()){
Element result = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true); Element result = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
if(result == null || !result.isDescendantOf(pane)){ if(result == null || !result.isDescendantOf(pane)){
Core.scene.setScrollFocus(null); Core.scene.setScrollFocus(null);
} }
} }
}).grow().get().setStyle(Styles.smallPane); }).grow().get();
blockPane.setStyle(Styles.smallPane);
blocksSelect.row(); blocksSelect.row();
blocksSelect.table(control.input::buildPlacementUI).name("inputTable").growX(); blocksSelect.table(control.input::buildPlacementUI).name("inputTable").growX();
}).fillY().bottom().touchable(Touchable.enabled); }).fillY().bottom().touchable(Touchable.enabled);
@@ -12,7 +12,7 @@ public class RadialTreeLayout implements TreeLayout{
@Override @Override
public void layout(TreeNode root){ public void layout(TreeNode root){
startRadius = root.height * 2.4f; startRadius = root.height * 2.4f;
delta = root.height * 2.4f; delta = root.height * 20.4f;
bfs(root, true); bfs(root, true);
@@ -0,0 +1,36 @@
package mindustry.ui.layout;
import arc.struct.*;
public class RowTreeLayout implements TreeLayout{
@Override
public void layout(TreeNode root){
layout(root, 0, new IntArray());
/*
def minimum_ws(tree, depth=0):
tree.x = nexts[depth]
tree.y = depth
nexts[depth] += 1
for c in tree.children:
minimum_ws(tree, c)
*/
}
void layout(TreeNode node, int depth, IntArray nexts){
float size = node.height * 5f;
if(nexts.size < depth + 1){
nexts.ensureCapacity(depth + 1);
nexts.size = depth + 1;
}
node.x = size * nexts.get(depth);
node.y = size * depth;
nexts.incr(depth, 1);
for(TreeNode child : node.children){
layout(child, depth + 1, nexts);
}
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=85e020b1565d7f6490d2281411b810916046e5ee archash=e5894c1aaa00d4ba1c75ba16c7f341d2ea70344c