From 63da634e7de7febbf2cae6ced4e5c00b95e61b98 Mon Sep 17 00:00:00 2001 From: Ronja Date: Sun, 11 Oct 2020 20:18:48 +0200 Subject: [PATCH] ugly fix for ugly bug --- Luxe/assets/names.lx | 21 +++++++++++++++++++++ Luxe/blocks/ui/adventure.wren | 9 +++++++-- Luxe/blocks/ui/image_button.wren | 2 ++ Luxe/math/rect.wren | 14 ++++++++++++-- Luxe/math/util.wren | 18 ++++++++++++++++++ 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/Luxe/assets/names.lx b/Luxe/assets/names.lx index b0f2136..22e3779 100644 --- a/Luxe/assets/names.lx +++ b/Luxe/assets/names.lx @@ -4,23 +4,44 @@ //probably better to do when I have a procgen text engine "Amelia" + "Bertine" "Bob" "Bug" "Chloe" + "Chris" "Claus" + "Cloud" + "Duck" + "Elliott" + "Freya" "Ida" "Innes" + "Jess" "Jules" "Karl" + "Karo" "Lara" + "Laura" "Lauren" + "Leibi" "Levi" + "Mandy" + "Mara" "Mercedes" + "Merryl" "Niels" + "Nina" "Rami" "Richard" + "Rob" + "Robin" "Ronja" "Sandra" "Simon" "Steve" + "Sven" + "Sy" + "Ty" + "Wocky" + "Zoe" ] \ No newline at end of file diff --git a/Luxe/blocks/ui/adventure.wren b/Luxe/blocks/ui/adventure.wren index 4a4afc2..9c59bed 100644 --- a/Luxe/blocks/ui/adventure.wren +++ b/Luxe/blocks/ui/adventure.wren @@ -4,7 +4,7 @@ import "luxe: world" for UILayout, UILayoutBehave, UILayoutContain import "luxe: ui/control" for Control import "luxe: ui/label" for UILabel import "luxe: ui/image" for UIImage -import "luxe: assets" for Assets +import "luxe: assets" for Assets, Strings import "luxe: render" for Material, TextAlign import "luxe: color" for Color import "luxe: game" for Frame @@ -226,10 +226,15 @@ class UiAdventure{ UILayout.set_contain(_ent, item, UILayoutContain.row | UILayoutContain.start)//| Control.set_size(item, -1, 12) Control.set_allow_input(item, true) - Control.set_id(item, "Person %(i)") + Control.set_id(item, "Person %(i) : %(Human.get_name(adventurer))") + System.print(Strings.get(Control.get_id(item))) Control.set_events(item) {|event| if(UI.event_cancelled(_ent, event.id)) return + if(!Util.valid_event(event)) return if(event.type == UIEvent.press){ + System.print("entity: %(Strings.get(Control.get_id(item)))") + System.print("focussed: %(UI.get_focused(_ent))") + System.print("event: %(event)") _ui.ui_mode = Ui.Info _ui.info.page.value = UiInfo.human _game.focus.value = adventurer diff --git a/Luxe/blocks/ui/image_button.wren b/Luxe/blocks/ui/image_button.wren index 373ce50..2c609c2 100644 --- a/Luxe/blocks/ui/image_button.wren +++ b/Luxe/blocks/ui/image_button.wren @@ -3,6 +3,7 @@ import "luxe: world" for UIEvent, UI import "luxe: ui/control" for Control import "globals" for Globals +import "math/util" for Util class ImageButton{ static create(ent){ @@ -16,6 +17,7 @@ class ImageButton{ Control.set_state_data(button, data) Control.set_events(button) {|event| + if(!Util.valid_event(event)) return var data = null if(event.type == UIEvent.enter){ data = Control.get_state_data(button) diff --git a/Luxe/math/rect.wren b/Luxe/math/rect.wren index 6cf9b17..b495313 100644 --- a/Luxe/math/rect.wren +++ b/Luxe/math/rect.wren @@ -1,5 +1,4 @@ import "math/vector" for Vector -import "math/math" for M class AABB{ x{_x} @@ -51,6 +50,11 @@ class AABB{ return M.inv_lerp(min, max, vector) } + contains_point(vector){ + return vector.x > min_x && vector.y > min_y && + vector.x < max_x && vector.y < max_y + } + static ONE(){ return new(0, 0, 1, 1) } @@ -66,6 +70,10 @@ class AABB{ _height = max_y - min_y } + static from_list(list){ + return new(list.x, list.y, list.z, list.w) + } + static intersects(one, other){ return one.max > other.min && one.min < other.max } @@ -89,4 +97,6 @@ class AABB{ var half_amount = [amount.x/2, amount.y/2] return AABB.new(rect.pos - half_amount, rect.size + amount) } -} \ No newline at end of file +} + +import "math/math" for M \ No newline at end of file diff --git a/Luxe/math/util.wren b/Luxe/math/util.wren index 71a0bc0..be40141 100644 --- a/Luxe/math/util.wren +++ b/Luxe/math/util.wren @@ -1,7 +1,11 @@ import "luxe: assets" for Assets import "luxe: render" for Material +import "luxe: ui/control" for Control +import "luxe: world" for UIEvent + import "math/math" for M import "math/Vector" for Vector +import "math/rect" for AABB class Util{ static material_from_image_path(path){ @@ -86,6 +90,20 @@ class Util{ } } + static valid_event(event){ + //events without a position are always valid + if(![UIEvent.press, UIEvent.release, UIEvent.move].contains(event.type)) return true + + //System.print("type: %(UIEvent.name(event.type))") + var valid = event.y > 0 //ugly bugs need ugly fixes + 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 static hsv(h, s, v){ //hue to rgb