From 312999b1b6b1c5a937f2d2f0da62e8243f8d2f68 Mon Sep 17 00:00:00 2001 From: tttsaurus Date: Thu, 9 Jan 2025 16:14:41 -0500 Subject: [PATCH] Made button control usable --- .../appcommunication/spotify/SpotifyView.java | 21 ++++---- .../spotify/SpotifyViewModel.java | 15 ++++++ .../impl/gui/control/AbstractButton.java | 50 +++++++++++++++++++ .../gui/style/wrapped/DoubleProperty.java | 2 +- .../impl/gui/style/wrapped/FloatProperty.java | 2 +- 5 files changed, 79 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyView.java b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyView.java index 3d83c5a..c8b62aa 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyView.java +++ b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyView.java @@ -10,16 +10,19 @@ public String getDefaultIxml() return """ - - - - - - - - - + + + + + + + + + + + + """; } diff --git a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java index 2eb266b..07025c2 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java +++ b/src/main/java/com/tttsaurus/ingameinfo/common/impl/appcommunication/spotify/SpotifyViewModel.java @@ -5,6 +5,7 @@ import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyOAuthUtils; import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyUserInfo; import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.TrackPlaying; +import com.tttsaurus.ingameinfo.common.api.gui.delegate.button.IMouseClickButton; import com.tttsaurus.ingameinfo.common.api.mvvm.binding.Reactive; import com.tttsaurus.ingameinfo.common.api.mvvm.binding.ReactiveObject; import com.tttsaurus.ingameinfo.common.api.mvvm.viewmodel.ViewModel; @@ -33,6 +34,12 @@ public class SpotifyViewModel extends ViewModel @Reactive(targetUid = "progressBar", property = "percentage", initiativeSync = true) public ReactiveObject progressBarPercentage = new ReactiveObject<>(){}; + @Reactive(targetUid = "editButton", property = "enabled", initiativeSync = true) + public ReactiveObject editButtonEnabled = new ReactiveObject<>(){}; + + @Reactive(targetUid = "editButton", property = "addClickListener", initiativeSync = true) + public ReactiveObject editButtonAddClickListener = new ReactiveObject<>(){}; + private float durationMs = 0; private float estimatedProgressMs; private boolean isPlaying = false; @@ -115,12 +122,19 @@ public void start() isActiveSetter.invoke(false); exitCallbackSetter.invoke(() -> { + editButtonEnabled.set(false); isFocusedSetter.invoke(false); return false; }); albumImageUrl.set(""); progressBarPercentage.set(0f); + editButtonEnabled.set(false); + editButtonAddClickListener.set((IMouseClickButton)(() -> + { + if (Minecraft.getMinecraft().player != null) + Minecraft.getMinecraft().player.sendChatMessage("test"); + })); EventCenter.spotifyOverlayEvent.addListener((flag) -> { @@ -171,6 +185,7 @@ public void start() { if (isActiveGetter.invoke()) { + editButtonEnabled.set(true); isFocusedSetter.invoke(true); } }); diff --git a/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/control/AbstractButton.java b/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/control/AbstractButton.java index 64f79da..a1a5615 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/control/AbstractButton.java +++ b/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/control/AbstractButton.java @@ -1,15 +1,65 @@ package com.tttsaurus.ingameinfo.common.impl.gui.control; import com.tttsaurus.ingameinfo.common.api.gui.delegate.button.*; +import com.tttsaurus.ingameinfo.common.api.gui.registry.RegisterElement; +import com.tttsaurus.ingameinfo.common.api.gui.style.CallbackInfo; +import com.tttsaurus.ingameinfo.common.api.gui.style.StyleProperty; +import com.tttsaurus.ingameinfo.common.api.gui.style.StylePropertyCallback; import com.tttsaurus.ingameinfo.common.api.input.MouseUtils; import java.util.ArrayList; import java.util.List; +@RegisterElement(constructable = false) public abstract class AbstractButton extends Sized { private boolean hover = false; private boolean hold = false; + @StylePropertyCallback + public void addEnterListenerHelper(IMouseEnterButton value, CallbackInfo callbackInfo) + { + callbackInfo.cancel = true; + addListener(value); + } + @StyleProperty(setterCallbackPre = "addEnterListenerHelper") + public IMouseEnterButton addEnterListener; + + @StylePropertyCallback + public void addLeaveListenerHelper(IMouseLeaveButton value, CallbackInfo callbackInfo) + { + callbackInfo.cancel = true; + addListener(value); + } + @StyleProperty(setterCallbackPre = "addLeaveListenerHelper") + public IMouseLeaveButton addLeaveListener; + + @StylePropertyCallback + public void addPressListenerHelper(IMousePressButton value, CallbackInfo callbackInfo) + { + callbackInfo.cancel = true; + addListener(value); + } + @StyleProperty(setterCallbackPre = "addPressListenerHelper") + public IMousePressButton addPressListener; + + @StylePropertyCallback + public void addReleaseListenerHelper(IMouseReleaseButton value, CallbackInfo callbackInfo) + { + callbackInfo.cancel = true; + addListener(value); + } + @StyleProperty(setterCallbackPre = "addReleaseListenerHelper") + public IMouseReleaseButton addReleaseListener; + + @StylePropertyCallback + public void addClickListenerHelper(IMouseClickButton value, CallbackInfo callbackInfo) + { + callbackInfo.cancel = true; + addListener(value); + } + @StyleProperty(setterCallbackPre = "addClickListenerHelper") + public IMouseClickButton addClickListener; + private final List enter = new ArrayList<>(); private final List leave = new ArrayList<>(); private final List press = new ArrayList<>(); diff --git a/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/DoubleProperty.java b/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/DoubleProperty.java index c867408..fe51986 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/DoubleProperty.java +++ b/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/DoubleProperty.java @@ -2,7 +2,7 @@ import com.tttsaurus.ingameinfo.common.api.gui.style.wrapped.IWrappedStyleProperty; -public class DoubleProperty extends IWrappedStyleProperty +public final class DoubleProperty extends IWrappedStyleProperty { } diff --git a/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/FloatProperty.java b/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/FloatProperty.java index cd2a3eb..e669623 100644 --- a/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/FloatProperty.java +++ b/src/main/java/com/tttsaurus/ingameinfo/common/impl/gui/style/wrapped/FloatProperty.java @@ -2,7 +2,7 @@ import com.tttsaurus.ingameinfo.common.api.gui.style.wrapped.IWrappedStyleProperty; -public class FloatProperty extends IWrappedStyleProperty +public final class FloatProperty extends IWrappedStyleProperty { }