Skip to content

Commit

Permalink
chore: bit of code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Sep 9, 2024
1 parent fd6aa94 commit d7cf41b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ public ChunkScreenPanel(ChunkScreen panel) {

this.isAdminEnabled = Minecraft.getInstance().isSingleplayer();


MapManager.getInstance().ifPresent(m -> m.updateAllRegions(false));

alignWidgets();

}

public static void notifyChunkUpdates(int totalChunks, int changedChunks, EnumMap<ClaimResult.StandardProblem, Integer> problems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class WaypointEditorScreen extends AbstractButtonListScreen {
private final Map<ResourceKey<Level>, Boolean> collapsed = new HashMap<>();
private final Map<ResourceKey<Level>, List<WaypointImpl>> waypoints = new HashMap<>();
private final Button buttonCollapseAll, buttonExpandAll;
private int widestWp = 0;
private int widestWaypoint = 0;

public WaypointEditorScreen() {
showBottomPanel(false);
Expand All @@ -56,19 +56,19 @@ public WaypointEditorScreen() {
waypoints.put(resourceKeyListEntry.getKey(), new ArrayList<>(resourceKeyListEntry.getValue()));
}

calcWidestWpText();
computeWaypointTextWidth();

buttonExpandAll = new SimpleButton(topPanel, List.of(Component.translatable("gui.expand_all"), hotkeyTooltip("="), hotkeyTooltip("+")), Icons.UP,
(widget, button) -> toggleAll(true));
buttonCollapseAll = new SimpleButton(topPanel, List.of(Component.translatable("gui.collapse_all"), hotkeyTooltip("-")), Icons.DOWN,
(widget, button) -> toggleAll(false));
}

private void calcWidestWpText() {
widestWp = 0;
private void computeWaypointTextWidth() {
widestWaypoint = 0;
for (var dimKey : waypoints.entrySet()) {
for (var wp : dimKey.getValue()) {
widestWp = Math.max(widestWp, getTheme().getStringWidth(wp.getName()));
widestWaypoint = Math.max(widestWaypoint, getTheme().getStringWidth(wp.getName()));
}
}
}
Expand All @@ -94,7 +94,7 @@ protected void doAccept() {

@Override
public boolean onInit() {
setWidth(Mth.clamp(widestWp + 80, 220, getScreen().getGuiScaledWidth() * 4 / 5));
setWidth(Mth.clamp(widestWaypoint + 80, 220, getScreen().getGuiScaledWidth() * 4 / 5));
setHeight(getScreen().getGuiScaledHeight() * 4 / 5);
return true;
}
Expand Down Expand Up @@ -306,7 +306,7 @@ public boolean mousePressed(MouseButton button) {
if (accepted) {
wp.setName(config.getValue());
}
calcWidestWpText();
computeWaypointTextWidth();
openGui();
});
}));
Expand Down

0 comments on commit d7cf41b

Please sign in to comment.