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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ 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.34]

### Added
* Backport keymapping abstraction system from 26.1
* Support for key modifiers on both NeoForge and Fabric (Fabric support requires the Amecs mod)
* Added `ConfigValue#setCanEdit` variant which takes a `BooleanSupplier`
* Allows more for dynamic updating of config editor screen

### Changed
* Reworked panel scrolling to properly support vanilla's multi-axis scrolling (e.g. simultaneous X/Y scrolling via trackpad)

### Fixed
* Fixed a bug in MultilineTextBox causing widget to blank under certain circumstances (used by FTB Quests quest description editor)

## [2101.1.33]

### Changed
Expand Down
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.10-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "2.0.0-beta.2"
id "architectury-plugin" version "3.5-SNAPSHOT"
id "dev.architectury.loom" version "1.17-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "2.1.1"
}

apply from: 'https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/changelog.gradle'
Expand Down Expand Up @@ -31,15 +31,17 @@ allprojects {

version = project.mod_version
group = project.maven_group
archivesBaseName = project.archives_base_name

base {
archivesName = project.archives_base_name
}

// needs to be done AFTER version is set
apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/publishing.gradle"

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 21

compileJava {
options.encoding = "UTF-8"
options.release = 21
}

repositories {
Expand Down Expand Up @@ -82,6 +84,7 @@ allprojects {

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.0-M1'
testImplementation 'org.junit.platform:junit-platform-launcher:1.14.3'
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import dev.ftb.mods.ftblibrary.icon.Icons;
import dev.ftb.mods.ftblibrary.ui.Widget;
import dev.ftb.mods.ftblibrary.ui.input.MouseButton;
import dev.ftb.mods.ftblibrary.util.BooleanConsumer;
import dev.ftb.mods.ftblibrary.util.TooltipList;
import net.minecraft.ChatFormatting;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;

public abstract class ConfigValue<T> implements Comparable<ConfigValue<T>> {
Expand All @@ -24,7 +26,7 @@ public abstract class ConfigValue<T> implements Comparable<ConfigValue<T>> {
private int order = 0;
private String nameKey = "";
private Icon icon = Icons.SETTINGS;
private boolean canEdit = true;
private BooleanSupplier canEdit = () -> true;

protected static Component info(String key) {
return Component.literal(key + ":").withStyle(ChatFormatting.AQUA);
Expand Down Expand Up @@ -153,10 +155,15 @@ public ConfigValue<T> setOrder(int o) {
}

public boolean getCanEdit() {
return canEdit;
return canEdit.getAsBoolean();
}

public ConfigValue<T> setCanEdit(boolean e) {
canEdit = () -> e;
return this;
}

public ConfigValue<T> setCanEdit(BooleanSupplier e) {
canEdit = e;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,19 @@ public void addMouseOverText(TooltipList list) {

@Override
public void onClicked(MouseButton button) {
playClickSound();
CV listType = listConfig.getType();
listType.setValue(listType.getDefaultValue() == null ? null : listType.copy(listType.getDefaultValue()));
listType.onClicked(this, button, accepted -> {
if (accepted) {
localValues.add(listType.getValue());
changed = true;
}
if (listConfig.getCanEdit()) {
playClickSound();
CV listType = listConfig.getType();
listType.setValue(listType.getDefaultValue() == null ? null : listType.copy(listType.getDefaultValue()));
listType.onClicked(this, button, accepted -> {
if (accepted) {
localValues.add(listType.getValue());
changed = true;
}

openGui();
});
openGui();
});
}
}

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

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

import static dev.ftb.mods.ftblibrary.util.TextComponentUtils.hotkeyTooltip;

Expand Down Expand Up @@ -110,7 +111,7 @@ public boolean onInit() {

allConfigButtons.forEach(w -> {
if (w instanceof ConfigEntryButton<?> eb) {
widestKey = Math.max(widestKey, getTheme().getFont().width(eb.keyText));
widestKey = Math.max(widestKey, getTheme().getFont().width(eb.keyText.get()));
widestValue = Math.max(widestValue, getTheme().getFont().width(eb.getValueStr()));
} else if (w instanceof ConfigGroupButton gb) {
widestGroup.setValue(Math.max(widestGroup.intValue(), getTheme().getStringWidth(gb.title)));
Expand Down Expand Up @@ -265,25 +266,25 @@ public void onClicked(MouseButton button) {
private class ConfigEntryButton<T> extends Button implements EditStringConfigOverlay.PosProvider {
private final ConfigGroupButton groupButton;
private final ConfigValue<T> configValue;
private final Component keyText;
private final Supplier<Component> keyText;

public ConfigEntryButton(Panel panel, ConfigGroupButton groupButton, ConfigValue<T> configValue) {
super(panel);
setHeight(getTheme().getFontHeight() + 2);
this.groupButton = groupButton;
this.configValue = configValue;

keyText = this.configValue.getCanEdit() ?
keyText = () -> this.configValue.getCanEdit() ?
Component.literal(this.configValue.getName()) :
Component.literal(this.configValue.getName()).withStyle(ChatFormatting.GRAY);
Component.literal(this.configValue.getName()).withStyle(ChatFormatting.DARK_GRAY);
}

@Override
public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
Icons.COLOR_BLANK.withColor(Color4I.GRAY).draw(graphics, x, y + 1, 10, 10);
Icons.INFO.draw(graphics, x + 1, y + 2, 8, 8);

theme.drawString(graphics, keyText, x + 13, y + 2, Bits.setFlag(0, Theme.SHADOW, isMouseOver()));
theme.drawString(graphics, keyText.get(), x + 13, y + 2, Bits.setFlag(0, Theme.SHADOW, isMouseOver()));

Component valueText = configValue.getStringForGUI(configValue.getValue());

Expand All @@ -293,7 +294,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
}

var textCol = configValue.getColor().mutable();
textCol.setAlpha(255);
textCol.setAlpha(configValue.getCanEdit() ? 255 : 128);

if (isMouseOver()) {
textCol.addBrightness(60);
Expand All @@ -307,7 +308,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)

@Override
public void onClicked(MouseButton button) {
if (!readOnly && getMouseY() >= 20) {
if (!readOnly && getMouseY() >= 20 && configValue.getCanEdit()) {
playClickSound();
configValue.onClicked(this, button, accepted -> {
if (accepted) changed = true;
Expand All @@ -321,7 +322,7 @@ public void addMouseOverText(TooltipList list) {
if (getMouseY() > 18) {
int x = getMouseX() - getX();
if (x < 16) {
list.add(keyText.copy().withStyle(ChatFormatting.UNDERLINE));
list.add(keyText.get().copy().withStyle(ChatFormatting.UNDERLINE));
var tooltip = configValue.getTooltip();

if (!tooltip.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ public void onEnterPressed() {
}

@Override
public boolean mouseScrolled(double scroll) {
return config.scrollValue(currentValue, scroll > 0).map(v -> {
public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double yDelta) {
var directionlessDelta = xDelta != 0 ? xDelta : yDelta;
return config.scrollValue(currentValue, directionlessDelta > 0).map(v -> {
textBox.setText(config.getStringFromValue(v));
textBox.setSelectionPos(textBox.getCursorPos());
return true;
}).orElse(super.mouseScrolled(scroll));
}).orElse(super.mouseScrolled(mouseX, mouseY, xDelta, yDelta));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.ftb.mods.ftblibrary.config.ui.resource;

import com.google.common.base.Stopwatch;
import com.mojang.datafixers.util.Pair;
import dev.ftb.mods.ftblibrary.FTBLibrary;
import dev.ftb.mods.ftblibrary.config.ConfigCallback;
import dev.ftb.mods.ftblibrary.config.ResourceConfigValue;
Expand All @@ -21,6 +19,8 @@
import dev.ftb.mods.ftblibrary.ui.misc.SimpleToast;
import dev.ftb.mods.ftblibrary.util.SearchTerms;
import dev.ftb.mods.ftblibrary.util.TooltipList;
import com.google.common.base.Stopwatch;
import com.mojang.datafixers.util.Pair;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -347,13 +347,15 @@ public CountTextBox() {
}

@Override
public boolean mouseScrolled(double scroll) {
public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double yDelta) {
if (!isMouseOver) return false;

var directionlessDelta = xDelta != 0 ? xDelta : yDelta;
if (isShiftKeyDown()) {
int adj = scroll > 0 ? getCount() : -getCount() / 2;
int adj = directionlessDelta > 0 ? getCount() : -getCount() / 2;
adjust(adj);
} else {
adjust((int) Math.signum(scroll));
adjust((int) Math.signum(directionlessDelta));
}
return true;
}
Expand Down
17 changes: 14 additions & 3 deletions common/src/main/java/dev/ftb/mods/ftblibrary/snbt/SNBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -72,11 +74,20 @@ public static List<String> writeLines(CompoundTag nbt) {

public static boolean write(Path path, CompoundTag nbt) {
try {
if (Files.notExists(path.getParent())) {
Files.createDirectories(path.getParent());
Path parent = path.getParent();
if (Files.notExists(parent)) {
Files.createDirectories(parent);
}

Files.write(path, writeLines(nbt));
// write to a temp file first and rename into place, so a crash/kill mid-write
// can never leave a truncated/corrupt file at the real path
Path tmp = parent.resolve(path.getFileName().toString() + ".tmp");
Files.write(tmp, writeLines(nbt));
try {
Files.move(tmp, path, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException ex) {
Files.move(tmp, path, StandardCopyOption.REPLACE_EXISTING);
}
return true;
} catch (Exception ex) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions common/src/main/java/dev/ftb/mods/ftblibrary/ui/BaseScreen.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.ftb.mods.ftblibrary.ui;

import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.platform.Window;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import dev.ftb.mods.ftblibrary.ui.input.Key;
import dev.ftb.mods.ftblibrary.ui.input.KeyModifiers;
Expand All @@ -10,6 +8,8 @@
import dev.ftb.mods.ftblibrary.util.BooleanConsumer;
import dev.ftb.mods.ftblibrary.util.TooltipList;
import dev.ftb.mods.ftblibrary.util.client.ClientUtils;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.platform.Window;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.ChatScreen;
Expand Down Expand Up @@ -468,11 +468,11 @@ public void mouseReleased(MouseButton button) {
}

@Override
public boolean mouseScrolled(double scroll) {
if (focusedWidget != null && focusedWidget.mouseScrolled(scroll)) {
public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double yDelta) {
if (focusedWidget != null && focusedWidget.mouseScrolled(mouseX, mouseY, xDelta, yDelta)) {
return true;
}
return modalPanels.isEmpty() ? super.mouseScrolled(scroll) : modalPanels.peekFirst().mouseScrolled(scroll);
return modalPanels.isEmpty() ? super.mouseScrolled(mouseX, mouseY, xDelta, yDelta) : modalPanels.peekFirst().mouseScrolled(mouseX, mouseY, xDelta, yDelta);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public void onTextChanged() {
this.scrollBar = new PanelScrollBar(this, ScrollBar.Plane.VERTICAL, mainPanel);
}

@Override
public boolean scrollPanel(double scroll) {
return super.scrollPanel(scroll);
}

@Override
public void addWidgets() {
add(textBox);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public void setMinMax(int min, int max) {
}

@Override
public boolean mouseScrolled(double scroll) {
public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double yDelta) {
var directionlessDelta = xDelta != 0 ? xDelta : yDelta;

if (allowInput()) {
setAmount(getIntValue() + (int) scroll);
setAmount(getIntValue() + (int) directionlessDelta);
return true;
}
return false;
Expand All @@ -69,4 +71,4 @@ public void ensureValue() {
setAmount(max);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package dev.ftb.mods.ftblibrary.ui;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.ftb.mods.ftblibrary.core.mixin.common.MultilineTextFieldAccess;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import dev.ftb.mods.ftblibrary.ui.input.Key;
import dev.ftb.mods.ftblibrary.ui.input.KeyModifiers;
import dev.ftb.mods.ftblibrary.ui.input.MouseButton;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.MultilineTextField;
Expand Down Expand Up @@ -322,6 +321,8 @@ private void scrollToCursor() {
}
}

d0 = Mth.clamp(d0, 0, Math.max(0, parent.getContentHeight() - parent.height));

parent.setScrollY(d0);
}

Expand Down
Loading
Loading