import "luxe: game" for Ready import "luxe: assets" for Assets import "luxe: input" for Input, Key, MouseButton import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera, UIEventData import "luxe: math" for Math import "luxe: draw" for Draw import "luxe: io" for IO import "luxe: ui" for UI, UIPanel, UILabel, Control, UIEvent import "luxe: color" for Color import "outline/app" for App class Game is Ready { construct ready() { super("ready!") app = App.new() app.color = Color.black System.print("render size: %(app.width) x %(app.height) @ %(app.scale)x") var ui = Entity.create(app.ui) UI.create(ui, 0, 0, app.width, app.height, 0, app.ui_camera) { //cross-control events dont work properly var event_reciever = UIPanel.create(ui) UIPanel.set_color(event_reciever, [1, 0, 0, 1]) Control.set_allow_input(event_reciever, true) Control.set_pos(event_reciever, 100, 100) Control.set_process(event_reciever){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| if(event.control != control) return //required if(event.type == UIEvent.change){ System.print("receive") UIPanel.set_color(event_reciever, [0, 0, 1, 1]) } } var event_sender = UILabel.create(ui) UILabel.set_text(event_sender, "click to change panel.") Control.set_pos(event_sender, 200, 100) Control.set_allow_input(event_sender, true) Control.set_process(event_sender){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| if(event.control != control) return //required if(event.type == UIEvent.press){ System.print("send") UI.events_emit(event_reciever, UIEvent.change) } } } { //cross-control capture doesnt work properly (clicking left control should capture right, but actually captures left with wrong debug vis) var captured = UIPanel.create(ui) Control.set_id(captured, "captured") UIPanel.set_color(captured, [1, 0, 0, 1]) Control.set_allow_input(captured, true) Control.set_pos(captured, 200, 200) Control.set_process(captured){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| if(event.control != control) return //required if(event.type == UIEvent.move){ System.print("move") var rel_pos = inv_lerp(y, y+h, event.y) var col = Color.lerp([1, 0, 0, 1], [0, 0, 1, 1], rel_pos) UIPanel.set_color(captured, col) } } var capturing = UIPanel.create(ui) Control.set_id(capturing, "capturing") UIPanel.set_color(capturing, [1, 0, 0, 1]) Control.set_allow_input(capturing, true) Control.set_pos(capturing, 100, 200) Control.set_process(capturing){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| if(event.control != control) return //required if(event.type == UIEvent.move){ System.print("move") var rel_pos = inv_lerp(y, y+h, event.y) var col = Color.lerp([1, 0, 0, 1], [0, 0, 1, 1], rel_pos) UIPanel.set_color(capturing, col) } if(event.type == UIEvent.press){ System.print("capture other") UI.capture(captured) } } } } //ready inv_lerp(from, to, x){ return (x - from) / (to - from) } tick(delta) { if(Input.key_state_released(Key.escape)) { IO.shutdown() } } //tick destroy() { System.print("unready!") app.destroy() } //destroy app:App { _app } app=(v) { _app=v } } //Game