From 027c8be5416b20cd5d87f472e8ef1096d203273d Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 20 Feb 2025 06:00:49 +0000 Subject: [PATCH] add functionality to move between start button/options button --- fcore/title/title-type.sml | 4 ++-- fcore/title/title-update.sml | 29 ++++++++++++++++++++++++++++- fcore/title/title-vec.sml | 32 ++++++++++++++++++++++++++------ 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/fcore/title/title-type.sml b/fcore/title/title-type.sml index df2bfc3..aaf6eed 100644 --- a/fcore/title/title-type.sml +++ b/fcore/title/title-type.sml @@ -1,6 +1,6 @@ signature TITLE_TYPE = sig - datatype focus = START_BUTTON + datatype focus = START_BUTTON | OPTIONS_BUTTON type title_type = {focus: focus} @@ -9,7 +9,7 @@ end structure TitleType :> TITLE_TYPE = struct - datatype focus = START_BUTTON + datatype focus = START_BUTTON | OPTIONS_BUTTON type title_type = {focus: focus} diff --git a/fcore/title/title-update.sml b/fcore/title/title-update.sml index 7b4dc65..a4761ba 100644 --- a/fcore/title/title-update.sml +++ b/fcore/title/title-update.sml @@ -9,8 +9,35 @@ struct val mode = if #attackHeld input orelse #jumpHeld input then GameType.LEVEL LevelType.initial - else + else + let + val titleState = + if #downHeld input then + {focus = OPTIONS_BUTTON} + else + titleState + in + GameType.TITLE titleState + end + in + {mode = mode, userKeys = userKeys} + end + | OPTIONS_BUTTON => + let + val mode = + if #attackHeld input orelse #jumpHeld input then + (* placeholder: go to configure screen instead once that is implemented *) GameType.TITLE titleState + else + let + val titleState = + if #upHeld input then + {focus = START_BUTTON} + else + titleState + in + GameType.TITLE titleState + end in {mode = mode, userKeys = userKeys} end diff --git a/fcore/title/title-vec.sml b/fcore/title/title-vec.sml index 86df033..108b3c1 100644 --- a/fcore/title/title-vec.sml +++ b/fcore/title/title-vec.sml @@ -17,7 +17,7 @@ struct , b ) = if pos = String.size str then - Vector.concat acc + acc else let val chr = String.sub (str, pos) @@ -51,7 +51,7 @@ struct in (Constants.worldWidth - textWidth) div 2 end - fun getTextVec (x, y, width, height, str, r, g, b) = + fun getTextVec (x, y, width, height, str, r, g, b, acc) = let val wratio = width / Constants.worldWidthReal val hratio = height / Constants.worldHeightReal @@ -76,7 +76,7 @@ struct val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace in helpGetTextVec - (x, y, fontSize, fontSpace, width, height, 0, str, [], r, g, b) + (x, y, fontSize, fontSpace, width, height, 0, str, acc, r, g, b) end else let @@ -98,14 +98,34 @@ struct val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace in helpGetTextVec - (x, y, fontSize, fontSpace, width, height, 0, str, [], r, g, b) + (x, y, fontSize, fontSpace, width, height, 0, str, acc, r, g, b) end end fun getDrawVec (title: TitleType.title_type, width, height) = case #focus title of START_BUTTON => - let val playX = getTextCentreX "Play game" - in getTextVec (playX, 500, width, height, "Play game", 0.0, 0.0, 0.0) + let + val playX = getTextCentreX "Play game" + val acc = + getTextVec (playX, 500, width, height, "Play game", 0.3, 0.3, 0.7, []) + + val optionsX = getTextCentreX "Options" + val acc = + getTextVec (optionsX, 600, width, height, "Options", 0.0, 0.0, 0.0, acc) + in + Vector.concat acc + end + | OPTIONS_BUTTON => + let + val playX = getTextCentreX "Play game" + val acc = + getTextVec (playX, 500, width, height, "Play game", 0.0, 0.0, 0.0, []) + + val optionsX = getTextCentreX "Options" + val acc = + getTextVec (optionsX, 600, width, height, "Options", 0.3, 0.3, 0.7, acc) + in + Vector.concat acc end end