Skip to content

Commit

Permalink
Adding tooltip if shortcuts share key combos.
Browse files Browse the repository at this point in the history
This isn't necessarily a problem, as multiple shortcuts can have the same key combos. In the future, it would be nice to make shortcuts know their contexts internally so that an overlap of key combo + context means a shortcut conflict.
  • Loading branch information
SolarLune committed Nov 6, 2023
1 parent 2af45ad commit a047e54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 10 additions & 2 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3905,12 +3905,14 @@ type Tooltip struct {
SpawnStart Point
Displaying bool
Text string
Visible bool
}

func NewTooltip(text string) *Tooltip {
tt := &Tooltip{
Button: NewIconButton(0, 0, &sdl.Rect{240, 352, 32, 32}, globals.GUITexture, false, nil),
Text: text,
Button: NewIconButton(0, 0, &sdl.Rect{240, 352, 32, 32}, globals.GUITexture, false, nil),
Text: text,
Visible: true,
}
tt.Button.Tint = ColorWhite
tt.Button.OnPressed = func() {
Expand All @@ -3921,6 +3923,9 @@ func NewTooltip(text string) *Tooltip {
}

func (tt *Tooltip) Update() {
if !tt.Visible {
return
}
tt.Button.Update()
if globals.Mouse.Button(sdl.BUTTON_LEFT).Pressed() && !globals.Mouse.RawPosition().Inside(tt.Button.Rect) {
tt.Displaying = false
Expand All @@ -3932,6 +3937,9 @@ func (tt *Tooltip) Update() {

}
func (tt *Tooltip) Draw() {
if !tt.Visible {
return
}
tt.Button.Draw()
}

Expand Down
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,21 @@ of images can be.`))

input.OnUpdate = func() {

for _, a := range globals.Keybindings.ShortcutsInOrder {
shortcut := input.FindElement("keyConflict-"+a.Name, false).(*Tooltip)
shortcut.Visible = false
shortcut.Text = "The following shortcuts share key combos:\n"
for _, b := range globals.Keybindings.ShortcutsInOrder {
if a == b {
continue
}
if a.KeysToString() == b.KeysToString() {
shortcut.Visible = true
shortcut.Text += "\n + " + b.Name
}
}
}

globals.Keybindings.On = false

if rebindingKey != nil {
Expand Down Expand Up @@ -2503,6 +2518,9 @@ where the cursor is over the window.`))
row = input.AddRow(AlignCenter)
row.AlternateBGColor = true

tooltip := NewTooltip("The following shortcuts share key combos:")
row.Add("keyConflict-"+shortcut.Name, tooltip)

shortcutName := NewLabel(shortcut.Name, nil, false, AlignLeft)

row.Add("key-"+shortcut.Name, shortcutName)
Expand All @@ -2525,7 +2543,9 @@ where the cursor is over the window.`))

row.Add(shortcut.Name+"-d", button)

row.ExpandElementSet.SelectAll()
row.ExpandElementSet.Select(shortcutName, redefineButton, button)

// row.ExpandElementSet.SelectAll()
}

about := settings.AddPage("about")
Expand Down

0 comments on commit a047e54

Please sign in to comment.