CabinGame/Luxe/blocks/ui.wren

72 lines
2.2 KiB
Text
Raw Normal View History

2020-08-16 13:59:43 +00:00
import "luxe: draw" for Draw, PathStyle
import "luxe: world" for Entity, Transform, UI, UIRenderMode
2020-09-12 09:35:28 +00:00
import "luxe: world" for UILayout, UILayoutBehave, UILayoutContain
2020-08-16 13:59:43 +00:00
import "luxe: ui/control" for Control
import "luxe: ui/panel" for UIPanel
import "luxe: ui/list" for UIList
import "luxe: ui/button" for UIButton
import "luxe: ui/image" for UIImage
import "luxe: assets" for Assets
2020-09-06 15:04:41 +00:00
import "luxe: ui/text" for UIText
2020-09-12 09:35:28 +00:00
import "luxe: render" for Material
import "globals" for Globals
import "blocks/ui/image_button" for ImageButton
2020-08-29 06:14:01 +00:00
import "math/observable" for Observable
2020-09-06 15:04:41 +00:00
import "blocks/ui/simple_text" for UISimpleText
2020-08-16 13:59:43 +00:00
class Ui{
2020-08-29 06:14:01 +00:00
static Planning{"planning"}
static Info {"info"}
2020-09-06 15:04:41 +00:00
font{"assets/fonts/BabyBlocks"}
2020-08-29 06:14:01 +00:00
ui_mode{_ui_mode.value}
ui_mode=(v){_ui_mode.value = v}
2020-08-29 06:14:01 +00:00
construct new(app){
2020-09-06 13:05:13 +00:00
var game = Globals["Game"]
var ui_rect = Globals["UiRect"]
2020-08-29 06:14:01 +00:00
_ui_mode = Observable.new(Ui.Info)
2020-09-13 15:58:22 +00:00
_ent = Entity.create(app.ui, "UI Root")
2020-09-13 15:58:22 +00:00
UI.create(_ent, ui_rect.x, ui_rect.y, ui_rect.width, ui_rect.height, 0, app.ui_camera)
UI.set_render_mode(_ent, UIRenderMode.world)
2020-09-12 09:35:28 +00:00
var solid_mat = Material.create("luxe: material_basis/ui_solid")
var text_mat = Material.create("luxe: material_basis/ui_font")
//var text_mat = Material.create("shaders/pixel_text_ui")
2020-09-13 15:58:22 +00:00
UI.set_material_basis(_ent, "luxe: material_basis/ui_solid", "shaders/pixel_text_ui")
2020-09-12 09:35:28 +00:00
2020-09-13 15:58:22 +00:00
UILayout.create(_ent)
2020-08-16 13:59:43 +00:00
2020-09-13 15:58:22 +00:00
_info = UiInfo.new(_ent, this)
_planning = UiAdventure.new(_ent, this)
2020-08-29 06:14:01 +00:00
_ui_mode.on_change(true) {|val|
2020-09-13 15:58:22 +00:00
Control.set_visible(_planning.root, val == Ui.Planning)
Control.set_visible(_info.root, val == Ui.Info)
UI.commit(_ent)
2020-08-29 06:14:01 +00:00
}
2020-09-06 13:05:13 +00:00
game.Focus.on_change() {|val|
ui_mode = Ui.Info
}
2020-08-29 06:14:01 +00:00
2020-09-13 15:58:22 +00:00
UI.commit(_ent)
UILayout.commit(_ent)
2020-08-29 06:14:01 +00:00
}
2020-09-06 13:05:13 +00:00
list_button(parent){
2020-09-13 15:58:22 +00:00
var button = ImageButton.create(_ent)
2020-08-29 06:14:01 +00:00
Control.set_size(button, 16, 16)
2020-09-12 09:35:28 +00:00
Control.child_add(parent, button)
2020-08-29 06:14:01 +00:00
return button
}
2020-09-06 15:04:34 +00:00
}
2020-09-06 15:04:41 +00:00
2020-09-06 15:04:34 +00:00
//this is behind the class def to make cyclic dependency happy lol
2020-09-13 15:58:22 +00:00
import "blocks/human/human" for Human
import "blocks/info" for UiInfo
import "blocks/adventure" for UiAdventure