Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting to Swap Confirm and Cancel in menu #522

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions menu/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,6 @@ func genericInput(list *entry, dt float32) {
genericAnimate(list)
})

// OK
if input.Released[0][libretro.DeviceIDJoypadA] == 1 {
if list.children[list.ptr].callbackOK != nil {
audio.PlayEffect(audio.Effects["ok"])
list.children[list.ptr].callbackOK()
}
}

// X
if input.Released[0][libretro.DeviceIDJoypadX] == 1 {
if list.children[list.ptr].callbackX != nil {
audio.PlayEffect(audio.Effects["ok"])
list.children[list.ptr].callbackX()
}
}

// Right
if input.Released[0][libretro.DeviceIDJoypadRight] == 1 {
if list.children[list.ptr].incr != nil {
Expand All @@ -117,15 +101,43 @@ func genericInput(list *entry, dt float32) {
}
}

var confirmKey uint32
var cancelKey uint32

confirmKey = libretro.DeviceIDJoypadA
cancelKey = libretro.DeviceIDJoypadB

// Optionally swap confirm and cancel
if settings.Current.SwapConfirm {
confirmKey = libretro.DeviceIDJoypadB
cancelKey = libretro.DeviceIDJoypadA
}

// OK
if input.Released[0][confirmKey] == 1 {
if list.children[list.ptr].callbackOK != nil {
audio.PlayEffect(audio.Effects["ok"])
list.children[list.ptr].callbackOK()
}
}

// Cancel
if input.Released[0][libretro.DeviceIDJoypadB] == 1 {
if input.Released[0][cancelKey] == 1 {
if len(menu.stack) > 1 {
audio.PlayEffect(audio.Effects["cancel"])
menu.stack[len(menu.stack)-2].segueBack()
menu.stack = menu.stack[:len(menu.stack)-1]
}
}

// X
if input.Released[0][libretro.DeviceIDJoypadX] == 1 {
if list.children[list.ptr].callbackX != nil {
audio.PlayEffect(audio.Effects["ok"])
list.children[list.ptr].callbackX()
}
}

// Jump to next letter
if input.Released[0][libretro.DeviceIDJoypadR] == 1 && len(list.indexes) > 0 {
list.ptr = indexed(list, +1)
Expand Down
11 changes: 9 additions & 2 deletions menu/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package menu

import (
"github.com/libretro/ludo/state"
"github.com/libretro/ludo/settings"
"github.com/tanema/gween"
"github.com/tanema/gween/ease"
)
Expand Down Expand Up @@ -273,6 +274,12 @@ func genericDrawHintBar() {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, upDown, "NAVIGATE", h)
stackHint(&stack, b, "BACK", h)
stackHint(&stack, a, "OK", h)

if settings.Current.SwapConfirm {
stackHint(&stack, b, "OK", h)
stackHint(&stack, a, "BACK", h)
} else {
stackHint(&stack, a, "OPEN", h)
stackHint(&stack, b, "OK", h)
}
}
11 changes: 9 additions & 2 deletions menu/scene_core_disk_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

ntf "github.com/libretro/ludo/notifications"
"github.com/libretro/ludo/state"
"github.com/libretro/ludo/settings"
)

type sceneCoreDiskControl struct {
Expand Down Expand Up @@ -79,13 +80,19 @@ func (s *sceneCoreDiskControl) drawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)

_, upDown, leftRight, _, b, _, _, _, _, guide := hintIcons()
_, upDown, leftRight, a, b, _, _, _, _, guide := hintIcons()

var stack float32
if state.CoreRunning {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, upDown, "NAVIGATE", h)
stackHint(&stack, b, "BACK", h)

if settings.Current.SwapConfirm {
stackHint(&stack, a, "BACK", h)
} else {
stackHint(&stack, b, "BACK", h)
}

stackHint(&stack, leftRight, "SET", h)
}
9 changes: 7 additions & 2 deletions menu/scene_core_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/libretro/ludo/core"
ntf "github.com/libretro/ludo/notifications"
"github.com/libretro/ludo/state"
"github.com/libretro/ludo/settings"
)

type sceneCoreOptions struct {
Expand Down Expand Up @@ -83,13 +84,17 @@ func (s *sceneCoreOptions) drawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)

_, upDown, leftRight, _, b, _, _, _, _, guide := hintIcons()
_, upDown, leftRight, a, b, _, _, _, _, guide := hintIcons()

