diff --git a/menu/input.go b/menu/input.go index 28b8c648..b518b737 100644 --- a/menu/input.go +++ b/menu/input.go @@ -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 { @@ -117,8 +101,28 @@ 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() @@ -126,6 +130,14 @@ func genericInput(list *entry, dt float32) { } } + // 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) diff --git a/menu/scene.go b/menu/scene.go index f3020a6b..761842f4 100644 --- a/menu/scene.go +++ b/menu/scene.go @@ -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" ) @@ -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) + } } diff --git a/menu/scene_core_disk_control.go b/menu/scene_core_disk_control.go index ef3dfd13..d5aa362a 100644 --- a/menu/scene_core_disk_control.go +++ b/menu/scene_core_disk_control.go @@ -5,6 +5,7 @@ import ( ntf "github.com/libretro/ludo/notifications" "github.com/libretro/ludo/state" + "github.com/libretro/ludo/settings" ) type sceneCoreDiskControl struct { @@ -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) } diff --git a/menu/scene_core_options.go b/menu/scene_core_options.go index e347d7dd..aeea7db7 100644 --- a/menu/scene_core_options.go +++ b/menu/scene_core_options.go @@ -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 { @@ -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) } diff --git a/menu/scene_dialog.go b/menu/scene_dialog.go index 7da8c35e..b10a78a2 100644 --- a/menu/scene_dialog.go +++ b/menu/scene_dialog.go @@ -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 { @@ -36,8 +37,20 @@ 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] @@ -45,7 +58,7 @@ func (s *sceneDialog) update(dt float32) { } // 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] diff --git a/menu/scene_history.go b/menu/scene_history.go index c52b4ccd..2bbdd3a7 100644 --- a/menu/scene_history.go +++ b/menu/scene_history.go @@ -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 { @@ -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 { diff --git a/menu/scene_keyboard.go b/menu/scene_keyboard.go index 96765b23..bb35b33f 100644 --- a/menu/scene_keyboard.go +++ b/menu/scene_keyboard.go @@ -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" ) @@ -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"]) @@ -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"]) diff --git a/menu/scene_playlist.go b/menu/scene_playlist.go index c140f192..ff42b4ae 100644 --- a/menu/scene_playlist.go +++ b/menu/scene_playlist.go @@ -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 { diff --git a/menu/scene_savestates.go b/menu/scene_savestates.go index 950888f6..38333c1a 100644 --- a/menu/scene_savestates.go +++ b/menu/scene_savestates.go @@ -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() diff --git a/menu/scene_settings.go b/menu/scene_settings.go index c5e93bf1..ac3bf17c 100644 --- a/menu/scene_settings.go +++ b/menu/scene_settings.go @@ -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) @@ -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) } diff --git a/menu/scene_tabs.go b/menu/scene_tabs.go index b46401e1..4ad44c4d 100644 --- a/menu/scene_tabs.go +++ b/menu/scene_tabs.go @@ -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() @@ -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) diff --git a/menu/scene_wifi.go b/menu/scene_wifi.go index 0af9d257..83716eb0 100644 --- a/menu/scene_wifi.go +++ b/menu/scene_wifi.go @@ -2,6 +2,7 @@ package menu import ( "github.com/libretro/ludo/ludos" + "github.com/libretro/ludo/settings" ntf "github.com/libretro/ludo/notifications" ) @@ -92,8 +93,17 @@ func (s *sceneWiFi) drawHintBar() { var stack float32 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 s.children[0].callbackOK != nil { - stackHint(&stack, a, "CONNECT", h) + if settings.Current.SwapConfirm { + stackHint(&stack, b, "CONNECT", h) + } else { + stackHint(&stack, a, "CONNECT", h) + } } } diff --git a/settings/defaults.go b/settings/defaults.go index c7a3a65f..ba08e6c2 100644 --- a/settings/defaults.go +++ b/settings/defaults.go @@ -13,6 +13,7 @@ func defaultSettings() Settings { VideoMonitorIndex: 0, VideoFilter: "Pixel Perfect", MapAxisToDPad: false, + SwapConfirm: false, AudioVolume: 0.5, MenuAudioVolume: 0.25, ShowHiddenFiles: false, diff --git a/settings/settings.go b/settings/settings.go index b03db8ac..c2338e91 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -33,6 +33,7 @@ type Settings struct { ShowHiddenFiles bool `toml:"menu_showhiddenfiles" label:"Show Hidden Files" fmt:"%t" widget:"switch"` MapAxisToDPad bool `toml:"input_map_axis_to_dpad" label:"Map Sticks To DPad" fmt:"%t" widget:"switch"` + SwapConfirm bool `toml:"input_swap_confirm" label:"Swap Confirm and Cancel" fmt:"%t" widget:"switch"` CoreForPlaylist map[string]string `hide:"always" toml:"core_for_playlist"`