Compare commits

...

2 commits

Author SHA1 Message Date
Ronja
1ad9014fb1 ui bug? 2020-09-06 17:04:41 +02:00
Ronja
a167c92d2c fix cyclic dependency 2020-09-06 17:04:34 +02:00
4 changed files with 51 additions and 27 deletions

View file

@ -5,9 +5,6 @@ import "math/util" for Util
import "globals" for Globals
import "luxe: assets" for Strings
import "luxe: input" for Input, MouseButton
import "blocks/ui" for Ui
System.print("ui is: %(Ui)")
//User facing API
//This is what the user of your modifier will interact with
@ -50,12 +47,12 @@ class Human {
//to do the actual work. You'll get notified when things change
//in the world and respond to them here.
class HumanSystem is ModifierSystem {
player_start{[26, 89]}
player_size{[10, 12]}
construct new() {
//called when your system is first created.
}
init(world) {
@ -80,8 +77,8 @@ class HumanSystem is ModifierSystem {
}
tick(delta) {
//called usually once every frame.
//called when the world that this modifier lives in, is ticked
//called usually once every frame.
//called when the world that this modifier lives in, is ticked
each {|entity, data|
if(!data.active) return
@ -92,21 +89,19 @@ class HumanSystem is ModifierSystem {
_hoverEnt = entity
Globals["Tooltip"].set(Strings.get(data.name), entity)
}
if(Input.mouse_state_pressed(MouseButton.left)){
var game = Globals["Game"]
System.print(Ui)
import "blocks/ui" for Ui
if(game.ui.ui_mode == Ui.Info){
game.Focus.value = entity
}
}
}
if(!over && _hoverEnt == entity){
_hoverEnt = null
Globals["Tooltip"].clear(entity)
}
}
if(Input.mouse_state_pressed(MouseButton.left)){
var game = Globals["Game"]
if(game.ui.ui_mode == Ui.Info && _hoverEnt){ //remove &&hoverEnt to allow unfocussing
game.Focus.value = _hoverEnt
}
}
} //tick
update(){
@ -132,3 +127,5 @@ class HumanSystem is ModifierSystem {
} //HumanSystem
var Modifier = HumanSystem //required
import "blocks/ui" for Ui //import at the end in case of cyclic dependency

View file

@ -6,16 +6,19 @@ 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 "globals" for Globals
import "blocks/ui/image_button" for ImageButton
import "math/observable" for Observable
import "blocks/human/human" for Human
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}
@ -40,7 +43,6 @@ class Ui{
}
game.Focus.on_change() {|val|
System.print(val)
ui_mode = Ui.Info
}
@ -83,13 +85,12 @@ class Ui{
ui_mode = Ui.Planning
}
}
//info
button = list_button(list)
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Stats")
ImageButton.set_tile_uv(button, tiles, [2, 0])
Control.child_add(list, button)
//read diary
button = list_button(list)
@ -105,6 +106,12 @@ class Ui{
}
setup_info_human(root){
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)
var frame = UIImage.create(_ui)
UIImage.set_image(frame, Assets.image("assets/wip/Frame"))
Control.set_pos(frame, 1, 1)
@ -112,16 +119,14 @@ class Ui{
Control.set_id(frame, "person info frame")
Control.child_add(root, frame)
var portrait = UIImage.create(_ui)
Control.set_size(portrait, 30, 46)
Control.set_id(portrait, "person info portrait")
Control.child_add(frame, portrait)
Globals["Game"].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) || [1, 1, 1, 1])
UIImage.set_color(portrait, Human.get_color(val) || [0, 0, 0, 1])
}
var name = Control.create(_ui)
Control.set_pos(name, 32, 1)
}
setup_planning(){
@ -191,10 +196,14 @@ class Ui{
var i = Control.child_index(parent, button)
Control.set_size(button, 16, 16)
Control.set_pos(button, i*16, 0) //let list handle this in future
System.print("%(Control.get_pos_x(button)), %(Control.get_pos_y(button))")
return button
}
test(){
ImageButton.get_data(_test)
}
}
}
//this is behind the class def to make cyclic dependency happy lol
import "blocks/human/human" for Human

View file

@ -0,0 +1,18 @@
import "luxe: ui/control" for Control
class UISimpleText{
static create(ent){
var text = Control.create(ent)
Control.set_render(text) {|control, state, x,y,w,h|
//System.print(control)
}
return text
}
static set_text(con, text){
System.print(text)
}
}

View file

@ -14,5 +14,5 @@ engine = {
depth = 0
}
//ui.debug_vis = true
ui.debug_vis = true
}