compassing
This commit is contained in:
parent
46fd094a79
commit
ee46e22899
13 changed files with 203 additions and 14 deletions
BIN
Assets/wipButtons.aseprite
(Stored with Git LFS)
Normal file
BIN
Assets/wipButtons.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
3
Luxe/assets/wip/AdventureButtons.image.lx
Normal file
3
Luxe/assets/wip/AdventureButtons.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
image = {
|
||||||
|
source = "assets/wip/AdventureButtons.png"
|
||||||
|
}
|
||||||
BIN
Luxe/assets/wip/AdventureButtons.png
(Stored with Git LFS)
Normal file
BIN
Luxe/assets/wip/AdventureButtons.png
(Stored with Git LFS)
Normal file
Binary file not shown.
3
Luxe/assets/wip/Needle.image.lx
Normal file
3
Luxe/assets/wip/Needle.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
image = {
|
||||||
|
source = "assets/wip/Needle.png"
|
||||||
|
}
|
||||||
BIN
Luxe/assets/wip/Needle.png
(Stored with Git LFS)
Normal file
BIN
Luxe/assets/wip/Needle.png
(Stored with Git LFS)
Normal file
Binary file not shown.
|
|
@ -34,6 +34,20 @@ class DrawDebug{
|
||||||
style.color = col
|
style.color = col
|
||||||
Draw.rect(__context, x, y, 0, w, h, 0, style)
|
Draw.rect(__context, x, y, 0, w, h, 0, style)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static line(v0, v1){
|
||||||
|
line(v0.x, v0.y, v1.x, v1.y)
|
||||||
|
}
|
||||||
|
|
||||||
|
static line(x0, y0, x1, y1){
|
||||||
|
line(x0, y0, x1, y1, [1, 0, 0, 1])
|
||||||
|
}
|
||||||
|
|
||||||
|
static line(x0, y0, x1, y1, col){
|
||||||
|
var style = PathStyle.new()
|
||||||
|
style.color = col
|
||||||
|
Draw.line(__context, x0, y0, x1, y1, 0, style)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import "luxe: draw" for Draw, PathStyle
|
import "luxe: draw" for Draw, PathStyle
|
||||||
import "luxe: world" for Entity, Transform, UI, UIRenderMode
|
import "luxe: world" for Entity, Transform, UI, UIRenderMode, UIEvent
|
||||||
import "luxe: world" for UILayout, UILayoutBehave, UILayoutContain
|
import "luxe: world" for UILayout, UILayoutBehave, UILayoutContain
|
||||||
import "luxe: ui/control" for Control
|
import "luxe: ui/control" for Control
|
||||||
import "luxe: ui/panel" for UIPanel
|
import "luxe: ui/panel" for UIPanel
|
||||||
|
|
@ -15,14 +15,23 @@ import "blocks/ui/image_button" for ImageButton
|
||||||
import "math/observable" for Observable
|
import "math/observable" for Observable
|
||||||
import "blocks/ui/simple_text" for UISimpleText
|
import "blocks/ui/simple_text" for UISimpleText
|
||||||
import "blocks/ui/ui" for Ui
|
import "blocks/ui/ui" for Ui
|
||||||
|
import "blocks/ui/compass" for UiCompass
|
||||||
|
|
||||||
class UiAdventure{
|
class UiAdventure{
|
||||||
root{_root}
|
root{_root}
|
||||||
|
|
||||||
|
static direction{"direction"}
|
||||||
|
static people{"people"}
|
||||||
|
static resources{"resources"}
|
||||||
|
static depart{"depart"}
|
||||||
|
|
||||||
construct new(ent, ui){
|
construct new(ent, ui){
|
||||||
_ent = ent
|
_ent = ent
|
||||||
_ui = ui
|
_ui = ui
|
||||||
|
|
||||||
|
_game = Globals["Game"]
|
||||||
|
_page = Observable.new(UiAdventure.direction)
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,8 +40,17 @@ class UiAdventure{
|
||||||
var game = Globals["Game"]
|
var game = Globals["Game"]
|
||||||
|
|
||||||
_root = Control.create(_ent)
|
_root = Control.create(_ent)
|
||||||
|
Control.set_allow_input(_root, true)
|
||||||
Control.set_size(_root, ui_rect.width, ui_rect.height)
|
Control.set_size(_root, ui_rect.width, ui_rect.height)
|
||||||
|
|
||||||
|
toolbar()
|
||||||
|
direction()
|
||||||
|
people()
|
||||||
|
resources()
|
||||||
|
depart()
|
||||||
|
}
|
||||||
|
|
||||||
|
toolbar(){
|
||||||
//list
|
//list
|
||||||
var list = Control.create(_ent)
|
var list = Control.create(_ent)
|
||||||
Control.child_add(_root, list)
|
Control.child_add(_root, list)
|
||||||
|
|
@ -43,10 +61,67 @@ class UiAdventure{
|
||||||
|
|
||||||
//toolbar icons
|
//toolbar icons
|
||||||
_ui.list_button(list, [1, 0], "Info") {_ui.ui_mode = Ui.Info}
|
_ui.list_button(list, [1, 0], "Info") {_ui.ui_mode = Ui.Info}
|
||||||
_ui.list_button(list, [0, 0], "Abort") {_ui.ui_mode = Ui.Info}
|
_ui.list_button(list, [0, 0], "Abort") {
|
||||||
_ui.list_button(list, [2, 0], "People") {}
|
_ui.ui_mode = Ui.Info
|
||||||
_ui.list_button(list, [4, 0], "Stuff") {}
|
_game.adventures.discard()
|
||||||
_ui.list_button(list, [3, 0], "Direction") {}
|
_page = UiAdventure.direction
|
||||||
_ui.list_button(list, [5, 0], "Depart") {}
|
}
|
||||||
|
_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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
69
Luxe/blocks/ui/compass.wren
Normal file
69
Luxe/blocks/ui/compass.wren
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
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 UiCompass{
|
||||||
|
static font{"assets/fonts/BabyBlocks"}
|
||||||
|
static size{8}
|
||||||
|
|
||||||
|
static create(ent){
|
||||||
|
var compass = Control.create(ent)
|
||||||
|
var style = PathStyle.new()
|
||||||
|
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_render(compass) {|control, state, x, y, w, h|
|
||||||
|
var depth = UI.draw_depth_of(control, 0)
|
||||||
|
var center = [x + w/2, y + h/2]
|
||||||
|
var image = Assets.image("assets/wip/Needle")
|
||||||
|
var ratio = Image.get_width(image) / Image.get_height(image)
|
||||||
|
var needleSize = [(Math.min(w, h) - 8) * ratio, (Math.min(w, h) - 8)]
|
||||||
|
UI.draw_ring(control, center.x, center.y, depth, w/2, h/2, 0, 360, 8, state["style"])
|
||||||
|
UI.draw_image(control, center.x - needleSize.x/2, center.y-needleSize.y/2, depth, needleSize.x, needleSize.y,
|
||||||
|
state["angle"], [1,1,1,1], [0, 0, 1, 1], image, true)
|
||||||
|
}
|
||||||
|
Control.set_process(compass){|control, state, event, x,y,w,h|
|
||||||
|
if(event.control != control) return
|
||||||
|
|
||||||
|
if(event.type == UIEvent.press){
|
||||||
|
var relative_pos = AABB.grow(AABB.new(x, y, w, h),[2, 2]).relative_pos([event.x, event.y])
|
||||||
|
var inside = M.length(relative_pos.map{|comp| comp - 0.5}) < 0.5
|
||||||
|
if(inside) {
|
||||||
|
state["pressed"] = true
|
||||||
|
UI.capture(control)
|
||||||
|
}
|
||||||
|
} else if(event.type == UIEvent.release){
|
||||||
|
state["pressed"] = false
|
||||||
|
UI.uncapture(control)
|
||||||
|
} else if(event.type == UIEvent.move && state["pressed"]){
|
||||||
|
var center = [x + w/2, y + h/2]
|
||||||
|
var diff = [center.x - event.x, center.y - event.y]
|
||||||
|
var angle = Math.atan2(diff.x, diff.y)
|
||||||
|
System.print("change %(Math.degrees(angle).round)")
|
||||||
|
UI.events_emit(control, UIEvent.change, Math.degrees(angle))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return compass
|
||||||
|
}
|
||||||
|
|
||||||
|
static set_angle(con, angle){
|
||||||
|
var data = Control.get_state_data(con)
|
||||||
|
|
||||||
|
data["angle"] = angle % 360
|
||||||
|
}
|
||||||
|
|
||||||
|
static set_color(control, color){
|
||||||
|
var data = Control.get_state_data(control)
|
||||||
|
data["style"].color = color
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -17,28 +17,23 @@ class ImageButton{
|
||||||
|
|
||||||
Control.set_events(button) {|event|
|
Control.set_events(button) {|event|
|
||||||
var data = null
|
var data = null
|
||||||
var string_type = ""
|
|
||||||
if(event.type == UIEvent.enter){
|
if(event.type == UIEvent.enter){
|
||||||
string_type = "enter"
|
|
||||||
data = Control.get_state_data(button)
|
data = Control.get_state_data(button)
|
||||||
data["hover"] = true
|
data["hover"] = true
|
||||||
} else if(event.type == UIEvent.exit) {
|
} else if(event.type == UIEvent.exit) {
|
||||||
string_type = "exit"
|
|
||||||
data = Control.get_state_data(button)
|
data = Control.get_state_data(button)
|
||||||
data["hover"] = false
|
data["hover"] = false
|
||||||
data["press"] = false
|
data["press"] = false
|
||||||
} else if(event.type == UIEvent.press) {
|
} else if(event.type == UIEvent.press) {
|
||||||
string_type = "press"
|
|
||||||
data = Control.get_state_data(button)
|
data = Control.get_state_data(button)
|
||||||
data["press"] = true
|
data["press"] = true
|
||||||
} else if(event.type == UIEvent.release) {
|
} else if(event.type == UIEvent.release) {
|
||||||
string_type = "release"
|
|
||||||
data = Control.get_state_data(button)
|
data = Control.get_state_data(button)
|
||||||
data["press"] = false
|
data["press"] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data){
|
if(data){
|
||||||
//System.print(string_type + " " + data["tooltip"])
|
//System.print(UIEvent.name(string_type) + " " + data["tooltip"])
|
||||||
var func = data["state_change"]
|
var func = data["state_change"]
|
||||||
if(func){
|
if(func){
|
||||||
func.call(data, button)
|
func.call(data, button)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class UiInfo{
|
||||||
var button
|
var button
|
||||||
|
|
||||||
//toolbar buttons
|
//toolbar buttons
|
||||||
_ui.list_button(list, [1, 0], "Adventure!") {
|
_ui.list_button(list, [6, 0], "Adventure!") {
|
||||||
Globals["Game"].adventures.new_or_current()
|
Globals["Game"].adventures.new_or_current()
|
||||||
_ui.ui_mode = Ui.Planning
|
_ui.ui_mode = Ui.Planning
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class Ui{
|
||||||
var button = ImageButton.create(_ent)
|
var button = ImageButton.create(_ent)
|
||||||
Control.set_size(button, 16, 16)
|
Control.set_size(button, 16, 16)
|
||||||
Control.child_add(parent, button)
|
Control.child_add(parent, button)
|
||||||
var adventureButtons = Assets.image("assets/AdventureButtons")
|
var adventureButtons = Assets.image("assets/wip/AdventureButtons")
|
||||||
UIImage.set_image(button, adventureButtons)
|
UIImage.set_image(button, adventureButtons)
|
||||||
return button
|
return button
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,4 +75,12 @@ class M{
|
||||||
System.print("can't clamp %(value.type) between %(min.type) and %(max.type)")
|
System.print("can't clamp %(value.type) between %(min.type) and %(max.type)")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sqr_length(vector){
|
||||||
|
return vector.reduce(0){|sum, val| sum + val * val }
|
||||||
|
}
|
||||||
|
|
||||||
|
static length(vector){
|
||||||
|
return sqr_length(vector).sqrt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import "math/vector" for Vector
|
import "math/vector" for Vector
|
||||||
|
import "math/math" for M
|
||||||
|
|
||||||
class AABB{
|
class AABB{
|
||||||
x{_x}
|
x{_x}
|
||||||
|
|
@ -45,6 +46,10 @@ class AABB{
|
||||||
_width = width
|
_width = width
|
||||||
_height = height
|
_height = height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
relative_pos(vector){
|
||||||
|
return M.inv_lerp(min, max, vector)
|
||||||
|
}
|
||||||
|
|
||||||
static ONE(){
|
static ONE(){
|
||||||
return new(0, 0, 1, 1)
|
return new(0, 0, 1, 1)
|
||||||
|
|
@ -76,4 +81,12 @@ class AABB{
|
||||||
var half_amount = [amount.x/2, amount.y/2]
|
var half_amount = [amount.x/2, amount.y/2]
|
||||||
return AABB.new(rect.pos + half_amount, rect.size - amount)
|
return AABB.new(rect.pos + half_amount, rect.size - amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static grow(rect, amount){
|
||||||
|
if(amount is Num){
|
||||||
|
amount = [amount, amount]
|
||||||
|
}
|
||||||
|
var half_amount = [amount.x/2, amount.y/2]
|
||||||
|
return AABB.new(rect.pos - half_amount, rect.size + amount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue