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)

This commit is contained in:
2025-02-21 18:18:39 +00:00
parent abcbc030e1
commit e1fb4004dd
3 changed files with 29 additions and 9 deletions

View File

@@ -11,9 +11,14 @@ sig
| CANCEL_BUTTON | CANCEL_BUTTON
type options_type = 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 end
structure OptionsType :> OPTIONS_TYPE = structure OptionsType :> OPTIONS_TYPE =
@@ -29,12 +34,18 @@ struct
| CANCEL_BUTTON | CANCEL_BUTTON
type options_type = 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 { focus = LEFT_KEY
, isSelected = false , isSelected = false
, lastUpPress = 0.0 , lastUpPress = 0.0
, lastDownPress = 0.0 , lastDownPress = 0.0
, tempKeys = userKeys
} }
end end

View File

@@ -9,7 +9,7 @@ end
functor MakeUpdateSelectedKey(Fn: MAKE_UPDATE_SELECTED_KEY) = functor MakeUpdateSelectedKey(Fn: MAKE_UPDATE_SELECTED_KEY) =
struct struct
fun setNewKeys (options, userKeys, time) = fun setNewKeys (options, tempKeys, userKeys, time) =
let let
val {focus, lastUpPress, lastDownPress, ...} = options val {focus, lastUpPress, lastDownPress, ...} = options
val options = val options =
@@ -17,6 +17,7 @@ struct
, lastUpPress = time , lastUpPress = time
, lastDownPress = time , lastDownPress = time
, isSelected = false , isSelected = false
, tempKeys = tempKeys
} }
in in
{mode = GameType.OPTIONS options, userKeys = userKeys} {mode = GameType.OPTIONS options, userKeys = userKeys}
@@ -31,8 +32,8 @@ struct
Fn.deselect (options, userKeys) Fn.deselect (options, userKeys)
(* what if new key collides with existing key? todo *) (* what if new key collides with existing key? todo *)
else else
let val userKeys = Fn.updateKeys (key, userKeys) let val tempKeys = Fn.updateKeys (key, userKeys)
in setNewKeys (options, userKeys, time) in setNewKeys (options, tempKeys, userKeys, time)
end end
| [] => Fn.default (options, userKeys) | [] => Fn.default (options, userKeys)
end end
@@ -52,6 +53,7 @@ struct
, lastUpPress = 0.0 , lastUpPress = 0.0
, lastDownPress = 0.0 , lastDownPress = 0.0
, isSelected = isSelected , isSelected = isSelected
, tempKeys = userKeys
} }
in in
{mode = GameType.OPTIONS options, userKeys = userKeys} {mode = GameType.OPTIONS options, userKeys = userKeys}
@@ -69,12 +71,14 @@ struct
, lastUpPress = time , lastUpPress = time
, lastDownPress = 0.0 , lastDownPress = 0.0
, isSelected = isSelected , isSelected = isSelected
, tempKeys = userKeys
} }
else else
{ focus = focus { focus = focus
, lastUpPress = lastUpPress , lastUpPress = lastUpPress
, lastDownPress = 0.0 , lastDownPress = 0.0
, isSelected = isSelected , isSelected = isSelected
, tempKeys = userKeys
} }
in in
{mode = GameType.OPTIONS options, userKeys = userKeys} {mode = GameType.OPTIONS options, userKeys = userKeys}
@@ -90,12 +94,14 @@ struct
, lastUpPress = 0.0 , lastUpPress = 0.0
, lastDownPress = time , lastDownPress = time
, isSelected = isSelected , isSelected = isSelected
, tempKeys = userKeys
} }
else else
{ focus = focus { focus = focus
, lastUpPress = 0.0 , lastUpPress = 0.0
, lastDownPress = lastDownPress , lastDownPress = lastDownPress
, isSelected = isSelected , isSelected = isSelected
, tempKeys = userKeys
} }
in in
{mode = GameType.OPTIONS options, userKeys = userKeys} {mode = GameType.OPTIONS options, userKeys = userKeys}
@@ -109,6 +115,7 @@ struct
, lastUpPress = lastUpPress , lastUpPress = lastUpPress
, lastDownPress = lastDownPress , lastDownPress = lastDownPress
, isSelected = true , isSelected = true
, tempKeys = userKeys
} }
in in
{mode = GameType.OPTIONS options, userKeys = userKeys} {mode = GameType.OPTIONS options, userKeys = userKeys}
@@ -122,6 +129,7 @@ struct
, lastUpPress = lastUpPress , lastUpPress = lastUpPress
, lastDownPress = lastDownPress , lastDownPress = lastDownPress
, isSelected = false , isSelected = false
, tempKeys = userKeys
} }
in in
{mode = GameType.OPTIONS options, userKeys = userKeys} {mode = GameType.OPTIONS options, userKeys = userKeys}

View File

@@ -24,8 +24,9 @@ struct
let let
val mode = val mode =
if #attackHeld input then if #attackHeld input then
(* placeholder: go to configure screen instead once that is implemented *) let val options = OptionsType.init userKeys
GameType.OPTIONS OptionsType.initial in GameType.OPTIONS options
end
else else
let let
val titleState = val titleState =