NAT color component

This commit is contained in:
2022-09-10 23:06:23 +00:00
parent 49734a071f
commit 10301cb4ae
4 changed files with 41 additions and 11 deletions

View File

@@ -351,4 +351,8 @@
(defCommand RemoveConnections [entries (SelectedEntries 1 null) entriesToRemove (Entries 1 null)]
(for e entries
(addConnections archive e entriesToRemove)))
(defCommand AddColorRGBA [entries (SelectedEntries 1 null) r (Number 0 1 null) g (Number 0 1 null) b (Number 0 1 null) a (Number 0 1 null)]
(for e entries
(addColorRGBA archive e r g b a)))
)

View File

@@ -149,6 +149,9 @@
(doFor e2 entriesToRemove (conn.remove e2.id))))
e)
(function addColorRGBA [:nat.Archive archive :nat.Entry e :Float r :Float g :Float b :Float a]
(addComponent archive e Color (objectWith r g b a)))
(function isEntry [o]
(let [fields (Reflect.fields o)]
(and (= fields.length 3)

View File

@@ -0,0 +1,8 @@
package nat.components;
typedef Color = {
r:Float,
g:Float,
b:Float,
a:Float
};

View File

@@ -7,10 +7,13 @@
&prop :Entry e
&prop :ArchiveController controller]
[&mut :Bool selected false
&mut :Bool isCircle false]
&mut :Bool isCircle false
&mut :FlxColor unselectedColor FlxColor.WHITE
&mut :FlxColor selectedColor FlxColor.WHITE]
(super position.x position.y)
(enableMouseClicks false)
(set mousePressedCallback ->:Void [_ _ _] null)
(cond
((hasComponent e Images2)
(let [images (readComponent e Images2)]
@@ -22,11 +25,26 @@
(set isCircle true)
(let [c (readComponent e Circle)
diam (Std.int (* 2 c.radius))
squareSize (+ diam CIRCLE_THICKNESS)]
squareSize (+ diam CIRCLE_THICKNESS)
color (if (hasComponent e Color)
(let [c (readComponent e Color)]
(FlxColor.fromRGBFloat c.r c.g c.b c.a))
CIRCLE_COLOR)]
(makeGraphic squareSize squareSize FlxColor.TRANSPARENT true)
(FlxSpriteUtil.drawCircle this -1 -1 c.radius FlxColor.TRANSPARENT (object thickness CIRCLE_THICKNESS color CIRCLE_COLOR))))
(set unselectedColor color)
(set selectedColor CIRCLE_SELECTED_COLOR)
(FlxSpriteUtil.drawCircle this -1 -1 c.radius FlxColor.TRANSPARENT (object thickness CIRCLE_THICKNESS color color))))
(true
(set pixels .pixels (new FlxText 0 0 0 (readComponent e Name) PlayState.TEXT_SIZE))))
(set pixels .pixels
(let [color (if (hasComponent e Color)
(let [c (readComponent e Color)]
(FlxColor.fromRGBFloat c.r c.g c.b c.a))
DEFAULT_COLOR)
t (new FlxText 0 0 0 (readComponent e Name) PlayState.TEXT_SIZE)]
(set unselectedColor color)
(set selectedColor SELECTED_COLOR)
(set t.color color)
t))))
(updateColor)
(let [:Float scale (getScale e)]
(this.scale.set scale scale)
@@ -73,13 +91,10 @@
(set fixedToSprite null))
(method updateColor []
(if (controller.isSelected e)
{
(set color (if isCircle CIRCLE_SELECTED_COLOR SELECTED_COLOR))
}
{
(set color FlxColor.WHITE)
}))
(set color
(if (controller.isSelected e)
selectedColor
unselectedColor)))
(var SELECTED_COLOR FlxColor.BLUE)
(var CIRCLE_COLOR FlxColor.LIME)