From b5ebda666e6cbc789b68c53481fa4a20f5d42845 Mon Sep 17 00:00:00 2001 From: BlackDeluxeCat <65377021+BlackDeluxeCat@users.noreply.github.com> Date: Mon, 19 Feb 2024 16:49:25 +0800 Subject: [PATCH] add drag bar not drag listener --- src/mi2u/MI2Utilities.java | 2 +- src/mi2u/ai/FullAI.java | 2 +- src/mi2u/ui/MI2UI.java | 2 +- src/mi2u/ui/WorldFinderTable.java | 1 - src/mi2u/ui/elements/PopupTable.java | 26 +++++++++++++++++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/mi2u/MI2Utilities.java b/src/mi2u/MI2Utilities.java index d89e618..982177a 100644 --- a/src/mi2u/MI2Utilities.java +++ b/src/mi2u/MI2Utilities.java @@ -184,7 +184,7 @@ public static void checkUpdate(){ this.pane(t -> { introl = t.add(intro).align(Align.left).growX().get(); //drawing update discription possibly cause font color bug. - }).width(300f).maxHeight(600f); + }).width(300f).maxHeight(500f); } }; diff --git a/src/mi2u/ai/FullAI.java b/src/mi2u/ai/FullAI.java index e2b07b9..34d8c8b 100644 --- a/src/mi2u/ai/FullAI.java +++ b/src/mi2u/ai/FullAI.java @@ -723,7 +723,7 @@ public void readCode(String str){ customAIUITable.touchable = Touchable.enabled; customAIUITable.margin(2f); customAIUITable.background(Styles.black3); - customAIUITable.addDragMove(); + customAIUITable.addDragBar(); customAIUITable.addCloseButton(20f); customAIUITable.add("@ai.config.logic.ui").height(20f).row(); customAIUITable.update(() -> customAIUITable.keepInScreen()); diff --git a/src/mi2u/ui/MI2UI.java b/src/mi2u/ui/MI2UI.java index 1cc37f4..2891b07 100644 --- a/src/mi2u/ui/MI2UI.java +++ b/src/mi2u/ui/MI2UI.java @@ -124,7 +124,7 @@ public MI2UI(){ }, textb, () -> { popup.clear(); popup.addCloseButton(); - popup.addDragMove(); + popup.addDragBar(); popup.addInGameVisible(); popup.setSize(300f, 200f); popup.margin(4f).setBackground(Styles.black8); diff --git a/src/mi2u/ui/WorldFinderTable.java b/src/mi2u/ui/WorldFinderTable.java index 9076eaa..279a13b 100644 --- a/src/mi2u/ui/WorldFinderTable.java +++ b/src/mi2u/ui/WorldFinderTable.java @@ -155,7 +155,6 @@ public void setupSelect(){ selectTable.clear(); selectTable.addCloseButton(); selectTable.background(Styles.black6); - selectTable.addDragMove(); selectTable.update(() -> { selectTable.setPositionInScreen(this.x, this.y - selectTable.getPrefHeight()); if(!this.shown || !this.visible) selectTable.hide(); diff --git a/src/mi2u/ui/elements/PopupTable.java b/src/mi2u/ui/elements/PopupTable.java index 39957d0..b52fd03 100644 --- a/src/mi2u/ui/elements/PopupTable.java +++ b/src/mi2u/ui/elements/PopupTable.java @@ -1,6 +1,7 @@ package mi2u.ui.elements; import arc.*; +import arc.graphics.*; import arc.input.*; import arc.math.*; import arc.math.geom.*; @@ -16,7 +17,6 @@ public class PopupTable extends Table{ public boolean shown = false; - public float fromx, fromy; public float popupDuration = 0.15f; public boolean cancelDrag; @@ -78,8 +78,32 @@ public void hideWithoutFocusOn(@Nullable Element...elements){ if(!hasMouse) hide(); } + public void addDragBar(){ + addDragBar(20f, Color.acid); + } + + public void addDragBar(float height, Color color){ + image().growX().height(height).color(color).get().addListener(new InputListener(){ + float fromx, fromy; + @Override + public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){ + fromx = x; + fromy = y; + return true; + } + + @Override + public void touchDragged(InputEvent event, float x, float y, int pointer){ + if(cancelDrag) return; + Vec2 v = localToStageCoordinates(MI2UTmp.v1.set(x, y)); + setPositionInScreen(v.x - fromx, v.y - fromy); + } + }); + } + public void addDragMove(){ addListener(new InputListener(){ + float fromx, fromy; @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){ fromx = x;