fix valid event check and use luxe functions instead of own bandaid
This commit is contained in:
parent
757ce4a72e
commit
c934369f31
6 changed files with 18 additions and 34 deletions
|
|
@ -8,6 +8,7 @@ import "luxe: assets" for Assets, Strings
|
||||||
import "luxe: render" for Material, TextAlign
|
import "luxe: render" for Material, TextAlign
|
||||||
import "luxe: color" for Color
|
import "luxe: color" for Color
|
||||||
import "luxe: game" for Frame
|
import "luxe: game" for Frame
|
||||||
|
import "luxe: containers" for Lists
|
||||||
|
|
||||||
import "globals" for Globals
|
import "globals" for Globals
|
||||||
import "blocks/ui/image_button" for ImageButton
|
import "blocks/ui/image_button" for ImageButton
|
||||||
|
|
@ -265,7 +266,7 @@ class UiAdventure{
|
||||||
if(data["press"]){
|
if(data["press"]){
|
||||||
Frame.end{
|
Frame.end{
|
||||||
Globals["Tooltip"].clear(button)
|
Globals["Tooltip"].clear(button)
|
||||||
Util.remove(adventure.adventurers, adventurer)
|
Lists.remove(adventure.adventurers, adventurer)
|
||||||
_game.adventures.planning.emit()
|
_game.adventures.planning.emit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -352,7 +353,7 @@ class UiAdventure{
|
||||||
if(data["press"]){
|
if(data["press"]){
|
||||||
Frame.end{
|
Frame.end{
|
||||||
Globals["Tooltip"].clear(button)
|
Globals["Tooltip"].clear(button)
|
||||||
Util.remove(adventure.adventurers, adventurer)
|
Lists.remove(adventure.adventurers, adventurer)
|
||||||
_game.adventures.planning.emit()
|
_game.adventures.planning.emit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class ImageButton{
|
||||||
|
|
||||||
Control.set_events(button) {|event|
|
Control.set_events(button) {|event|
|
||||||
if(!Util.valid_event(event)) return
|
if(!Util.valid_event(event)) return
|
||||||
|
if(UI.event_cancelled(ent, event.id)) return
|
||||||
var data = null
|
var data = null
|
||||||
if(event.type == UIEvent.enter){
|
if(event.type == UIEvent.enter){
|
||||||
data = Control.get_state_data(button)
|
data = Control.get_state_data(button)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import "math/rect" for AABB
|
||||||
import "math/math" for M
|
import "math/math" for M
|
||||||
import "blocks/debug" for DrawDebug
|
import "blocks/debug" for DrawDebug
|
||||||
import "blocks/ui/slider" for UiSlider
|
import "blocks/ui/slider" for UiSlider
|
||||||
|
import "math/util" for Util
|
||||||
|
|
||||||
class UiScrollBox{
|
class UiScrollBox{
|
||||||
|
|
||||||
|
|
@ -52,11 +53,12 @@ class UiScrollBox{
|
||||||
UILayout.set_contain(ent, childContainer, UILayoutContain.column | UILayoutContain.start) //|
|
UILayout.set_contain(ent, childContainer, UILayoutContain.column | UILayoutContain.start) //|
|
||||||
Control.set_allow_input(childContainer, true)
|
Control.set_allow_input(childContainer, true)
|
||||||
Control.set_events(childContainer){ |event|
|
Control.set_events(childContainer){ |event|
|
||||||
|
if(!Util.valid_event(event)) return
|
||||||
if(event.type == UIEvent.press) {
|
if(event.type == UIEvent.press) {
|
||||||
Control.set_state_data(childContainer, true)
|
Control.set_state_data(childContainer, true)
|
||||||
UI.capture(childContainer)
|
UI.capture(childContainer)
|
||||||
}
|
}
|
||||||
if(event.type == UIEvent.release) {
|
if(event.type == UIEvent.release) {
|
||||||
Control.set_state_data(childContainer, false)
|
Control.set_state_data(childContainer, false)
|
||||||
UI.uncapture(childContainer)
|
UI.uncapture(childContainer)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ class Ui{
|
||||||
|
|
||||||
planning{_planning}
|
planning{_planning}
|
||||||
info{_info}
|
info{_info}
|
||||||
|
entity{_ent}
|
||||||
|
|
||||||
construct new(app){
|
construct new(app){
|
||||||
var game = Globals["Game"]
|
var game = Globals["Game"]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import "luxe: game" for Ready
|
import "luxe: game" for Ready
|
||||||
import "luxe: input" for Input, Key
|
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: math" for Math
|
||||||
import "luxe: draw" for Draw
|
import "luxe: draw" for Draw
|
||||||
import "luxe: io" for IO
|
import "luxe: io" for IO
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import "luxe: assets" for Assets
|
import "luxe: assets" for Assets
|
||||||
import "luxe: render" for Material
|
import "luxe: render" for Material
|
||||||
import "luxe: ui/control" for Control
|
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/math" for M
|
||||||
import "math/Vector" for Vector
|
import "math/Vector" for Vector
|
||||||
|
|
@ -19,28 +19,6 @@ class Util{
|
||||||
return material
|
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){
|
static for_all(sequences, fn){
|
||||||
var count = sequences.count
|
var count = sequences.count
|
||||||
var counter = (0...count)
|
var counter = (0...count)
|
||||||
|
|
@ -91,17 +69,18 @@ class Util{
|
||||||
}
|
}
|
||||||
|
|
||||||
static valid_event(event){
|
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
|
//events without a position are always valid
|
||||||
if(![UIEvent.press, UIEvent.release, UIEvent.move].contains(event.type)) return true
|
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))")
|
//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 = event.y > 0 //ugly bugs need ugly fixes
|
var valid = Control.contains(event.control, event.x, event.y)
|
||||||
return valid
|
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
|
//hue value saturation to rgb colors. all values in 0-1 range
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue