add kenney assets and start gui screen

This commit is contained in:
Insality 2019-09-25 22:10:44 +03:00
parent aaac514a3d
commit f447afb4f7
31 changed files with 970 additions and 15 deletions

View File

@ -16,36 +16,40 @@ function M.init(self, node, value, is_locale, max_width)
self.max_width = max_width self.max_width = max_width
self.node = helper.get_node(node) self.node = helper.get_node(node)
self.start_scale = gui.get_scale(self.node) self.start_scale = gui.get_scale(self.node)
self.scale = self.start_scale
self.last_color = gui.get_color(self.node) self.last_color = gui.get_color(self.node)
if is_locale then if is_locale then
self.text_id = value self:translate(value)
self:translate()
else else
self:set_to(value or 0) self:set_to(value or 0)
end end
return self return self
end end
function M.translate(self) function M.translate(self, locale_id)
if self.text_id then self.last_locale = locale_id or self.last_locale
self:set_to(settings.get_text(self.text_id)) self:set_to(settings.get_text(self.last_locale))
end end
function M.on_change_language(self)
M.translate(self)
end end
--- Setup scale x, but can only be smaller, than start text scale --- Setup scale x, but can only be smaller, than start text scale
local function setup_max_width(self) local function setup_max_width(self)
local metrics = gui.get_text_metrics_from_node(self.node) local metrics = gui.get_text_metrics_from_node(self.node)
local cur_scale = gui.get_scale(self.node) local cur_scale = gui.get_scale(self.node)
if metrics.width * cur_scale.x > self.max_width then local scale_modifier = self.max_width / metrics.width
local scale_modifier = self.max_width / metrics.width scale_modifier = math.min(scale_modifier, self.start_scale.x)
scale_modifier = math.min(scale_modifier, self.start_scale.x) local new_scale = vmath.vector3(scale_modifier, scale_modifier, cur_scale.z)
local new_scale = vmath.vector3(scale_modifier, scale_modifier, cur_scale.z) gui.set_scale(self.node, new_scale)
gui.set_scale(self.node, new_scale) self.scale = new_scale
end
end end

Binary file not shown.

View File

@ -0,0 +1,17 @@
font: "/example/kenney/assets/fonts/exo2.ttf"
material: "/builtins/fonts/font-df.material"
size: 40
antialias: 1
alpha: 1.0
outline_alpha: 1.0
outline_width: 2.0
shadow_alpha: 1.0
shadow_blur: 0
shadow_x: 3.0
shadow_y: -4.0
extra_characters: ""
output_format: TYPE_DISTANCE_FIELD
all_chars: false
cache_width: 0
cache_height: 0
render_mode: MODE_MULTI_LAYER

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1,60 @@
images {
image: "/example/kenney/assets/images/back/back_blue.png"
}
images {
image: "/example/kenney/assets/images/back/back_gray.png"
}
images {
image: "/example/kenney/assets/images/back/back_green.png"
}
images {
image: "/example/kenney/assets/images/back/back_red.png"
}
images {
image: "/example/kenney/assets/images/buttons/button_green.png"
}
images {
image: "/example/kenney/assets/images/buttons/button_red.png"
}
images {
image: "/example/kenney/assets/images/buttons/button_yellow.png"
}
images {
image: "/example/kenney/assets/images/empty.png"
}
images {
image: "/example/kenney/assets/images/progress/progress_back.png"
}
images {
image: "/example/kenney/assets/images/progress/progress_fill_green.png"
}
images {
image: "/example/kenney/assets/images/progress/progress_fill_red.png"
}
images {
image: "/example/kenney/assets/images/progress/progress_fill_yellow.png"
}
images {
image: "/example/kenney/assets/images/radio/check_back_circle.png"
}
images {
image: "/example/kenney/assets/images/radio/check_back_square.png"
}
images {
image: "/example/kenney/assets/images/radio/checkmark.png"
}
images {
image: "/example/kenney/assets/images/radio/tick.png"
}
images {
image: "/example/kenney/assets/images/slider/slider_back.png"
}
images {
image: "/example/kenney/assets/images/slider/slider_move.png"
}
images {
image: "/example/kenney/assets/images/buttons/button_blue.png"
}
margin: 0
extrude_borders: 2
inner_padding: 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 817 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 897 B

Binary file not shown.

View File

