diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index b7623ce7..fefff40c 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -161,7 +161,7 @@ (prop &mut :FlxSave save 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 [] (doFor window [entryWindow] @@ -672,39 +672,22 @@ (collected.push piece) (recursivelyConnectedPieces piece collected)))) collected) - (prop &mut :FlxGroup nextPuzzleChoiceGroup null) - -(method startPuzzlePackChoice [nextStartingPoints] - (unless nextPuzzleChoiceGroup - (set nextPuzzleChoiceGroup (new FlxGroup)) - (set nextPuzzleChoiceGroup.cameras [uiCamera]) - - // TODO position these aesthetically with a partly transparent background behind them - // like the habit ui window should also have - (let [x 0 &mut y 0] - (doFor pack (PuzzlePack.availablePacks model) - (let [text (new FlxText x y 0 "$pack" textSize)] - // TODO not that color though - (set text.color FlxColor.LIME) - (nextPuzzleChoiceGroup.add text) - (whenLet [(Some np) pack.nextPuzzle] - (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))) +(method :Void startPuzzlePackChoice [nextStartingPoints] + (set puzzlePackChoiceWindow (SimpleWindow.promptForChoice "Choose a puzzle pack:" + (PuzzlePack.availablePacks model) + ->[:PuzzlePack pack] (ifLet [(Some np) pack.nextPuzzle] + (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))) + (startPuzzlePackChoice nextStartingPoints)))) + (set puzzlePackChoiceWindow.cameras [uiCamera])) (var MIN_PUZZLE_SIZE 5) (var MAX_PUZZLE_SIZE 32) diff --git a/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss b/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss index b4e03ad5..5b4e4c16 100644 --- a/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss +++ b/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss @@ -5,7 +5,7 @@ (prop &mut keyboardEnabled true) // TODO tooltip support with left-click and right-click action -// icons and explanations +// icons and explanations? (defNew [&opt :String _title :FlxColor bgColor @@ -129,4 +129,23 @@ } { (set text.color color) - }))))))) \ No newline at end of file + }))))))) + +(function :SimpleWindow promptForChoice <>[T] [:String prompt + :Array 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)) \ No newline at end of file