CabinGame/Luxe/blocks/ui/info.wren

185 lines
No EOL
5.7 KiB
Text

import "luxe: draw" for Draw, PathStyle
import "luxe: world" for Entity, Transform, UI, UIRenderMode
import "luxe: world" for UIBehave, UIContain
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/clickable" for Clickable
import "blocks/ui/image_util" for UiImageUtil
import "math/observable" for Observable
import "math/stringUtil" for StringUtil
import "blocks/ui/simple_text" for UISimpleText
import "blocks/ui/ui" for Ui
import "blocks/human/human" for Human
class UiInfo{
root{_root}
static human{"human"}
static diary{"diary"}
static resources{"resources"}
page{_page}
construct new(ent, ui){
_ent = ent
_ui = ui
_page = Observable.new(UiInfo.human)
_game = Globals["Game"]
_game.focus.on_change(true) {|val|
if(ui.ui_mode == Ui.Info){
if(_page.value == UiInfo.resources){
_page.value = UiInfo.human
}
}
}
setup()
}
setup(){
var ui_rect = Globals["UiRect"]
_root = Control.create(_ent)
Control.set_behave(_root, UIBehave.fill)
Control.set_margin(_root, 0, 0, 0, 0)
toolbar()
human()
diary()
resources()
}
toolbar(){
var ui_rect = Globals["UiRect"]
//list
var list = Control.create(_ent)
Control.set_id(list, "info list")
Control.child_add(_root, list)
//make list span bottom area
Control.set_behave(list, UIBehave.left | UIBehave.right | UIBehave.bottom) //|
Control.set_margin(list, 0, 0, 0, 0)
Control.set_contain(list, UIContain.row | UIContain.start) //|
Control.set_size(list, 16, 16)
var adventureButtons = Assets.image("assets/AdventureButtons")
var tiles = [10, 1]
var button
//toolbar buttons
_ui.list_button(list, [6, 0], "Adventure!") {
_game.adventures.new_or_current()
_ui.ui_mode = Ui.Planning
}
_ui.list_button(list, [2, 0], "Stats") {_page.value = UiInfo.human}
_ui.list_button(list, [1, 0], "Diary") {_page.value = UiInfo.diary}
_ui.list_button(list, [4, 0], "Resources") {_page.value = UiInfo.resources}
}
human(){
var page = Control.create(_ent)
Control.child_add(_root, page)
Control.set_behave(page, UIBehave.fill)
Control.set_margin(page, 0, 0, 0, 16)
_page.on_change(true){|val|
Control.set_visible(page, val == UiInfo.human)
}
var portrait = UIImage.create(_ent)
Control.set_size(portrait, 30, 46)
Control.set_id(portrait, "person info portrait")
Control.child_add(page, portrait)
Control.set_behave(portrait, UIBehave.left | UIBehave.top) //|
Control.set_margin(portrait, 1, 1, 0, 0)
var frame = UIImage.create(_ent)
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")
Control.child_add(portrait, frame)
_game.focus.on_change(true) {|human|
//todo: more sophisticated portrait generation
UIImage.set_image(portrait, Assets.image("assets/wip/Portrait"))
UIImage.set_color(portrait, human ? human.color : [0, 0, 0, 1])
}
var statBlock = Control.create(_ent)
Control.child_add(page, statBlock)
Control.set_behave(statBlock, UIBehave.fill)
Control.set_margin(statBlock, 33, 1, 0, 16)
Control.set_contain(statBlock, UIContain.column | UIContain.start) //|
var name = UISimpleText.create(_ent)
Control.child_add(statBlock, name)
Control.set_id(name, "human name info")
_game.focus.on_change(true) {|human|
var name_string = human ? human.name : "-"
UISimpleText.set_text(name, name_string)
}
var adventures = UISimpleText.create(_ent)
Control.child_add(statBlock, adventures)
Control.set_id(name, "human adventure count")
_game.focus.on_change(true) {|human|
var count = human ? human.adv_count : null
var text = count ? "Adventures: %(count)" : ""
UISimpleText.set_text(adventures, text)
}
}
diary(){
var page = Control.create(_ent)
Control.child_add(_root, page)
Control.set_behave(page, UIBehave.fill)
Control.set_margin(page, 0, 0, 0, 16)
_page.on_change(true){|val|
Control.set_visible(page, val == UiInfo.diary)
}
var title = UISimpleText.create(_ent)
Control.child_add(page, title)
Control.set_id(title, "human name info")
Control.set_behave(title, UIBehave.left | UIBehave.top) //|
Control.set_margin(title, 1, 1, 0, 0)
_game.focus.on_change(true) {|human|
var name = human ? human.name : null
var diary_title = name ? "%(StringUtil.possesive(name)) Diary" : "Diary"
UISimpleText.set_text(title, diary_title)
}
}
resources(){
var page = Control.create(_ent)
Control.child_add(_root, page)
Control.set_behave(page, UIBehave.fill)
Control.set_margin(page, 0, 0, 0, 16)
_page.on_change(true){|val|
Control.set_visible(page, val == UiInfo.resources)
}
var resList = UISimpleText.create(_ent)
Control.child_add(page, resList)
Control.set_behave(resList, UIBehave.left | UIBehave.top) //|
Control.set_margin(resList, 7, 3, 0, 0)
_game.resources.on_change{|val|
var resources = val.list()
var text = resources.map{|res| "%(res["name"]): %(res["amount"])"}.join("\n")
UISimpleText.set_text(resList, text)
}
}
}