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
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

View File

@@ -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}

View File

@@ -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 =