SimpleWindow.promptForChoice

This commit is contained in:
2022-08-29 19:19:08 +00:00
parent fa2fa22de2
commit 4e0235746d
2 changed files with 37 additions and 35 deletions

View File

@@ -161,7 +161,7 @@
(prop &mut :FlxSave save null) (prop &mut :FlxSave save null)
(prop &mut :SimpleWindow entryWindow null) (prop &mut :SimpleWindow entryWindow null)
// TODO add other windows and add them to the windowIsShown and tempWindowIsShown lists (prop &mut :SimpleWindow puzzlePackChoiceWindow null)
(method windowIsShown [] (method windowIsShown []
(doFor window [entryWindow] (doFor window [entryWindow]
@@ -672,39 +672,22 @@
(collected.push piece) (collected.push piece)
(recursivelyConnectedPieces piece collected)))) (recursivelyConnectedPieces piece collected))))
collected) collected)
(prop &mut :FlxGroup nextPuzzleChoiceGroup null) (prop &mut :FlxGroup nextPuzzleChoiceGroup null)
(method :Void startPuzzlePackChoice [nextStartingPoints]
(method startPuzzlePackChoice [nextStartingPoints] (set puzzlePackChoiceWindow (SimpleWindow.promptForChoice "Choose a puzzle pack:"
(unless nextPuzzleChoiceGroup (PuzzlePack.availablePacks model)
(set nextPuzzleChoiceGroup (new FlxGroup)) ->[:PuzzlePack pack] (ifLet [(Some np) pack.nextPuzzle]
(set nextPuzzleChoiceGroup.cameras [uiCamera]) (startPuzzleSizeChoice
->[chosenSize pointsPerPiece]
// TODO position these aesthetically with a partly transparent background behind them (let [bmd (BitmapData.fromFile np.path)
// like the habit ui window should also have aspectRatioX (/ bmd.width bmd.height)
(let [x 0 &mut y 0] aspectRatioY (/ bmd.height bmd.width)
(doFor pack (PuzzlePack.availablePacks model) w (max 1 (Math.round (* aspectRatioX chosenSize)))
(let [text (new FlxText x y 0 "$pack" textSize)] h (max 1 (Math.round (* aspectRatioY chosenSize)))]
// TODO not that color though (model.addRewardFile np.path nextStartingPoints w h pointsPerPiece)
(set text.color FlxColor.LIME) (setModel model)))
(nextPuzzleChoiceGroup.add text) (startPuzzlePackChoice nextStartingPoints))))
(whenLet [(Some np) pack.nextPuzzle] (set puzzlePackChoiceWindow.cameras [uiCamera]))
(nextPuzzleChoiceGroup.add
(new FlxButton (+ x text.width) y "CHOOSE" ->:Void {
(remove nextPuzzleChoiceGroup)
(set nextPuzzleChoiceGroup null)
(startPuzzleSizeChoice
->[chosenSize pointsPerPiece]
(let [bmd (BitmapData.fromFile np.path)
aspectRatioX (/ bmd.width bmd.height)
aspectRatioY (/ bmd.height bmd.width)
w (max 1 (Math.round (* aspectRatioX chosenSize)))
h (max 1 (Math.round (* aspectRatioY chosenSize)))]
(model.addRewardFile np.path nextStartingPoints w h pointsPerPiece)
(setModel model)))
}))))
(+= y textSize)))
(add nextPuzzleChoiceGroup)))
(var MIN_PUZZLE_SIZE 5) (var MIN_PUZZLE_SIZE 5)
(var MAX_PUZZLE_SIZE 32) (var MAX_PUZZLE_SIZE 32)

View File

@@ -5,7 +5,7 @@
(prop &mut keyboardEnabled true) (prop &mut keyboardEnabled true)
// TODO tooltip support with left-click and right-click action // TODO tooltip support with left-click and right-click action
// icons and explanations // icons and explanations?
(defNew [&opt :String _title (defNew [&opt :String _title
:FlxColor bgColor :FlxColor bgColor
@@ -130,3 +130,22 @@
{ {
(set text.color color) (set text.color color)
}))))))) })))))))
(function :SimpleWindow promptForChoice <>[T] [:String prompt
:Array<T> choices
:T->Void onChoice
&opt :FlxColor bgColor
:FlxColor titleColor
:FlxColor choiceColor
:Float percentWidth
:Float percentHeight]
(let [window (new SimpleWindow prompt bgColor titleColor percentWidth percentHeight)
choiceColor (or choiceColor titleColor FlxColor.WHITE)]
(doFor choice choices
(window.makeText (Std.string choice) choiceColor
->:Void s {
(window.hide)
(onChoice choice)
}))
(window.show)
window))