Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2101.1.30]

### Added
* Added support for read-only config viewing in `EditConfigScreen`
* Can be used to allow regular non-admin players to see server configs but not edit them
* Select screen for enum-based config values now has better width and height (based on number of entries and max entry name length)

### Fixed
* Modal Panel gui elements didn't have their tick() method called via `BaseScreen`

## [2101.1.29]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dev.ftb.mods.ftblibrary.util.TooltipList;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.Nullable;

public class EnumConfig<E> extends ConfigWithVariants<E> {
Expand Down Expand Up @@ -89,9 +90,13 @@ public Icon getIcon(@Nullable E v) {

private class EnumSelectScreen extends AbstractButtonListScreen {
private final Panel parent;
private int maxWidth = 176;

public EnumSelectScreen(Panel parent) {
this.parent = parent;
for (var v : nameMap) {
maxWidth = Math.max(maxWidth, getTheme().getStringWidth(nameMap.getDisplayName(v)));
}
}

@Override
Expand All @@ -108,6 +113,15 @@ public void onClicked(MouseButton button) {
}
}

@Override
public boolean onInit() {
setSize(
Mth.clamp(maxWidth + 35, 176, getWindow().getGuiScaledWidth() * 3 / 4),
Mth.clamp(nameMap.size() * 20 + 50, 166, getWindow().getGuiScaledHeight() * 4 / 5)
);
return super.onInit();
}

@Override
protected void doCancel() {
parent.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ private static void onClientStarted(Minecraft minecraft) {
}

public static void editConfig(String configName) {
editConfig(configName, false);
}

public static void editConfig(String configName, boolean isReadOnly) {
ConfigManager.getInstance().createConfigGroup(configName)
.ifPresent(group -> new EditConfigScreen(group).setAutoclose(true).openGui());
.ifPresent(group -> new EditConfigScreen(group, isReadOnly).setAutoclose(true).openGui());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ public class EditConfigScreen extends AbstractThreePanelScreen<EditConfigScreen.
private int widestValue = 0;
private boolean changed = false;
private boolean openPrevScreenOnClose = true;
private final boolean readOnly;

public EditConfigScreen(ConfigGroup configGroup) {
this(configGroup, false);
}

public EditConfigScreen(ConfigGroup configGroup, boolean readOnly) {
super();

this.readOnly = readOnly;
group = configGroup;
title = configGroup.getName().copy().withStyle(ChatFormatting.BOLD);
MutableComponent baseTitle = configGroup.getName().copy().withStyle(ChatFormatting.BOLD);
title = readOnly ? baseTitle.append(" (").append(Component.translatable("ftblibrary.read_only")).append(")") : baseTitle;
allConfigButtons = new ArrayList<>();

List<ConfigValue<?>> list = new ArrayList<>();
Expand Down Expand Up @@ -148,7 +155,7 @@ protected ConfigPanel createMainPanel() {

@Override
protected void doAccept() {
group.save(true);
if (!readOnly) group.save(true);
if (autoclose) closeGui(openPrevScreenOnClose);
}

Expand Down Expand Up @@ -300,7 +307,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)

@Override
public void onClicked(MouseButton button) {
if (getMouseY() >= 20) {
if (!readOnly && getMouseY() >= 20) {
playClickSound();
configValue.onClicked(this, button, accepted -> {
if (accepted) changed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ public boolean anyModalPanelOpen() {
return !modalPanels.isEmpty();
}

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

modalPanels.forEach(Panel::tick);
}

@Nullable
public Screen getPrevScreen() {
if (prevScreen instanceof ScreenWrapper sw && sw.getGui() instanceof LoadingScreen) {
Expand Down Expand Up @@ -314,7 +321,7 @@ public final void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, i
graphics.pose().popPose();

setOnlyRenderWidgetsInside(r);
setOnlyRenderWidgetsInside(i);
setOnlyInteractWithWidgetsInside(i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"item.ftblibrary.fluid_container.use": "Right-click on a tank to empty the container",
"ftblibrary.mb": "%d mB of %s",
"ftblibrary.empty": "Empty",
"ftblibrary.read_only": "read-only",
"ftblibrary.gui.listSize1": "1 item",
"ftblibrary.gui.listSize": "%d items",
"ftblibrary.gui.error": "Error!",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false
# Mod
mod_id=ftblibrary
readable_name=FTB Library
mod_version=2101.1.29
mod_version=2101.1.30
mod_author=FTB Team
# Maven
archives_base_name=ftb-library
Expand Down