onSelectionChanged UI event
This commit is contained in:
@@ -3,16 +3,16 @@
|
|||||||
(method :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation]
|
(method :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation]
|
||||||
(case arg.type
|
(case arg.type
|
||||||
(SelectedEntry
|
(SelectedEntry
|
||||||
(if (= 1 selectedEntries.length)
|
(if (= 1 _selectedEntries.length)
|
||||||
(continuation (first selectedEntries))
|
(continuation (first _selectedEntries))
|
||||||
(ui.reportError "The requested command expects 1 entry to be selected. You have selected: $selectedEntries.length")))
|
(ui.reportError "The requested command expects 1 entry to be selected. You have selected: $_selectedEntries.length")))
|
||||||
((SelectedEntries min max)
|
((SelectedEntries min max)
|
||||||
(unless min (set min 0))
|
(unless min (set min 0))
|
||||||
// TODO might want to optimize this O(n) count operation by pre-calculating it
|
// TODO might want to optimize this O(n) count operation by pre-calculating it
|
||||||
(unless max (set max (count archive.entries)))
|
(unless max (set max (count archive.entries)))
|
||||||
(if !(<= min selectedEntries.length max)
|
(if !(<= min _selectedEntries.length max)
|
||||||
(ui.reportError "The requested command expects between $min and $max entries to be selected. You have selected: $selectedEntries.length")
|
(ui.reportError "The requested command expects between $min and $max entries to be selected. You have selected: $_selectedEntries.length")
|
||||||
(continuation selectedEntries)))
|
(continuation _selectedEntries)))
|
||||||
((Text maxLength)
|
((Text maxLength)
|
||||||
(unless maxLength (set maxLength Math.POSITIVE_INFINITY))
|
(unless maxLength (set maxLength Math.POSITIVE_INFINITY))
|
||||||
(ui.enterText
|
(ui.enterText
|
||||||
@@ -113,14 +113,12 @@
|
|||||||
(set lastCollector (_composeArgCollector collectedArgs arg lastCollector)))
|
(set lastCollector (_composeArgCollector collectedArgs arg lastCollector)))
|
||||||
(lastCollector)))
|
(lastCollector)))
|
||||||
|
|
||||||
|
|
||||||
(defMacro defCommand [name args &body body]
|
(defMacro defCommand [name args &body body]
|
||||||
(let [argPairs
|
(let [argPairs
|
||||||
(groups (expList args) 2)
|
(groups (expList args) 2)
|
||||||
methodArgs
|
methodArgs
|
||||||
(for [name type] argPairs
|
(for [name type] argPairs
|
||||||
// TODO write an exprCase macro that simplifies this terrible mess,
|
|
||||||
// and maybe adds back precise pattern matching instead of relying
|
|
||||||
// on partial string matching
|
|
||||||
(exprCase type
|
(exprCase type
|
||||||
((exprOr SelectedEntry OneEntry) `:nat.Entry ,name)
|
((exprOr SelectedEntry OneEntry) `:nat.Entry ,name)
|
||||||
((exprOr (SelectedEntries _ _) (Entries _ _)) `:Array<nat.Entry> ,name)
|
((exprOr (SelectedEntries _ _) (Entries _ _)) `:Array<nat.Entry> ,name)
|
||||||
@@ -139,10 +137,12 @@
|
|||||||
|
|
||||||
(var :Array<String> commandNames [])
|
(var :Array<String> commandNames [])
|
||||||
|
|
||||||
|
(method isSelected [:Entry e]
|
||||||
|
!(= -1 (_selectedEntries.indexOf e)))
|
||||||
|
|
||||||
(defNew [&prop :Archive archive
|
(defNew [&prop :Archive archive
|
||||||
&prop :ArchiveUI ui]
|
&prop :ArchiveUI ui]
|
||||||
[&mut :Array<Entry> selectedEntries []
|
[&mut :Array<Entry> _selectedEntries []
|
||||||
&mut :ChangeSet lastChangeSet []
|
&mut :ChangeSet lastChangeSet []
|
||||||
:Map<String,Command> commands (new Map)
|
:Map<String,Command> commands (new Map)
|
||||||
:NameSystem nameSystem (new NameSystem)]
|
:NameSystem nameSystem (new NameSystem)]
|
||||||
@@ -163,21 +163,28 @@
|
|||||||
(+ "Available commands:\n"
|
(+ "Available commands:\n"
|
||||||
(commandNames.join "\n"))) [])
|
(commandNames.join "\n"))) [])
|
||||||
|
|
||||||
|
(method selectionCommand [entries]
|
||||||
|
(let [lastSelectedEntries _selectedEntries]
|
||||||
|
(set _selectedEntries entries)
|
||||||
|
(ui.onSelectionChanged entries lastSelectedEntries)) [])
|
||||||
|
|
||||||
(defCommand SelectEntry [e OneEntry]
|
(defCommand SelectEntry [e OneEntry]
|
||||||
(set selectedEntries [e]) [])
|
(selectionCommand [e]))
|
||||||
|
|
||||||
(defCommand ToggleEntrySelection [e OneEntry]
|
(defCommand ToggleEntrySelection [e OneEntry]
|
||||||
(unless (selectedEntries.remove e)
|
(let [newSelection (_selectedEntries.copy)]
|
||||||
(selectedEntries.push e)) [])
|
(unless (newSelection.remove e)
|
||||||
|
(newSelection.push e))
|
||||||
|
(selectionCommand newSelection)))
|
||||||
|
|
||||||
(defCommand SelectEntries [entries (Entries null null)]
|
(defCommand SelectEntries [entries (Entries null null)]
|
||||||
(set selectedEntries entries) [])
|
(selectionCommand entries) [])
|
||||||
|
|
||||||
(defCommand SelectAllEntries []
|
(defCommand SelectAllEntries []
|
||||||
(set selectedEntries (for =>id e archive.entries e)) [])
|
(selectionCommand (for =>id e archive.entries e)))
|
||||||
|
|
||||||
(defCommand SelectLastChangeSet []
|
(defCommand SelectLastChangeSet []
|
||||||
(set selectedEntries lastChangeSet) [])
|
(selectionCommand lastChangeSet))
|
||||||
|
|
||||||
(defCommand PrintSelectedEntries [entries (SelectedEntries null null)]
|
(defCommand PrintSelectedEntries [entries (SelectedEntries null null)]
|
||||||
(doFor e entries (ui.displayMessage (archive.fullString e))) [])
|
(doFor e entries (ui.displayMessage (archive.fullString e))) [])
|
||||||
|
@@ -42,4 +42,9 @@ interface ArchiveUI {
|
|||||||
* Tell the user that something is wrong
|
* Tell the user that something is wrong
|
||||||
*/
|
*/
|
||||||
function reportError(error:String):Void;
|
function reportError(error:String):Void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update UI to show that the set of selected entries has changed
|
||||||
|
*/
|
||||||
|
function onSelectionChanged(selectedEntries:Array<Entry>, lastSelectedEntries:Array<Entry>):Void;
|
||||||
}
|
}
|
||||||
|
@@ -90,3 +90,7 @@
|
|||||||
|
|
||||||
(method :Void reportError [error]
|
(method :Void reportError [error]
|
||||||
(print error))
|
(print error))
|
||||||
|
|
||||||
|
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> _]
|
||||||
|
(print "Selected:")
|
||||||
|
(controller.PrintSelectedEntries selectedEntries))
|
||||||
|
@@ -22,12 +22,10 @@
|
|||||||
(enableMouseDrag)
|
(enableMouseDrag)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// TODO add onEntrySelected(), onEntryDeselected() callback to ArchiveUI and use these to change color if SelectByName or SelectByTags are used on an Entry that has a sprite in the entryspritesystem's dictionary
|
|
||||||
(set mousePressedCallback
|
(set mousePressedCallback
|
||||||
->[self _x _y]
|
->[self _x _y]
|
||||||
{
|
{
|
||||||
(controller.ToggleEntrySelection e)
|
(controller.ToggleEntrySelection e)
|
||||||
(updateColor)
|
|
||||||
})
|
})
|
||||||
(set mouseStopDragCallback
|
(set mouseStopDragCallback
|
||||||
->[self _dx _dy]
|
->[self _dx _dy]
|
||||||
@@ -35,7 +33,7 @@
|
|||||||
(dictSet positions positionKey (object x (cast this.x Float) y (cast this.y Float) z 0.0)))))
|
(dictSet positions positionKey (object x (cast this.x Float) y (cast this.y Float) z 0.0)))))
|
||||||
|
|
||||||
(method updateColor []
|
(method updateColor []
|
||||||
(if !(= -1 (controller.selectedEntries.indexOf e))
|
(if (controller.isSelected e)
|
||||||
{
|
{
|
||||||
(set color FlxColor.BLUE)
|
(set color FlxColor.BLUE)
|
||||||
}
|
}
|
||||||
|
@@ -208,3 +208,8 @@
|
|||||||
(let [text (new FlxText 0 0 0 (error.replace "\n" "|"))]
|
(let [text (new FlxText 0 0 0 (error.replace "\n" "|"))]
|
||||||
(text.setFormat null 8 FlxColor.RED)
|
(text.setFormat null 8 FlxColor.RED)
|
||||||
(showUI text)))
|
(showUI text)))
|
||||||
|
|
||||||
|
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> lastSelectedEntries]
|
||||||
|
(doFor e (selectedEntries.concat lastSelectedEntries)
|
||||||
|
(whenLet [sprite (dictGet spriteSystem.sprites e.id)]
|
||||||
|
(sprite.updateColor))))
|
Reference in New Issue
Block a user