UI to delete habits

This commit is contained in:
2022-08-29 21:03:22 +00:00
parent e60115818a
commit f777eda5da
4 changed files with 45 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
(defNew [&prop &mut :EntryType type
&prop :Array<EntryLabel> labels])
&prop &mut :Array<EntryLabel> labels])
(method toString []
"$(case type

View File

@@ -113,7 +113,15 @@
(otherwise (break))))))
(method :Array<Entry> allEntries []
(cast (concat dailyEntries monthlyEntries intervalEntries bonusEntries todoEntries)))
(cast (concat
dailyEntries
monthlyEntries
intervalEntries
bonusEntries
todoEntries)))
(method :Array<Entry> 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))

View File

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