fix valid event check and use luxe functions instead of own bandaid

This commit is contained in:
Ronja 2020-10-12 20:37:03 +02:00
parent 757ce4a72e
commit c934369f31
6 changed files with 18 additions and 34 deletions

View file

@ -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()
}
}

View file

@ -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)

View file

@ -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)
}

View file

@ -26,6 +26,7 @@ class Ui{
planning{_planning}
info{_info}
entity{_ent}
construct new(app){
var game = Globals["Game"]

View file

@ -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

View file

@ -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