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

View File

@ -1,6 +1,7 @@
package mindustry.ui;
import arc.graphics.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import mindustry.core.GameState.*;
import mindustry.gen.*;
@ -21,18 +22,31 @@ public class ItemsDisplay extends Table{
top().left();
margin(0);
table(Tex.button,t -> {
t.margin(10).marginLeft(15).marginTop(15f);
t.label(() -> state.is(State.menu) ? "$launcheditems" : "$launchinfo").colspan(3).padBottom(4).left().colspan(3).width(210f).wrap();
t.row();
for(Item item : content.items()){
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();
table(Tex.button, c -> {
c.margin(10).marginLeft(12).marginTop(15f);
c.marginRight(12f);
c.left();
Collapser col = new Collapser(base -> base.pane(t -> {
t.marginRight(30f);
t.left();
for(Item item : content.items()){
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);
});
}

View File

@ -110,7 +110,7 @@ public class TechTreeDialog extends FloatingDialog{
}
void treeLayout(){
RadialTreeLayout layout = new RadialTreeLayout();
TreeLayout layout = new RadialTreeLayout();
LayoutNode node = new LayoutNode(root, null);
layout.layout(node);
float minx = 0f, miny = 0f, maxx = 0f, maxy = 0f;

View File

@ -31,11 +31,13 @@ public class PlacementFragment extends Fragment{
Array<Block> returnArray = new Array<>();
Array<Category> returnCatArray = new Array<>();
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;
Tile lastHover;
Tile hoverTile;
Table blockTable, toggler, topTable;
ScrollPane blockPane;
boolean lastGround;
boolean blockSelectEnd;
int blockSelectSeq;
@ -86,6 +88,8 @@ public class PlacementFragment extends Fragment{
}
boolean gridUpdate(InputHandler input){
scrollPositions.put(currentCategory, blockPane.getScrollY());
if(Core.input.keyDown(Binding.pick)){ //mouse eyedropper select
Tile tile = world.ltileWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);
Block tryRecipe = tile == null ? null : tile.block();
@ -240,6 +244,9 @@ public class PlacementFragment extends Fragment{
}
}
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
@ -343,14 +350,15 @@ public class PlacementFragment extends Fragment{
frame.row();
frame.table(Tex.pane2, blocksSelect -> {
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()){
Element result = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
if(result == null || !result.isDescendantOf(pane)){
Core.scene.setScrollFocus(null);
}
}
}).grow().get().setStyle(Styles.smallPane);
}).grow().get();
blockPane.setStyle(Styles.smallPane);
blocksSelect.row();
blocksSelect.table(control.input::buildPlacementUI).name("inputTable").growX();
}).fillY().bottom().touchable(Touchable.enabled);

View File

@ -12,7 +12,7 @@ public class RadialTreeLayout implements TreeLayout{
@Override
public void layout(TreeNode root){
startRadius = root.height * 2.4f;
delta = root.height * 2.4f;
delta = root.height * 20.4f;
bfs(root, true);

View File

@ -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);
}
}
}

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=85e020b1565d7f6490d2281411b810916046e5ee
archash=e5894c1aaa00d4ba1c75ba16c7f341d2ea70344c