Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Button hover!

  • Loading branch information...
commit 66d4b6e7322ac9081f3f4b57c153f925127186a4 1 parent c0b9617
@nddrylliog authored
Showing with 35 additions and 3 deletions.
  1. +1 −1  source/game/Player.ooc
  2. +34 −2 source/ui/Toolbar.ooc
View
2  source/game/Player.ooc
@@ -20,7 +20,7 @@ Player: class {
}
update: func (date: GameDate) {
- agencies each(|a| a update(date))
+ // agencies each(|a| a update(date))
cashHistory add(date, getCash())
}
View
36 source/ui/Toolbar.ooc
@@ -1,5 +1,5 @@
-import structs/[ArrayList]
+import structs/[ArrayList, HashMap]
import ldkit/[Sprites, Input, Math]
import ui/[MainUI, Pass]
@@ -11,6 +11,8 @@ Placement: enum {
SOUTH
}
+
+
/*
* A toolbar is a set of items that are clickable
*/
@@ -36,6 +38,17 @@ Toolbar: class {
case Placement EAST =>
pos set!(ui display getWidth() - itemWidth / 2, itemWidth + 80)
}
+
+ ui input onMouseMove(||
+ point := ui input mousepos
+ items each(|item|
+ if(item rect containsPoint(point)) {
+ item _changeState(ItemState HOVER)
+ } else {
+ item _changeState(ItemState IDLE)
+ }
+ )
+ )
}
add: func (item: Item) {
@@ -66,9 +79,12 @@ Toolbar: class {
}
+
+
ItemState: enum {
IDLE
- CLICKED
+ HOVER
+ PRESSED
}
/*
@@ -80,12 +96,21 @@ Item: class {
icon: String
width, height: Int
+ colors := static HashMap<ItemState, Vec3> new()
+
state := ItemState IDLE
sprite: GroupSprite
rect: RectSprite
init: func (=name) {
+ // FIXME: static initialization workaround suxxorz
+ if (colors empty?()) {
+ colors add(s1 := ItemState IDLE, vec3(0.5, 0.5, 0.5))
+ colors add(s2 := ItemState HOVER, vec3(0.7, 0.7, 0.7))
+ colors add(s3 := ItemState PRESSED, vec3(0.4, 0.4, 0.4))
+ }
+
sprite = GroupSprite new()
rect = RectSprite new(vec2(0, 0))
@@ -110,5 +135,12 @@ Item: class {
rect size set!(width, height)
}
+ _changeState: func (=state) {
+ // TODO: validate state?
+ // TODO: notify listeners?
+ rect color set!(colors get(state))
+ }
+
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.