Skip to content

Commit

Permalink
Update sorting to function when adding other components
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Aug 5, 2024
1 parent d239919 commit afd66d0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Changes 🌽
- Fixed issue with the new attribute **Focus** not being recognized in `RefundFactory`.
- Updated mixinextras directly in the mod to 0.4.0.
- Fixed out-of-bounds exception when registering a menu.
- Renamed `rootComponent` in `MenuComponent` -> `screenRoot` to refer to the actual screens root.
- If you plan on using this component, know that you can access the functions/members you need directly from the object itself.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parchment_version=1.20.1:2023.09.03
quilt_mappings_version=23

# Mod Properties
mod_version=4.0.0+1.20.1-alpha.10
mod_version=4.0.0+1.20.1-alpha.11
maven_group=com.bibireden.playerex
archives_base_name=playerex-directors-cut

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public final class PlayerEXMenuRegistry {
@NotNull
private static final List<Pair<ResourceLocation, Class<? extends MenuComponent>>> ENTRIES = new ArrayList<>();
private static final ArrayList<Pair<ResourceLocation, Class<? extends MenuComponent>>> ENTRIES = new ArrayList<>();

@NotNull
private static final HashMap<String, Integer> PRIORITY_ORDER = new HashMap<>();
Expand All @@ -29,19 +29,12 @@ public final class PlayerEXMenuRegistry {
* which will be applied to the {@link PlayerEXScreen} as a page.
*/
public static void register(ResourceLocation id, @NotNull Class<? extends MenuComponent> menu) {
Integer position = PRIORITY_ORDER.get(id.getNamespace());
if (position != null) {
for (int i = 0; i < ENTRIES.size(); i++) {
ResourceLocation entryId = ENTRIES.get(i).getFirst();
if (PRIORITY_ORDER.get(entryId.getNamespace()) >= position) {
position = i + 1;
}
}
ENTRIES.add(position, new Pair<>(id, menu));
}
else {
ENTRIES.add(new Pair<>(id, menu));
}
ENTRIES.add(new Pair<>(id, menu));
ENTRIES.sort((a, b) -> {
var order = PRIORITY_ORDER.getOrDefault(a.getFirst().getNamespace(), Integer.MAX_VALUE);
var order2 = PRIORITY_ORDER.getOrDefault(b.getFirst().getNamespace(), Integer.MAX_VALUE);
return order.compareTo(order2);
});
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class MenuComponent(horizontalSizing: Sizing = Sizing.fill(100), vertic
}

/** Where ui-based logic should occur at, built off of the root of the screen's provided content area. */
abstract fun build(rootComponent: FlowLayout)
abstract fun build(screenRoot: FlowLayout)

fun interface OnLevelUpdated {
fun onLevelUpdated(level: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PlayerEXAttributesMenu : MenuComponent(algorithm = Algorithm.HORIZONTAL) {

}

override fun build(rootComponent: FlowLayout) {
override fun build(screenRoot: FlowLayout) {
val player = client?.player ?: return
val component = playerComponent ?: return

Expand Down

0 comments on commit afd66d0

Please sign in to comment.