var stack float32
if state.CoreRunning {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, upDown, "NAVIGATE", h)
stackHint(&stack, b, "BACK", h)
if settings.Current.SwapConfirm {
stackHint(&stack, a, "BACK", h)
} else {
stackHint(&stack, b, "BACK", h)
}
stackHint(&stack, leftRight, "SET", h)
}
17 changes: 15 additions & 2 deletions menu/scene_dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/libretro/ludo/audio"
"github.com/libretro/ludo/input"
"github.com/libretro/ludo/libretro"
"github.com/libretro/ludo/settings"
)

type sceneDialog struct {
Expand Down Expand Up @@ -36,16 +37,28 @@ func (s *sceneDialog) segueBack() {
}

func (s *sceneDialog) update(dt float32) {
var confirmKey uint32
var cancelKey uint32

confirmKey = libretro.DeviceIDJoypadA
cancelKey = libretro.DeviceIDJoypadB

// Optionally swap confirm and cancel
if settings.Current.SwapConfirm {
confirmKey = libretro.DeviceIDJoypadB
cancelKey = libretro.DeviceIDJoypadA
}

// OK
if input.Released[0][libretro.DeviceIDJoypadA] == 1 {
if input.Released[0][confirmKey] == 1 {
audio.PlayEffect(audio.Effects["ok"])
menu.stack[len(menu.stack)-2].segueBack()
menu.stack = menu.stack[:len(menu.stack)-1]
s.callbackOK()
}

// Cancel
if input.Released[0][libretro.DeviceIDJoypadB] == 1 {
if input.Released[0][cancelKey] == 1 {
audio.PlayEffect(audio.Effects["cancel"])
menu.stack[len(menu.stack)-2].segueBack()
menu.stack = menu.stack[:len(menu.stack)-1]
Expand Down
11 changes: 9 additions & 2 deletions menu/scene_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/libretro/ludo/history"
ntf "github.com/libretro/ludo/notifications"
"github.com/libretro/ludo/state"
"github.com/libretro/ludo/settings"
)

type sceneHistory struct {
Expand Down Expand Up @@ -242,8 +243,14 @@ func (s *sceneHistory) drawHintBar() {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, upDown, "NAVIGATE", h)
stackHint(&stack, b, "BACK", h)
stackHint(&stack, a, "RUN", h)

if settings.Current.SwapConfirm {
stackHint(&stack, b, "RUN", h)
stackHint(&stack, a, "BACK", h)
} else {
stackHint(&stack, a, "RUN", h)
stackHint(&stack, b, "BACK", h)
}

list := menu.stack[len(menu.stack)-1].Entry()
if list.children[list.ptr].callbackX != nil {
Expand Down
29 changes: 21 additions & 8 deletions menu/scene_keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/libretro/ludo/input"
"github.com/libretro/ludo/libretro"
"github.com/libretro/ludo/video"
"github.com/libretro/ludo/settings"
"github.com/tanema/gween"
"github.com/tanema/gween/ease"
)
Expand Down Expand Up @@ -109,12 +110,31 @@ func (s *sceneKeyboard) update(dt float32) {
}
})

var confirmKey uint32
var cancelKey uint32

confirmKey = libretro.DeviceIDJoypadA
cancelKey = libretro.DeviceIDJoypadB

// Optionally swap confirm and cancel
if settings.Current.SwapConfirm {
confirmKey = libretro.DeviceIDJoypadB
cancelKey = libretro.DeviceIDJoypadA
}

// OK
if input.Released[0][libretro.DeviceIDJoypadA] == 1 {
if input.Released[0][confirmKey] == 1 {
audio.PlayEffect(audio.Effects["ok"])
s.value += layouts[s.layout][s.index]
}

// Cancel
if input.Released[0][cancelKey] == 1 && len(menu.stack) > 1 {
audio.PlayEffect(audio.Effects["cancel"])
menu.stack[len(menu.stack)-2].segueBack()
menu.stack = menu.stack[:len(menu.stack)-1]
}

// Switch layout
if input.Released[0][libretro.DeviceIDJoypadX] == 1 {
audio.PlayEffect(audio.Effects["ok"])
Expand All @@ -132,13 +152,6 @@ func (s *sceneKeyboard) update(dt float32) {
}
})

// Cancel
if input.Released[0][libretro.DeviceIDJoypadB] == 1 && len(menu.stack) > 1 {
audio.PlayEffect(audio.Effects["cancel"])
menu.stack[len(menu.stack)-2].segueBack()
menu.stack = menu.stack[:len(menu.stack)-1]
}

// Done
if input.Released[0][libretro.DeviceIDJoypadStart] == 1 && s.value != "" {
audio.PlayEffect(audio.Effects["notice"])
Expand Down
10 changes: 8 additions & 2 deletions menu/scene_playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,14 @@ func (s *scenePlaylist) drawHintBar() {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, upDown, "NAVIGATE", h)
stackHint(&stack, b, "BACK", h)
stackHint(&stack, a, "RUN", h)

if settings.Current.SwapConfirm {
stackHint(&stack, b, "RUN", h)
stackHint(&stack, a, "BACK", h)
} else {
stackHint(&stack, a, "RUN", h)
stackHint(&stack, b, "BACK", h)
}

list := menu.stack[len(menu.stack)-1].Entry()
if list.children[list.ptr].callbackX != nil {
Expand Down
22 changes: 18 additions & 4 deletions menu/scene_savestates.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,25 @@ func (s *sceneSavestates) drawHintBar() {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, upDown, "NAVIGATE", h)
stackHint(&stack, b, "BACK", h)
if ptr == 0 {
stackHint(&stack, a, "SAVE", h)

if settings.Current.SwapConfirm {
stackHint(&stack, a, "BACK", h)
} else {
stackHint(&stack, b, "BACK", h)
}

if settings.Current.SwapConfirm {
if ptr == 0 {
stackHint(&stack, b, "SAVE", h)
} else {
stackHint(&stack, b, "LOAD", h)
}
} else {
stackHint(&stack, a, "LOAD", h)
if ptr == 0 {
stackHint(&stack, a, "SAVE", h)
} else {
stackHint(&stack, a, "LOAD", h)
}
}

list := menu.stack[len(menu.stack)-1].Entry()
Expand Down
21 changes: 19 additions & 2 deletions menu/scene_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ var incrCallbacks = map[string]callbackIncrement{
f.Set(v)
settings.Save()
},
"SwapConfirm": func(f *structs.Field, direction int) {
v := f.Value().(bool)
v = !v
f.Set(v)
settings.Save()
},
"AudioVolume": func(f *structs.Field, direction int) {
v := f.Value().(float32)
v += 0.1 * float32(direction)
Expand Down Expand Up @@ -284,9 +290,20 @@ func (s *sceneSettings) drawHintBar() {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, upDown, "NAVIGATE", h)
stackHint(&stack, b, "BACK", h)

if settings.Current.SwapConfirm {
stackHint(&stack, a, "BACK", h)
} else {
stackHint(&stack, b, "BACK", h)
}


if list.children[list.ptr].callbackOK != nil {
stackHint(&stack, a, "SET", h)
if settings.Current.SwapConfirm {
stackHint(&stack, b, "SET", h)
} else {
stackHint(&stack, a, "SET", h)
}
} else {
stackHint(&stack, leftRight, "SET", h)
}
Expand Down
20 changes: 16 additions & 4 deletions menu/scene_tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,17 @@ func (tabs *sceneTabs) update(dt float32) {
tabs.animate()
})

var confirmKey uint32

confirmKey = libretro.DeviceIDJoypadA

// Optionally swap confirm and cancel
if settings.Current.SwapConfirm {
confirmKey = libretro.DeviceIDJoypadB
}

// OK
if input.Released[0][libretro.DeviceIDJoypadA] == 1 {
if input.Released[0][confirmKey] == 1 {
if tabs.children[tabs.ptr].callbackOK != nil {
audio.PlayEffect(audio.Effects["ok"])
tabs.segueNext()
Expand Down Expand Up @@ -315,15 +324,18 @@ func (tabs sceneTabs) drawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)

_, _, leftRight, a, _, x, _, _, _, guide := hintIcons()
_, _, leftRight, a, b, x, _, _, _, guide := hintIcons()

var stack float32
if state.CoreRunning {
stackHint(&stack, guide, "RESUME", h)
}
stackHint(&stack, leftRight, "NAVIGATE", h)
stackHint(&stack, a, "OPEN", h)

if settings.Current.SwapConfirm {
stackHint(&stack, b, "OPEN", h)
} else {
stackHint(&stack, a, "OPEN", h)
}
list := menu.stack[0].Entry()
if list.children[list.ptr].callbackX != nil {
stackHint(&stack, x, "DELETE", h)
Expand Down
Loading
Loading