From e1fb4004dd73455458143fc1730dc5faf76bab59 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 21 Feb 2025 18:18:39 +0000 Subject: [PATCH] add 'tempKeys' field to OptionsType.options_type, so that any key binding changes in the menu do not take immediate effect (requires pressing 'save button' in order for changes to be saved and take effect) --- fcore/options/options-type.sml | 19 +++++++++++++++---- fcore/options/options-update.sml | 14 +++++++++++--- fcore/title/title-update.sml | 5 +++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/fcore/options/options-type.sml b/fcore/options/options-type.sml index 6407f45..76e00b6 100644 --- a/fcore/options/options-type.sml +++ b/fcore/options/options-type.sml @@ -11,9 +11,14 @@ sig | CANCEL_BUTTON type options_type = - {focus: focus, isSelected: bool, lastUpPress: real, lastDownPress: real} + { focus: focus + , isSelected: bool + , lastUpPress: real + , lastDownPress: real + , tempKeys: CoreKey.user_key + } - val initial: options_type + val init: CoreKey.user_key -> options_type end structure OptionsType :> OPTIONS_TYPE = @@ -29,12 +34,18 @@ struct | CANCEL_BUTTON type options_type = - {focus: focus, isSelected: bool, lastUpPress: real, lastDownPress: real} + { focus: focus + , isSelected: bool + , lastUpPress: real + , lastDownPress: real + , tempKeys: CoreKey.user_key + } - val initial = + fun init userKeys = { focus = LEFT_KEY , isSelected = false , lastUpPress = 0.0 , lastDownPress = 0.0 + , tempKeys = userKeys } end diff --git a/fcore/options/options-update.sml b/fcore/options/options-update.sml index 884a7fb..06abec9 100644 --- a/fcore/options/options-update.sml +++ b/fcore/options/options-update.sml @@ -9,7 +9,7 @@ end functor MakeUpdateSelectedKey(Fn: MAKE_UPDATE_SELECTED_KEY) = struct - fun setNewKeys (options, userKeys, time) = + fun setNewKeys (options, tempKeys, userKeys, time) = let val {focus, lastUpPress, lastDownPress, ...} = options val options = @@ -17,6 +17,7 @@ struct , lastUpPress = time , lastDownPress = time , isSelected = false + , tempKeys = tempKeys } in {mode = GameType.OPTIONS options, userKeys = userKeys} @@ -31,8 +32,8 @@ struct Fn.deselect (options, userKeys) (* what if new key collides with existing key? todo *) else - let val userKeys = Fn.updateKeys (key, userKeys) - in setNewKeys (options, userKeys, time) + let val tempKeys = Fn.updateKeys (key, userKeys) + in setNewKeys (options, tempKeys, userKeys, time) end | [] => Fn.default (options, userKeys) end @@ -52,6 +53,7 @@ struct , lastUpPress = 0.0 , lastDownPress = 0.0 , isSelected = isSelected + , tempKeys = userKeys } in {mode = GameType.OPTIONS options, userKeys = userKeys} @@ -69,12 +71,14 @@ struct , lastUpPress = time , lastDownPress = 0.0 , isSelected = isSelected + , tempKeys = userKeys } else { focus = focus , lastUpPress = lastUpPress , lastDownPress = 0.0 , isSelected = isSelected + , tempKeys = userKeys } in {mode = GameType.OPTIONS options, userKeys = userKeys} @@ -90,12 +94,14 @@ struct , lastUpPress = 0.0 , lastDownPress = time , isSelected = isSelected + , tempKeys = userKeys } else { focus = focus , lastUpPress = 0.0 , lastDownPress = lastDownPress , isSelected = isSelected + , tempKeys = userKeys } in {mode = GameType.OPTIONS options, userKeys = userKeys} @@ -109,6 +115,7 @@ struct , lastUpPress = lastUpPress , lastDownPress = lastDownPress , isSelected = true + , tempKeys = userKeys } in {mode = GameType.OPTIONS options, userKeys = userKeys} @@ -122,6 +129,7 @@ struct , lastUpPress = lastUpPress , lastDownPress = lastDownPress , isSelected = false + , tempKeys = userKeys } in {mode = GameType.OPTIONS options, userKeys = userKeys} diff --git a/fcore/title/title-update.sml b/fcore/title/title-update.sml index 2f33745..31e4e8b 100644 --- a/fcore/title/title-update.sml +++ b/fcore/title/title-update.sml @@ -24,8 +24,9 @@ struct let val mode = if #attackHeld input then - (* placeholder: go to configure screen instead once that is implemented *) - GameType.OPTIONS OptionsType.initial + let val options = OptionsType.init userKeys + in GameType.OPTIONS options + end else let val titleState =