NAT flixel playground multiple playground views
This commit is contained in:
@@ -4,6 +4,7 @@ import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import flash.display.BitmapData;
|
||||
import flixel.addons.display.FlxExtendedSprite;
|
||||
import flixel.text.FlxText;
|
||||
import nat.Entry;
|
||||
import nat.Archive;
|
||||
import nat.ArchiveController;
|
||||
|
||||
@@ -7,24 +7,24 @@
|
||||
&prop :Entry e
|
||||
&prop :ArchiveController controller]
|
||||
[&mut :Bool selected false]
|
||||
|
||||
(let [images (readComponent e Images)]
|
||||
(super position.x position.y)
|
||||
(.onComplete (BitmapData.loadFromFile (joinPath archive.archiveDir "files" (nth images.imageFiles images.pinnedImageIndex)))
|
||||
->bitmapData {
|
||||
(loadGraphic bitmapData)
|
||||
(updateColor)
|
||||
(when (hasComponent e Scale)
|
||||
(let [:Float scale (readComponent e Scale)]
|
||||
(this.scale.set scale scale)
|
||||
(updateHitbox)))
|
||||
(enableMouseClicks false)
|
||||
(enableMouseDrag)
|
||||
}))
|
||||
|
||||
(super position.x position.y)
|
||||
(if (hasComponent e Images)
|
||||
(let [images (readComponent e Images)]
|
||||
(.onComplete (BitmapData.loadFromFile (joinPath archive.archiveDir "files" (nth images.imageFiles images.pinnedImageIndex)))
|
||||
->bitmapData {
|
||||
(loadGraphic bitmapData)
|
||||
}))
|
||||
(set pixels .pixels (new FlxText 0 0 0 (readComponent e Name) 16)))
|
||||
(updateColor)
|
||||
(when (hasComponent e Scale)
|
||||
(let [:Float scale (readComponent e Scale)]
|
||||
(this.scale.set scale scale)
|
||||
(updateHitbox)))
|
||||
(enableMouseClicks false)
|
||||
(enableMouseDrag)
|
||||
(set mouseStartDragCallback
|
||||
->[self _dx _dy]
|
||||
(doFor sprite ~(system.getSelectedSprites)
|
||||
(doFor sprite (system.getSelectedSprites)
|
||||
(unless (= sprite.e.id this.e.id)
|
||||
(sprite.fixToSprite this))))
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import nat.Entry;
|
||||
import nat.System;
|
||||
import nat.BoolExpInterp;
|
||||
import nat.ArchiveController;
|
||||
import nat.components.Positions;
|
||||
import flixel.FlxG;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class EntrySpriteDepthSystem extends System {}
|
||||
@@ -1,33 +0,0 @@
|
||||
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
|
||||
|
||||
(method z [:Entry e]
|
||||
.z (dictGet (readComponent e Positions) (spriteSystem.getPlaygroundKey)))
|
||||
|
||||
(method :Array<EntrySprite> collectOverlapping [:EntrySprite s &opt :Array<EntrySprite> overlapping]
|
||||
(unless overlapping (set overlapping []))
|
||||
(overlapping.push s)
|
||||
(FlxG.overlap s state.entryGroup
|
||||
->[_ s2]
|
||||
(unless (contains overlapping s2)
|
||||
(collectOverlapping s2 overlapping)))
|
||||
overlapping)
|
||||
|
||||
(defNew [&prop :PlayState state
|
||||
&prop :EntrySpriteSystem spriteSystem]
|
||||
(super
|
||||
->[archive e]
|
||||
?(and
|
||||
(spriteSystem.sprites.exists e.id)
|
||||
!(= 0 (z e)))
|
||||
->[archive e &opt ui]
|
||||
(let [:Array<EntrySprite> inOrder
|
||||
(sortBy
|
||||
(collectOverlapping (dictGet spriteSystem.sprites e.id))
|
||||
->s (- (z s.e)))]
|
||||
// Looping twice avoids having to splice() the group
|
||||
(doFor s inOrder
|
||||
// This will leave null holes
|
||||
(state.entryGroup.remove s))
|
||||
(doFor s inOrder
|
||||
// this will fill the null holes in the right order
|
||||
(state.entryGroup.add s)))))
|
||||
@@ -6,8 +6,13 @@ import nat.System;
|
||||
import nat.BoolExpInterp;
|
||||
import nat.ArchiveController;
|
||||
import nat.ArchiveUI;
|
||||
import nat.Archive;
|
||||
import nat.Entry;
|
||||
import nat.components.Position;
|
||||
using kiss_flixel.CameraTools;
|
||||
import nat.components.Positions;
|
||||
import nat.systems.PlaygroundSystem;
|
||||
import flixel.util.FlxSort;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class EntrySpriteSystem extends PlaygroundSystem {}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
// just make the FlxText every time at runtime -- so PinNextImage won't be needed
|
||||
// when the media tag is added
|
||||
|
||||
(defNew [:PlayState playState
|
||||
(defNew [&prop :PlayState playState
|
||||
&prop :ArchiveController controller]
|
||||
(super
|
||||
playState
|
||||
->[archive e]
|
||||
?(hasComponent e Images)
|
||||
?(hasComponent e Name)
|
||||
->[archive e pos &opt ui]
|
||||
(unless (sprites.exists e.id)
|
||||
(let [sprite (new EntrySprite this _playgroundKey pos archive e controller)]
|
||||
@@ -27,7 +27,27 @@
|
||||
(controller.DeSelectEntry e)
|
||||
}))
|
||||
|
||||
// TODO override process to z-sort all sprites after making them
|
||||
(method &override :Void clear []
|
||||
(sprites.clear)
|
||||
(playState.entryGroup.kill)
|
||||
(playState.entryGroup.clear)
|
||||
(playState.entryGroup.revive)
|
||||
(controller.SelectEntries []))
|
||||
|
||||
(method z [:Entry e]
|
||||
.z (dictGet (readComponent e Positions) _playgroundKey))
|
||||
|
||||
// override process to z-sort all sprites after making them
|
||||
(method &override :Void process [:Archive archive &opt :ArchiveUI ui]
|
||||
(super.process archive ui)
|
||||
(FlxG.camera.calculateScrollBounds playState.entryGroup PlayState.SCROLL_BOUND_MARGIN)
|
||||
(playState.entryGroup.sort ->[o s1 s2] (FlxSort.byValues o (z s1.e) (z s2.e))))
|
||||
|
||||
(method getSelectedSprites []
|
||||
(filter (for e (controller.getSelectedEntries) (dictGet sprites e.id))))
|
||||
(filter (for e (controller.getSelectedEntries) (dictGet sprites e.id))))
|
||||
|
||||
(prop defaultSpacing 100)
|
||||
(prop &mut defaultX 0)
|
||||
(method &override :Position defaultPosition [_]
|
||||
(+= defaultX defaultSpacing)
|
||||
(object x defaultX y 0.0 z 0.0))
|
||||
@@ -9,6 +9,7 @@
|
||||
(method :PlaygroundSystem playgroundSystem []
|
||||
(set spriteSystem (new EntrySpriteSystem this controller)))
|
||||
|
||||
(prop :KeyShortcutHandler<Entry> shortcutHandler (new FlxKeyShortcutHandler<Entry>))
|
||||
(method &override :Void create []
|
||||
(super.create)
|
||||
|
||||
@@ -28,7 +29,6 @@
|
||||
archive
|
||||
this)))
|
||||
|
||||
(prop :KeyShortcutHandler<Entry> shortcutHandler (new FlxKeyShortcutHandler<Entry>))
|
||||
|
||||
(prop &mut :FlxGroup uiGroup (new FlxGroup))
|
||||
(add uiGroup)
|
||||
@@ -95,14 +95,6 @@
|
||||
(when !(= overlaps (controller.isSelected entrySprite.e))
|
||||
(controller.ToggleSelectEntry entrySprite.e))))))))
|
||||
|
||||
// make text-only sprites for entries that have no images:
|
||||
(archive.addSystem (new TextSpriteSystem))
|
||||
|
||||
(prop &mut :EntrySpriteDepthSystem spriteDepthSystem)
|
||||
(set spriteDepthSystem (new EntrySpriteDepthSystem this spriteSystem))
|
||||
(archive.addSystem spriteDepthSystem)
|
||||
|
||||
(archive.processSystems this)
|
||||
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
||||
|
||||
(defAlias &ident sh (cast shortcutHandler FlxKeyShortcutHandler<Dynamic>))
|
||||
@@ -112,10 +104,16 @@
|
||||
(when sh.currentMap
|
||||
(sh.update))
|
||||
|
||||
(spriteDepthSystem.process archive)
|
||||
|
||||
(when FlxG.keys.justPressed.ESCAPE
|
||||
(Sys.exit 0))
|
||||
(if (and textInput textInput.hasFocus)
|
||||
{
|
||||
(set textInput.callback null)
|
||||
(hideUI textInput)
|
||||
// This part is hacky...
|
||||
(set lastUI textInputLabel)
|
||||
(hideUI textInputLabel)
|
||||
}
|
||||
(Sys.exit 0)))
|
||||
|
||||
// Press ENTER to type a command to run
|
||||
(when (and !textInput FlxG.keys.justPressed.ENTER)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
?(and !(hasComponent e Images) (hasComponent e Name))
|
||||
->[archive e &opt ui]
|
||||
{
|
||||
// TODO refactor this to kiss-flixel SpriteTools as #if sys savePNG
|
||||
(let [name (readComponent e Name)
|
||||
sprite (new FlxText 0 0 0 name 16)
|
||||
bitmapData sprite.pixels
|
||||
|
||||
Reference in New Issue
Block a user