Skip to content

Commit

Permalink
add drag bar not drag listener
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDeluxeCat committed Feb 19, 2024
1 parent 3ebfa97 commit b5ebda6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mi2u/MI2Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

};
Expand Down
2 changes: 1 addition & 1 deletion src/mi2u/ai/FullAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/mi2u/ui/MI2UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/mi2u/ui/WorldFinderTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 25 additions & 1 deletion src/mi2u/ui/elements/PopupTable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mi2u.ui.elements;

import arc.*;
import arc.graphics.*;
import arc.input.*;
import arc.math.*;
import arc.math.geom.*;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b5ebda6

Please sign in to comment.