Skip to content

Commit 44d5d94

Browse files
Move to menu package
This is because shift is frequently called at iteration so using less getters is a noticable change Also because you type less :)))))
1 parent 9b3a0b2 commit 44d5d94

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
package me.flame.menus.menu;
2+
3+
/**
4+
* Iteration direction of a {@link Page} or {@link Menu}
5+
* @author Mqzn (Mqzen), FlameyosFlow (Mostly Mqzen)
6+
*/
7+
@SuppressWarnings("unused")
8+
public enum IterationDirection {
9+
HORIZONTAL {
10+
@Override
11+
public Slot shift(Slot oldPos, int maxRows) {
12+
int oldCol = oldPos.col;
13+
int oldRow = oldPos.row;
14+
15+
if (oldCol == 9 && oldRow < maxRows) {
16+
oldCol = 1;
17+
oldRow++;
18+
} else {
19+
oldCol++;
20+
}
21+
22+
return new Slot(oldRow, oldCol);
23+
}
24+
},
25+
26+
VERTICAL {
27+
@Override
28+
public Slot shift(Slot oldPos, int maxRows) {
29+
int oldCol = oldPos.col;
30+
int oldRow = oldPos.row;
31+
32+
if (oldCol < 9 && oldRow == maxRows) {
33+
oldCol++;
34+
oldRow = 1;
35+
} else {
36+
oldRow++;
37+
}
38+
39+
return new Slot(oldRow, oldCol);
40+
}
41+
},
42+
43+
UPWARDS_ONLY {
44+
@Override
45+
public Slot shift(Slot oldPos, int maxRows) {
46+
return new Slot(oldPos.row - 1, oldPos.col);
47+
}
48+
},
49+
50+
DOWNWARDS_ONLY {
51+
@Override
52+
public Slot shift(Slot oldPos, int maxRows) {
53+
return new Slot(oldPos.row + 1, oldPos.col);
54+
}
55+
},
56+
57+
RIGHT_ONLY {
58+
@Override
59+
public Slot shift(Slot oldPos, int maxRows) {
60+
int col = oldPos.col + 1;
61+
if (col > 9) {
62+
return Slot.NaS;
63+
}
64+
return new Slot(oldPos.row, col);
65+
}
66+
},
67+
68+
LEFT_ONLY {
69+
@Override
70+
public Slot shift(Slot oldPos, int maxRows) {
71+
int col = oldPos.col - 1;
72+
if (col < 0) {
73+
return Slot.NaS;
74+
}
75+
return new Slot(oldPos.row, col);
76+
}
77+
},
78+
79+
RIGHT_UPWARDS_ONLY {
80+
@Override
81+
public Slot shift(Slot oldPos, int maxRows) {
82+
Slot upwardSlot = UPWARDS_ONLY.shift(oldPos, maxRows);
83+
int row = upwardSlot.row;
84+
85+
Slot rightSlot = RIGHT_ONLY.shift(oldPos, maxRows);
86+
int col = rightSlot.col;
87+
88+
return new Slot(row, col);
89+
}
90+
},
91+
92+
RIGHT_DOWNWARDS_ONLY {
93+
@Override
94+
public Slot shift(Slot oldPos, int maxRows) {
95+
Slot downwardSlot = DOWNWARDS_ONLY.shift(oldPos, maxRows);
96+
int row = downwardSlot.row;
97+
98+
Slot rightSlot = RIGHT_ONLY.shift(oldPos, maxRows);
99+
int col = rightSlot.col;
100+
101+
return new Slot(row, col);
102+
}
103+
},
104+
105+
LEFT_UPWARDS {
106+
@Override
107+
public Slot shift(Slot oldPos, int maxRows) {
108+
Slot upwardSlot = UPWARDS_ONLY.shift(oldPos, maxRows);
109+
int row = upwardSlot.row;
110+
111+
Slot leftSlot = LEFT_ONLY.shift(oldPos, maxRows);
112+
int col = leftSlot.col;
113+
114+
return new Slot(row, col);
115+
}
116+
},
117+
118+
LEFT_DOWNWARDS {
119+
@Override
120+
public Slot shift(Slot oldPos, int maxRows) {
121+
Slot downwardSlot = DOWNWARDS_ONLY.shift(oldPos, maxRows);
122+
int row = downwardSlot.row;
123+
124+
Slot leftSlot = LEFT_ONLY.shift(oldPos, maxRows);
125+
int col = leftSlot.col;
126+
127+
return new Slot(row, col);
128+
}
129+
},
130+
131+
BACKWARDS_HORIZONTAL {
132+
@Override
133+
public Slot shift(Slot oldPos, int maxRows) {
134+
int oldCol = oldPos.col;
135+
int oldRow = oldPos.row;
136+
137+
if (oldCol == 1 && oldRow >= 1) {
138+
oldCol = 9;
139+
oldRow--;
140+
} else {
141+
oldCol--;
142+
}
143+
144+
return new Slot(oldRow, oldCol);
145+
}
146+
},
147+
148+
BACKWARDS_VERTICAL {
149+
@Override
150+
public Slot shift(Slot oldPos, int maxRows) {
151+
int oldCol = oldPos.col;
152+
int oldRow = oldPos.row;
153+
154+
if (oldCol > 1 && oldRow < 6) {
155+
oldCol--;
156+
oldRow = 6;
157+
} else {
158+
oldRow--;
159+
}
160+
161+
return new Slot(oldRow, oldCol);
162+
}
163+
};
164+
165+
/**
166+
* Shifting the slot "oldPos" by "maxRows" to the next slot.
167+
*
168+
* @param oldPos the old position to shift FROM
169+
* @param maxRows the maximum amount of rows the menu may have
170+
* @return the shifted position that can AND will depend on the {@link IterationDirection} direction
171+
* <p>How different directions work:</p>
172+
* <p></p>
173+
* HORIZONTAL: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, etc.
174+
* <p></p>
175+
* VERTICAL: 0, 9, 18, 27, 36, 45, 1, 10, etc.
176+
* <p></p>
177+
* UPWARDS_ONLY: 45, 36, 27, 18, 9, 0.
178+
* <p></p>
179+
* DOWNWARDS_ONLY: 0, 9, 18, 27, 36, 45.
180+
* <p></p>
181+
* RIGHT_ONLY: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
182+
* <p></p>
183+
* LEFT_ONLY: 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
184+
* <p></p>
185+
* RIGHT_UPWARDS_ONLY: 45, 37, 29, 21, 13, 5, 0.
186+
* <p></p>
187+
* RIGHT_DOWNWARDS_ONLY: 0, 10, 20, 30, 40, 50.
188+
* <p></p>
189+
* LEFT_UPWARDS: 53, 44, 35, 26, 17, 8, 0.
190+
* <p></p>
191+
* LEFT_DOWNWARDS: 7, 16, 25, 34, 40, 48.
192+
* <p></p>
193+
* BACKWARDS_HORIZONTAL: 53, 52, 51, 50, 49, etc.
194+
* <p></p>
195+
* BACKWARDS_VERTICAL: 53, 44, 35, 26, 17, 17, 8, 52, etc.
196+
*
197+
*/
198+
public abstract Slot shift(Slot oldPos, int maxRows);
199+
}

0 commit comments

Comments
 (0)