CabinGame/Luxe/blocks/ui/adventure.wren

127 lines
3.7 KiB
Text
Raw Normal View History

2020-09-13 15:58:22 +00:00
import "luxe: draw" for Draw, PathStyle
2020-09-21 19:18:07 +00:00
import "luxe: world" for Entity, Transform, UI, UIRenderMode, UIEvent
2020-09-13 15:58:22 +00:00
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
2020-09-19 14:06:46 +00:00
import "blocks/ui/ui" for Ui
2020-09-21 19:18:07 +00:00
import "blocks/ui/compass" for UiCompass
2020-09-13 15:58:22 +00:00
class UiAdventure{
root{_root}
2020-09-21 19:18:07 +00:00
static direction{"direction"}
static people{"people"}
static resources{"resources"}
static depart{"depart"}
2020-09-13 15:58:22 +00:00
construct new(ent, ui){
_ent = ent
_ui = ui
2020-09-21 19:18:07 +00:00
_game = Globals["Game"]
_page = Observable.new(UiAdventure.direction)
2020-09-13 15:58:22 +00:00
setup()
}
setup(){
var ui_rect = Globals["UiRect"]
var game = Globals["Game"]
_root = Control.create(_ent)
2020-09-21 19:18:07 +00:00
Control.set_allow_input(_root, true)
2020-09-13 15:58:22 +00:00
Control.set_size(_root, ui_rect.width, ui_rect.height)
2020-09-21 19:18:07 +00:00
toolbar()
direction()
people()
resources()
depart()
}
toolbar(){
2020-09-13 15:58:22 +00:00
//list
var list = Control.create(_ent)
Control.child_add(_root, list)
Control.set_size(list, 0, 16)
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) //|
2020-09-20 09:56:25 +00:00
//toolbar icons
_ui.list_button(list, [1, 0], "Info") {_ui.ui_mode = Ui.Info}
2020-09-21 19:18:07 +00:00
_ui.list_button(list, [0, 0], "Abort") {
_ui.ui_mode = Ui.Info
_game.adventures.discard()
_page = UiAdventure.direction
}
_ui.list_button(list, [3, 0], "Direction") {_page = UiAdventure.direction}
_ui.list_button(list, [2, 0], "People") {_page = UiAdventure.people}
_ui.list_button(list, [4, 0], "Stuff") {_page = UiAdventure.resources}
_ui.list_button(list, [5, 0], "Depart") {_page = UiAdventure.depart}
}
direction(){
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 == UiAdventure.direction)
}
var compass = UiCompass.create(_ent)
Control.child_add(page, compass)
Control.set_size(compass, 32, 32)
Control.set_events(compass){|event|
if(event.type == UIEvent.change){
System.print(event)
}
}
}
people(){
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 == UiAdventure.people)
}
}
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 == UiAdventure.resources)
}
}
depart(){
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 == UiAdventure.depart)
}
2020-09-13 15:58:22 +00:00
}
}