Skip to content

Commit

Permalink
Removed Screen.getContent()
Browse files Browse the repository at this point in the history
  • Loading branch information
SmylerMC committed Jun 7, 2024
1 parent 260bd9a commit e0e481f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,68 +142,67 @@ public void init() {
float width = this.getWidth();
float height = this.getHeight();

WidgetContainer content = this.getContent();
content.removeAllWidgets();
this.removeAllWidgets();
this.map.setPosition(0, 0);
this.map.setSize(width, height);
this.map.setTileScaling(TerramapConfig.CLIENT.getEffectiveTileScaling());

content.addWidget(this.map);
this.addWidget(this.map);

// Map control buttons
this.closeButton.setX(width - this.closeButton.getWidth() - 5).setY(5);
this.closeButton.setOnClick(() -> Minecraft.getMinecraft().displayGuiScreen(this.parent));
this.closeButton.setTooltip(translator.format("terramap.terramapscreen.buttons.close.tooltip"));
this.closeButton.enable();
content.addWidget(this.closeButton);
this.addWidget(this.closeButton);
this.compass.setOnClick(() -> this.map.getController().setRotation(0f, true));
this.compass.setFadeAwayOnZero(true);
this.compass.setTooltip(translator.format("terramap.terramapscreen.buttons.compass.tooltip"));
this.compass.setX(this.closeButton.getX());
this.compass.setY(this.closeButton.getY() + this.closeButton.getHeight() + 5);
this.compass.setSize(this.closeButton.getWidth());
content.addWidget(this.compass);
this.addWidget(this.compass);
this.zoomInButton.setX(this.compass.getX()).setY(this.compass.getY() + this.compass.getHeight() + 5);
this.zoomInButton.setOnClick(() -> {
this.map.getController().setZoomStaticLocation(this.map.getController().getCenterLocation());
this.map.getController().zoom(1, true);
});
this.zoomInButton.setTooltip(translator.format("terramap.terramapscreen.buttons.zoomin.tooltip"));
this.zoomInButton.enable();
content.addWidget(this.zoomInButton);
this.addWidget(this.zoomInButton);
this.zoomText = new TextWidget(49, game.defaultFont());
this.zoomText.setAnchorX(this.zoomInButton.getX() + this.zoomInButton.getWidth() / 2 + 1).setAnchorY(this.zoomInButton.getY() + this.zoomInButton.getHeight() + 2);
this.zoomText.setAlignment(TextAlignment.CENTER).setBackgroundColor(Color.DARKER_OVERLAY).setPadding(3);
this.zoomText.setVisibility(!this.f1Mode);
content.addWidget(this.zoomText);
this.addWidget(this.zoomText);
this.zoomOutButton.setX(this.zoomInButton.getX()).setY(this.zoomText.getY() + zoomText.getHeight() + 2);
this.zoomOutButton.setOnClick(() -> {
this.map.getController().setZoomStaticLocation(this.map.getController().getCenterLocation());
this.map.getController().zoom(-1, true);
});
this.zoomOutButton.setTooltip(translator.format("terramap.terramapscreen.buttons.zoomout.tooltip"));
this.zoomOutButton.enable();
content.addWidget(this.zoomOutButton);
this.addWidget(this.zoomOutButton);
this.centerButton.setX(this.zoomOutButton.getX()).setY(this.zoomOutButton.getY() + this.zoomOutButton.getHeight() + 15);
this.centerButton.setOnClick(() -> this.map.getController().track(this.map.getMainPlayerMarker()));
this.centerButton.enable();
this.centerButton.setTooltip(translator.format("terramap.terramapscreen.buttons.track.tooltip"));
content.addWidget(this.centerButton);
this.addWidget(this.centerButton);
this.styleButton.setX(this.centerButton.getX()).setY(this.centerButton.getY() + this.centerButton.getHeight() + 5);
this.styleButton.setOnClick(this.stylePanel::open);
this.styleButton.setTooltip(translator.format("terramap.terramapscreen.buttons.style.tooltip"));
this.styleButton.enable();
content.addWidget(this.styleButton);
this.addWidget(this.styleButton);
this.offsetWarning.setTooltip(translator.format("terramap.terramapscreen.warning.offset.tooltip"));
content.addWidget(this.offsetWarning.setPosition(this.styleButton.getX(), this.styleButton.getY() + this.styleButton.getHeight() + 5));
this.addWidget(this.offsetWarning.setPosition(this.styleButton.getX(), this.styleButton.getY() + this.styleButton.getHeight() + 5));
this.debugText = new TextWidget(49, game.smallestFont());
this.debugText.setAnchorX(3).setAnchorY(0);
this.debugText.setAlignment(TextAlignment.RIGHT).setBackgroundColor(Color.DARKER_OVERLAY).setPadding(3);
this.debugText.setVisibility(this.debugMode);
content.addWidget(this.debugText);
this.addWidget(this.debugText);

// Info panel
Font infoFont = content.getFont();
Font infoFont = this.getFont();
this.infoPanel.removeAllWidgets();
this.infoPanel.setSize(250, height);
this.infoPanel.setOpenX(0).setOpenY(0).setClosedX(-this.infoPanel.getWidth() + 25).setClosedY(0);
Expand Down Expand Up @@ -257,7 +256,7 @@ public void init() {
//searchButton.enable();
this.infoPanel.addWidget(searchButton);
this.infoPanel.setHeight(this.searchBox.getY() + this.searchBox.getHeight() + 5);
content.addWidget(this.infoPanel);
this.addWidget(this.infoPanel);

// Layers panel
this.layerPanel.removeAllWidgets();
Expand All @@ -270,7 +269,7 @@ public void init() {
this.layerPanel.addWidget(new TextWidget(
this.layerPanel.getWidth() / 2, 7, 1,
ofTranslation("terramap.terramapscreen.layerscreen.title"), TextAlignment.CENTER,
content.getFont()));
this.getFont()));
this.layerPanel.addWidget(new SpriteButtonWidget(
this.layerPanel.getWidth() - 20, 5, 1,
ButtonSprites.CROSS, this.layerPanel::close));
Expand All @@ -287,7 +286,7 @@ public void init() {
buttonWidth,
translator.format("terramap.terramapscreen.layerscreen.new"),
this::openInitialNewLayerSelector));
content.addWidget(this.layerPanel);
this.addWidget(this.layerPanel);

