Compare commits
2 commits
129dc58f66
...
7f062de6e6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f062de6e6 | ||
|
|
7da8b274a5 |
19 changed files with 237 additions and 32 deletions
|
|
@ -16,4 +16,8 @@
|
|||
"Mercedes"
|
||||
"Karl"
|
||||
"Lara"
|
||||
"Bug"
|
||||
"Sandra"
|
||||
"Claus"
|
||||
"Niels"
|
||||
]
|
||||
3
Luxe/assets/wip/8Cross.image.lx
Normal file
3
Luxe/assets/wip/8Cross.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
image = {
|
||||
source = "assets/wip/8Cross.png"
|
||||
}
|
||||
BIN
Luxe/assets/wip/8Cross.png
(Stored with Git LFS)
Normal file
BIN
Luxe/assets/wip/8Cross.png
(Stored with Git LFS)
Normal file
Binary file not shown.
3
Luxe/assets/wip/8Head.image.lx
Normal file
3
Luxe/assets/wip/8Head.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
image = {
|
||||
source = "assets/wip/8Head.png"
|
||||
}
|
||||
BIN
Luxe/assets/wip/8Head.png
(Stored with Git LFS)
Normal file
BIN
Luxe/assets/wip/8Head.png
(Stored with Git LFS)
Normal file
Binary file not shown.
|
|
@ -27,6 +27,11 @@ class Adventures{
|
|||
discard(){
|
||||
_planning.value = null
|
||||
}
|
||||
|
||||
set_max_distance(dist){
|
||||
_max_distance = dist
|
||||
planning.emit()
|
||||
}
|
||||
}
|
||||
|
||||
class Adventure{
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class HumanSystem is ModifierSystem {
|
|||
if(Input.mouse_state_pressed(MouseButton.left)){
|
||||
var game = Globals["Game"]
|
||||
if(_hoverEnt){ //remove if statement to allow clicking away (probably needs extra code to allow ui clicking)
|
||||
game.Focus.value = _hoverEnt
|
||||
game.focus.value = _hoverEnt
|
||||
}
|
||||
}
|
||||
} //tick
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import "luxe: world" for Entity, Text, Transform
|
||||
import "luxe: assets" for Assets
|
||||
import "luxe: render" for Material
|
||||
import "luxe: math" for Math
|
||||
|
||||
import "globals" for Globals
|
||||
import "math/vector" for Vector
|
||||
|
|
@ -29,6 +30,8 @@ class Tooltip{
|
|||
Transform.set_snap(shadow, 1, 1, 0)
|
||||
_shadows.add(shadow)
|
||||
}
|
||||
_width = 0
|
||||
_height = 0
|
||||
|
||||
Globals["Tooltip"] = this
|
||||
}
|
||||
|
|
@ -36,6 +39,8 @@ class Tooltip{
|
|||
tick(){
|
||||
var pos = Vector.new(Globals["UiMouse"])
|
||||
if(pos){
|
||||
pos.x = Math.clamp(pos.x, 1, Globals["Renderer"].width - _width - 1)
|
||||
pos.y = Math.clamp(pos.y, 1, Globals["Renderer"].height - _height - 1)
|
||||
if(_x){
|
||||
pos.x = _x
|
||||
}
|
||||
|
|
@ -76,6 +81,10 @@ class Tooltip{
|
|||
_source = source
|
||||
_x = null
|
||||
_y = null
|
||||
|
||||
var extents = Text.get_extents(_text)
|
||||
_width = extents.x
|
||||
_height = extents.y
|
||||
}
|
||||
|
||||
clear(){
|
||||
|
|
@ -84,7 +93,7 @@ class Tooltip{
|
|||
|
||||
clear(source){
|
||||
if(_source != source) return
|
||||
set("", null)
|
||||
set("")
|
||||
_active = false
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,11 @@ import "luxe: world" for Entity, Transform, UI, UIRenderMode, UIEvent
|
|||
import "luxe: world" for UILayout, UILayoutBehave, UILayoutContain
|
||||
import "luxe: ui/control" for Control
|
||||
import "luxe: ui/label" for UILabel
|
||||
import "luxe: ui/image" for UIImage
|
||||
import "luxe: assets" for Assets
|
||||
import "luxe: render" for Material, TextAlign
|
||||
import "luxe: color" for Color
|
||||
import "luxe: game" for Frame
|
||||
|
||||
import "globals" for Globals
|
||||
import "blocks/ui/image_button" for ImageButton
|
||||
|
|
@ -12,8 +15,12 @@ import "math/observable" for Observable
|
|||
import "blocks/ui/simple_text" for UISimpleText
|
||||
import "blocks/ui/ui" for Ui
|
||||
import "blocks/ui/slider" for UiSlider
|
||||
import "blocks/ui/box" for UiBox
|
||||
import "blocks/ui/compass" for UiCompass
|
||||
import "blocks/ui/info" for UiInfo //this is a cyclic dependency waiting to happen
|
||||
import "math/math" for M
|
||||
import "math/util" for Util
|
||||
import "blocks/human/human" for Human
|
||||
|
||||
class UiAdventure{
|
||||
root{_root}
|
||||
|
|
@ -59,15 +66,15 @@ class UiAdventure{
|
|||
|
||||
//toolbar icons
|
||||
_ui.list_button(list, [1, 0], "Info") {_ui.ui_mode = Ui.Info}
|
||||
_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.value = UiAdventure.direction}
|
||||
_ui.list_button(list, [2, 0], "People") {_page.value = UiAdventure.people}
|
||||
_ui.list_button(list, [4, 0], "Stuff") {_page.value = UiAdventure.resources}
|
||||
_ui.list_button(list, [5, 0], "Depart") {_page.value = UiAdventure.depart}
|
||||
_ui.list_button(list, [0, 0], "Abort") {
|
||||
_ui.ui_mode = Ui.Info
|
||||
_game.adventures.discard()
|
||||
_page.value = UiAdventure.direction
|
||||
}
|
||||
}
|
||||
|
||||
direction(){
|
||||
|
|
@ -161,18 +168,13 @@ class UiAdventure{
|
|||
UILayout.set_behave(_ent, text, UILayoutBehave.left) //|
|
||||
UILayout.set_margin(_ent, text, 4, 8, 4, 0)
|
||||
|
||||
var update_text = Fn.new{
|
||||
var adventure = _game.adventures.planning.value
|
||||
if(adventure == null) return
|
||||
var direction = full_step_names[adventure.direction]
|
||||
System.print("-----")
|
||||
System.print(adventure)
|
||||
System.print(adventure.distance)
|
||||
var dist = adventure.distance
|
||||
System.print(dist)
|
||||
UILabel.set_text(text, "%(dist)km %(direction)")
|
||||
_game.adventures.planning.on_change(true) { |val|
|
||||
if(val == null) return
|
||||
//this stuff does bad things
|
||||
var dir = full_step_names[val.direction]
|
||||
var dist = val.distance
|
||||
UILabel.set_text(text, "%(dist)km\n%(dir)")
|
||||
}
|
||||
_game.adventures.planning.on_change(true, update_text)
|
||||
}
|
||||
|
||||
people(){
|
||||
|
|
@ -184,6 +186,94 @@ class UiAdventure{
|
|||
_page.on_change(true){|val|
|
||||
Control.set_visible(page, val == UiAdventure.people)
|
||||
}
|
||||
|
||||
_game.focus.on_change(true) {|val|
|
||||
if(!val) return
|
||||
if(_ui.ui_mode == Ui.Planning && _page.value == UiAdventure.people){
|
||||
var adventure = _game.adventures.planning
|
||||
if(adventure.value && !adventure.value.adventurers.contains(val)) {
|
||||
adventure.value.adventurers.insert(0, val)
|
||||
adventure.emit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var list = UiBox.create(_ent)
|
||||
Control.child_add(page, list)
|
||||
Control.set_clip(list, true)
|
||||
UILayout.set_contain(_ent, list, UILayoutContain.column | UILayoutContain.start) //|
|
||||
UILayout.set_behave(_ent, list, UILayoutBehave.fill)
|
||||
UILayout.set_margin(_ent, list, 40, 0, 0, 0)
|
||||
|
||||
var tiny_head = Assets.image("assets/wip/8Head")
|
||||
var x_image = Assets.image("assets/wip/8Cross")
|
||||
|
||||
_adventurerListItems = []
|
||||
_game.adventures.planning.on_change(true) {|adventure|
|
||||
//cleanup
|
||||
_adventurerListItems.each{|item|
|
||||
Control.destroy(item)
|
||||
}
|
||||
_adventurerListItems.clear()
|
||||
|
||||
if(!adventure) return
|
||||
|
||||
//rebuild
|
||||
adventure.adventurers.each{ |adventurer|
|
||||
var item = UiBox.create(_ent)
|
||||
Control.child_add(list, item)
|
||||
UILayout.set_behave(_ent, item, UILayoutBehave.left | UILayoutBehave.right)//|
|
||||
UILayout.set_margin(_ent, item, 0, 0, 0, 0)
|
||||
UILayout.set_contain(_ent, item, UILayoutContain.row | UILayoutContain.start)//|
|
||||
Control.set_size(item, -1, 12)
|
||||
Control.set_allow_input(item, true)
|
||||
Control.set_events(item) {|event|
|
||||
if(UI.event_cancelled(_ent, event.id)) return
|
||||
if(event.type == UIEvent.press){
|
||||
_ui.ui_mode = Ui.Info
|
||||
_ui.info.page.value = UiInfo.human
|
||||
_game.focus.value = adventurer
|
||||
}
|
||||
}
|
||||
|
||||
var head = UIImage.create(_ent)
|
||||
Control.child_add(item, head)
|
||||
Control.set_size(head, 8, 8)
|
||||
UIImage.set_image(head, tiny_head)
|
||||
UIImage.set_color(head, Human.get_color(adventurer))
|
||||
UILayout.set_margin(_ent, head, 2, 0, 0, 0)
|
||||
|
||||
var name = UILabel.create(_ent)
|
||||
Control.child_add(item, name)
|
||||
UILabel.set_align_vertical(name, TextAlign.bottom)
|
||||
UILabel.set_font(name, _ui.font)
|
||||
UILabel.set_text_size(name, 8)
|
||||
UILabel.set_text(name, Human.get_name(adventurer))
|
||||
UILayout.set_behave(_ent, name, UILayoutBehave.hfill | UILayoutBehave.left)//|
|
||||
UILayout.set_margin(_ent, name, 2, 1, 0, 1)
|
||||
|
||||
var remove = ImageButton.create(_ent)
|
||||
Control.child_add(item, remove)
|
||||
Control.set_size(remove, 8, 8)
|
||||
UIImage.set_image(remove, x_image)
|
||||
UIImage.set_color(remove, Color.hex(0xec172a))
|
||||
UILayout.set_margin(_ent, remove, 0, 0, 2, 0)
|
||||
ImageButton.set_tooltip(remove, "remove")
|
||||
ImageButton.set_state_change(remove) { |data, button|
|
||||
if(data["press"]){
|
||||
Frame.end{
|
||||
Globals["Tooltip"].clear(button)
|
||||
Util.remove(adventure.adventurers, adventurer)
|
||||
_game.adventures.planning.emit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_adventurerListItems.add(item)
|
||||
}
|
||||
UILayout.commit(_ent)
|
||||
UI.commit(_ent)
|
||||
}
|
||||
}
|
||||
|
||||
resources(){
|
||||
|
|
|
|||
28
Luxe/blocks/ui/box.wren
Normal file
28
Luxe/blocks/ui/box.wren
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import "luxe: ui/control" for Control
|
||||
import "luxe: world" for UI, World, UIEvent
|
||||
import "luxe: draw" for PathStyle
|
||||
import "luxe: assets" for Assets
|
||||
import "luxe: render" for Image
|
||||
import "luxe: math" for Math
|
||||
|
||||
import "globals" for Globals
|
||||
import "math/rect" for AABB
|
||||
import "math/math" for M
|
||||
import "blocks/debug" for DrawDebug
|
||||
|
||||
class UiBox{
|
||||
|
||||
static create(ent){
|
||||
var box = Control.create(ent)
|
||||
var style = PathStyle.new()
|
||||
style.color = [1,1,1,1]
|
||||
style.thickness = 1
|
||||
Control.set_state_data(box, {"style": style})
|
||||
Control.set_render(box) {|control, state, x, y, w, h|
|
||||
var depth = UI.draw_depth_of(control, 0)
|
||||
UI.draw_rect(control, x+0.5, y+0.5, depth, w-1, h-1, 0, state["style"])
|
||||
}
|
||||
return box
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ class UiCompass{
|
|||
style.color = [1,1,1,1]
|
||||
style.thickness = 2
|
||||
Control.set_allow_input(compass, true)
|
||||
Control.set_state_data(compass, {"angle": 0, "style": style, "pressed": false}) //angle is in radians between 0 and tau
|
||||
Control.set_state_data(compass, {"angle": 0, "style": style, "pressed": false}) //angle is in degree tragically
|
||||
Control.set_render(compass) {|control, state, x, y, w, h|
|
||||
var depth = UI.draw_depth_of(control, 0)
|
||||
var center = [x + w/2, y + h/2]
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class ImageButton{
|
|||
Globals["Tooltip"].clear(button)
|
||||
}
|
||||
}
|
||||
UI.event_cancel(ent, event.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ class UiInfo{
|
|||
static diary{"diary"}
|
||||
static resources{"resources"}
|
||||
|
||||
page{_page}
|
||||
|
||||
construct new(ent, ui){
|
||||
_ent = ent
|
||||
_ui = ui
|
||||
|
|
@ -32,7 +34,7 @@ class UiInfo{
|
|||
_page = Observable.new(UiInfo.human)
|
||||
|
||||
_focus = Observable.new()
|
||||
Globals["Game"].Focus.on_change(true) {|val|
|
||||
Globals["Game"].focus.on_change(true) {|val|
|
||||
if(ui.ui_mode == Ui.Info){
|
||||
_focus.value = val
|
||||
if(_page.value == UiInfo.resources){
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ class Ui{
|
|||
ui_mode{_ui_mode.value}
|
||||
ui_mode=(v){_ui_mode.value = v}
|
||||
|
||||
planning{_planning}
|
||||
info{_info}
|
||||
|
||||
construct new(app){
|
||||
var game = Globals["Game"]
|
||||
var ui_rect = Globals["UiRect"]
|
||||
|
|
@ -34,9 +37,6 @@ class Ui{
|
|||
|
||||
UI.create(_ent, ui_rect.x, ui_rect.y, ui_rect.width, ui_rect.height, 0, app.ui_camera)
|
||||
UI.set_render_mode(_ent, UIRenderMode.world)
|
||||
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(_ent, "luxe: material_basis/ui_solid", "shaders/pixel_text_ui")
|
||||
|
||||
UILayout.create(_ent)
|
||||
|
|
@ -44,15 +44,11 @@ class Ui{
|
|||
_info = UiInfo.new(_ent, this)
|
||||
_planning = UiAdventure.new(_ent, this)
|
||||
|
||||
_ui_mode.on_change(true) {|val|
|
||||
_ui_mode.on_change(true) {|val|
|
||||
Control.set_visible(_planning.root, val == Ui.Planning)
|
||||
Control.set_visible(_info.root, val == Ui.Info)
|
||||
UI.commit(_ent)
|
||||
}
|
||||
|
||||
game.Focus.on_change() {|val|
|
||||
ui_mode = Ui.Info
|
||||
}
|
||||
|
||||
UI.commit(_ent)
|
||||
UILayout.commit(_ent)
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class Game is Ready {
|
|||
Human.set_name(human, name)
|
||||
}
|
||||
|
||||
Focus{_focus}
|
||||
focus{_focus}
|
||||
adventures{_adventures}
|
||||
resources{_resources}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,4 +72,26 @@ class ListenerToken{
|
|||
discard(){
|
||||
event.unlisten(index)
|
||||
}
|
||||
}
|
||||
|
||||
class MultiListenerToken{
|
||||
events{_events}
|
||||
indices{_indices}
|
||||
|
||||
construct new(tokens){
|
||||
_events = []
|
||||
_indices = []
|
||||
tokens.each{|token| add(token)}
|
||||
}
|
||||
|
||||
add(token){
|
||||
_events.add(token.event)
|
||||
_indices.add(token.index)
|
||||
}
|
||||
|
||||
discard(){
|
||||
Util.for_all([events, indices]) {|event, index|
|
||||
event.unlisten(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import "math/event" for Event
|
||||
import "math/event" for Event, MultiListenerToken
|
||||
import "math/util" for Util
|
||||
|
||||
class Observable{
|
||||
value{_value}
|
||||
|
|
@ -47,4 +48,21 @@ class Observable{
|
|||
_event.once(fn)
|
||||
}
|
||||
}
|
||||
|
||||
static any_change(observables, fn){
|
||||
var change_method = Fn.new{|whatever|
|
||||
Util.call_arg_list(fn, observables.map{|observable| observable.value.toList})
|
||||
}
|
||||
var tokens = observables.map{|observable|
|
||||
return observable.on_change(change_method)
|
||||
}
|
||||
return MultiListenerToken.new(tokens)
|
||||
}
|
||||
|
||||
static any_change(observables, initial, fn){
|
||||
if(initial){
|
||||
Util.call_arg_list(fn, observables.map{|observable|observable.value}.toList)
|
||||
}
|
||||
any_change(observables, fn)
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,22 @@ class Util{
|
|||
}
|
||||
}
|
||||
|
||||
static index_of(sequence, element){
|
||||
var index = -1
|
||||
var any = sequence.any{|elem|
|
||||
index = index + 1
|
||||
return elem == element
|
||||
}
|
||||
return any ? index : -1
|
||||
}
|
||||
|
||||
static remove(list, element){
|
||||
var index = index_of(list, element)
|
||||
if(index < 0) return false
|
||||
list.removeAt(index)
|
||||
return true
|
||||
}
|
||||
|
||||
static for_all(sequences, fn){
|
||||
var count = sequences.count
|
||||
var counter = (0...count)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ engine = {
|
|||
stencil = 0
|
||||
depth = 0
|
||||
}
|
||||
}
|
||||
|
||||
//ui.debug_vis = true
|
||||
}
|
||||
//debug stuff
|
||||
//engine.ui.debug_vis = true
|
||||
engine.render.opengl.debug_level = 3
|
||||
Loading…
Reference in a new issue