Skip to content

Commit

Permalink
Merge pull request #77 from flowerinsnow-lights-opensource/72
Browse files Browse the repository at this point in the history
feat(1.20.1-forge) Reset scrolling when cursor moved away from an item (#72)
  • Loading branch information
flowerinsnowdh authored Aug 28, 2024
2 parents b311c9c + e5a502d commit de340bd
Show file tree
Hide file tree
Showing 21 changed files with 940 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tagged-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:

- name: Distributions with Gradle Wrapper
run: |
cd 1.18.2-forge/
cd 1.20.1-forge/
./gradlew build
- name: Release
uses: softprops/action-gh-release@v2
with:
files: 1.18.2-forge/build/libs/*.jar
files: 1.20.1-forge/build/libs/*.jar
4 changes: 3 additions & 1 deletion 1.20.1-forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ dependencies() {

annotationProcessor('org.spongepowered:mixin:0.8.5:processor')

implementation(fg.deobf("curse.maven:iceberg-520110:5138899"))
// LegendaryTooltips 1.4.5
// https://www.curseforge.com/minecraft/mc-mods/legendary-tooltips/files/4662781
implementation(fg.deobf("curse.maven:legendary-tooltips-532127:4662781"))
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down
6 changes: 3 additions & 3 deletions 1.20.1-forge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ minecraft_version=1.20.1
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.1]
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=47.3.5
forge_version=47.3.7
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[47,)
# The loader version range can only use the major version of Forge/FML as bounds
Expand Down Expand Up @@ -48,7 +48,7 @@ mod_name=Great Scrollable Tooltips
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MPL-2.0
# The mod version. See https://semver.org/
mod_version=15.1.2+forge
mod_version=15.1.4+forge
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand All @@ -59,4 +59,4 @@ mod_authors=flowerinsnow
mod_description=Allow scrolling of item tooltips in the inventory.

# Dependencies
version_fnml4j=2.0.0-beta.2
version_fnml4j=2.0.0-beta.3
2 changes: 1 addition & 1 deletion 1.20.1-forge/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package online.flowerinsnow.greatscrollabletooltips;

import com.mojang.logging.LogUtils;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -18,24 +18,21 @@
import online.flowerinsnow.greatscrollabletooltips.event.MouseScrolledInParentElementEvent;
import online.flowerinsnow.greatscrollabletooltips.event.RenderMouseoverTooltipEvent;
import online.flowerinsnow.greatscrollabletooltips.listener.CursorKeyListener;
import online.flowerinsnow.greatscrollabletooltips.object.ScrollSession;
import online.flowerinsnow.greatscrollabletooltips.screen.ConfigScreen;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;

import java.util.function.Consumer;

@Mod(GreatScrollableTooltips.MODID)
public class GreatScrollableTooltips {
public static final String MODID = "great_scrollable_tooltips";
private static final Logger LOGGER = LogUtils.getLogger();

private static GreatScrollableTooltips instance;

private Config config;

private int horizontal;
private int vertical;
private boolean rendering;
private ScrollSession scrollSession;

public static final Lazy<KeyMapping> KEY_BINDING_SCROLL_UP = Lazy.of(() -> new KeyMapping("great-scrollable-tooltips.key-binding.scroll-up", GLFW.GLFW_KEY_UP, "great-scrollable-tooltips.key-binding.category"));
public static final Lazy<KeyMapping> KEY_BINDING_SCROLL_LEFT = Lazy.of(() -> new KeyMapping("great-scrollable-tooltips.key-binding.scroll-left", GLFW.GLFW_KEY_LEFT, "great-scrollable-tooltips.key-binding.category"));
Expand All @@ -49,6 +46,7 @@ public GreatScrollableTooltips() {

public void onClientSetup(FMLClientSetupEvent event) {
GreatScrollableTooltips.instance = this;
this.scrollSession = new ScrollSession();

this.config = new Config();
this.config.saveDefaultConfig();
Expand All @@ -60,30 +58,45 @@ public void onClientSetup(FMLClientSetupEvent event) {

IEventBus eventBus = MinecraftForge.EVENT_BUS;

// 鼠标滚动时
eventBus.addListener((Consumer<MouseScrolledInParentElementEvent>) e -> {
Minecraft client = Minecraft.getInstance();
if (client.screen != null && GreatScrollableTooltips.this.config.enable && GreatScrollableTooltips.this.rendering) {
if (client.screen != null && GreatScrollableTooltips.this.config.enable && GreatScrollableTooltips.this.getScrollSession().isRendering()) { // 只有渲染物品提示时才允许滚动
ScrollSession session = GreatScrollableTooltips.this.getScrollSession();
if (Screen.hasShiftDown()) {
GreatScrollableTooltips.this.horizontal += (int) e.getAmount();
session.addHorizontal((int) e.getAmount());
} else {
GreatScrollableTooltips.this.vertical += (int) e.getAmount();
session.addVertical((int) e.getAmount());
}
}
});

eventBus.addListener((Consumer<RenderMouseoverTooltipEvent.Post>) e ->
GreatScrollableTooltips.this.rendering = true
);
eventBus.addListener((Consumer<RenderMouseoverTooltipEvent.Post>) e -> {
ScrollSession session = GreatScrollableTooltips.this.getScrollSession();
session.setRendering(true);
ItemStack itemStack = e.getStack();
if (itemStack != session.getLastItemStackRendered()) {
session.setLastItemStackRendered(itemStack);

eventBus.addListener((Consumer<RenderMouseoverTooltipEvent.Miss>) e ->
GreatScrollableTooltips.this.rendering = false
);
if (GreatScrollableTooltips.this.config.autoReset) {
session.resetScroll();
}
}
});

eventBus.addListener((Consumer<RenderMouseoverTooltipEvent.Miss>) e -> {
ScrollSession session = GreatScrollableTooltips.this.getScrollSession();
session.setRendering(false);
session.setLastItemStackRendered(null);
if (GreatScrollableTooltips.this.config.autoReset) {
session.resetScroll();
}
});

eventBus.addListener((Consumer<TickEvent.ClientTickEvent>) e -> {
if (e.phase == TickEvent.Phase.END) {
if (Minecraft.getInstance().screen == null) {
GreatScrollableTooltips.this.horizontal = 0;
GreatScrollableTooltips.this.vertical = 0;
GreatScrollableTooltips.this.getScrollSession().resetScroll();
}
}
});
Expand All @@ -93,10 +106,10 @@ public void onClientSetup(FMLClientSetupEvent event) {
}

public void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {
event.register(KEY_BINDING_SCROLL_UP.get());
event.register(KEY_BINDING_SCROLL_LEFT.get());
event.register(KEY_BINDING_SCROLL_DOWN.get());
event.register(KEY_BINDING_SCROLL_RIGHT.get());
event.register(GreatScrollableTooltips.KEY_BINDING_SCROLL_UP.get());
event.register(GreatScrollableTooltips.KEY_BINDING_SCROLL_LEFT.get());
event.register(GreatScrollableTooltips.KEY_BINDING_SCROLL_DOWN.get());
event.register(GreatScrollableTooltips.KEY_BINDING_SCROLL_RIGHT.get());
}

public static GreatScrollableTooltips getInstance() {
Expand All @@ -107,23 +120,7 @@ public Config getConfig() {
return this.config;
}

public int getHorizontal() {
return this.horizontal;
}

public void setHorizontal(int horizontal) {
this.horizontal = horizontal;
}

public int getVertical() {
return this.vertical;
}

public void setVertical(int vertical) {
this.vertical = vertical;
}

public boolean isRendering() {
return this.rendering;
public ScrollSession getScrollSession() {
return this.scrollSession;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Config {
public boolean enable;
public int sensitivity;

public boolean autoReset;

public void saveDefaultConfig() {
BiConsumer<Throwable, String> crashFunction = this.crashFunction();
Path configFile = this.getConfigFile();
Expand Down Expand Up @@ -48,8 +50,9 @@ public void load() {
BiConsumer<Throwable, String> crashFunction = this.crashFunction();
try {
this.rootNode = FNML4J.parse(getConfigFile(), StandardCharsets.UTF_8);
this.enable = rootNode.getChildNodeNotNull("enable", FNML4JPresentParser.BOOLEAN, StringNode.class);
this.sensitivity = rootNode.getChildNodeNotNull("sensitivity", FNML4JPresentParser.INT, StringNode.class);
this.enable = Boolean.parseBoolean(this.rootNode.getChildNode("enable", FNML4JPresentParser.STRING, StringNode.class));
this.sensitivity = this.rootNode.getChildNodeNotNull("sensitivity", FNML4JPresentParser.INT, StringNode.class);
this.autoReset = Boolean.parseBoolean(this.rootNode.getChildNode("auto_reset", FNML4JPresentParser.STRING, StringNode.class));
} catch (IOException e) {
crashFunction.accept(e, "Failed to load config.");
}
Expand All @@ -60,6 +63,7 @@ public void save() {
try (FileWriter fw = new FileWriter(getConfigFile().toFile(), StandardCharsets.UTF_8)) {
this.rootNode.set("enable", new StringNode(Boolean.toString(this.enable)));
this.rootNode.set("sensitivity", new StringNode(Integer.toString(this.sensitivity)));
this.rootNode.set("auto_reset", new StringNode(Boolean.toString(this.autoReset)));
this.rootNode.writeRoot(0, fw);
} catch (IOException e) {
crashFunction.accept(e, "Failed to save config.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import online.flowerinsnow.greatscrollabletooltips.GreatScrollableTooltips;
import online.flowerinsnow.greatscrollabletooltips.event.HandledScreenKeyPressedEvent;
import online.flowerinsnow.greatscrollabletooltips.object.ScrollSession;

@OnlyIn(Dist.CLIENT)
public class CursorKeyListener {
@SubscribeEvent
public void onScreenKeyPressed(HandledScreenKeyPressedEvent event) {
ScrollSession session = GreatScrollableTooltips.getInstance().getScrollSession();
final GreatScrollableTooltips instance = GreatScrollableTooltips.getInstance();
int keyCode = event.getKeyCode();
int scanCode = event.getScanCode();

if (instance.isRendering()) {
if (session.isRendering()) {
if (GreatScrollableTooltips.KEY_BINDING_SCROLL_UP.get().matches(keyCode, scanCode)) {
instance.setVertical(instance.getVertical() + 1);
session.addVertical(1);
event.setCanceled(true);
}
if (GreatScrollableTooltips.KEY_BINDING_SCROLL_LEFT.get().matches(keyCode, scanCode)) {
instance.setHorizontal(instance.getHorizontal() + 1);
session.addHorizontal(1);
event.setCanceled(true);
}
if (GreatScrollableTooltips.KEY_BINDING_SCROLL_DOWN.get().matches(keyCode, scanCode)) {
instance.setVertical(instance.getVertical() - 1);
session.addVertical(-1);
event.setCanceled(true);
}
if (GreatScrollableTooltips.KEY_BINDING_SCROLL_RIGHT.get().matches(keyCode, scanCode)) {
instance.setHorizontal(instance.getHorizontal() - 1);
session.addHorizontal(-1);
event.setCanceled(true);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MixinScreen {
)
private int modifyBackgroundX(int x) {
GreatScrollableTooltips instance = GreatScrollableTooltips.getInstance();
return x + (instance.getHorizontal() * instance.getConfig().sensitivity);
return x + (instance.getScrollSession().getHorizontal() * instance.getConfig().sensitivity);
}

@ModifyArg(
Expand All @@ -37,7 +37,7 @@ private int modifyBackgroundX(int x) {
)
private int modifyTextX(int x) {
GreatScrollableTooltips instance = GreatScrollableTooltips.getInstance();
return x + (instance.getHorizontal() * instance.getConfig().sensitivity);
return x + (instance.getScrollSession().getHorizontal() * instance.getConfig().sensitivity);
}

@ModifyArg(
Expand All @@ -52,7 +52,7 @@ private int modifyTextX(int x) {
)
private int modifyBackgroundY(int y) {
GreatScrollableTooltips instance = GreatScrollableTooltips.getInstance();
return y + (instance.getVertical() * instance.getConfig().sensitivity);
return y + (instance.getScrollSession().getVertical() * instance.getConfig().sensitivity);
}

@ModifyArg(
Expand All @@ -66,6 +66,6 @@ private int modifyBackgroundY(int y) {
)
private int modifyTextY(int y) {
GreatScrollableTooltips instance = GreatScrollableTooltips.getInstance();
return y + (instance.getVertical() * instance.getConfig().sensitivity);
return y + (instance.getScrollSession().getVertical() * instance.getConfig().sensitivity);
}
}
Loading

0 comments on commit de340bd

Please sign in to comment.