CabinGame/Luxe/blocks/ui.wren

237 lines
7.5 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)
_ui = Entity.create(app.ui, "UI Root")
UI.create(_ui, ui_rect.x, ui_rect.y, ui_rect.width, ui_rect.height, 0, app.ui_camera)
UI.set_render_mode(_ui, 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")
UI.set_material_basis(_ui, "luxe: material_basis/ui_solid", "shaders/pixel_text_ui")
UILayout.create(_ui)
2020-08-16 13:59:43 +00:00
2020-08-29 06:14:01 +00:00
_info = setup_info()
_planning = setup_planning()
_ui_mode.on_change(true) {|val|
Control.set_visible(_planning, val == Ui.Planning)
Control.set_visible(_info, val == Ui.Info)
UI.commit(_ui)
}
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
UI.commit(_ui)
2020-09-12 09:35:28 +00:00
UILayout.commit(_ui)
2020-08-29 06:14:01 +00:00
}
setup_info(){
var ui_rect = Globals["UiRect"]
var root = Control.create(_ui)
2020-09-12 09:35:28 +00:00
UILayout.set_behave(_ui, root, UILayoutBehave.fill)
UILayout.set_margin(_ui, root, 0, 0, 0, 0)
2020-09-06 13:05:13 +00:00
setup_info_toolbar(root)
setup_info_human(root)
return root
}
setup_info_toolbar(root){
var ui_rect = Globals["UiRect"]
2020-08-29 06:14:01 +00:00
//list
2020-09-03 16:24:42 +00:00
var list = Control.create(_ui)
2020-09-03 15:31:23 +00:00
Control.set_id(list, "info list")
2020-08-29 06:14:01 +00:00
Control.child_add(root, list)
2020-09-12 09:35:28 +00:00
//make list span bottom area
UILayout.set_behave(_ui, list, UILayoutBehave.left | UILayoutBehave.right | UILayoutBehave.bottom)
UILayout.set_margin(_ui, list, 0, 0, 0, 0)
UILayout.set_contain(_ui, list, UILayoutContain.row | UILayoutContain.start)
Control.set_size(list, 16, 16)
2020-08-16 13:59:43 +00:00
var adventureButtons = Assets.image("assets/AdventureButtons")
2020-08-29 06:14:01 +00:00
var tiles = [10, 1]
var button
2020-08-16 13:59:43 +00:00
2020-08-29 06:14:01 +00:00
//plan adventure
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Adventure!")
ImageButton.set_tile_uv(button, tiles, [1, 0])
2020-08-29 19:25:16 +00:00
ImageButton.set_state_change(button) { |data|
2020-08-29 06:14:01 +00:00
if(data["press"]){
ui_mode = Ui.Planning
}
}
2020-09-06 15:04:41 +00:00
2020-08-29 06:14:01 +00:00
//info
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Stats")
ImageButton.set_tile_uv(button, tiles, [2, 0])
//read diary
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Diary")
ImageButton.set_tile_uv(button, tiles, [1, 0])
2020-09-06 13:05:13 +00:00
//resources
button = list_button(list)
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Resources")
ImageButton.set_tile_uv(button, tiles, [4, 0])
}
2020-08-16 13:59:43 +00:00
2020-09-06 13:05:13 +00:00
setup_info_human(root){
2020-09-06 15:04:41 +00:00
var portrait = UIImage.create(_ui)
Control.set_pos(portrait, 1, 1)
Control.set_size(portrait, 30, 46)
Control.set_id(portrait, "person info portrait")
Control.child_add(root, portrait)
2020-09-12 09:35:28 +00:00
UILayout.set_behave(_ui, portrait, UILayoutBehave.left | UILayoutBehave.top)
UILayout.set_margin(_ui, portrait, 1, 1, 0, 0)
2020-09-06 15:04:41 +00:00
2020-09-06 13:05:13 +00:00
var frame = UIImage.create(_ui)
UIImage.set_image(frame, Assets.image("assets/wip/Frame"))
Control.set_pos(frame, 1, 1)
Control.set_size(frame, 30, 46)
Control.set_id(frame, "person info frame")
2020-09-12 09:35:28 +00:00
Control.child_add(portrait, frame)
2020-09-06 13:05:13 +00:00
Globals["Game"].Focus.on_change(true) {|val|
//todo: more sophisticated portrait generation
UIImage.set_image(portrait, Assets.image("assets/wip/Portrait"))
2020-09-06 15:04:41 +00:00
UIImage.set_color(portrait, Human.get_color(val) || [0, 0, 0, 1])
2020-09-06 13:05:13 +00:00
}
2020-09-06 15:04:41 +00:00
2020-09-12 09:35:28 +00:00
var statBlock = Control.create(_ui)
UILayout.set_behave(_ui, statBlock, UILayoutBehave.fill)
UILayout.set_margin(_ui, statBlock, 33, 1, 0, 16)
UILayout.set_contain(_ui, statBlock, UILayoutContain.column | UILayoutContain.start)
var name = UISimpleText.create(_ui)
2020-09-12 09:35:28 +00:00
Control.child_add(statBlock, name)
Control.set_id(name, "human name info")
Globals["Game"].Focus.on_change(true) {|val|
var name_string = Human.get_name(val) || "-"
2020-09-12 05:21:12 +00:00
UISimpleText.set_text(name, name_string)
}
var adventures = UISimpleText.create(_ui)
2020-09-12 09:35:28 +00:00
Control.child_add(statBlock, adventures)
2020-09-12 05:21:12 +00:00
Control.set_id(name, "human adventure count")
Globals["Game"].Focus.on_change(true) {|val|
var count = Human.get_adventure_count(val)
var text = count ? "Adventures: %(count)" : ""
UISimpleText.set_text(adventures, text)
}
2020-08-29 06:14:01 +00:00
}
2020-08-16 13:59:43 +00:00
2020-08-29 06:14:01 +00:00
setup_planning(){
var ui_rect = Globals["UiRect"]
var game = Globals["Game"]
var root = Control.create(_ui)
Control.set_size(root, ui_rect.width, ui_rect.height)
//list
2020-09-03 16:24:42 +00:00
var list = Control.create(_ui)
2020-08-29 06:14:01 +00:00
Control.child_add(root, list)
2020-09-12 09:35:28 +00:00
Control.set_size(list, 0, 16)
UILayout.set_behave(_ui, list, UILayoutBehave.left | UILayoutBehave.right | UILayoutBehave.bottom)
UILayout.set_margin(_ui, list, 0, 0, 0, 0)
UILayout.set_contain(_ui, list, UILayoutContain.row | UILayoutContain.start)
2020-08-29 06:14:01 +00:00
var adventureButtons = Assets.image("assets/AdventureButtons")
var tiles = [10, 1]
var button
//back to info
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Info")
ImageButton.set_tile_uv(button, tiles, [1, 0])
2020-09-12 05:21:12 +00:00
ImageButton.set_state_change(button) { |data|
2020-08-29 06:14:01 +00:00
if(data["press"]){
ui_mode = Ui.Info
}
}
2020-08-29 06:14:01 +00:00
//abort
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Abort")
ImageButton.set_tile_uv(button, tiles, [0, 0])
//people
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
2020-09-06 13:05:13 +00:00
ImageButton.set_tooltip(button, "People")
2020-08-29 06:14:01 +00:00
ImageButton.set_tile_uv(button, tiles, [2, 0])
2020-08-16 13:59:43 +00:00
2020-08-29 06:14:01 +00:00
//stuff
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Stuff")
ImageButton.set_tile_uv(button, tiles, [4, 0])
//direction
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Direction")
ImageButton.set_tile_uv(button, tiles, [3, 0])
2020-08-29 06:14:01 +00:00
//go
2020-09-06 13:05:13 +00:00
button = list_button(list)
2020-08-29 06:14:01 +00:00
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Depart")
ImageButton.set_tile_uv(button, tiles, [5, 0])
return root
}
2020-09-06 13:05:13 +00:00
list_button(parent){
2020-08-29 06:14:01 +00:00
var button = ImageButton.create(_ui)
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
import "blocks/human/human" for Human