almost have some interactivity
This commit is contained in:
parent
10da4eb456
commit
db0fe205ec
10 changed files with 166 additions and 47 deletions
|
|
@ -5,7 +5,6 @@ names = [
|
|||
|
||||
"Bob",
|
||||
"Steve",
|
||||
"Sven",
|
||||
"Ronja",
|
||||
"Amelia",
|
||||
"Chloe",
|
||||
|
|
|
|||
3
Luxe/assets/wip/Frame.image.lx
Normal file
3
Luxe/assets/wip/Frame.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
image = {
|
||||
source = "assets/wip/Frame.png"
|
||||
}
|
||||
BIN
Luxe/assets/wip/Frame.png
Normal file
BIN
Luxe/assets/wip/Frame.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 130 B |
3
Luxe/assets/wip/Portrait.image.lx
Normal file
3
Luxe/assets/wip/Portrait.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
image = {
|
||||
source = "assets/wip/Portrait.png"
|
||||
}
|
||||
BIN
Luxe/assets/wip/Portrait.png
Normal file
BIN
Luxe/assets/wip/Portrait.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 454 B |
|
|
@ -4,6 +4,8 @@ import "math/vector" for Vector
|
|||
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
|
||||
|
||||
//User facing API
|
||||
//This is what the user of your modifier will interact with
|
||||
|
|
@ -27,6 +29,18 @@ class Human {
|
|||
//data.name = id
|
||||
}
|
||||
|
||||
static get_name(entity){
|
||||
if(entity == 0 || !entity) return null
|
||||
var data = Modifiers.get(This, entity)
|
||||
return data.name
|
||||
}
|
||||
|
||||
static get_color(entity){
|
||||
if(entity == 0 || !entity) return null
|
||||
var data = Modifiers.get(This, entity)
|
||||
return data.color
|
||||
}
|
||||
|
||||
} //Human
|
||||
|
||||
//Your modifier system implementation.
|
||||
|
|
@ -71,9 +85,19 @@ class HumanSystem is ModifierSystem {
|
|||
|
||||
var mouse = Globals["GameMouse"]
|
||||
var over = Sprite.contains(entity,mouse.x, mouse.y)
|
||||
if(over && _hoverEnt != entity){
|
||||
_hoverEnt = entity
|
||||
Globals["Tooltip"].set(Strings.get(data.name), entity)
|
||||
if(over){
|
||||
if(_hoverEnt != entity){
|
||||
_hoverEnt = entity
|
||||
Globals["Tooltip"].set(Strings.get(data.name), entity)
|
||||
}
|
||||
if(Input.mouse_state_pressed(MouseButton.left)){
|
||||
|
||||
var game = Globals["Game"]
|
||||
System.print(Ui)
|
||||
if(game.ui.ui_mode == Ui.Info){
|
||||
game.Focus.value = entity
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!over && _hoverEnt == entity){
|
||||
_hoverEnt = null
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import "luxe: assets" for Assets
|
|||
import "globals" for Globals
|
||||
import "blocks/ui/image_button" for ImageButton
|
||||
import "math/observable" for Observable
|
||||
import "blocks/human/human" for Human
|
||||
|
||||
class Ui{
|
||||
static Planning{"planning"}
|
||||
|
|
@ -19,6 +20,7 @@ class Ui{
|
|||
ui_mode=(v){_ui_mode.value = v}
|
||||
|
||||
construct new(app){
|
||||
var game = Globals["Game"]
|
||||
var ui_rect = Globals["UiRect"]
|
||||
|
||||
_ui_mode = Observable.new(Ui.Info)
|
||||
|
|
@ -36,16 +38,27 @@ class Ui{
|
|||
Control.set_visible(_info, val == Ui.Info)
|
||||
UI.commit(_ui)
|
||||
}
|
||||
|
||||
game.Focus.on_change() {|val|
|
||||
System.print(val)
|
||||
ui_mode = Ui.Info
|
||||
}
|
||||
|
||||
UI.commit(_ui)
|
||||
}
|
||||
|
||||
setup_info(){
|
||||
var ui_rect = Globals["UiRect"]
|
||||
var game = Globals["Game"]
|
||||
|
||||
var root = Control.create(_ui)
|
||||
Control.set_size(root, ui_rect.width, ui_rect.height)
|
||||
setup_info_toolbar(root)
|
||||
setup_info_human(root)
|
||||
return root
|
||||
}
|
||||
|
||||
setup_info_toolbar(root){
|
||||
var ui_rect = Globals["UiRect"]
|
||||
|
||||
//list
|
||||
var list = Control.create(_ui)
|
||||
|
|
@ -60,7 +73,7 @@ class Ui{
|
|||
var button
|
||||
|
||||
//plan adventure
|
||||
button = list_button(0)
|
||||
button = list_button(list)
|
||||
Control.set_id(button, "info button %(0)")
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Adventure!")
|
||||
|
|
@ -70,26 +83,45 @@ class Ui{
|
|||
ui_mode = Ui.Planning
|
||||
}
|
||||
}
|
||||
Control.child_add(list, button)
|
||||
|
||||
//info
|
||||
button = list_button(1)
|
||||
Control.set_id(button, "info button %(1)")
|
||||
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(2)
|
||||
Control.set_id(button, "info button %(2)")
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Diary")
|
||||
ImageButton.set_tile_uv(button, tiles, [1, 0])
|
||||
Control.child_add(list, button)
|
||||
|
||||
//resources
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Resources")
|
||||
ImageButton.set_tile_uv(button, tiles, [4, 0])
|
||||
}
|
||||
|
||||
//UIList.refresh(list) //uncomment this when list learns not to be vertical
|
||||
return root
|
||||
setup_info_human(root){
|
||||
var frame = UIImage.create(_ui)
|
||||
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(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])
|
||||
}
|
||||
}
|
||||
|
||||
setup_planning(){
|
||||
|
|
@ -109,11 +141,8 @@ class Ui{
|
|||
var tiles = [10, 1]
|
||||
var button
|
||||
|
||||
var list_id = 0
|
||||
|
||||
//back to info
|
||||
button = list_button(list_id)
|
||||
Control.set_id(button, "plan button %(list_id)")
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Info")
|
||||
ImageButton.set_tile_uv(button, tiles, [1, 0])
|
||||
|
|
@ -122,59 +151,44 @@ class Ui{
|
|||
ui_mode = Ui.Info
|
||||
}
|
||||
}
|
||||
Control.child_add(list, button)
|
||||
list_id = list_id+1
|
||||
|
||||
//abort
|
||||
button = list_button(list_id)
|
||||
Control.set_id(button, "plan button %(list_id)")
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Abort")
|
||||
ImageButton.set_tile_uv(button, tiles, [0, 0])
|
||||
Control.child_add(list, button)
|
||||
list_id = list_id+1
|
||||
|
||||
//people
|
||||
button = list_button(list_id)
|
||||
Control.set_id(button, "plan button %(list_id)")
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Adventurers")
|
||||
ImageButton.set_tooltip(button, "People")
|
||||
ImageButton.set_tile_uv(button, tiles, [2, 0])
|
||||
Control.child_add(list, button)
|
||||
list_id = list_id+1
|
||||
|
||||
//stuff
|
||||
button = list_button(list_id)
|
||||
Control.set_id(button, "plan button %(list_id)")
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Stuff")
|
||||
ImageButton.set_tile_uv(button, tiles, [4, 0])
|
||||
Control.child_add(list, button)
|
||||
list_id = list_id+1
|
||||
|
||||
//direction
|
||||
button = list_button(list_id)
|
||||
Control.set_id(button, "plan button %(list_id)")
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Direction")
|
||||
ImageButton.set_tile_uv(button, tiles, [3, 0])
|
||||
Control.child_add(list, button)
|
||||
list_id = list_id+1
|
||||
|
||||
//go
|
||||
button = list_button(list_id)
|
||||
Control.set_id(button, "plan button %(list_id)")
|
||||
button = list_button(list)
|
||||
UIImage.set_image(button, adventureButtons)
|
||||
ImageButton.set_tooltip(button, "Depart")
|
||||
ImageButton.set_tile_uv(button, tiles, [5, 0])
|
||||
Control.child_add(list, button)
|
||||
list_id = list_id+1
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
list_button(i){
|
||||
list_button(parent){
|
||||
var button = ImageButton.create(_ui)
|
||||
Control.child_add(parent, button)
|
||||
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
|
||||
return button
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import "globals" for Globals, RandomInst
|
|||
import "math/vector" for Vector
|
||||
import "math/rect" for AABB
|
||||
import "math/util" for Util
|
||||
import "math/observable" for Observable
|
||||
import "blocks/tooltip" for Tooltip
|
||||
import "blocks/human/human" for Human
|
||||
|
||||
|
|
@ -22,6 +23,9 @@ class game is Game {
|
|||
construct ready() {
|
||||
Globals["Game"] = this
|
||||
|
||||
_focus = Observable.new()
|
||||
_adventure = Observable.new()
|
||||
|
||||
app = App.new()
|
||||
_ui = Ui.new(app)
|
||||
_tooltip = Tooltip.new(app)
|
||||
|
|
@ -52,13 +56,11 @@ class game is Game {
|
|||
|
||||
_ui.test()
|
||||
|
||||
DrawDebug.rect(game_mouse.x, game_mouse.y, 1, 1)
|
||||
DrawDebug.commit()
|
||||
|
||||
_tooltip.tick()
|
||||
|
||||
app.tick(delta)
|
||||
|
||||
_tooltip.tick() //important to tick after systems to not have a 1 frame lag after setting text
|
||||
} //tick
|
||||
|
||||
destroy() {
|
||||
|
|
@ -94,6 +96,9 @@ class game is Game {
|
|||
Human.set_name(human, name)
|
||||
}
|
||||
|
||||
Focus{_focus}
|
||||
Adventure{_adventure}
|
||||
|
||||
app { _app }
|
||||
app=(v) { _app=v }
|
||||
|
||||
|
|
|
|||
71
Luxe/math/event.wren
Normal file
71
Luxe/math/event.wren
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import "math/util" for Util
|
||||
|
||||
//my own event class because Events does too much with its tags and too little with disposing
|
||||
class Event{
|
||||
construct new(){
|
||||
_listeners = {}
|
||||
_listenersOnce = {}
|
||||
_index = -1
|
||||
}
|
||||
|
||||
listen(fn){
|
||||
_index = _index + 1
|
||||
_listeners[_index] = fn
|
||||
return ListenerToken.new(this, _index)
|
||||
}
|
||||
|
||||
listenOnce(fn){
|
||||
_index = _index + 1
|
||||
_listenersOnce[_index] = fn
|
||||
return ListenerToken.new(this, _index)
|
||||
}
|
||||
|
||||
unlisten(id){
|
||||
if(id is Num) {
|
||||
var removed = false
|
||||
removed = removed || _listeners.remove(id)
|
||||
removed = removed || _listenersOnce.remove(id)
|
||||
if(!removed){
|
||||
System.print("[warn] tried to remove unknown listener id")
|
||||
}
|
||||
} else if(id is Fn){
|
||||
var removed = false
|
||||
System.print(_listeners.keys)
|
||||
for(index in _listeners.keys){
|
||||
if(_listeners[index] == id){
|
||||
//! this might lead to problems because I'm modifying the thing I'm iterating over
|
||||
//in that case we need to defer the removal
|
||||
_listeners.remove(index)
|
||||
removed = true
|
||||
}
|
||||
}
|
||||
if(!removed){
|
||||
System.print("[warn] tried to remove unknown listener fn")
|
||||
}
|
||||
} else if(id is ListenerToken) {
|
||||
id.discard()
|
||||
} else {
|
||||
System.print("[warn] how is a %(id.type.name) related to the listener? pass the listener index or function.")
|
||||
}
|
||||
}
|
||||
|
||||
emit(arguments){
|
||||
_listeners.each{|val|
|
||||
Util.call_arg_list(val, arguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ListenerToken{
|
||||
event{_event}
|
||||
index{_index}
|
||||
|
||||
construct new(event, index){
|
||||
_event = event
|
||||
_index = index
|
||||
}
|
||||
|
||||
discard(){
|
||||
event.unlisten(index)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
engine = {
|
||||
runtime = {
|
||||
window = {
|
||||
width = 540
|
||||
height = 960
|
||||
width = 512
|
||||
height = 768
|
||||
resizable = true
|
||||
fullscreen = false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue