Skip to content

Commit 68bcb27

Browse files
committed
Add tooltip field to SplicingTableIotaRenderer (close #65)
1 parent 3a4f473 commit 68bcb27

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Common/src/main/java/gay/object/hexdebug/api/client/splicing/SplicingTableIotaRenderer.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.network.chat.Component;
1111
import org.jetbrains.annotations.ApiStatus;
1212
import org.jetbrains.annotations.NotNull;
13+
import org.jetbrains.annotations.Nullable;
1314

1415
public abstract class SplicingTableIotaRenderer {
1516
@NotNull
@@ -19,6 +20,9 @@ public abstract class SplicingTableIotaRenderer {
1920
private int x;
2021
private int y;
2122

23+
@Nullable
24+
private Tooltip tooltip;
25+
2226
public SplicingTableIotaRenderer(
2327
@NotNull IotaType<?> type,
2428
@NotNull SplicingTableIotaClientView iota,
@@ -59,6 +63,24 @@ public void setY(int y) {
5963
this.y = y;
6064
}
6165

66+
/**
67+
* Returns the current tooltip for this renderer. This is called every frame, immediately after
68+
* {@link SplicingTableIotaRenderer#render}.
69+
*/
70+
@Nullable
71+
public Tooltip getTooltip() {
72+
return tooltip;
73+
}
74+
75+
/**
76+
* Sets the cached tooltip for this renderer. By default, this is called only when the renderer
77+
* is moved to a new position, receiving the value returned by
78+
* {@link SplicingTableIotaRenderer#createTooltip}.
79+
*/
80+
public void setTooltip(@Nullable Tooltip tooltip) {
81+
this.tooltip = tooltip;
82+
}
83+
6284
/** Renders one frame of this iota. */
6385
public abstract void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick);
6486

@@ -69,7 +91,8 @@ public SplicingTableIotaBackgroundType getBackgroundType() {
6991
}
7092

7193
/**
72-
* Creates and returns a new {@link Tooltip} for the provided iota.
94+
* Creates and returns a new {@link Tooltip} for the provided iota. By default, this is called
95+
* only when the renderer is moved to a new position.
7396
* <br>
7497
* In most cases, you'll likely want to override
7598
* {@link SplicingTableIotaRenderer#buildTooltip} instead.

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/widgets/BaseIotaButton.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ abstract class BaseIotaButton(x: Int, y: Int) : HexagonButton(
4141

4242
try {
4343
renderer.render(guiGraphics, mouseX, mouseY, partialTick)
44+
tooltip = renderer.tooltip
4445
} catch (e: Exception) {
4546
HexDebug.LOGGER.error("Caught exception while rendering ${renderer.type.typeName().string}", e)
4647
this.renderer = null
@@ -71,8 +72,8 @@ abstract class BaseIotaButton(x: Int, y: Int) : HexagonButton(
7172
}.getOrNull()
7273
renderer?.x = x
7374
renderer?.y = y
75+
renderer?.tooltip = renderer?.createTooltip()
7476
this.renderer = renderer
75-
this.tooltip = renderer?.createTooltip()
7677
} catch (e: Exception) {
7778
HexDebug.LOGGER.error("Caught exception while preparing renderer for ${iotaType.typeName().string}", e)
7879
renderer = null

0 commit comments

Comments
 (0)