Skip to content

Commit

Permalink
Made button control usable
Browse files Browse the repository at this point in the history
  • Loading branch information
tttsaurus committed Jan 9, 2025
1 parent d7a56fb commit 312999b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ public String getDefaultIxml()
return
"""
<Def debug = false>
<VerticalGroup padding = {"top": 10, "left": 10} backgroundStyle = "roundedBoxWithOutline">
<HorizontalGroup padding = {"top": 10, "bottom": 5}>
<UrlImage uid = "albumImage" rounded = true width = 40 height = 40 padding = {"left": 10, "right": 10}>
</Group>
<HorizontalGroup padding = {"bottom": 5}>
<SlidingText uid = "trackTitle" width = 40 spareWidth = 20 onDemandSliding = true padding = {"left": 10, "right": 10}>
</Group>
<HorizontalGroup padding = {"bottom": 10}>
<ProgressBar uid = "progressBar" width = 50 height = 3 padding = {"left": 5, "right": 5}>
<VerticalGroup padding = {"top": 10, "left": 10}>
<VerticalGroup backgroundStyle = "roundedBoxWithOutline">
<HorizontalGroup padding = {"top": 10, "bottom": 5}>
<UrlImage uid = "albumImage" rounded = true width = 40 height = 40 padding = {"left": 10, "right": 10}>
</Group>
<HorizontalGroup padding = {"bottom": 5}>
<SlidingText uid = "trackTitle" width = 40 spareWidth = 20 onDemandSliding = true padding = {"left": 10, "right": 10}>
</Group>
<HorizontalGroup padding = {"bottom": 10}>
<ProgressBar uid = "progressBar" width = 50 height = 3 padding = {"left": 5, "right": 5}>
</Group>
</Group>
<SimpleButton uid = "editButton" text = "test" enabled = false padding = {"top": 5}>
</Group>
""";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,6 +34,12 @@ public class SpotifyViewModel extends ViewModel<SpotifyView>
@Reactive(targetUid = "progressBar", property = "percentage", initiativeSync = true)
public ReactiveObject<Float> progressBarPercentage = new ReactiveObject<>(){};

@Reactive(targetUid = "editButton", property = "enabled", initiativeSync = true)
public ReactiveObject<Boolean> editButtonEnabled = new ReactiveObject<>(){};

@Reactive(targetUid = "editButton", property = "addClickListener", initiativeSync = true)
public ReactiveObject<IMouseClickButton> editButtonAddClickListener = new ReactiveObject<>(){};

private float durationMs = 0;
private float estimatedProgressMs;
private boolean isPlaying = false;
Expand Down Expand Up @@ -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) ->
{
Expand Down Expand Up @@ -171,6 +185,7 @@ public void start()
{
if (isActiveGetter.invoke())
{
editButtonEnabled.set(true);
isFocusedSetter.invoke(true);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IMouseEnterButton> enter = new ArrayList<>();
private final List<IMouseLeaveButton> leave = new ArrayList<>();
private final List<IMousePressButton> press = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.tttsaurus.ingameinfo.common.api.gui.style.wrapped.IWrappedStyleProperty;

public class DoubleProperty extends IWrappedStyleProperty<Double>
public final class DoubleProperty extends IWrappedStyleProperty<Double>
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.tttsaurus.ingameinfo.common.api.gui.style.wrapped.IWrappedStyleProperty;

public class FloatProperty extends IWrappedStyleProperty<Float>
public final class FloatProperty extends IWrappedStyleProperty<Float>
{

}

0 comments on commit 312999b

Please sign in to comment.