From c3752dba547f87a8140b16795848df3b7683b0aa Mon Sep 17 00:00:00 2001 From: Insality Date: Sat, 11 Jan 2020 02:14:14 +0500 Subject: [PATCH 1/3] Separate text on text and locale components. Auto adjust text sizing --- druid/base/locale.lua | 47 +++++++++++++++++++++++++++++++++ druid/base/text.lua | 60 +++++++++++++++++++------------------------ druid/druid.lua | 1 + 3 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 druid/base/locale.lua diff --git a/druid/base/locale.lua b/druid/base/locale.lua new file mode 100644 index 0000000..3dc914b --- /dev/null +++ b/druid/base/locale.lua @@ -0,0 +1,47 @@ +--- Component to handle all GUI texts +-- Good working with localization system +-- @module base.text + +local const = require("druid.const") +local settings = require("druid.settings") +local helper = require("druid.helper") + +local M = {} +M.interest = { + const.ON_CHANGE_LANGUAGE, +} + + +function M.init(self, node, lang_id) + self.druid = helper.get_druid(self) + self.text = self.druid:new_text(node) + self:translate(lang_id) + + return self +end + + +function M.raw_set(self, text) + self.last_locale = false + self.text:set_to(text) +end + + +--- Translate the text by locale_id +-- @function text:translate +-- @tparam table self Component instance +-- @tparam string locale_id Locale id +function M.translate(self, locale_id) + self.last_locale = locale_id or self.last_locale + self.text:set_to(settings.get_text(self.last_locale)) +end + + +function M.on_change_language(self) + if self.last_locale then + M.translate(self) + end +end + + +return M diff --git a/druid/base/text.lua b/druid/base/text.lua index f04bbf7..17feddd 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -2,57 +2,44 @@ -- Good working with localization system -- @module base.text -local const = require("druid.const") -local settings = require("druid.settings") local helper = require("druid.helper") local M = {} -M.interest = { - const.ON_CHANGE_LANGUAGE, -} +M.interest = {} -function M.init(self, node, value, is_locale, max_width) - self.max_width = max_width +function M.init(self, node, value, no_text_adjust) self.node = helper.node(node) self.start_scale = gui.get_scale(self.node) + self.start_pivot = gui.get_pivot(self.node) + + self.text_area = gui.get_size(self.node) + self.text_area.x = self.text_area.x * self.start_scale.x + self.text_area.y = self.text_area.y * self.start_scale.y + + self.is_no_text_adjust = no_text_adjust self.scale = self.start_scale self.last_color = gui.get_color(self.node) - if is_locale then - self:translate(value) - else - self:set_to(value or 0) - end - + self:set_to(value or 0) return self end ---- Translate the text by locale_id --- @function text:translate --- @tparam table self Component instance --- @tparam string locale_id Locale id -function M.translate(self, locale_id) - self.last_locale = locale_id or self.last_locale - self:set_to(settings.get_text(self.last_locale)) -end - - -function M.on_change_language(self) - if self.last_locale then - M.translate(self) - end -end - - --- Setup scale x, but can only be smaller, than start text scale -local function setup_max_width(self) +local function update_text_area_size(self) + local max_width = self.text_area.x + local max_height = self.text_area.y + local metrics = gui.get_text_metrics_from_node(self.node) local cur_scale = gui.get_scale(self.node) - local scale_modifier = self.max_width / metrics.width + local scale_modifier = max_width / metrics.width scale_modifier = math.min(scale_modifier, self.start_scale.x) + + local scale_modifier_height = max_height / metrics.height + scale_modifier = math.min(scale_modifier, scale_modifier_height) + local new_scale = vmath.vector3(scale_modifier, scale_modifier, cur_scale.z) gui.set_scale(self.node, new_scale) self.scale = new_scale @@ -67,8 +54,8 @@ function M.set_to(self, set_to) self.last_value = set_to gui.set_text(self.node, set_to) - if self.max_width then - setup_max_width(self) + if not self.is_no_text_adjust then + update_text_area_size(self) end end @@ -103,4 +90,9 @@ function M.set_scale(self, scale) end +function M.set_pivot(self, pivot) + +end + + return M diff --git a/druid/druid.lua b/druid/druid.lua index 3f9e40f..161a4c0 100644 --- a/druid/druid.lua +++ b/druid/druid.lua @@ -24,6 +24,7 @@ M.comps = { blocker = require("druid.base.blocker"), back_handler = require("druid.base.back_handler"), text = require("druid.base.text"), + locale = require("druid.base.locale"), timer = require("druid.base.timer"), progress = require("druid.base.progress"), grid = require("druid.base.grid"), From 59c9dc8a9bfb5fe25e2007dc3a1a081b15cfcac2 Mon Sep 17 00:00:00 2001 From: Insality Date: Sat, 11 Jan 2020 15:04:53 +0500 Subject: [PATCH 2/3] Add set_pivot to text component --- druid/base/locale.lua | 4 +-- druid/base/text.lua | 34 ++++++++++++++++++++----- druid/const.lua | 2 +- example/kenney/gui/main/main.gui | 2 +- example/kenney/gui/main/main.gui_script | 3 ++- example/kenney/page/main.lua | 18 ++++++------- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/druid/base/locale.lua b/druid/base/locale.lua index 3dc914b..b53a8cf 100644 --- a/druid/base/locale.lua +++ b/druid/base/locale.lua @@ -12,9 +12,9 @@ M.interest = { } -function M.init(self, node, lang_id) +function M.init(self, node, lang_id, no_adjust) self.druid = helper.get_druid(self) - self.text = self.druid:new_text(node) + self.text = self.druid:new_text(node, lang_id, no_adjust) self:translate(lang_id) return self diff --git a/druid/base/text.lua b/druid/base/text.lua index 17feddd..2df969c 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -2,23 +2,27 @@ -- Good working with localization system -- @module base.text +local const = require("druid.const") local helper = require("druid.helper") local M = {} -M.interest = {} -function M.init(self, node, value, no_text_adjust) +function M.init(self, node, value, no_adjust) self.node = helper.node(node) - self.start_scale = gui.get_scale(self.node) self.start_pivot = gui.get_pivot(self.node) + self.start_pos = gui.get_position(self.node) + self.pos = gui.get_position(self.node) + + self.start_scale = gui.get_scale(self.node) + self.scale = gui.get_scale(self.node) + self.text_area = gui.get_size(self.node) self.text_area.x = self.text_area.x * self.start_scale.x self.text_area.y = self.text_area.y * self.start_scale.y - self.is_no_text_adjust = no_text_adjust - self.scale = self.start_scale + self.is_no_adjust = no_adjust self.last_color = gui.get_color(self.node) self:set_to(value or 0) @@ -54,7 +58,7 @@ function M.set_to(self, set_to) self.last_value = set_to gui.set_text(self.node, set_to) - if not self.is_no_text_adjust then + if not self.is_no_adjust then update_text_area_size(self) end end @@ -90,8 +94,26 @@ function M.set_scale(self, scale) end +--- Set text pivot. Text will re-anchor inside +-- his text area +-- @function text:set_pivot +-- @tparam table self Component instance +-- @tparam gui.pivot pivot Gui pivot constant function M.set_pivot(self, pivot) + local prev_pivot = gui.get_pivot(self.node) + local prev_offset = const.PIVOTS[prev_pivot] + gui.set_pivot(self.node, pivot) + local cur_offset = const.PIVOTS[pivot] + + local pos_offset = vmath.vector3( + self.text_area.x * (cur_offset.x - prev_offset.x), + self.text_area.y * (cur_offset.y - prev_offset.y), + 0 + ) + + self.pos = self.pos + pos_offset + gui.set_position(self.node, self.pos) end diff --git a/druid/const.lua b/druid/const.lua index e199b59..4ac6a3d 100644 --- a/druid/const.lua +++ b/druid/const.lua @@ -32,7 +32,7 @@ M.PIVOTS = { [gui.PIVOT_S] = vmath.vector3(0, -0.5, 0), [gui.PIVOT_SW] = vmath.vector3(-0.5, -0.5, 0), [gui.PIVOT_W] = vmath.vector3(-0.5, 0, 0), - [gui.PIVOT_NW] = vmath.vector3(-0.5, -0.5, 0), + [gui.PIVOT_NW] = vmath.vector3(-0.5, 0.5, 0), } M.SIDE = { diff --git a/example/kenney/gui/main/main.gui b/example/kenney/gui/main/main.gui index e92b20c..c6f22c3 100644 --- a/example/kenney/gui/main/main.gui +++ b/example/kenney/gui/main/main.gui @@ -840,7 +840,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "SImple" + text: "Simple" font: "game" id: "text_simple" xanchor: XANCHOR_NONE diff --git a/example/kenney/gui/main/main.gui_script b/example/kenney/gui/main/main.gui_script index c0b923b..55a4996 100644 --- a/example/kenney/gui/main/main.gui_script +++ b/example/kenney/gui/main/main.gui_script @@ -12,12 +12,13 @@ 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) + self.header = self.druid:new_locale("text_header", "main_page") end function init(self) druid.set_default_style(empty_style) + druid.set_default_style(bounce_style) self.druid = druid.new(self) init_top_panel(self) diff --git a/example/kenney/page/main.lua b/example/kenney/page/main.lua index 225f1cb..db04392 100644 --- a/example/kenney/page/main.lua +++ b/example/kenney/page/main.lua @@ -26,17 +26,17 @@ end local function setup_texts(self) - self.druid:new_text("text_button", "ui_section_button", true) - self.druid:new_text("text_text", "ui_section_text", true) - self.druid:new_text("text_timer", "ui_section_timer", true) - self.druid:new_text("text_progress", "ui_section_progress", true) - self.druid:new_text("text_slider", "ui_section_slider", true) - self.druid:new_text("text_radio", "ui_section_radio", true) - self.druid:new_text("text_checkbox", "ui_section_checkbox", true) + self.druid:new_locale("text_button", "ui_section_button") + self.druid:new_locale("text_text", "ui_section_text") + self.druid:new_locale("text_timer", "ui_section_timer") + self.druid:new_locale("text_progress", "ui_section_progress") + self.druid:new_locale("text_slider", "ui_section_slider") + self.druid:new_locale("text_radio", "ui_section_radio") + self.druid:new_locale("text_checkbox", "ui_section_checkbox") + self.druid:new_locale("text_translated", "ui_text_example") + self.druid:new_locale("text_button_lang", "ui_text_change_lang") self.druid:new_text("text_simple", "Simple") - self.druid:new_text("text_translated", "ui_text_example", true) - self.druid:new_text("text_button_lang", "ui_text_change_lang", true, 150 * 0.7) end From 41a820a1fbbeb3146192f1d3838b67a9bd392918 Mon Sep 17 00:00:00 2001 From: Insality Date: Sat, 11 Jan 2020 15:37:14 +0500 Subject: [PATCH 3/3] Add texts text page --- druid/base/locale.lua | 2 +- example/kenney/gui/main/main.gui | 994 +++++++++++++++++++++++- example/kenney/gui/main/main.gui_script | 30 +- example/kenney/lang.lua | 2 + example/kenney/page/texts.lua | 55 ++ 5 files changed, 1075 insertions(+), 8 deletions(-) create mode 100644 example/kenney/page/texts.lua diff --git a/druid/base/locale.lua b/druid/base/locale.lua index b53a8cf..f2abda7 100644 --- a/druid/base/locale.lua +++ b/druid/base/locale.lua @@ -21,7 +21,7 @@ function M.init(self, node, lang_id, no_adjust) end -function M.raw_set(self, text) +function M.set_to(self, text) self.last_locale = false self.text:set_to(text) end diff --git a/example/kenney/gui/main/main.gui b/example/kenney/gui/main/main.gui index c6f22c3..0d74dfd 100644 --- a/example/kenney/gui/main/main.gui +++ b/example/kenney/gui/main/main.gui @@ -160,7 +160,7 @@ nodes { xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT + adjust_mode: ADJUST_MODE_STRETCH parent: "C_Anchor" layer: "" inherit_alpha: true @@ -2989,6 +2989,998 @@ nodes { template_node_child: false size_mode: SIZE_MODE_MANUAL } +nodes { + position { + x: 600.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: 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: "text_page" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_STRETCH + parent: "C_Anchor" + 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: -250.0 + y: 280.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: "Inline:" + font: "game" + id: "inline" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: -250.0 + y: 190.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: "Multiline:" + font: "game" + id: "multiline" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: -250.0 + y: 100.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: "Anchoring:" + font: "game" + id: "anchoring" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: -250.0 + y: 10.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: "No adjust:" + font: "game" + id: "no_adjust" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: -250.0 + y: -80.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: "Locale:" + font: "game" + id: "locale" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: -250.0 + y: -170.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: "Max Width:" + font: "game" + id: "max_width" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: -250.0 + y: -260.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: "Max height:" + font: "game" + id: "max_height" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 150.0 + y: 280.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: 300.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: "Inline:" + font: "game" + id: "text_inline" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 150.0 + y: 190.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: 300.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: "Multiline" + font: "game" + id: "text_multiline" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: true + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 150.0 + y: 100.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: 300.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.7019608 + y: 0.8 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "anchoring_zone_visual" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "text_page" + 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_MANUAL +} +nodes { + position { + x: 150.0 + y: 100.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: 300.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: "Anchoring:" + font: "game" + id: "text_anchoring" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 150.0 + y: 10.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: 300.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: "No adjust:" + font: "game" + id: "text_no_adjust" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 150.0 + y: -80.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: 300.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: "Locale:" + font: "game" + id: "text_locale" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 150.0 + y: -170.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: 300.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: "Max Width:" + font: "game" + id: "text_max_width" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 150.0 + y: -260.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: 300.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: "Max height:" + font: "game" + id: "text_max_height" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: true + parent: "text_page" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} nodes { position { x: 0.0 diff --git a/example/kenney/gui/main/main.gui_script b/example/kenney/gui/main/main.gui_script index 55a4996..0f9fed2 100644 --- a/example/kenney/gui/main/main.gui_script +++ b/example/kenney/gui/main/main.gui_script @@ -1,28 +1,46 @@ local druid = require("druid.druid") -local bounce_style = require("druid.styles.bounce.style") + local empty_style = require("druid.styles.empty.style") +local bounce_style = require("druid.styles.bounce.style") local main_page = require("example.kenney.page.main") +local text_page = require("example.kenney.page.texts") -local function on_control_button(self, side) - print("Click on button side", side) +local pages = { + "main_page", + "texts_page" +} + +local function on_control_button(self, delta) + self.page = self.page + delta + if self.page < 1 then + self.page = #pages + end + if self.page > #pages then + self.page = 1 + end + + self.header:translate(pages[self.page]) + local node = gui.get_node("C_Anchor") + gui.animate(node, "position.x", (self.page-1) * -600, gui.EASING_OUTSINE, 0.2) 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.druid:new_button("button_left/button", on_control_button, -1) + self.druid:new_button("button_right/button", on_control_button, 1) self.header = self.druid:new_locale("text_header", "main_page") end function init(self) - druid.set_default_style(empty_style) druid.set_default_style(bounce_style) self.druid = druid.new(self) init_top_panel(self) + self.page = 1 main_page.setup_page(self) + text_page.setup_page(self) end diff --git a/example/kenney/lang.lua b/example/kenney/lang.lua index d36cef7..43f0f91 100644 --- a/example/kenney/lang.lua +++ b/example/kenney/lang.lua @@ -4,6 +4,7 @@ local M = {} local en = { main_page = "Main page", + texts_page = "Text page", ui_section_button = "Button", ui_section_text = "Text", ui_section_timer = "Timer", @@ -17,6 +18,7 @@ local en = { local ru = { main_page = "Основное", + texts_page = "Текст", ui_section_button = "Кнопка", ui_section_text = "Текст", ui_section_timer = "Таймер", diff --git a/example/kenney/page/texts.lua b/example/kenney/page/texts.lua new file mode 100644 index 0000000..c1386ce --- /dev/null +++ b/example/kenney/page/texts.lua @@ -0,0 +1,55 @@ +local lang = require("example.kenney.lang") + +local M = {} + +local pivots = { + gui.PIVOT_CENTER, + gui.PIVOT_N, + gui.PIVOT_NE, + gui.PIVOT_E, + gui.PIVOT_SE, + gui.PIVOT_S, + gui.PIVOT_SW, + gui.PIVOT_W, + gui.PIVOT_NW +} + +local function setup_texts(self) + self.druid:new_text("text_inline", "Simple inline text") + self.druid:new_text("text_multiline", "Simple multiline text with smth") + local anchoring = self.druid:new_text("text_anchoring", "Anchoring") + self.druid:new_text("text_no_adjust", "Without adjust size", true) + self.druid:new_locale("text_locale", "ui_text_example") + + local big_text = "Check max size" + local width = self.druid:new_text("text_max_width", big_text) + local height = self.druid:new_text("text_max_height", big_text) + + local pivot_index = 1 + timer.delay(0.3, true, function() + anchoring:set_pivot(pivots[pivot_index]) + + pivot_index = pivot_index + 1 + if pivot_index > #pivots then + pivot_index = 1 + end + end) + + timer.delay(0.2, true, function() + big_text = big_text .. " max" + width:set_to(big_text) + height:set_to(big_text) + + if #big_text > 50 then + big_text = "Check max size" + end + end) +end + + +function M.setup_page(self) + setup_texts(self) +end + + +return M