Skip to content

Commit 8e0f975

Browse files
committed
fix guiList
1 parent f8665c5 commit 8e0f975

2 files changed

Lines changed: 46 additions & 31 deletions

File tree

src/MightyLibrary/mightylib/graphics/GUI/GUIList.java

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class GUIList {
2323

2424
public boolean ShouldLoop = true;
2525

26+
private boolean mouseMoved;
27+
2628
public GUIList(InputManager inputManager, MouseManager mouseManager) {
2729
this.mouseManager = mouseManager;
2830
this.inputManager = inputManager;
@@ -31,6 +33,8 @@ public GUIList(InputManager inputManager, MouseManager mouseManager) {
3133
selected = null;
3234
id = null;
3335
mouseId = null;
36+
37+
mouseMoved = false;
3438
}
3539

3640
public Integer getSelected(){
@@ -52,6 +56,8 @@ public void update(){
5256
}
5357

5458
shouldUpdateSelected();
59+
60+
mouseMoved = true;
5561
}
5662

5763
Integer id = null;
@@ -62,11 +68,16 @@ public void update(){
6268
id = selectDown();
6369
}
6470

65-
if (id != null && (!id.equals(this.mouseId)) && !id.equals(this.id)) {
66-
unselectAll();
67-
GUIs.get(id).forceSelect(true);
68-
shouldUpdateSelected();
69-
}
71+
if (id == null)
72+
return;
73+
74+
if (id.equals(this.id) && !mouseMoved)
75+
return;
76+
77+
unselectAll();
78+
GUIs.get(id).forceSelect(true);
79+
shouldUpdateSelected();
80+
mouseMoved = false;
7081
}
7182

7283
private void unselectAll(){
@@ -76,10 +87,13 @@ private void unselectAll(){
7687
}
7788

7889
private Integer selectUp(){
79-
if (id == null) {
80-
selectMinimum();
81-
return null;
82-
}
90+
if (this.id == null)
91+
return selectMinimum();
92+
93+
94+
if (mouseMoved)
95+
return this.id;
96+
8397

8498
Integer maxId = null, minId = null;
8599

@@ -98,19 +112,19 @@ private Integer selectUp(){
98112
if (minId != null && ShouldLoop) {
99113
return minId;
100114
}
101-
} else {
102-
return maxId;
103115
}
104116

105-
return null;
117+
return maxId;
106118
}
107119

108120

109121
private Integer selectDown(){
110-
if (id == null) {
111-
selectMinimum();
112-
return null;
113-
}
122+
if (this.id == null)
123+
return selectMinimum();
124+
125+
if (mouseMoved)
126+
return this.id;
127+
114128

115129
Integer maxId = null, minId = null;
116130

@@ -129,14 +143,12 @@ private Integer selectDown(){
129143
if (maxId != null && ShouldLoop) {
130144
return maxId;
131145
}
132-
} else {
133-
return minId;
134146
}
135147

136-
return null;
148+
return minId;
137149
}
138150

139-
private void selectMinimum(){
151+
private Integer selectMinimum(){
140152
Integer min = null;
141153
for (Map.Entry<Integer, GUI> pair : GUIs.entrySet()) {
142154
if (min == null)
@@ -145,8 +157,7 @@ else if (min > pair.getKey())
145157
min = pair.getKey();
146158
}
147159

148-
if (min != null)
149-
GUIs.get(min).forceSelect(true);
160+
return min;
150161
}
151162

152163
private void shouldUpdateSelected(){

src/MightyLibrary/project/scenes/MenuScene.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,43 @@ public void init(String[] args) {
3131
.setReference(EDirection.None)
3232
.setPosition(new Vector2f(windowSize.x * 0.5f, windowSize.y * 0.5f))
3333
.setFontSize(40)
34-
.setText("->Test2DScene<-");
34+
.setText("Test2DScene");
3535

3636
button2DScene.Text.copyTo(button2DScene.OverlapsText);
37-
button2DScene.OverlapsText.setColor(new Color4f(0.3f));
37+
button2DScene.OverlapsText.setColor(new Color4f(0.3f))
38+
.setText("->Test2DScene<-");
3839

3940
BackgroundlessButton button3DScene = button2DScene.copy();
4041
button3DScene.Text.setPosition(new Vector2f(windowSize.x * 0.5f, windowSize.y * 0.6f))
41-
.setText("->Test3DScene<-");
42+
.setText("Test3DScene");
4243

4344
button3DScene.Text.copyTo(button3DScene.OverlapsText);
44-
button3DScene.OverlapsText.setColor(new Color4f(0.3f));
45+
button3DScene.OverlapsText.setColor(new Color4f(0.3f))
46+
.setText("->Test3DScene<-");
4547

4648
BackgroundlessButton buttonCollisionTest = button2DScene.copy();
4749
buttonCollisionTest.Text.setPosition(new Vector2f(windowSize.x * 0.5f, windowSize.y * 0.7f))
48-
.setText("->TestCollisionScene<-");
50+
.setText("TestCollisionScene");
4951

5052
buttonCollisionTest.Text.copyTo(buttonCollisionTest.OverlapsText);
51-
buttonCollisionTest.OverlapsText.setColor(new Color4f(0.3f));
53+
buttonCollisionTest.OverlapsText.setColor(new Color4f(0.3f))
54+
.setText("->TestCollisionScene<-");
5255

5356
BackgroundlessButton buttonQuit = button2DScene.copy();
5457
buttonQuit.Text.setPosition(new Vector2f(windowSize.x * 0.5f, windowSize.y * 0.9f))
55-
.setText("->Quit<-");
58+
.setText("Quit");
5659

5760
buttonQuit.Text.copyTo(buttonQuit.OverlapsText);
58-
buttonQuit.OverlapsText.setColor(new Color4f(0.3f));
61+
buttonQuit.OverlapsText.setColor(new Color4f(0.3f))
62+
.setText("->Quit<-");
5963

6064
guiList = new GUIList(mainContext.getInputManager(), mainContext.getMouseManager());
6165
guiList.setupActionInputValues(ActionId.SELECT_UP, ActionId.SELECT_DOWN);
6266
guiList.GUIs.put(0, button2DScene);
6367
guiList.GUIs.put(1, button3DScene);
6468
guiList.GUIs.put(2, buttonCollisionTest);
6569
guiList.GUIs.put(3, buttonQuit);
66-
guiList.ShouldLoop = true;
70+
guiList.ShouldLoop = false;
6771
}
6872

6973

0 commit comments

Comments
 (0)