From 9ceaa0339b3a015b7e444d153d7b5029392241fa Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 3 Oct 2024 16:54:49 -0400 Subject: [PATCH] Right menu removed in editor mode --- core/src/mindustry/input/DesktopInput.java | 2 - core/src/mindustry/input/MobileInput.java | 2 - .../mindustry/ui/fragments/HudFragment.java | 40 ++++++++++++++++ .../ui/fragments/PlacementFragment.java | 47 +++++++++++++------ 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 49bd8eb068..4b39263af0 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -540,8 +540,6 @@ public class DesktopInput extends InputHandler{ @Override public void buildPlacementUI(Table table){ - table.image().color(Pal.gray).height(4f).colspan(4).growX(); - table.row(); table.left().margin(0f).defaults().size(48f).left(); table.button(Icon.paste, Styles.clearNonei, () -> { diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index eff27140cb..470849fd81 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -188,8 +188,6 @@ public class MobileInput extends InputHandler implements GestureListener{ @Override public void buildPlacementUI(Table table){ - table.image().color(Pal.gray).height(4f).colspan(4).growX(); - table.row(); table.left().margin(0f).defaults().size(48f); table.button(Icon.hammer, Styles.clearNoneTogglei, () -> { diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java index c676f67bb1..3708f11b34 100644 --- a/core/src/mindustry/ui/fragments/HudFragment.java +++ b/core/src/mindustry/ui/fragments/HudFragment.java @@ -344,6 +344,46 @@ public class HudFragment{ t.row(); + t.table(control.input::buildPlacementUI).growX().left().with(in -> in.left()).row(); + + //hovering item display + t.table(h -> { + Runnable rebuild = () -> { + h.clear(); + h.left(); + + Displayable hover = blockfrag.hovered(); + UnlockableContent toDisplay = control.input.block; + + if(toDisplay == null && hover != null){ + if(hover instanceof Building b){ + toDisplay = b.block; + }else if(hover instanceof Tile tile){ + toDisplay = + tile.block().itemDrop != null ? tile.block() : + tile.overlay().itemDrop != null || tile.wallDrop() != null ? tile.overlay() : + tile.floor(); + }else if(hover instanceof Unit u){ + toDisplay = u.type; + } + } + + if(toDisplay != null){ + h.image(toDisplay.uiIcon).scaling(Scaling.fit).size(8 * 4); + h.add(toDisplay.localizedName).ellipsis(true).left().growX().padLeft(5); + } + }; + + Object[] hovering = {null}; + h.update(() -> { + Object nextHover = control.input.block != null ? control.input.block : blockfrag.hovered(); + if(nextHover != hovering[0]){ + hovering[0] = nextHover; + rebuild.run(); + } + }); + }).growX().left().minHeight(36f).row(); + t.table(blocks -> { addBlockSelection(blocks); }).fillX().left(); diff --git a/core/src/mindustry/ui/fragments/PlacementFragment.java b/core/src/mindustry/ui/fragments/PlacementFragment.java index 603d816011..a5a1063bd3 100644 --- a/core/src/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/mindustry/ui/fragments/PlacementFragment.java @@ -124,9 +124,7 @@ public class PlacementFragment{ toggler.setZIndex(index); } - boolean gridUpdate(InputHandler input){ - scrollPositions.put(currentCategory, blockPane.getScrollY()); - + boolean updatePick(InputHandler input){ if(Core.input.keyTap(Binding.pick) && player.isBuilder() && !Core.scene.hasDialog()){ //mouse eyedropper select var build = world.buildWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y); @@ -150,9 +148,9 @@ public class PlacementFragment{ var tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY()); if(tile != null){ tryRecipe = - tile.block() != Blocks.air ? tile.block() : - tile.overlay() != Blocks.air ? tile.overlay() : - tile.floor() != Blocks.air ? tile.floor() : null; + tile.block() != Blocks.air ? tile.block() : + tile.overlay() != Blocks.air ? tile.overlay() : + tile.floor() != Blocks.air ? tile.floor() : null; } } @@ -165,6 +163,15 @@ public class PlacementFragment{ return true; } } + return false; + } + + boolean gridUpdate(InputHandler input){ + scrollPositions.put(currentCategory, blockPane.getScrollY()); + + if(updatePick(input)){ + return true; + } if(ui.chatfrag.shown() || ui.consolefrag.shown() || Core.scene.hasKeyboard()) return false; @@ -258,7 +265,14 @@ public class PlacementFragment{ public void build(Group parent){ parent.fill(full -> { toggler = full; - full.bottom().right().visible(() -> ui.hudfrag.shown); + full.bottom().right().visible(() -> { + if(state.rules.editor){ + //force update the mouse picking, since it otherwise would not happen + updatePick(control.input); + } + + return ui.hudfrag.shown && !state.rules.editor; + }); full.table(frame -> { @@ -644,7 +658,11 @@ public class PlacementFragment{ }).grow().get(); blockPane.setStyle(Styles.smallPane); blocksSelect.row(); - blocksSelect.table(control.input::buildPlacementUI).name("inputTable").growX(); + blocksSelect.table(t -> { + t.image().color(Pal.gray).height(4f).colspan(4).growX(); + t.row(); + control.input.buildPlacementUI(t); + }).name("inputTable").growX(); }).fillY().bottom().touchable(Touchable.enabled); blockCatTable.table(categories -> { categories.bottom(); @@ -730,13 +748,14 @@ public class PlacementFragment{ return control.input.block != null || menuHoverBlock != null || hover != null; } - /** Returns the thing being hovered over. */ - @Nullable - Displayable hovered(){ - Vec2 v = topTable.stageToLocalCoordinates(Core.input.mouse()); + /** @return the thing being hovered over. */ + public @Nullable Displayable hovered(){ + if(!state.rules.editor){ + Vec2 v = topTable.stageToLocalCoordinates(Core.input.mouse()); - //if the mouse intersects the table or the UI has the mouse, no hovering can occur - if(Core.scene.hasMouse() || topTable.hit(v.x, v.y, false) != null) return null; + //if the mouse intersects the table or the UI has the mouse, no hovering can occur + if(Core.scene.hasMouse() || topTable.hit(v.x, v.y, false) != null) return null; + } //check for a unit Unit unit = Units.closestOverlap(player.team(), Core.input.mouseWorldX(), Core.input.mouseWorldY(), 5f, u -> !u.isLocal() && u.displayable());