click to add/remove entry from playground selection

This commit is contained in:
2021-09-18 20:41:44 -06:00
parent 4adbd7d750
commit f3d7cecd4e
6 changed files with 46 additions and 17 deletions

View File

@@ -166,6 +166,10 @@
(defCommand SelectEntry [e OneEntry] (defCommand SelectEntry [e OneEntry]
(set selectedEntries [e]) []) (set selectedEntries [e]) [])
(defCommand ToggleEntrySelection [e OneEntry]
(unless (selectedEntries.remove e)
(selectedEntries.push e)) [])
(defCommand SelectEntries [entries (Entries null null)] (defCommand SelectEntries [entries (Entries null null)]
(set selectedEntries entries) []) (set selectedEntries entries) [])

View File

@@ -6,6 +6,7 @@ import flash.display.BitmapData;
import flixel.addons.display.FlxExtendedSprite; import flixel.addons.display.FlxExtendedSprite;
import nat.Entry; import nat.Entry;
import nat.Archive; import nat.Archive;
import nat.ArchiveController;
import nat.BoolExpInterp; import nat.BoolExpInterp;
import nat.components.Images; import nat.components.Images;
import nat.components.Positions; import nat.components.Positions;

View File

@@ -2,7 +2,10 @@
(defNew [:String positionKey (defNew [:String positionKey
&prop :Archive archive &prop :Archive archive
&prop :Entry e] &prop :Entry e
&prop :ArchiveController controller]
[&mut :Bool selected false]
(let [images (readComponent archive e Images)] (let [images (readComponent archive e Images)]
(case (dictGet (readComponent archive e Positions) positionKey) (case (dictGet (readComponent archive e Positions) positionKey)
((object x x y y z z) ((object x x y y z z)
@@ -13,6 +16,20 @@
(enableMouseClicks false) (enableMouseClicks false)
(enableMouseDrag) (enableMouseDrag)
})) }))
(set mousePressedCallback
->[self _x _y]
{
(controller.ToggleEntrySelection e)
(set selected !selected)
(if selected
{
(set color FlxColor.BLUE)
}
{
(set color FlxColor.WHITE)
})
})
(set mouseStopDragCallback (set mouseStopDragCallback
->[self _dx _dy] ->[self _dx _dy]
(withWritableComponents archive e [positions Positions] (withWritableComponents archive e [positions Positions]

View File

@@ -4,6 +4,7 @@ import kiss.Prelude;
import kiss.List; import kiss.List;
import nat.System; import nat.System;
import nat.BoolExpInterp; import nat.BoolExpInterp;
import nat.ArchiveController;
import nat.components.Positions; import nat.components.Positions;
@:build(kiss.Kiss.build()) @:build(kiss.Kiss.build())

View File

@@ -2,7 +2,10 @@
(prop :Map<String,EntrySprite> sprites (new Map)) (prop :Map<String,EntrySprite> sprites (new Map))
(defNew [:String tagFilterString :String positionKey :PlayState playState] (defNew [:String tagFilterString
:String positionKey
:PlayState playState
&prop :ArchiveController controller]
(super (super
->[archive e] ->[archive e]
?(and (tagsMatch archive e tagFilterString) (hasComponent e Images)) ?(and (tagsMatch archive e tagFilterString) (hasComponent e Images))
@@ -14,7 +17,7 @@
(withWritableComponents archive e [positions Positions] (withWritableComponents archive e [positions Positions]
(when !(positions.exists positionKey) (when !(positions.exists positionKey)
(dictSet positions positionKey (object x 0.0 y 0.0 z 0.0)))) (dictSet positions positionKey (object x 0.0 y 0.0 z 0.0))))
(let [sprite (new EntrySprite positionKey archive e)] (let [sprite (new EntrySprite positionKey archive e controller)]
(playState.entryGroup.add sprite) (playState.entryGroup.add sprite)
(dictSet sprites e.id sprite)) (dictSet sprites e.id sprite))
}) })

View File

@@ -16,9 +16,10 @@
archive archive
(new Archive archiveDir)] (new Archive archiveDir)]
(set this.archive archive) (set this.archive archive)
(new ArchiveController (set controller
archive (new ArchiveController
this)) archive
this)))
(prop &mut :FlxGroup uiGroup (new FlxGroup)) (prop &mut :FlxGroup uiGroup (new FlxGroup))
(add uiGroup) (add uiGroup)
@@ -39,7 +40,7 @@
// TODO allow configuring the tags at runtime and erasing/re-creating sprites later // TODO allow configuring the tags at runtime and erasing/re-creating sprites later
// TODO allow using other position keys and erasing/re-creating sprites later // TODO allow using other position keys and erasing/re-creating sprites later
(prop &mut :EntrySpriteSystem spriteSystem) (prop &mut :EntrySpriteSystem spriteSystem)
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this)) (set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
(archive.addSystem spriteSystem) (archive.addSystem spriteSystem)
(spriteSystem.process archive)) (spriteSystem.process archive))
@@ -114,16 +115,18 @@
(set textInput.hasFocus true) (set textInput.hasFocus true)
(set textInput.callback (set textInput.callback
->:Void [text action] ->:Void [text action]
(case [text action] // Super weird that this check is necessary
([text FlxInputText.ENTER_ACTION] (when textInput
(set textInput.callback null) (case [text action]
(hideUI textInput) ([text FlxInputText.ENTER_ACTION]
// This part is hacky... (set textInput.callback null)
(set lastUI textInputLabel) (hideUI textInput)
(hideUI textInputLabel) // This part is hacky...
(resolve text)) (set lastUI textInputLabel)
//([_ FlxInputText.]) (hideUI textInputLabel)
(otherwise {}))) (resolve text))
//([_ FlxInputText.])
(otherwise {}))))
(showUI textInput)) (showUI textInput))
(method :Void enterNumber [prompt resolve min max &opt inStepsOf] (method :Void enterNumber [prompt resolve min max &opt inStepsOf]