@ -0,0 +1,561 @@
script: "/example/kenney/gui/main/main.gui_script"
fonts {
name: "game"
font: "/example/kenney/assets/fonts/game.font"
}
textures {
name: "kenney"
texture: "/example/kenney/assets/images/kenney.atlas"
}
background_color {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
nodes {
position {
x: 300.0
y: 450.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 1.0
y: 1.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/empty"
id: "root"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_STRETCH
layer: ""
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 0.0
y: 450.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 1.0
y: 1.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/empty"
id: "N_Anchor"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_STRETCH
parent: "root"
layer: ""
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 600.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/back_gray"
id: "panel_top"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_N
adjust_mode: ADJUST_MODE_STRETCH
parent: "N_Anchor"
layer: ""
inherit_alpha: true
slice9 {
x: 20.0
y: 20.0
z: 20.0
w: 20.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: -200.0
y: -50.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "button_left"
parent: "panel_top"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/example/kenney/templates/button.gui"
template_node_child: false
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 130.0
y: 60.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/button_blue"
id: "button_left/button"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "button_left"
layer: ""
inherit_alpha: true
slice9 {
x: 15.0
y: 15.0
z: 15.0
w: 15.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 7.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.7
y: 0.7
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Tap me!"
font: "game"
id: "button_left/text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 0.101960786
y: 0.2
z: 0.6
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "button_left/button"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 0.0
shadow_alpha: 0.78
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 200.0
y: -50.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "button_right"
parent: "panel_top"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/example/kenney/templates/button.gui"
template_node_child: false
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 130.0
y: 60.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/button_blue"
id: "button_right/button"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "button_right"
layer: ""
inherit_alpha: true
slice9 {
x: 15.0
y: 15.0
z: 15.0
w: 15.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 7.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.7
y: 0.7
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Tap me!"
font: "game"
id: "button_right/text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 0.101960786
y: 0.2
z: 0.6
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "button_right/button"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 0.0
shadow_alpha: 0.78
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 0.0
y: -43.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Title"
font: "game"
id: "text_header"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
shadow {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "panel_top"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
max_nodes: 512

View File

@ -0,0 +1,35 @@
local druid = require("druid.druid")
local function on_control_button(self, side)
print("Click on button side", side)
end
local function init_top_panel(self)
self.druid:new_button("button_left/button", on_control_button, "left")
self.druid:new_button("button_right/button", on_control_button, "right")
self.header = self.druid:new_text("text_header", "main_page", true)
end
function init(self)
self.druid = druid.new(self)
init_top_panel(self)
end
function update(self, dt)
self.druid:update(dt)
end
function on_message(self, message_id, message, sender)
self.druid:on_message(message_id, message, sender)
end
function on_input(self, action_id, action)
self.druid:on_input(action_id, action)
end

View File

@ -0,0 +1,24 @@
local const = require("druid.const")
local settings = require("druid.settings")
local lang = require("example.kenney.lang")
local function setup_druid()
settings.play_sound = function(name)
sound.play("kenney:/sound#" .. name)
end
settings.get_text = function(lang_id)
return lang.get_locale(lang_id)
end
-- TODO: Call druid.finish_setup?
-- Need to update all gui, in case, when gui init was befure this init
msg.post("/gui#main", const.ON_CHANGE_LANGUAGE)
end
function init(self)
setup_druid()
msg.post("@render:", "clear_color", { color = vmath.vector4(0.8, 0.9, 0.85, 1) })
end

View File

@ -0,0 +1,107 @@
name: "kenney"
scale_along_z: 0
embedded_instances {
id: "gui"
data: "components {\n"
" id: \"main\"\n"
" component: \"/example/kenney/gui/main/main.gui\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "system"
data: "components {\n"
" id: \"init\"\n"
" component: \"/example/kenney/init.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "sound"
data: "components {\n"
" id: \"click\"\n"
" component: \"/example/kenney/assets/sounds/click.ogg\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}

12
example/kenney/lang.lua Normal file
View File

@ -0,0 +1,12 @@
local M = {}
local data = {
main_page = "Main page",
}
function M.get_locale(lang_id)
return data[lang_id] or lang_id
end
return M

View File

@ -0,0 +1,135 @@
script: ""
fonts {
name: "game"
font: "/example/kenney/assets/fonts/game.font"
}
textures {
name: "kenney"
texture: "/example/kenney/assets/images/kenney.atlas"
}
background_color {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 130.0
y: 60.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/button_blue"
id: "button"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
layer: ""
inherit_alpha: true
slice9 {
x: 15.0
y: 15.0
z: 15.0
w: 15.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 7.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.7
y: 0.7
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Tap me!"
font: "game"
id: "text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 0.101960786
y: 0.2
z: 0.6
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "button"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 0.0
shadow_alpha: 0.78
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
max_nodes: 512

View File

@ -1,5 +1,5 @@
[bootstrap] [bootstrap]
main_collection = /example/scroll.collectionc main_collection = /example/kenney/kenney.collectionc
[script] [script]
shared_state = 1 shared_state = 1