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

183 lines
No EOL
5.9 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 "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"}
construct new(ent, ui){
_ent = ent
_ui = ui
_page = Observable.new(UiInfo.human)
_focus = Observable.new()
Globals["Game"].Focus.on_change(true) {|val|
if(ui.ui_mode == Ui.Info){
_focus.value = val
if(_page.value == UiInfo.resources){
_page.value = UiInfo.human
}
}
}
setup()
}
setup(){
var ui_rect = Globals["UiRect"]
_root = Control.create(_ent)
UILayout.set_behave(_ent, _root, UILayoutBehave.fill)
UILayout.set_margin(_ent, _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
UILayout.set_behave(_ent, list, UILayoutBehave.left | UILayoutBehave.right | UILayoutBehave.bottom) //|
UILayout.set_margin(_ent, list, 0, 0, 0, 0)
UILayout.set_contain(_ent, list, UILayoutContain.row | UILayoutContain.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!") {
Globals["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)
UILayout.set_behave(_ent, page, UILayoutBehave.fill)
UILayout.set_margin(_ent, 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)
UILayout.set_behave(_ent, portrait, UILayoutBehave.left | UILayoutBehave.top) //|
UILayout.set_margin(_ent, 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)
_focus.on_change(true) {|val|
//todo: more sophisticated portrait generation
UIImage.set_image(portrait, Assets.image("assets/wip/Portrait"))
UIImage.set_color(portrait, Human.get_color(val) || [0, 0, 0, 1])
}
var statBlock = Control.create(_ent)
Control.child_add(page, statBlock)
UILayout.set_behave(_ent, statBlock, UILayoutBehave.fill)
UILayout.set_margin(_ent, statBlock, 33, 1, 0, 16)
UILayout.set_contain(_ent, statBlock, UILayoutContain.column | UILayoutContain.start) //|
var name = UISimpleText.create(_ent)
Control.child_add(statBlock, name)
Control.set_id(name, "human name info")
_focus.on_change(true) {|val|
var name_string = Human.get_name(val) || "-"
UISimpleText.set_text(name, name_string)
}
var adventures = UISimpleText.create(_ent)
Control.child_add(statBlock, adventures)
Control.set_id(name, "human adventure count")
_focus.on_change(true) {|val|
var count = Human.get_adventure_count(val)
var text = count ? "Adventures: %(count)" : ""
UISimpleText.set_text(adventures, text)
}
}
diary(){
var page = Control.create(_ent)
Control.child_add(_root, page)
UILayout.set_behave(_ent, page, UILayoutBehave.fill)
UILayout.set_margin(_ent, 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")
UILayout.set_behave(_ent, title, UILayoutBehave.left | UILayoutBehave.top) //|
UILayout.set_margin(_ent, title, 1, 1, 0, 0)
_focus.on_change(true) {|val|
var name = Human.get_name(val)
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)
UILayout.set_behave(_ent, page, UILayoutBehave.fill)
UILayout.set_margin(_ent, 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)
UILayout.set_behave(_ent, resList, UILayoutBehave.left | UILayoutBehave.top) //|
UILayout.set_margin(_ent, resList, 7, 3, 0, 0)
Globals["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)
}
}
}