add functionality to move between start button/options button

This commit is contained in:
2025-02-20 06:00:49 +00:00
parent 6d39c17a11
commit 027c8be541
3 changed files with 56 additions and 9 deletions

View File

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

View File

@@ -10,7 +10,34 @@ struct
if #attackHeld input orelse #jumpHeld input then
GameType.LEVEL LevelType.initial
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

View File

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