CabinGame/Luxe/blocks/tooltip.wren

82 lines
1.7 KiB
Text
Raw Normal View History

import "luxe: world" for Entity, Text, Transform
import "luxe: assets" for Assets
import "globals" for Globals
import "math/vector" for Vector
class Tooltip{
2020-08-29 06:14:01 +00:00
depth{100}
2020-08-29 19:25:16 +00:00
color{[1, 1, 1, 1]}
2020-09-09 14:12:39 +00:00
background{[1, 0, 1, 1]}
2020-08-29 06:14:01 +00:00
construct new(app){
2020-09-09 14:12:39 +00:00
_text = Entity.create(app.ui)
_bg = Entity.create(app.ui)
var font1 = Assets.material("luxe: material/font")
var font2 = Assets.material("luxe: material/font")
Text.create(_bg, font1, 8, "assets/fonts/BabyBlocksBigger", background)
Text.create(_text, font2, 8, "assets/fonts/BabyBlocks", color)
2020-09-09 14:12:39 +00:00
Transform.create(_text)
Transform.set_pos(_text, 64, 128, depth)
Transform.set_snap(_text, 1, 1, 0)
Transform.create(_bg)
Transform.set_pos(_bg, 64, 128, depth)
Transform.set_snap(_bg, 1, 1, 0)
2020-08-29 06:14:01 +00:00
Globals["Tooltip"] = this
}
tick(){
var pos = Vector.new(Globals["UiMouse"])
if(_active && pos){
2020-08-29 06:14:01 +00:00
if(_x){
pos.x = _x
}
if(_y){
pos.y = _y
}
2020-09-09 14:12:39 +00:00
Transform.set_pos(_text, pos.x, pos.y, depth)
Transform.set_pos(_bg, pos.x, pos.y - 1, depth-1)
}
}
2020-08-29 06:14:01 +00:00
set(text) {
set(text, null)
}
fix_y(value){
_y = value
}
fix_x(value){
_x = value
}
set(text, source){
2020-09-09 14:12:39 +00:00
Text.set_text_buffer(_bg, text)
Text.commit(_bg)
//Text.set_text_buffer(_text, text)
//Text.commit(_text)
_active = true
2020-08-29 06:14:01 +00:00
_source = source
_x = null
_y = null
}
clear(){
2020-08-29 06:14:01 +00:00
clear(_source)
}
clear(source){
if(_source != source) {
return
}
2020-09-09 14:12:39 +00:00
Text.set_text_buffer(_text, "")
Text.commit(_text)
Text.set_text_buffer(_bg, "")
Text.commit(_bg)
_active = false
}
}