Skip to content

Commit a2f7c32

Browse files
committed
Show hotkeys in tooltips
1 parent 7bc365a commit a2f7c32

File tree

2 files changed

+53
-40
lines changed

2 files changed

+53
-40
lines changed

Common/src/main/kotlin/gay/object/hexdebug/config/HexDebugClientConfig.kt

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object HexDebugClientConfig {
3939
when (config) {
4040
is ClientConfig.SplicingTableKeybinds,
4141
is ClientConfig.SplicingTableKeybinds.Enlightened -> {
42-
SplicingTableScreen.buttonText(field.name.camelToSnakeCase())
42+
SplicingTableScreen.buttonText(field.name.camelToSnakeCase(), null)
4343
}
4444
else -> i18n.asTranslatedComponent
4545
},
@@ -145,41 +145,47 @@ object HexDebugClientConfig {
145145
@CollapsibleObject
146146
val enlightened = Enlightened()
147147

148+
fun getActionMap() = mapOf(
149+
SplicingTableAction.VIEW_LEFT to viewLeft,
150+
SplicingTableAction.VIEW_LEFT_PAGE to viewLeftPage,
151+
SplicingTableAction.VIEW_LEFT_FULL to viewLeftFull,
152+
SplicingTableAction.VIEW_RIGHT to viewRight,
153+
SplicingTableAction.VIEW_RIGHT_PAGE to viewRightPage,
154+
SplicingTableAction.VIEW_RIGHT_FULL to viewRightFull,
155+
SplicingTableAction.CURSOR_LEFT to cursorLeft,
156+
SplicingTableAction.CURSOR_RIGHT to cursorRight,
157+
SplicingTableAction.EXPAND_SELECTION_LEFT to expandSelectionLeft,
158+
SplicingTableAction.EXPAND_SELECTION_RIGHT to expandSelectionRight,
159+
SplicingTableAction.MOVE_SELECTION_LEFT to moveSelectionLeft,
160+
SplicingTableAction.MOVE_SELECTION_RIGHT to moveSelectionRight,
161+
SplicingTableAction.SELECT_NONE to selectNone,
162+
SplicingTableAction.SELECT_ALL to selectAll,
163+
SplicingTableAction.UNDO to undo,
164+
SplicingTableAction.REDO to redo,
165+
SplicingTableAction.NUDGE_LEFT to nudgeLeft,
166+
SplicingTableAction.NUDGE_RIGHT to nudgeRight,
167+
SplicingTableAction.DUPLICATE to duplicate,
168+
SplicingTableAction.DELETE to delete,
169+
SplicingTableAction.BACKSPACE to backspace,
170+
SplicingTableAction.CUT to cut,
171+
SplicingTableAction.COPY to copy,
172+
SplicingTableAction.PASTE_SPLAT to pasteSplat,
173+
SplicingTableAction.PASTE_VERBATIM to pasteVerbatim,
174+
)
175+
148176
fun getActionForKey(keyCode: Int, scanCode: Int): SplicingTableAction? {
149-
for ((key, action) in arrayOf(
150-
viewLeft to SplicingTableAction.VIEW_LEFT,
151-
viewLeftPage to SplicingTableAction.VIEW_LEFT_PAGE,
152-
viewLeftFull to SplicingTableAction.VIEW_LEFT_FULL,
153-
viewRight to SplicingTableAction.VIEW_RIGHT,
154-
viewRightPage to SplicingTableAction.VIEW_RIGHT_PAGE,
155-
viewRightFull to SplicingTableAction.VIEW_RIGHT_FULL,
156-
cursorLeft to SplicingTableAction.CURSOR_LEFT,
157-
cursorRight to SplicingTableAction.CURSOR_RIGHT,
158-
expandSelectionLeft to SplicingTableAction.EXPAND_SELECTION_LEFT,
159-
expandSelectionRight to SplicingTableAction.EXPAND_SELECTION_RIGHT,
160-
moveSelectionLeft to SplicingTableAction.MOVE_SELECTION_LEFT,
161-
moveSelectionRight to SplicingTableAction.MOVE_SELECTION_RIGHT,
162-
selectNone to SplicingTableAction.SELECT_NONE,
163-
selectAll to SplicingTableAction.SELECT_ALL,
164-
undo to SplicingTableAction.UNDO,
165-
redo to SplicingTableAction.REDO,
166-
nudgeLeft to SplicingTableAction.NUDGE_LEFT,
167-
nudgeRight to SplicingTableAction.NUDGE_RIGHT,
168-
duplicate to SplicingTableAction.DUPLICATE,
169-
delete to SplicingTableAction.DELETE,
170-
backspace to SplicingTableAction.BACKSPACE,
171-
cut to SplicingTableAction.CUT,
172-
copy to SplicingTableAction.COPY,
173-
pasteSplat to SplicingTableAction.PASTE_SPLAT,
174-
pasteVerbatim to SplicingTableAction.PASTE_VERBATIM,
175-
)) {
176-
if (key.matchesKey(keyCode, scanCode)) {
177+
for ((action, key) in getActionMap().entries) {
178+
if (key.inner.matchesKey(keyCode, scanCode)) {
177179
return action
178180
}
179181
}
180182
return null
181183
}
182184

185+
fun getKeyForAction(action: SplicingTableAction): ConfigModifierKey? {
186+
return getActionMap()[action]
187+
}
188+
183189
class Enlightened {
184190
val cast = ConfigModifierKey(InputConstants.KEY_RETURN, ctrl = true)
185191
}
@@ -228,8 +234,6 @@ data class ConfigModifierKey(
228234
Modifier.of(alt, ctrl, shift),
229235
)
230236
}
231-
232-
fun matchesKey(keyCode: Int, scanCode: Int) = inner.matchesKey(keyCode, scanCode)
233237
}
234238

235239
// https://stackoverflow.com/a/60010299

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package gay.`object`.hexdebug.gui.splicing
22

33
import at.petrak.hexcasting.api.utils.asTranslatedComponent
4+
import at.petrak.hexcasting.api.utils.gray
5+
import at.petrak.hexcasting.api.utils.italic
46
import at.petrak.hexcasting.client.gui.GuiSpellcasting
57
import com.mojang.blaze3d.systems.RenderSystem
68
import gay.`object`.hexdebug.HexDebug
9+
import gay.`object`.hexdebug.config.ConfigModifierKey
710
import gay.`object`.hexdebug.config.HexDebugClientConfig
811
import gay.`object`.hexdebug.config.HexDebugServerConfig
912
import gay.`object`.hexdebug.gui.splicing.widgets.*
@@ -141,7 +144,7 @@ class SplicingTableScreen(
141144
vOffset = 293,
142145
width = 38,
143146
height = 25,
144-
message = buttonText("clear_grid"),
147+
message = buttonText("clear_grid", null),
145148
onPress = {
146149
guiSpellcasting.mixin.`clearPatterns$hexdebug`()
147150
},
@@ -167,7 +170,7 @@ class SplicingTableScreen(
167170
vOffset = 392,
168171
width = exportButtonWidth,
169172
height = exportButtonHeight,
170-
message = buttonText("export"),
173+
message = buttonText("export", null),
171174
onPress = {
172175
exportToSystemClipboard()
173176
},
@@ -391,7 +394,7 @@ class SplicingTableScreen(
391394
vOffset = 392,
392395
width = castButtonWidth,
393396
height = castButtonHeight,
394-
message = buttonText("cast"),
397+
message = buttonText("cast", HexDebugClientConfig.config.splicingTableKeybinds.enlightened.cast),
395398
onPress = {
396399
menu.table.castHex(null)
397400
castingCooldown = maxCastingCooldown
@@ -502,7 +505,8 @@ class SplicingTableScreen(
502505
onPress = action.onPress,
503506
) to action.test
504507

505-
private val SplicingTableAction.buttonText get() = buttonText(name.lowercase())
508+
private val SplicingTableAction.buttonText get() =
509+
buttonText(name.lowercase(), HexDebugClientConfig.config.splicingTableKeybinds.getKeyForAction(this))
506510

507511
private val SplicingTableAction.onPress get(): () -> Unit = { menu.table.runAction(this, null) }
508512

@@ -559,7 +563,7 @@ class SplicingTableScreen(
559563
val keybinds = HexDebugClientConfig.config.splicingTableKeybinds
560564

561565
if (
562-
keybinds.enlightened.cast.matchesKey(keyCode, scanCode)
566+
keybinds.enlightened.cast.inner.matchesKey(keyCode, scanCode)
563567
&& canCastIgnoringCooldown
564568
&& castingCooldown <= 0
565569
) {
@@ -837,12 +841,17 @@ class SplicingTableScreen(
837841
guiGraphics.blit(TEXTURE, x, y, uOffset.toFloat(), vOffset.toFloat(), width, height, 512, 512)
838842
}
839843

840-
fun buttonText(name: String, vararg args: Any) = buttonKey(name).asTranslatedComponent(*args)
844+
fun buttonText(name: String, key: ConfigModifierKey?): Component {
845+
val text = buttonKey(name).asTranslatedComponent
846+
if (key == null) return text
847+
return text.append("\n").append(key.inner.localizedName.copy().gray.italic)
848+
}
849+
841850
fun tooltipText(name: String, vararg args: Any) = tooltipKey(name).asTranslatedComponent(*args)
842851

843-
fun buttonKey(name: String) = splicingTableKey("button.$name")
844-
fun tooltipKey(name: String) = splicingTableKey("tooltip.$name")
845-
fun splicingTableKey(name: String) = "text.hexdebug.splicing_table.$name"
852+
private fun buttonKey(name: String) = splicingTableKey("button.$name")
853+
private fun tooltipKey(name: String) = splicingTableKey("tooltip.$name")
854+
private fun splicingTableKey(name: String) = "text.hexdebug.splicing_table.$name"
846855
}
847856

848857
inner class IotaButton(val offset: Int) : BaseIotaButton(

0 commit comments

Comments
 (0)