CabinGame/Luxe/blocks/ui/ui.wren

94 lines
2.6 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/clickable" for Clickable
import "blocks/ui/image_util" for UiImageUtil
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-10-04 16:35:12 +00:00
planning{_planning}
info{_info}
entity{_ent}
2020-10-04 16:35:12 +00:00
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)
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
2020-10-04 16:35:12 +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-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){
var button = UIImage.create(_ent)
Clickable.make_clickable(button)
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-09-21 19:18:07 +00:00
var adventureButtons = Assets.image("assets/wip/AdventureButtons")
2020-09-19 14:06:46 +00:00
UIImage.set_image(button, adventureButtons)
2020-08-29 06:14:01 +00:00
return button
}
2020-09-19 14:06:46 +00:00
list_button(parent, tile){
var tiles = [10, 1]
var button = list_button(parent)
UiImageUtil.set_tile_uv(button, tiles, tile)
2020-09-19 14:06:46 +00:00
return button
}
list_button(parent, tile, tooltip){
var button = list_button(parent, tile)
Clickable.set_tooltip(button, tooltip)
2020-09-20 09:56:25 +00:00
return button
2020-09-19 14:06:46 +00:00
}
list_button(parent, tile, tooltip, pressFn){
2020-09-20 09:56:25 +00:00
var button = list_button(parent, tile, tooltip)
Clickable.set_on_click(button) {
pressFn.call()
2020-09-19 14:06:46 +00:00
}
2020-09-20 09:56:25 +00:00
return button
2020-09-19 14:06:46 +00:00
}
2020-09-06 15:04:34 +00:00
}
2020-09-06 15:04:41 +00:00
2020-09-20 09:56:25 +00:00
//this is behind the class def to make cyclic dependency happy ^^
2020-09-19 14:06:46 +00:00
import "blocks/ui/info" for UiInfo
import "blocks/ui/adventure" for UiAdventure