Skip to content

Commit f8665c5

Browse files
author
BAZIN Maxence
committed
begin to fix the Shouldloop system in guiList
1 parent 773b23e commit f8665c5

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,27 @@ public void setupActionInputValues(int actionUpValue, int actionDownValue){
4646
}
4747

4848
public void update(){
49-
boolean needUpdate = false;
50-
5149
if (!mouseManager.oldPos().equals(mouseManager.pos(), PIXEL_PER_SECOND_DISABLE)){
5250
if (selected != null && selected.mouseDisableIt()) {
5351
selected.forceSelect(false);
5452
}
5553

56-
needUpdate = true;
54+
shouldUpdateSelected();
5755
}
5856

57+
Integer id = null;
58+
5959
if (actionUpValue != -1 && inputManager.inputPressed(actionUpValue)) {
60-
needUpdate = true;
61-
unselectAll();
62-
selectUp();
60+
id = selectUp();
6361
} else if (actionDownValue != -1 && inputManager.inputPressed(actionDownValue)) {
64-
needUpdate = true;
65-
unselectAll();
66-
selectDown();
62+
id = selectDown();
6763
}
6864

69-
if (needUpdate)
65+
if (id != null && (!id.equals(this.mouseId)) && !id.equals(this.id)) {
66+
unselectAll();
67+
GUIs.get(id).forceSelect(true);
7068
shouldUpdateSelected();
69+
}
7170
}
7271

7372
private void unselectAll(){
@@ -76,10 +75,10 @@ private void unselectAll(){
7675
}
7776
}
7877

79-
private void selectUp(){
78+
private Integer selectUp(){
8079
if (id == null) {
8180
selectMinimum();
82-
return;
81+
return null;
8382
}
8483

8584
Integer maxId = null, minId = null;
@@ -96,18 +95,21 @@ private void selectUp(){
9695
}
9796

9897
if (maxId == null){
99-
if (minId != null) {
100-
GUIs.get(minId).forceSelect(true);
98+
if (minId != null && ShouldLoop) {
99+
return minId;
101100
}
102101
} else {
103-
GUIs.get(maxId).forceSelect(true);
102+
return maxId;
104103
}
104+
105+
return null;
105106
}
106107

107-
private void selectDown(){
108+
109+
private Integer selectDown(){
108110
if (id == null) {
109111
selectMinimum();
110-
return;
112+
return null;
111113
}
112114

113115
Integer maxId = null, minId = null;
@@ -124,12 +126,14 @@ private void selectDown(){
124126
}
125127

126128
if (minId == null){
127-
if (maxId != null) {
128-
GUIs.get(maxId).forceSelect(true);
129+
if (maxId != null && ShouldLoop) {
130+
return maxId;
129131
}
130132
} else {
131-
GUIs.get(minId).forceSelect(true);
133+
return minId;
132134
}
135+
136+
return null;
133137
}
134138

135139
private void selectMinimum(){

src/MightyLibrary/project/scenes/MenuScene.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public void init(String[] args) {
6363
guiList.GUIs.put(1, button3DScene);
6464
guiList.GUIs.put(2, buttonCollisionTest);
6565
guiList.GUIs.put(3, buttonQuit);
66+
guiList.ShouldLoop = true;
6667
}
6768

6869

0 commit comments

Comments
 (0)