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 (defNew [&prop &mut :EntryType type
&prop :Array<EntryLabel> labels]) &prop &mut :Array<EntryLabel> labels])
(method toString [] (method toString []
"$(case type "$(case type

View File

@@ -113,7 +113,15 @@
(otherwise (break)))))) (otherwise (break))))))
(method :Array<Entry> allEntries [] (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 [] (method :Int totalPoints []
(apply + (for l (flatten (for e (allEntries) e.labels)) l.points))) (apply + (for l (flatten (for e (allEntries) e.labels)) l.points)))
@@ -149,8 +157,17 @@
(function todayString [] (function todayString []
(let [d (Date.now)] "$(d.getDate)-$(+ 1 (d.getMonth))-$(d.getFullYear)")) (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] (function isActive [:Entry e]
(when (.startsWith .label (first e.labels) "~") (when (isDeleted e)
(return false)) (return false))
(case e.type (case e.type
((Daily days lastDayDone) ((Daily days lastDayDone)
@@ -203,6 +220,10 @@
(new Entry type (for label labels (objectWith [points 0] label)))) (new Entry type (for label labels (objectWith [points 0] label))))
(save)) (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] (method addRewardFile [path startingPoints puzzleWidth puzzleHeight piecesPerPoint]
(rewardFiles.push (objectWith [skipped false] path startingPoints puzzleWidth puzzleHeight piecesPerPoint)) (rewardFiles.push (objectWith [skipped false] path startingPoints puzzleWidth puzzleHeight piecesPerPoint))
(save)) (save))

View File

@@ -265,6 +265,20 @@
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#) (set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
(save.flush) (save.flush)
(refreshModel))) (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)) (when (= rewardFileIndex (- m.rewardFiles.length 1))
(_makeText "Abandon this puzzle" 0 (_makeText "Abandon this puzzle" 0
->_ ->_

View File

@@ -51,7 +51,7 @@
(prop :Map<FlxSprite,Action> _actions (new Map)) (prop :Map<FlxSprite,Action> _actions (new Map))
(prop :Map<FlxSprite,FlxColor> _colors (new Map)) (prop :Map<FlxSprite,FlxColor> _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)] (let [ftext (new FlxText nextControlX nextControlY 0 text textSize)]
(set ftext.color (or color textColor)) (set ftext.color (or color textColor))
(dictSet _colors ftext ftext.color) (dictSet _colors ftext ftext.color)
@@ -67,7 +67,8 @@
(when onClick (when onClick
(dictSet _actions ftext onClick) (dictSet _actions ftext onClick)
// TODO right click? // TODO right click?
(keyHandler.registerItem text ->:Void (onClick ftext))) (unless noShortcut
(keyHandler.registerItem text ->:Void (onClick ftext))))
ftext)) ftext))
// TODO makeButton // TODO makeButton
@@ -138,7 +139,8 @@
:FlxColor titleColor :FlxColor titleColor
:FlxColor choiceColor :FlxColor choiceColor
:Float percentWidth :Float percentWidth
:Float percentHeight] :Float percentHeight
:Bool noShortcuts]
(let [window (new SimpleWindow prompt bgColor titleColor percentWidth percentHeight) (let [window (new SimpleWindow prompt bgColor titleColor percentWidth percentHeight)
choiceColor (or choiceColor titleColor FlxColor.WHITE)] choiceColor (or choiceColor titleColor FlxColor.WHITE)]
(doFor choice choices (doFor choice choices
@@ -146,6 +148,7 @@
->:Void s { ->:Void s {
(window.hide) (window.hide)
(onChoice choice) (onChoice choice)
})) }
noShortcuts))
(window.show) (window.show)
window)) window))