From 6cd7edb5ab59340216617ad80d50506d99cbb8a5 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 20 Feb 2025 14:25:20 +0000 Subject: [PATCH] draw options screen when that is selected --- fcore/game-type.sml | 10 +- fcore/game-update.sml | 1 + fcore/options/options-type.sml | 35 ++++- fcore/options/options-update.sml | 5 + fcore/options/options-vec.sml | 250 +++++++++++++++++++++++++++++++ fcore/title/title-update.sml | 2 +- oms.mlb | 4 + shell/gl-draw.sml | 14 ++ 8 files changed, 315 insertions(+), 6 deletions(-) create mode 100644 fcore/options/options-update.sml create mode 100644 fcore/options/options-vec.sml diff --git a/fcore/game-type.sml b/fcore/game-type.sml index de08858..1b1d4a9 100644 --- a/fcore/game-type.sml +++ b/fcore/game-type.sml @@ -1,6 +1,9 @@ signature GAME_TYPE = sig - datatype mode = LEVEL of LevelType.level_type | TITLE of TitleType.title_type + datatype mode = + LEVEL of LevelType.level_type + | TITLE of TitleType.title_type + | OPTIONS of OptionsType.options_type type game_type = {userKeys: CoreKey.user_key, mode: mode} @@ -9,7 +12,10 @@ end structure GameType :> GAME_TYPE = struct - datatype mode = LEVEL of LevelType.level_type | TITLE of TitleType.title_type + datatype mode = + LEVEL of LevelType.level_type + | TITLE of TitleType.title_type + | OPTIONS of OptionsType.options_type type game_type = {userKeys: CoreKey.user_key, mode: mode} diff --git a/fcore/game-update.sml b/fcore/game-update.sml index 6ac0555..e0cffd0 100644 --- a/fcore/game-update.sml +++ b/fcore/game-update.sml @@ -9,5 +9,6 @@ struct case mode of LEVEL level => LevelUpdate.update (level, input, userKeys) | TITLE title => TitleUpdate.update (title, input, userKeys) + | OPTIONS options => OptionsUpdate.update (options, input, userKeys) end end diff --git a/fcore/options/options-type.sml b/fcore/options/options-type.sml index c980b84..d1c7aa9 100644 --- a/fcore/options/options-type.sml +++ b/fcore/options/options-type.sml @@ -1,4 +1,33 @@ -structure OptionsType = -struct - datatype focus = +signature OPTIONS_TYPE = +sig + datatype focus = + LEFT_KEY + | RIGHT_KEY + | UP_KEY + | DOWN_KEY + | JUMP_KEY + | ATTACK_KEY + | SAVE_BUTTON + | CANCEL_BUTTON + + type options_type = {focus: focus} + + val initial: options_type +end + +structure OptionsType :> OPTIONS_TYPE = +struct + datatype focus = + LEFT_KEY + | RIGHT_KEY + | UP_KEY + | DOWN_KEY + | JUMP_KEY + | ATTACK_KEY + | SAVE_BUTTON + | CANCEL_BUTTON + + type options_type = {focus: focus} + + val initial = {focus = LEFT_KEY} end diff --git a/fcore/options/options-update.sml b/fcore/options/options-update.sml new file mode 100644 index 0000000..fe0c3bf --- /dev/null +++ b/fcore/options/options-update.sml @@ -0,0 +1,5 @@ +structure OptionsUpdate = +struct + fun update (options, input, userKeys) = + {mode = GameType.OPTIONS options, userKeys = userKeys} +end diff --git a/fcore/options/options-vec.sml b/fcore/options/options-vec.sml new file mode 100644 index 0000000..1b5223c --- /dev/null +++ b/fcore/options/options-vec.sml @@ -0,0 +1,250 @@ +structure OptionsVec = +struct + open OptionsType + + (* There's code duplication here because we want to avoid + * branhing if/case expressions per draw-call because of + * the branch prediction cost *) + fun drawLeftKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.3, 0.3, 0.7, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + + fun drawRightKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.0, 0.0, 0.0, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.3, 0.3, 0.7, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + + fun drawUpKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.0, 0.0, 0.0, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.3, 0.3, 0.7, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + + fun drawDownKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.0, 0.0, 0.0, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.3, 0.3, 0.7, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + + fun drawJumpKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.0, 0.0, 0.0, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.3, 0.3, 0.7, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + + fun drawAttackKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.0, 0.0, 0.0, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.3, 0.3, 0.7, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + + fun drawSaveKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.0, 0.0, 0.0, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.3, 0.3, 0.7, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + + fun drawCancelKey (options, width, height) = + let + val acc = MakeTextVec.make + (155, 35, width, height, "Left key", 0.0, 0.0, 0.0, []) + + val acc = MakeTextVec.make + (155, 95, width, height, "Right key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 155, width, height, "Up key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 215, width, height, "Down key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 275, width, height, "Jump key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 335, width, height, "Attack key", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 395, width, height, "Save changes", 0.0, 0.0, 0.0, acc) + + val acc = MakeTextVec.make + (155, 455, width, height, "Cancel changes", 0.3, 0.3, 0.7, acc) + in + Vector.concat acc + end + + fun getDrawVec (options: OptionsType.options_type, width, height) = + case #focus options of + LEFT_KEY => drawLeftKey (options, width, height) + | RIGHT_KEY => drawRightKey (options, width, height) + | UP_KEY => drawUpKey (options, width, height) + | DOWN_KEY => drawDownKey (options, width, height) + | JUMP_KEY => drawJumpKey (options, width, height) + | ATTACK_KEY => drawAttackKey (options, width, height) + | SAVE_BUTTON => drawSaveKey (options, width, height) + | CANCEL_BUTTON => drawCancelKey (options, width, height) +end diff --git a/fcore/title/title-update.sml b/fcore/title/title-update.sml index 9fb0121..445d9dc 100644 --- a/fcore/title/title-update.sml +++ b/fcore/title/title-update.sml @@ -25,7 +25,7 @@ struct val mode = if #attackHeld input orelse #jumpHeld input then (* placeholder: go to configure screen instead once that is implemented *) - GameType.TITLE titleState + GameType.OPTIONS OptionsType.initial else let val titleState = diff --git a/oms.mlb b/oms.mlb index 669969c..33a7f1d 100644 --- a/oms.mlb +++ b/oms.mlb @@ -42,6 +42,7 @@ fcore/frame-input-type.sml fcore/level/player/player-type.sml fcore/level/level-type.sml fcore/title/title-type.sml +fcore/options/options-type.sml fcore/game-type.sml fcore/level/player/player-patch.sml @@ -60,6 +61,9 @@ fcore/level/level-update.sml fcore/title/title-update.sml fcore/title/title-vec.sml +fcore/options/options-update.sml +fcore/options/options-vec.sml + fcore/game-update.sml (* shell *) diff --git a/shell/gl-draw.sml b/shell/gl-draw.sml index 7ed07a4..dcf9fa8 100644 --- a/shell/gl-draw.sml +++ b/shell/gl-draw.sml @@ -263,6 +263,19 @@ struct shellState end + fun helpDrawOptions shellState = drawPlayer shellState + + fun drawOptions (shellState: t, options) = + let + val width = InputState.getWidth () + val height = InputState.getHeight () + val vec = OptionsVec.getDrawVec (options, width, height) + val shellState = uploadPlayer (shellState, vec) + val () = helpDrawOptions shellState + in + shellState + end + fun drawMode (shellState: t, game: GameType.game_type) = let open GameType @@ -270,6 +283,7 @@ struct case #mode game of LEVEL level => drawLevel (shellState, level) | TITLE title => drawTitle (shellState, title) + | OPTIONS options => drawOptions (shellState, options) end fun helpLoop (shellState as {window, ...}: t, game) =