Skip to content

Commit c36c21d

Browse files
committed
Make menu navigable, as well as items clickable.
1 parent b25e512 commit c36c21d

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/main/java/Flameborn/InSpire/Access/AContainer.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package Flameborn.InSpire.Access;
22

3+
import Flameborn.InSpire.InSpire;
34
import Flameborn.InSpire.utils.Reflection;
45
import Flameborn.InSpire.utils.Speech;
6+
import com.megacrit.cardcrawl.core.CardCrawlGame;
57
import com.megacrit.cardcrawl.helpers.Hitbox;
68
import java.util.ArrayList;
79

@@ -21,6 +23,7 @@ public void add(Object item, AObject.Types type) {
2123
obj.type = type;
2224
if (Reflection.hasField(item, "label") && Reflection.isPrivate(item, "label")) {
2325
obj.label = (String) Reflection.getPrivate(item, item.getClass(), "label");
26+
InSpire.logger.info(obj.label);
2427
}
2528
this.items.add(obj);
2629
}
@@ -31,8 +34,7 @@ public AObject curItem() {
3134

3235
public void readCurItem() {
3336
AObject o = this.curItem();
34-
this.handleHitbox(o.hb);
35-
Speech.speak(o.label);
37+
Speech.speak(o.label, true);
3638
}
3739

3840
public void handleHitbox(Hitbox hb) {
@@ -42,13 +44,27 @@ public void handleHitbox(Hitbox hb) {
4244

4345
public void prevItem() {
4446
this.index--;
45-
if (this.index < 0) this.index = 0;
47+
if (this.index < 0) {
48+
this.index = 0;
49+
return;
50+
}
4651
this.readCurItem();
52+
CardCrawlGame.sound.play("UI_HOVER", 0.75f);
4753
}
4854

4955
public void nextItem() {
5056
this.index++;
51-
if (this.index > items.size() - 1) this.index = this.items.size() - 1;
57+
if (this.index > items.size() - 1) {
58+
this.index = this.items.size() - 1;
59+
return;
60+
}
5261
this.readCurItem();
62+
CardCrawlGame.sound.play("UI_HOVER");
63+
}
64+
65+
public void activateItem() {
66+
if (this.curItem().hb == null) return;
67+
CardCrawlGame.sound.playA("UI_CLICK_1", -0.1f);
68+
this.curItem().hb.clicked = true;
5369
}
5470
}

src/main/java/Flameborn/InSpire/utils/Reflection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static Object getField(Object obj, String fieldName) {
3232
}
3333

3434
public static boolean hasField(Object object, String fieldName) {
35-
return Arrays.stream(object.getClass().getFields())
35+
return Arrays.stream(object.getClass().getDeclaredFields())
3636
.anyMatch(f -> f.getName().equals(fieldName));
3737
}
3838

src/main/java/Flameborn/InSpire/utils/autil.java

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public static void checkKeys() {
3636
if (InputActionSet.down.isJustPressed()) {
3737
curContainer().nextItem();
3838
}
39+
40+
if (InputActionSet.confirm.isJustPressed()) {
41+
curContainer().activateItem();
42+
}
3943
}
4044

4145
public enum Screens {

0 commit comments

Comments
 (0)