CabinGame/Luxe/blocks/ui/ui.wren
2020-09-21 21:18:07 +02:00

97 lines
No EOL
2.8 KiB
Text

import "luxe: draw" for Draw, PathStyle
import "luxe: world" for Entity, Transform, UI, UIRenderMode
import "luxe: world" for UILayout, UILayoutBehave, UILayoutContain
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
import "luxe: ui/text" for UIText
import "luxe: render" for Material
import "globals" for Globals
import "blocks/ui/image_button" for ImageButton
import "math/observable" for Observable
import "blocks/ui/simple_text" for UISimpleText
class Ui{
static Planning{"planning"}
static Info {"info"}
font{"assets/fonts/BabyBlocks"}
ui_mode{_ui_mode.value}
ui_mode=(v){_ui_mode.value = v}
construct new(app){
var game = Globals["Game"]
var ui_rect = Globals["UiRect"]
_ui_mode = Observable.new(Ui.Info)
_ent = Entity.create(app.ui, "UI Root")
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)
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")
UI.set_material_basis(_ent, "luxe: material_basis/ui_solid", "shaders/pixel_text_ui")
UILayout.create(_ent)
_info = UiInfo.new(_ent, this)
_planning = UiAdventure.new(_ent, this)
_ui_mode.on_change(true) {|val|
Control.set_visible(_planning.root, val == Ui.Planning)
Control.set_visible(_info.root, val == Ui.Info)
UI.commit(_ent)
}
game.Focus.on_change() {|val|
ui_mode = Ui.Info
}
UI.commit(_ent)
UILayout.commit(_ent)
}
list_button(parent){
var button = ImageButton.create(_ent)
Control.set_size(button, 16, 16)
Control.child_add(parent, button)
var adventureButtons = Assets.image("assets/wip/AdventureButtons")
UIImage.set_image(button, adventureButtons)
return button
}
list_button(parent, tile){
var tiles = [10, 1]
var button = list_button(parent)
ImageButton.set_tile_uv(button, tiles, tile)
return button
}
list_button(parent, tile, tooltip){
var button = list_button(parent, tile)
ImageButton.set_tooltip(button, tooltip)
return button
}
list_button(parent, tile, tooltip, pressFn){
var button = list_button(parent, tile, tooltip)
ImageButton.set_state_change(button) { |data|
if(data["press"]){
pressFn.call()
}
}
return button
}
}
//this is behind the class def to make cyclic dependency happy ^^
import "blocks/ui/info" for UiInfo
import "blocks/ui/adventure" for UiAdventure