Skip to content

Commit

Permalink
Deleted methods that did the same thing
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Aug 21, 2023
1 parent 1ab3589 commit f64ea5f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mods.railcraft.client.gui.screen;

import mods.railcraft.Translations;
import mods.railcraft.client.util.GuiUtil;
import mods.railcraft.network.NetworkChannel;
import mods.railcraft.network.play.SetEmbarkingTrackAttributesMessage;
import mods.railcraft.world.level.block.track.outfitted.EmbarkingTrackBlock;
Expand Down Expand Up @@ -54,8 +55,8 @@ private void updateButtons() {

@Override
protected void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
this.drawCenteredString(guiGraphics,
Component.translatable(Translations.Screen.EMBARKING_TRACK_RADIUS, this.radius),
this.windowWidth / 2, 25);
var componentRadius =
Component.translatable(Translations.Screen.EMBARKING_TRACK_RADIUS, this.radius);
GuiUtil.drawCenteredString(guiGraphics, this.font, componentRadius, this.windowWidth, 25);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY, fl
var help = Component.translatable(Translations.Screen.GOLDEN_TICKET_HELP)
.withStyle(ChatFormatting.BLACK);

drawCenteredString(guiGraphics, about, 15, false);
GuiUtil.drawCenteredString(guiGraphics, font, about, windowWidth, 15);
guiGraphics.drawWordWrap(this.font, help, 15, 30, 230, IngameWindowScreen.TEXT_COLOR);
this.helpButton.setMessage(CommonComponents.GUI_BACK);
} else {
Expand All @@ -96,10 +96,10 @@ protected void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY, fl
var poseStack = guiGraphics.pose();
poseStack.pushPose();
poseStack.scale(2, 2, 2);
drawCenteredString(guiGraphics, title, IMAGE_WIDTH / 2, 8, true);
GuiUtil.drawCenteredString(guiGraphics, font, title, IMAGE_WIDTH / 2, 8, true);
poseStack.popPose();
drawCenteredString(guiGraphics, desc1, 45, false);
drawCenteredString(guiGraphics, desc2, 60, false);
GuiUtil.drawCenteredString(guiGraphics, font, desc1, windowWidth, 45);
GuiUtil.drawCenteredString(guiGraphics, font, desc2, windowWidth, 60);
this.editBoxDest.setVisible(true);
this.helpButton.setMessage(Component.translatable(Translations.Screen.HELP));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package mods.railcraft.client.gui.screen;

import mods.railcraft.Railcraft;
import mods.railcraft.client.util.GuiUtil;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;

public class IngameWindowScreen extends Screen {

Expand Down Expand Up @@ -50,7 +50,7 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
var poseStack = guiGraphics.pose();
poseStack.pushPose();
poseStack.translate(centredX, centredY, 0.0F);
this.drawCenteredString(guiGraphics, this.title, this.windowWidth / 2, this.font.lineHeight);
GuiUtil.drawCenteredString(guiGraphics, this.font, this.title, this.windowWidth, this.font.lineHeight);
this.renderContent(guiGraphics, mouseX, mouseY, partialTicks);
poseStack.popPose();
super.render(guiGraphics, mouseX, mouseY, partialTicks);
Expand All @@ -67,21 +67,4 @@ public void tick() {
this.onClose();
}
}

public void drawCenteredString(GuiGraphics guiGraphics, Component text, float x, float y) {
FormattedCharSequence orderedText = text.getVisualOrderText();
guiGraphics.drawString(this.font, orderedText, x - (float) this.font.width(orderedText) / 2, y,
TEXT_COLOR, false);
}

public void drawCenteredString(GuiGraphics guiGraphics, Component component, int y, boolean shadow) {
drawCenteredString(guiGraphics, component, windowWidth, y, shadow);
}

public void drawCenteredString(GuiGraphics guiGraphics, Component component, int width, int y,
boolean shadow) {
int length = font.width(component);
int x = width / 2 - length / 2;
guiGraphics.drawString(font, component, x, y, TEXT_COLOR, shadow);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mods.railcraft.RailcraftConfig;
import mods.railcraft.Translations;
import mods.railcraft.client.util.GuiUtil;
import mods.railcraft.network.NetworkChannel;
import mods.railcraft.network.play.SetLauncherTrackAttributesMessage;
import mods.railcraft.world.level.block.entity.track.LauncherTrackBlockEntity;
Expand Down Expand Up @@ -44,9 +45,9 @@ public void init() {
@Override
protected void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY,
float partialTicks) {
this.drawCenteredString(guiGraphics,
Component.translatable(Translations.Screen.LAUNCHER_TRACK_LAUNCH_FORCE,
this.track.getLaunchForce()), this.windowWidth / 2, 25);
var componentForce = Component.translatable(Translations.Screen.LAUNCHER_TRACK_LAUNCH_FORCE,
this.track.getLaunchForce());
GuiUtil.drawCenteredString(guiGraphics, this.font, componentForce, this.windowWidth, 25);
}

private void incrementForce(int incrementAmount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mods.railcraft.Translations;
import mods.railcraft.client.gui.widget.button.ButtonTexture;
import mods.railcraft.client.gui.widget.button.MultiButton;
import mods.railcraft.client.util.GuiUtil;
import mods.railcraft.network.NetworkChannel;
import mods.railcraft.network.play.SetSignalCapacitorBoxAttributesMessage;
import mods.railcraft.world.level.block.entity.signal.SignalCapacitorBoxBlockEntity;
Expand Down Expand Up @@ -52,9 +53,10 @@ public void init() {
@Override
protected void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY,
float partialTicks) {
this.drawCenteredString(guiGraphics,
var componentDuration =
Component.translatable(Translations.Screen.SIGNAL_CAPACITOR_BOX_DURATION,
this.signalBox.getTicksToPower() / 20), this.windowWidth / 2, 25);
this.signalBox.getTicksToPower() / 20);
GuiUtil.drawCenteredString(guiGraphics, this.font, componentDuration, this.windowWidth, 25);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mods.railcraft.Translations;
import mods.railcraft.api.signal.SignalAspect;
import mods.railcraft.client.util.GuiUtil;
import mods.railcraft.network.NetworkChannel;
import mods.railcraft.network.play.SetSignalControllerBoxAttributesMessage;
import mods.railcraft.world.level.block.entity.signal.SignalControllerBoxBlockEntity;
Expand Down Expand Up @@ -48,16 +49,16 @@ public void init() {
@Override
protected void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY,
float partialTicks) {
this.drawCenteredString(guiGraphics,
GuiUtil.drawCenteredString(guiGraphics, this.font,
Component.translatable(Translations.Screen.SINGAL_CONTROLLER_BOX_DEFAULT),
this.windowWidth / 2, 25);
this.drawCenteredString(guiGraphics, this.defaultAspect.getDisplayName(),
this.windowWidth / 2, 35);
this.drawCenteredString(guiGraphics,
this.windowWidth, 25);
GuiUtil.drawCenteredString(guiGraphics, this.font,
this.defaultAspect.getDisplayName(), this.windowWidth, 35);
GuiUtil.drawCenteredString(guiGraphics, this.font,
Component.translatable(Translations.Screen.SINGAL_CONTROLLER_BOX_POWERED),
this.windowWidth / 2, 60);
this.drawCenteredString(guiGraphics, this.poweredAspect.getDisplayName(),
this.windowWidth / 2, 70);
this.windowWidth, 60);
GuiUtil.drawCenteredString(guiGraphics, this.font,
this.poweredAspect.getDisplayName(), this.windowWidth, 70);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderLabels(guiGraphics, mouseX, mouseY);
guiGraphics.drawString(this.font, PATTERN, 8, 23, IngameWindowScreen.TEXT_COLOR, false);
guiGraphics.drawString(this.font, STOCK, 125, 21, IngameWindowScreen.TEXT_COLOR, false);

//guiGraphics.drawString(this.font, UNDER, 125, 21, IngameWindowScreen.TEXT_COLOR, false);
//guiGraphics.drawString(this.font, SIDES, 125, 21, IngameWindowScreen.TEXT_COLOR, false);

GuiUtil.drawCenteredString(guiGraphics, this.font, UNDER, imageWidth, 23, false);
GuiUtil.drawCenteredString(guiGraphics, this.font, SIDES, imageWidth, 65, false);
GuiUtil.drawCenteredString(guiGraphics, this.font, UNDER, imageWidth, 23);
GuiUtil.drawCenteredString(guiGraphics, this.font, SIDES, imageWidth, 65);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/mods/railcraft/client/util/GuiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public static void drawCenteredString(GuiGraphics guiGraphics, Font font, Compon
int x = windowWidth / 2 - length / 2;
guiGraphics.drawString(font, component, x, y, IngameWindowScreen.TEXT_COLOR, shadow);
}

public static void drawCenteredString(GuiGraphics guiGraphics, Font font, Component component,
int windowWidth, int y) {
drawCenteredString(guiGraphics, font, component, windowWidth, y, false);
}
}

0 comments on commit f64ea5f

Please sign in to comment.