// Style panel
this.stylePanel.setSize(200, height);
Expand All @@ -300,9 +299,9 @@ public void init() {
this.styleScrollbar.setViewPort(height / (this.backgroundStylePanelListContainer.getHeight() - 10f));
if(this.styleScrollbar.getViewPort() >= 1) this.styleScrollbar.setProgress(0);
this.stylePanel.addWidget(this.backgroundStylePanelListContainer);
content.addWidget(this.stylePanel);
this.addWidget(this.stylePanel);

if(TerramapConfig.CLIENT.chatOnMap) content.addWidget(this.chat);
if(TerramapConfig.CLIENT.chatOnMap) this.addWidget(this.chat);

if(!TerramapClientContext.getContext().isInstalledOnServer() && TerramapClientContext.getContext().getProjection() == null && TerramapClientContext.getContext().isOnEarthWorld()) {
StringBuilder warningBuilder = new StringBuilder();
Expand All @@ -315,7 +314,7 @@ public void init() {
c = c.withStyle(style);
TextWidget warningWidget = new TextWidget(150, 0, 1000, 300, c, TextAlignment.CENTER, Color.WHITE, true, game.defaultFont());
warningWidget.setBackgroundColor(Color.DARKER_OVERLAY).setPadding(5).setAnchorY(height - warningWidget.getHeight());
content.addWidget(warningWidget);
this.addWidget(warningWidget);
}

TerramapClientContext.getContext().setupMaps();
Expand Down Expand Up @@ -506,7 +505,7 @@ private void toggleInfoPanel() {

@Override
public void onKeyTyped(char typedChar, Key key, WidgetContainer parent) {
if(this.getContent().getFocusedWidget() == null || (!this.getContent().getFocusedWidget().equals(this.searchBox) && !this.chat.isOpen())) {
if(this.getFocusedWidget() == null || (!this.getFocusedWidget().equals(this.searchBox) && !this.chat.isOpen())) {
MapController controller = this.map.getController();
if(key.code == KeyBindings.TOGGLE_DEBUG.getKeyCode()) this.setDebugMode(!this.debugMode);
if(key.code == Keyboard.KEY_F1) this.setF1Mode(!this.f1Mode);
Expand Down Expand Up @@ -563,7 +562,7 @@ private void openInitialNewLayerSelector() {
Map<String, Runnable> options = MapLayerRegistry.INSTANCE.getRegistrations().values().stream()
.filter(MapLayerRegistry.LayerRegistration::showsOnNewLayerMenu)
.collect(toMap(LayerRegistration::getNewLayerMenuTranslationKey, l -> () -> this.addMapLayer(l.getId())));
this.getContent().scheduleBeforeNextUpdate(() ->
this.scheduleBeforeNextUpdate(() ->
getGameClient().displayPopup(new MultiChoicePopup("terramap.terramapscreen.layerscreen.newlayer", options))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ public HudConfigScreen() {
public void init() {
GameClient game = getGameClient();
Translator translator = game.translator();
WidgetContainer content = this.getContent();
content.removeAllWidgets();
this.removeAllWidgets();

float width = this.getWidth();
float height = this.getHeight();
Expand All @@ -152,7 +151,7 @@ public void init() {
this.compassWindow.setWidth(this.compassWindow.getWidth() / this.lastWidth * width);
}
this.minimapWindow.init();
content.addWidget(this.minimapWindow);
this.addWidget(this.minimapWindow);

// Buttons
this.buttonPanel.addWidget(
Expand Down Expand Up @@ -264,11 +263,11 @@ public void init() {
this.settingsPanel.setOpenY(height - this.settingsPanel.getHeight());

TextWidget explain = new TextWidget(width / 2f, height / 2f - 100f, 10, ofTranslation("terramap.hudconfig.explain"), TextAlignment.CENTER, game.defaultFont());
content.addWidget(explain.setMaxWidth(width * .8f).setAnchorY(height / 2f - explain.getHeight() - 10f));
this.addWidget(explain.setMaxWidth(width * .8f).setAnchorY(height / 2f - explain.getHeight() - 10f));

content.addWidget(this.buttonPanel);
content.addWidget(this.settingsPanel);
content.addWidget(this.compassWindow);
this.addWidget(this.buttonPanel);
this.addWidget(this.settingsPanel);
this.addWidget(this.compassWindow);
this.lastHeight = height;
this.lastWidth = width;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public void init() {
float height = this.getHeight();

int inter = 9;
WidgetContainer content = this.getContent();
content.removeAllWidgets(); //Remove the widgets that were already there
content.cancelAllScheduled(); //Cancel all callbacks that were already there
this.removeAllWidgets(); //Remove the widgets that were already there
this.cancelAllScheduled(); //Cancel all callbacks that were already there
this.title = new TextWidget(width / 2f, 10, 5, ofTranslation("terramap.configmenu.title"), TextAlignment.CENTER, game.defaultFont());
content.addWidget(this.title);
this.addWidget(this.title);
TextButtonWidget save = new TextButtonWidget(
width / 2f + 30, height - 30, 10,
100,
Expand All @@ -89,11 +88,11 @@ public void init() {
50,
translator.format("terramap.configmenu.reset"),
this::reset);
content.addWidget(save.setTooltip(translator.format("terramap.configmenu.save.tooltip")));
content.addWidget(cancel.setTooltip(translator.format("terramap.configmenu.cancel")));
content.addWidget(reset.setTooltip(translator.format("terramap.configmenu.reset")));
content.addWidget(this.next.setX(save.getX() + save.getWidth() + 5).setY(save.getY() + 2));
content.addWidget(this.previous.setX(cancel.getX() - 20).setY(this.next.getY()));
this.addWidget(save.setTooltip(translator.format("terramap.configmenu.save.tooltip")));
this.addWidget(cancel.setTooltip(translator.format("terramap.configmenu.cancel")));
this.addWidget(reset.setTooltip(translator.format("terramap.configmenu.reset")));
this.addWidget(this.next.setX(save.getX() + save.getWidth() + 5).setY(save.getY() + 2));
this.addWidget(this.previous.setX(cancel.getX() - 20).setY(this.next.getY()));
FlexibleWidgetContainer mapConfigScreen = new FlexibleWidgetContainer(20, 20, 1, width - 40, height - 75);
FlexibleWidgetContainer mapStylesConfigScreen = new FlexibleWidgetContainer(20, 20, 1, width - 40, height - 75);
FlexibleWidgetContainer otherConfigScreen = new FlexibleWidgetContainer(20, 20, 1, width - 40, height - 75);
Expand Down Expand Up @@ -191,24 +190,24 @@ public void init() {
otherConfigScreen.addWidget(this.tpCommandField.setX(tpCommandText.getX() + tpCommandText.getWidth() + inter).setY(tpCommandText.getY() - 7));

// Footer
this.getContent().addWidget(this.pages[this.currentSubScreen]);
this.addWidget(this.pages[this.currentSubScreen]);
this.title.setText(ofPlainText(this.titles[this.currentSubScreen]));
this.getContent().addWidget(this.pageText.setAnchorX(width / 2f).setAnchorY(height - 45f).setAlignment(TextAlignment.CENTER));
this.addWidget(this.pageText.setAnchorX(width / 2f).setAnchorY(height - 45f).setAlignment(TextAlignment.CENTER));
this.updateButtons();
}

private void nextPage() {
this.getContent().removeWidget(this.pages[this.currentSubScreen]);
this.removeWidget(this.pages[this.currentSubScreen]);
this.currentSubScreen++;
this.getContent().addWidget(this.pages[this.currentSubScreen]);
this.addWidget(this.pages[this.currentSubScreen]);
this.title.setText(ofPlainText(this.titles[currentSubScreen]));
this.updateButtons();
}

private void previousPage() {
this.getContent().removeWidget(this.pages[this.currentSubScreen]);
this.removeWidget(this.pages[this.currentSubScreen]);
this.currentSubScreen--;
this.getContent().addWidget(this.pages[this.currentSubScreen]);
this.addWidget(this.pages[this.currentSubScreen]);
this.title.setText(ofPlainText(this.titles[currentSubScreen]));
this.updateButtons();
}
Expand Down Expand Up @@ -269,23 +268,22 @@ public ConfirmScreen() {
@Override
public void init() {
Translator translator = getGameClient().translator();
WidgetContainer content = this.getContent();
content.removeAllWidgets();
content.cancelAllScheduled();
TextWidget text = new TextWidget(content.getWidth() / 2, content.getHeight() / 2 - 20, 10, ofTranslation("terramap.configmenu.asksave.prompt"), TextAlignment.CENTER, getGameClient().defaultFont());
content.addWidget(text);
content.addWidget(new TextButtonWidget(
content.getWidth() / 2 - 125, text.getY() + text.getHeight() + 15, 10,
this.removeAllWidgets();
this.cancelAllScheduled();
TextWidget text = new TextWidget(this.getWidth() / 2, this.getHeight() / 2 - 20, 10, ofTranslation("terramap.configmenu.asksave.prompt"), TextAlignment.CENTER, getGameClient().defaultFont());
this.addWidget(text);
this.addWidget(new TextButtonWidget(
this.getWidth() / 2 - 125, text.getY() + text.getHeight() + 15, 10,
80,
translator.format("terramap.configmenu.asksave.deny"),
TerramapConfigScreen.this::close));
content.addWidget(new TextButtonWidget(
content.getWidth() / 2 - 40, text.getY() + text.getHeight() + 15, 10,
this.addWidget(new TextButtonWidget(
this.getWidth() / 2 - 40, text.getY() + text.getHeight() + 15, 10,
80,
translator.format("terramap.configmenu.asksave.cancel"),
() -> getGameClient().displayScreen(TerramapConfigScreen.this)));
content.addWidget(new TextButtonWidget(
content.getWidth() / 2 + 45, text.getY() + text.getHeight() + 15, 10,
this.addWidget(new TextButtonWidget(
this.getWidth() / 2 + 45, text.getY() + text.getHeight() + 15, 10,
80,
translator.format("terramap.configmenu.asksave.confirm"),
TerramapConfigScreen.this::saveAndClose));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import net.smyler.smylib.gui.containers.RootContainer;

import net.smyler.smylib.gui.containers.WidgetContainer;

/**
* A {@link Screen} is where everything happens in SmyLib.
* <br>
* To use this class, add widgets to your screen by retrieving its {@link WidgetContainer} using {@link #getContent()}.
*
* @author Smyler
*/
Expand All @@ -21,11 +18,6 @@ public Screen(BackgroundOption background) {
this.background = background;
}

@Deprecated
public WidgetContainer getContent() {
return this;
}

public boolean shouldPauseGame() {
return false;
}
Expand Down
Loading

0 comments on commit e0e481f

Please sign in to comment.