Skip to content

Commit

Permalink
Bump MaLiLib / add safer versions for Some GUI Functionality, such as…
Browse files Browse the repository at this point in the history
… GuiTextFieldGeneric
  • Loading branch information
sakura-ryoko committed Jan 12, 2025
1 parent 8164bbe commit ca20468
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 183 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

repositories {
maven { url = 'https://masa.dy.fi/maven' }
maven { url = 'https://maven.terraformersmc.com/releases/' }
maven { url = 'https://maven.terraformersmc.com/releases/' }
maven { url = 'https://jitpack.io' }
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ author = masa
mod_file_name = litematica-fabric

# Current mod version
mod_version = 0.21.999
mod_version = 0.21.999-dev

# Required malilib version
malilib_version = 014f183a6e
malilib_version = 7565079dbc

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 25w02a
minecraft_version = 25w02a
mappings_version = 25w02a+build.6
mappings_version = 25w02a+build.9

fabric_loader_version = 0.16.10
mod_menu_version = 13.0.0-beta.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected void createSelectionEditFields()

int width = 202;
this.textFieldSelectionName = new GuiTextFieldGeneric(x, y + 2, width, 16, this.textRenderer);
this.textFieldSelectionName.setText(this.selection.getName());
this.textFieldSelectionName.setTextWrapper(this.selection.getName());
this.addTextField(this.textFieldSelectionName, new TextFieldListenerDummy());
x += width + 4;
x += this.createButton(x, y, -1, ButtonListener.Type.SET_SELECTION_NAME) + 10;
Expand Down Expand Up @@ -140,7 +140,7 @@ protected int addSubRegionFields(int x, int y)

this.addRenderingDisabledWarning(120, y + 2);

y = this.height - 26;
y = this.getScreenHeight() - 26;

ButtonListenerChangeMenu.ButtonType type = ButtonListenerChangeMenu.ButtonType.AREA_SELECTION_BROWSER;
String label = StringUtils.translate(type.getLabelKey());
Expand All @@ -159,7 +159,7 @@ protected int addSubRegionFields(int x, int y)
type = ButtonListenerChangeMenu.ButtonType.MAIN_MENU;
label = StringUtils.translate(type.getLabelKey());
int buttonWidth = this.getStringWidth(label) + 10;
x = this.width - buttonWidth - 10;
x = this.getScreenWidth() - buttonWidth - 10;
button = new ButtonGeneric(x, y, buttonWidth, 20, label);
this.addButton(button, new ButtonListenerChangeMenu(type, this.getParent()));

Expand All @@ -176,7 +176,7 @@ protected void addRenderingDisabledWarning(int x, int y)
String hotkeyVal = hotkey.getKeybind().getKeysDisplayString();
String str = StringUtils.translate("litematica.warning.area_editor.area_rendering_disabled", configName, hotkeyName, hotkeyVal);
List<String> lines = new ArrayList<>();
int maxLineLength = this.width - x - 20;
int maxLineLength = this.getScreenWidth() - x - 20;
StringUtils.splitTextToLines(lines, str, maxLineLength);
this.addLabel(x, y, maxLineLength, lines.size() * (StringUtils.getFontHeight() + 1), 0xFFFFAA00, lines);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ protected void createCoordinateInput(int x, int y, int width, CoordinateType coo

GuiTextFieldInteger textField = new GuiTextFieldInteger(x + offset, y, width, 16, this.textRenderer);
TextFieldListener listener = new TextFieldListener(coordType, corner, this);
textField.setText(text);
textField.setTextWrapper(text);
this.addTextField(textField, listener);

this.createCoordinateButton(x + offset + width + 4, y, corner, coordType, type);
Expand Down Expand Up @@ -390,7 +390,7 @@ else if (this.getBox() != null)

protected void renameSelection()
{
String newName = this.textFieldSelectionName.getText();
String newName = this.textFieldSelectionName.getTextWrapper();

if (DataManager.getSchematicProjectsManager().hasProjectOpen())
{
Expand Down Expand Up @@ -596,7 +596,7 @@ public TextFieldListener(CoordinateType type, Corner corner, GuiAreaSelectionEdi
@Override
public boolean onTextChange(GuiTextFieldGeneric textField)
{
this.parent.updatePosition(textField.getText(), this.corner, this.type);
this.parent.updatePosition(textField.getTextWrapper(), this.corner, this.type);
return false;
}
}
Expand Down Expand Up @@ -674,13 +674,13 @@ public void onSelectionChange(WidgetCheckBox entry)
@Override
protected int getBrowserWidth()
{
return this.width - 20;
return this.getScreenWidth() - 20;
}

@Override
protected int getBrowserHeight()
{
return this.height - 146;
return this.getScreenHeight() - 146;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected int addSubRegionFields(int x, int y)

int width = 202;
this.textFieldBoxName = new GuiTextFieldGeneric(x, y + 2, width, 16, this.textRenderer);
this.textFieldBoxName.setText(this.getBox().getName());
this.textFieldBoxName.setTextWrapper(this.getBox().getName());
this.addTextField(this.textFieldBoxName, new TextFieldListenerDummy());
this.createButton(x + width + 4, y, -1, ButtonListener.Type.SET_BOX_NAME);
y += 20;
Expand Down Expand Up @@ -82,7 +82,7 @@ protected Box getBox()
protected void renameSubRegion()
{
String oldName = this.selection.getCurrentSubRegionBoxName();
String newName = this.textFieldBoxName.getText();
String newName = this.textFieldBoxName.getTextWrapper();
this.selection.renameSubRegionBox(oldName, newName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected int addSubRegionFields(int x, int y)

int width = 202;
this.textFieldBoxName = new GuiTextFieldGeneric(x, y + 2, width, 16, this.textRenderer);
this.textFieldBoxName.setText(this.getBox().getName());
this.textFieldBoxName.setTextWrapper(this.getBox().getName());
this.addTextField(this.textFieldBoxName, new TextFieldListenerDummy());
this.createButton(x + width + 4, y, -1, ButtonListener.Type.SET_BOX_NAME);
y += 20;
Expand All @@ -64,7 +64,7 @@ protected Box getBox()
protected void renameSubRegion()
{
String oldName = this.box.getName();
String newName = this.textFieldBoxName.getText();
String newName = this.textFieldBoxName.getTextWrapper();
this.selection.renameSubRegionBox(oldName, newName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public GuiAreaSelectionManager()
@Override
protected int getBrowserWidth()
{
return this.width - 20;
return this.getScreenWidth() - 20;
}

@Override
protected int getBrowserHeight()
{
return this.height - 68;
return this.getScreenHeight() - 68;
}

@Override
Expand All @@ -67,7 +67,7 @@ protected void reCreateGuiElements()
this.clearButtons();
this.clearWidgets();

int x = this.width - 13;
int x = this.getScreenWidth() - 13;
int y = 24;

ButtonListenerChangeMenu.ButtonType type = ButtonListenerChangeMenu.ButtonType.AREA_EDITOR;
Expand All @@ -90,7 +90,7 @@ protected void reCreateGuiElements()
currentSelection = FileUtils.getNameWithoutExtension(currentSelection.substring(len + 1));
String str = StringUtils.translate("litematica.gui.label.area_selection_manager.current_selection", currentSelection);
int w = this.getStringWidth(str);
this.addLabel(10, this.height - 15, w, 14, 0xFFFFFFFF, str);
this.addLabel(10, this.getScreenHeight() - 15, w, 14, 0xFFFFFFFF, str);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/dy/masa/litematica/gui/GuiMainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void initGui()
label = StringUtils.translate("litematica.gui.button.tool_mode", DataManager.getToolMode().getName());
int width2 = this.getStringWidth(label) + 10;

y = this.height - 26;
y = this.getScreenHeight() - 26;
button = new ButtonGeneric(x, y, width2, 20, label);
this.addButton(button, new ButtonListenerCycleToolMode(this));

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/fi/dy/masa/litematica/gui/GuiMaterialList.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ public GuiMaterialList(MaterialListBase materialList)
@Override
protected int getBrowserWidth()
{
return this.width - 20;
return this.getScreenWidth() - 20;
}

@Override
protected int getBrowserHeight()
{
return this.height - 80;
return this.getScreenHeight() - 80;
}

@Override
public void initGui()
{
super.initGui();

boolean isNarrow = this.width < this.getElementTotalWidth();
boolean isNarrow = this.getScreenWidth() < this.getElementTotalWidth();

int x = 12;
int y = 24;
Expand All @@ -84,14 +84,14 @@ public void initGui()

String str = StringUtils.translate("litematica.gui.label.material_list.multiplier");
int w = this.getStringWidth(str);
this.addLabel(this.width - w - 56, y + 5, w, 12, 0xFFFFFFFF, str);
this.addLabel(this.getScreenWidth() - w - 56, y + 5, w, 12, 0xFFFFFFFF, str);

GuiTextFieldInteger tf = new GuiTextFieldInteger(this.width - 52, y + 2, 40, 16, this.textRenderer);
tf.setText(String.valueOf(this.materialList.getMultiplier()));
GuiTextFieldInteger tf = new GuiTextFieldInteger(this.getScreenWidth() - 52, y + 2, 40, 16, this.textRenderer);
tf.setTextWrapper(String.valueOf(this.materialList.getMultiplier()));
MultiplierListener listener = new MultiplierListener(this.materialList, this);
this.addTextField(tf, listener);

this.addWidget(new WidgetInfoIcon(this.width - 23, 10, Icons.INFO_11, "litematica.info.material_list"));
this.addWidget(new WidgetInfoIcon(this.getScreenWidth() - 23, 10, Icons.INFO_11, "litematica.info.material_list"));

int gap = 1;
x += this.createButton(x, y, -1, ButtonListener.Type.REFRESH_LIST) + gap;
Expand All @@ -107,19 +107,19 @@ public void initGui()
if (isNarrow)
{
x = 12;
y = this.height - 22;
y = this.getScreenHeight() - 22;
}

x += this.createButton(x, y, -1, ButtonListener.Type.CLEAR_IGNORED) + gap;
x += this.createButton(x, y, -1, ButtonListener.Type.CLEAR_CACHE) + gap;
x += this.createButton(x, y, -1, ButtonListener.Type.WRITE_TO_FILE) + gap;
y += 22;

y = this.height - 36;
y = this.getScreenHeight() - 36;
ButtonListenerChangeMenu.ButtonType type = ButtonListenerChangeMenu.ButtonType.MAIN_MENU;
label = StringUtils.translate(type.getLabelKey());
buttonWidth = this.getStringWidth(label) + 20;
x = this.width - buttonWidth - 10;
x = this.getScreenWidth() - buttonWidth - 10;
button = new ButtonGeneric(x, y, buttonWidth, 20, label);
this.addButton(button, new ButtonListenerChangeMenu(type, this.getParent()));

Expand Down Expand Up @@ -150,7 +150,7 @@ public void initGui()

str = strt + " / " + StringUtils.translate("litematica.gui.label.material_list.progress", strp);
w = this.getStringWidth(str);
this.addLabel(12, this.height - 36, w, 12, 0xFFFFFFFF, str);
this.addLabel(12, this.getScreenHeight() - 36, w, 12, 0xFFFFFFFF, str);
}
}

Expand Down Expand Up @@ -380,7 +380,7 @@ public boolean onTextChange(GuiTextFieldInteger textField)
{
try
{
int multiplier = Integer.parseInt(textField.getText());
int multiplier = Integer.parseInt(textField.getTextWrapper());

if (multiplier != this.materialList.getMultiplier())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public GuiPlacementConfiguration(SchematicPlacement placement)
@Override
protected int getBrowserWidth()
{
return this.width - 150;
return this.getScreenWidth() - 150;
}

@Override
protected int getBrowserHeight()
{
return this.height - 84;
return this.getScreenHeight() - 84;
}

@Override
Expand All @@ -68,8 +68,8 @@ public void initGui()
int y = 22;

this.textFieldRename = new GuiTextFieldGeneric(x, y + 2, width, 16, this.textRenderer);
this.textFieldRename.setMaxLength(256);
this.textFieldRename.setText(this.placement.getName());
this.textFieldRename.setMaxLengthWrapper(256);
this.textFieldRename.setTextWrapper(this.placement.getName());
this.addTextField(this.textFieldRename, null);
this.createButton(x + width + 4, y, -1, ButtonListener.Type.RENAME_PLACEMENT);

Expand All @@ -81,7 +81,7 @@ public void initGui()
this.createButton(x, y + 22, -1, ButtonListener.Type.TOGGLE_ALL_REGIONS_ON);

width = 120;
x = this.width - width - 10;
x = this.getScreenWidth() - width - 10;

this.createButtonOnOff(x, y, width - 22, this.placement.isEnabled(), ButtonListener.Type.TOGGLE_ENABLED);
this.createButton(x + width - 20, y, 20, ButtonListener.Type.TOGGLE_RENDERING);
Expand Down Expand Up @@ -130,7 +130,7 @@ public void initGui()
if (GuiUtils.getScaledWindowHeight() < 328)
{
x = 10;
y = this.height - 22;
y = this.getScreenHeight() - 22;

x += this.createButton(x, y, -1, ButtonListener.Type.OPEN_MATERIAL_LIST_GUI) + 1;
x += this.createButton(x, y, -1, ButtonListener.Type.OPEN_VERIFIER_GUI) + 1;
Expand All @@ -153,7 +153,7 @@ public void initGui()
type = ButtonListenerChangeMenu.ButtonType.SCHEMATIC_PLACEMENTS;
label = StringUtils.translate(type.getLabelKey());
int buttonWidth = this.getStringWidth(label) + 10;
x = this.width - buttonWidth - 9;
x = this.getScreenWidth() - buttonWidth - 9;
ButtonGeneric button = new ButtonGeneric(x, y, buttonWidth, 20, label);
this.addButton(button, new ButtonListenerChangeMenu(type, this.getParent()));
}
Expand All @@ -178,7 +178,7 @@ protected void createCoordinateInput(int x, int y, int width, CoordinateType typ
}

GuiTextFieldInteger textField = new GuiTextFieldInteger(x + offset, y + 2, width, 14, this.textRenderer);
textField.setText(text);
textField.setTextWrapper(text);
TextFieldListener listener = new TextFieldListener(type, this.placement, this);
this.addTextField(textField, listener);

Expand Down Expand Up @@ -354,7 +354,7 @@ public void actionPerformedWithButton(ButtonBase button, int mouseButton)
switch (this.type)
{
case RENAME_PLACEMENT:
this.placement.setName(this.parent.textFieldRename.getText());
this.placement.setName(this.parent.textFieldRename.getTextWrapper());
break;

case ROTATE:
Expand Down Expand Up @@ -517,7 +517,7 @@ public boolean onTextChange(GuiTextFieldInteger textField)
{
try
{
int value = Integer.parseInt(textField.getText());
int value = Integer.parseInt(textField.getTextWrapper());
BlockPos posOld = this.placement.getOrigin();
this.parent.setNextMessageType(MessageType.ERROR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ protected WidgetSchematicBrowser createListWidget(int listX, int listY)

/**
* This is the string the DataManager uses for saving/loading/storing the last used directory
* for each browser GUI type/contet.
* @return
* for each browser GUI type/context.
* @return ()
*/
public abstract String getBrowserContext();

Expand All @@ -41,13 +41,13 @@ protected ISelectionListener<DirectoryEntry> getSelectionListener()
@Override
protected int getBrowserWidth()
{
return this.width - 20;
return this.getScreenWidth() - 20;
}

@Override
protected int getBrowserHeight()
{
return this.height - 70;
return this.getScreenHeight() - 70;
}

public int getMaxInfoHeight()
Expand Down
Loading

0 comments on commit ca20468

Please sign in to comment.