From f777eda5da2bc0f09c52d8cf8e31f9cb7d1051cb Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 29 Aug 2022 21:03:22 +0000 Subject: [PATCH] UI to delete habits --- .../source/Entry.kiss | 2 +- .../source/HabitModel.kiss | 25 +++++++++++++++++-- .../source/HabitState.kiss | 14 +++++++++++ .../src/kiss_flixel/SimpleWindow.kiss | 11 +++++--- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss b/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss index fbcd844d..e62fc150 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/Entry.kiss @@ -1,5 +1,5 @@ (defNew [&prop &mut :EntryType type - &prop :Array labels]) + &prop &mut :Array labels]) (method toString [] "$(case type diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss index 9de07e20..d45cda66 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitModel.kiss @@ -113,7 +113,15 @@ (otherwise (break)))))) (method :Array allEntries [] - (cast (concat dailyEntries monthlyEntries intervalEntries bonusEntries todoEntries))) + (cast (concat + dailyEntries + monthlyEntries + intervalEntries + bonusEntries + todoEntries))) + +(method :Array allUndeletedEntries [] + (filter (allEntries) isNotDeleted)) (method :Int totalPoints [] (apply + (for l (flatten (for e (allEntries) e.labels)) l.points))) @@ -149,8 +157,17 @@ (function todayString [] (let [d (Date.now)] "$(d.getDate)-$(+ 1 (d.getMonth))-$(d.getFullYear)")) +(function isDeleted [:Entry e] + (or (.startsWith .label (first e.labels) "~") + (case e.type + (Todo !(= 0 .points (activeLabel e))) + (otherwise false)))) + +(function isNotDeleted [:Entry e] + !(isDeleted e)) + (function isActive [:Entry e] - (when (.startsWith .label (first e.labels) "~") + (when (isDeleted e) (return false)) (case e.type ((Daily days lastDayDone) @@ -203,6 +220,10 @@ (new Entry type (for label labels (objectWith [points 0] label)))) (save)) +(method deleteEntry [:Entry e] + (set e.labels (for label e.labels (object points label.points label "~"))) + (save)) + (method addRewardFile [path startingPoints puzzleWidth puzzleHeight piecesPerPoint] (rewardFiles.push (objectWith [skipped false] path startingPoints puzzleWidth puzzleHeight piecesPerPoint)) (save)) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index 50a2cdd6..f92ed361 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -265,6 +265,20 @@ (set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#) (save.flush) (refreshModel))) + (set entryWindow.textColor FlxColor.RED) + (_makeText "Delete a habit or task" 0 + ->_ + (defAndCall method deleteHabitOrTask + (entryWindow.hide) + (let [delWindow (SimpleWindow.promptForChoice "Delete which habit/task? (You will keep all your points)" + (model.allUndeletedEntries) + ->:Void [:Entry e] { + (model.deleteEntry e) + (refreshModel) + (entryWindow.show) + } + null null FlxColor.WHITE 0.9 0.9 true)] + (set delWindow.cameras [uiCamera])))) (when (= rewardFileIndex (- m.rewardFiles.length 1)) (_makeText "Abandon this puzzle" 0 ->_ diff --git a/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss b/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss index 5b4e4c16..fec85b10 100644 --- a/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss +++ b/projects/kiss-flixel/src/kiss_flixel/SimpleWindow.kiss @@ -51,7 +51,7 @@ (prop :Map _actions (new Map)) (prop :Map _colors (new Map)) -(method makeText [:String text &opt :FlxColor color :Action onClick] +(method makeText [:String text &opt :FlxColor color :Action onClick :Bool noShortcut] (let [ftext (new FlxText nextControlX nextControlY 0 text textSize)] (set ftext.color (or color textColor)) (dictSet _colors ftext ftext.color) @@ -67,7 +67,8 @@ (when onClick (dictSet _actions ftext onClick) // TODO right click? - (keyHandler.registerItem text ->:Void (onClick ftext))) + (unless noShortcut + (keyHandler.registerItem text ->:Void (onClick ftext)))) ftext)) // TODO makeButton @@ -138,7 +139,8 @@ :FlxColor titleColor :FlxColor choiceColor :Float percentWidth - :Float percentHeight] + :Float percentHeight + :Bool noShortcuts] (let [window (new SimpleWindow prompt bgColor titleColor percentWidth percentHeight) choiceColor (or choiceColor titleColor FlxColor.WHITE)] (doFor choice choices @@ -146,6 +148,7 @@ ->:Void s { (window.hide) (onChoice choice) - })) + } + noShortcuts)) (window.show) window)) \ No newline at end of file