diff --git a/Luxe/blocks/ui/adventure.wren b/Luxe/blocks/ui/adventure.wren index 2c75506..78227da 100644 --- a/Luxe/blocks/ui/adventure.wren +++ b/Luxe/blocks/ui/adventure.wren @@ -8,6 +8,7 @@ import "luxe: assets" for Assets, Strings import "luxe: render" for Material, TextAlign import "luxe: color" for Color import "luxe: game" for Frame +import "luxe: containers" for Lists import "globals" for Globals import "blocks/ui/image_button" for ImageButton @@ -265,7 +266,7 @@ class UiAdventure{ if(data["press"]){ Frame.end{ Globals["Tooltip"].clear(button) - Util.remove(adventure.adventurers, adventurer) + Lists.remove(adventure.adventurers, adventurer) _game.adventures.planning.emit() } } @@ -352,7 +353,7 @@ class UiAdventure{ if(data["press"]){ Frame.end{ Globals["Tooltip"].clear(button) - Util.remove(adventure.adventurers, adventurer) + Lists.remove(adventure.adventurers, adventurer) _game.adventures.planning.emit() } } diff --git a/Luxe/blocks/ui/image_button.wren b/Luxe/blocks/ui/image_button.wren index 2c609c2..c78f13a 100644 --- a/Luxe/blocks/ui/image_button.wren +++ b/Luxe/blocks/ui/image_button.wren @@ -18,6 +18,7 @@ class ImageButton{ Control.set_events(button) {|event| if(!Util.valid_event(event)) return + if(UI.event_cancelled(ent, event.id)) return var data = null if(event.type == UIEvent.enter){ data = Control.get_state_data(button) diff --git a/Luxe/blocks/ui/scroll_box.wren b/Luxe/blocks/ui/scroll_box.wren index c9f1e8b..4ddad1c 100644 --- a/Luxe/blocks/ui/scroll_box.wren +++ b/Luxe/blocks/ui/scroll_box.wren @@ -11,6 +11,7 @@ import "math/rect" for AABB import "math/math" for M import "blocks/debug" for DrawDebug import "blocks/ui/slider" for UiSlider +import "math/util" for Util class UiScrollBox{ @@ -52,11 +53,12 @@ class UiScrollBox{ UILayout.set_contain(ent, childContainer, UILayoutContain.column | UILayoutContain.start) //| Control.set_allow_input(childContainer, true) Control.set_events(childContainer){ |event| + if(!Util.valid_event(event)) return if(event.type == UIEvent.press) { Control.set_state_data(childContainer, true) UI.capture(childContainer) } - if(event.type == UIEvent.release) { + if(event.type == UIEvent.release) { Control.set_state_data(childContainer, false) UI.uncapture(childContainer) } diff --git a/Luxe/blocks/ui/ui.wren b/Luxe/blocks/ui/ui.wren index caae32b..09441c6 100644 --- a/Luxe/blocks/ui/ui.wren +++ b/Luxe/blocks/ui/ui.wren @@ -26,6 +26,7 @@ class Ui{ planning{_planning} info{_info} + entity{_ent} construct new(app){ var game = Globals["Game"] diff --git a/Luxe/game.wren b/Luxe/game.wren index e516426..33e35cd 100644 --- a/Luxe/game.wren +++ b/Luxe/game.wren @@ -1,6 +1,6 @@ import "luxe: game" for Ready import "luxe: input" for Input, Key -import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera +import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera, UI import "luxe: math" for Math import "luxe: draw" for Draw import "luxe: io" for IO diff --git a/Luxe/math/util.wren b/Luxe/math/util.wren index be40141..eb74a50 100644 --- a/Luxe/math/util.wren +++ b/Luxe/math/util.wren @@ -1,7 +1,7 @@ import "luxe: assets" for Assets import "luxe: render" for Material import "luxe: ui/control" for Control -import "luxe: world" for UIEvent +import "luxe: world" for UIEvent, UI, Entity import "math/math" for M import "math/Vector" for Vector @@ -19,28 +19,6 @@ class Util{ return material } - static copy_list(from, to){ - for(i in 0...from.count){ - to[i] = from[i] - } - } - - static index_of(sequence, element){ - var index = -1 - var any = sequence.any{|elem| - index = index + 1 - return elem == element - } - return any ? index : -1 - } - - static remove(list, element){ - var index = index_of(list, element) - if(index < 0) return false - list.removeAt(index) - return true - } - static for_all(sequences, fn){ var count = sequences.count var counter = (0...count) @@ -91,17 +69,18 @@ class Util{ } static valid_event(event){ + //cancelled events are not valid :V + var entity = Control.get_entity(event.control) + if(UI.event_cancelled(entity, event.id)) return false + //events without a position are always valid if(![UIEvent.press, UIEvent.release, UIEvent.move].contains(event.type)) return true + //when a coltrol has captured the mouse, also everything is valid + if(UI.get_captured(entity)) return true - //System.print("type: %(UIEvent.name(event.type))") - var valid = event.y > 0 //ugly bugs need ugly fixes + //if its a event with a position (checked with list) and not captured, the event is only valid when the mouse is over the control + var valid = Control.contains(event.control, event.x, event.y) return valid - - //those are the remains of a cleaner solution - /*var bounds = [0,0,0,0] - Control.get_bounds_abs(event.control, bounds) - var rect = AABB.from_list(bounds)*/ } //hue value saturation to rgb colors. all values in 0-1 range