diff --git a/druid/base/button.lua b/druid/base/button.lua index 001f1a1..f7ebb6c 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -1,7 +1,7 @@ local data = require("druid.data") local ui_animate = require("druid.helper.druid_animate") local settings = require("druid.settings") -local helper = require("druid.helper.helper") +local helper = require("druid.helper") local b_settings = settings.button local M = {} @@ -18,7 +18,7 @@ M.DEFAUL_ACTIVATION_TIME = 0.2 function M.init(instance, node, callback, params, anim_node, event) instance.node = helper.get_node(node) instance.event = data.A_TOUCH - instance.anim_node = anim_node and gui.get_node(anim_node) or instance.node + instance.anim_node = anim_node and helper.get_node(anim_node) or instance.node instance.scale_from = gui.get_scale(instance.anim_node) instance.scale_to = instance.scale_from + b_settings.SCALE_CHANGE instance.scale_hover_to = instance.scale_from + b_settings.HOVER_SCALE diff --git a/druid/base/progress.lua b/druid/base/progress.lua new file mode 100644 index 0000000..69eebe3 --- /dev/null +++ b/druid/base/progress.lua @@ -0,0 +1,150 @@ +local data = require("druid.data") +local helper = require("druid.helper") +local settings = require("druid.settings") +local p_settings = settings.progress + +local M = {} + +M.interest = { + data.ON_UPDATE, +} + +local PROP_Y = "y" +local PROP_X = "x" + + +function M.init(instance, name, key, init_value) + if key ~= PROP_X and key ~= PROP_Y then + settings.log("progress component: key must be 'x' or 'y'. Passed:", key) + key = PROP_X + end + + instance.prop = hash("scale."..key) + instance.key = key + + instance.node = helper.get_node(name) + instance.scale = gui.get_scale(instance.node) + instance.size = gui.get_size(instance.node) + instance.max_size = instance.size[instance.key] + instance.slice = gui.get_slice9(instance.node) + if key == PROP_X then + instance.slice_size = instance.slice.x + instance.slice.z + else + instance.slice_size = instance.slice.y + instance.slice.w + end + + instance:set_to(init_value or 1) +end + + +local function check_steps(instance, from, to, exactly) + if not instance.steps then + return + end + + for i = 1, #instance.steps do + local step = instance.steps[i] + local v1, v2 = from, to + if v1 > v2 then + v1, v2 = v2, v1 + end + + if v1 < step and step < v2 then + instance.step_callback(instance.parent.parent, step) + end + if exactly and exactly == step then + instance.step_callback(instance.parent.parent, step) + end + end +end + + +local function set_bar_to(instance, set_to, is_silence) + local prev_value = instance.last_value + instance.last_value = set_to + + local total_width = set_to * instance.max_size + + local scale = math.min(total_width / instance.slice_size, 1) + local size = math.max(total_width, instance.slice_size) + + instance.scale[instance.key] = scale + gui.set_scale(instance.node, instance.scale) + instance.size[instance.key] = size + gui.set_size(instance.node, instance.size) + + if not is_silence then + check_steps(instance, prev_value, set_to) + end +end + + +--- Fill a progress bar and stop progress animation +function M.fill(instance) + set_bar_to(instance, 1, true) +end + + +--- To empty a progress bar +function M.empty(instance) + set_bar_to(instance, 0, true) +end + + +--- Set fill a progress bar to value +-- @param to - value between 0..1 +function M.set_to(instance, to) + set_bar_to(instance, to) +end + + +function M.get(instance) + return instance.last_value +end + + +function M.set_steps(instance, steps, step_callback) + instance.steps = steps + instance.step_callback = step_callback +end + + +--- Start animation of a progress bar +-- @param to - value between 0..1 +-- @param callback - callback when progress ended if need +function M.to(instance, to, callback) + to = helper.clamp(to, 0, 1) + -- cause of float error + local value = helper.round(to, 5) + if value ~= instance.last_value then + instance.target = value + instance.target_callback = callback + else + if callback then + callback(instance.parent.parent, to) + end + end +end + + +function M.update(instance, dt) + if instance.target then + local prev_value = instance.last_value + local step = math.abs(instance.last_value - instance.target) * (p_settings.SPEED*dt) + step = math.max(step, p_settings.MIN_DELTA) + instance:set_to(helper.step(instance.last_value, instance.target, step)) + + if instance.last_value == instance.target then + check_steps(instance, prev_value, instance.target, instance.target) + + if instance.target_callback then + instance.target_callback(instance.parent.parent, instance.target) + end + + instance.target = nil + end + end +end + + +return M \ No newline at end of file diff --git a/druid/base/text.lua b/druid/base/text.lua index f107589..3f3993f 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -1,11 +1,10 @@ local data = require("druid.data") local settings = require("druid.settings") -local helper = require("druid.helper.helper") +local helper = require("druid.helper") local M = {} M.interest = { data.TRANSLATABLE, - data.LAYOUT_CHANGED } @@ -82,15 +81,4 @@ function M.set_scale(instance, scale) end ---- Called when layout updated (rotate for example) -function M.on_layout_updated(instance) - if instance.last_color then - M.set_color(instance, instance.last_color) - end - if instance.last_scale then - M.set_scale(instance, instance.last_scale) - end -end - - return M \ No newline at end of file diff --git a/druid/base/timer.lua b/druid/base/timer.lua index 38deb1c..14cb8c6 100644 --- a/druid/base/timer.lua +++ b/druid/base/timer.lua @@ -1,10 +1,9 @@ local data = require("druid.data") local formats = require("druid.helper.formats") -local helper = require("druid.helper.helper") +local helper = require("druid.helper") local M = {} M.interest = { - data.LAYOUT_CHANGED, data.ON_UPDATE } @@ -36,12 +35,6 @@ function M.set_to(instance, set_to) end ---- Called when layout updated (rotate for example) -function M.on_layout_updated(instance) - M.set_to(instance, instance.last_value) -end - - --- Called when update -- @param is_on - boolean is timer on function M.set_state(instance, is_on) diff --git a/druid/druid.lua b/druid/druid.lua index a7592b0..b85147e 100644 --- a/druid/druid.lua +++ b/druid/druid.lua @@ -12,6 +12,9 @@ M.comps = { android_back = require("druid.base.android_back"), text = require("druid.base.text"), timer = require("druid.base.timer"), + progress = require("druid.base.progress"), + + progress_rich = require("druid.rich.progress_rich"), } diff --git a/druid/helper/helper.lua b/druid/helper.lua similarity index 79% rename from druid/helper/helper.lua rename to druid/helper.lua index a23f5c9..0e01c65 100644 --- a/druid/helper/helper.lua +++ b/druid/helper.lua @@ -36,6 +36,27 @@ function M.step(current, target, step) end +function M.clamp(a, min, max) + if min > max then + min, max = max, min + end + + if a >= min and a <= max then + return a + elseif a < min then + return min + else + return max + end +end + + +function M.round(num, numDecimalPlaces) + local mult = 10^(numDecimalPlaces or 0) + return math.floor(num * mult + 0.5) / mult +end + + function M.is_enabled(node) local is_enabled = gui.is_enabled(node) local parent = gui.get_parent(node) diff --git a/druid/rich/progress_rich.lua b/druid/rich/progress_rich.lua new file mode 100644 index 0000000..8785794 --- /dev/null +++ b/druid/rich/progress_rich.lua @@ -0,0 +1,55 @@ +local settings = require("druid.settings") +local pr_settings = settings.progress_rich + +local M = {} + +function M.init(instance, name, red, green, key) + instance.red = instance.parent:new_progress(red, key) + instance.green = instance.parent:new_progress(green, key) + instance.fill = instance.parent:new_progress(name, key) +end + + +function M.set_to(instance, value) + instance.red:set_to(value) + instance.green:set_to(value) + instance.fill:set_to(value) +end + + +function M.empty(instance) + instance.red:empty() + instance.green:empty() + instance.fill:empty() +end + + +function M.to(instance, to, callback) + if instance.timer then + timer.cancel(instance.timer) + instance.timer = nil + end + + if instance.fill.last_value < to then + instance.red:to(instance.fill.last_value) + instance.green:to(to, function() + instance.timer = timer.delay(pr_settings.DELAY, false, function() + instance.red:to(to) + instance.fill:to(to, callback) + end) + end) + end + + if instance.fill.last_value > to then + instance.green:to(instance.red.last_value) + instance.fill:to(to, function() + instance.timer = timer.delay(pr_settings.DELAY, false, function() + instance.green:to(to) + instance.red:to(to, callback) + end) + end) + end +end + + +return M \ No newline at end of file diff --git a/druid/settings.lua b/druid/settings.lua index 4cf4fbc..323ab3e 100644 --- a/druid/settings.lua +++ b/druid/settings.lua @@ -12,6 +12,14 @@ M.button = { SCALE_CHANGE = vmath.vector3(-0.05, - 0.05, 1), } +M.progress = { + SPEED = 5, -- progress bar fill rate, more faster + MIN_DELTA = 0.005 +} + +M.progress_rich = { + DELAY = 1, -- delay in seconds before main fill +} function M.get_text(name) diff --git a/example/example.gui b/example/example.gui index eb5d5b0..5669836 100644 --- a/example/example.gui +++ b/example/example.gui @@ -15,8 +15,407 @@ background_color { } nodes { position { + x: 300.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: "gui/empty" + id: "control" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + 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: -150.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: 0.5 + y: 0.5 + z: 1.0 + w: 1.0 + } + size { + x: 426.0 + y: 190.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: "gui/green_long" + id: "prev" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "control" + 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: 20.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: 325.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: "Prev" + font: "game" + id: "prev_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.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "prev" + 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 +} +nodes { + position { + x: 150.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: 0.5 + y: 0.5 + z: 1.0 + w: 1.0 + } + size { + x: 426.0 + y: 190.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: "gui/green_long" + id: "next" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "control" + 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: 20.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: "Next" + font: "game" + id: "next_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.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "next" + 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 +} +nodes { + position { + x: 300.0 + y: 400.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: "gui/empty" + id: "center" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + 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: 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: "gui/empty" + id: "buttons" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "center" + 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: 254.0 z: 0.0 w: 1.0 } @@ -52,6 +451,7 @@ nodes { yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT + parent: "buttons" layer: "" inherit_alpha: true slice9 { @@ -132,8 +532,8 @@ nodes { } nodes { position { - x: 200.0 - y: 200.0 + x: 0.0 + y: 129.0 z: 0.0 w: 1.0 } @@ -169,6 +569,7 @@ nodes { yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT + parent: "buttons" layer: "" inherit_alpha: true slice9 { @@ -249,8 +650,503 @@ nodes { } nodes { position { - x: 200.0 - y: 75.0 + 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: "gui/empty" + id: "progress" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "center" + 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: 391.0 + y: 40.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: "gui/progress_back" + id: "simple_back" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "progress" + 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: -194.5 + y: 2.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: 389.0 + y: 35.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: "gui/progress_yellow" + id: "simple_fill" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + adjust_mode: ADJUST_MODE_FIT + parent: "simple_back" + layer: "" + inherit_alpha: true + slice9 { + x: 15.0 + y: 0.0 + z: 15.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: 0.0 + y: 106.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: 391.0 + y: 40.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: "gui/progress_back" + id: "simple_vert" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "progress" + 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: -17.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: 389.0 + y: 35.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: "gui/progress_yellow" + id: "simple_vert_fill" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_S + adjust_mode: ADJUST_MODE_FIT + parent: "simple_vert" + layer: "" + inherit_alpha: true + slice9 { + x: 15.0 + y: 0.0 + z: 15.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: 0.0 + y: -130.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: 391.0 + y: 40.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: "gui/progress_back" + id: "rich_back" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "progress" + 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: -194.5 + y: 2.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: 389.0 + y: 35.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.6 + y: 0.6 + z: 0.6 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "gui/progress_green" + id: "rich_green" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + adjust_mode: ADJUST_MODE_FIT + parent: "rich_back" + layer: "" + inherit_alpha: true + slice9 { + x: 15.0 + y: 0.0 + z: 15.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: -194.5 + y: 2.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: 389.0 + y: 35.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: "gui/progress_red" + id: "rich_red" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + adjust_mode: ADJUST_MODE_FIT + parent: "rich_back" + layer: "" + inherit_alpha: true + slice9 { + x: 15.0 + y: 0.0 + z: 15.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: -194.5 + y: 2.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: 389.0 + y: 35.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: "gui/progress_yellow" + id: "rich_fill" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_W + adjust_mode: ADJUST_MODE_FIT + parent: "rich_back" + layer: "" + inherit_alpha: true + slice9 { + x: 15.0 + y: 0.0 + z: 15.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: 110.0 + y: 250.0 z: 0.0 w: 1.0 } @@ -281,11 +1177,12 @@ nodes { type: TYPE_BOX blend_mode: BLEND_MODE_ALPHA texture: "gui/green_long" - id: "button_3" + id: "rich_add" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER adjust_mode: ADJUST_MODE_FIT + parent: "progress" layer: "" inherit_alpha: true slice9 { @@ -334,9 +1231,9 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Button 3" + text: "add rich" font: "game" - id: "text_3" + id: "rich_add_text" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE pivot: PIVOT_CENTER @@ -354,7 +1251,126 @@ nodes { } adjust_mode: ADJUST_MODE_FIT line_break: false - parent: "button_3" + parent: "rich_add" + 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 +} +nodes { + position { + x: -110.0 + y: 250.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.5 + y: 0.5 + z: 1.0 + w: 1.0 + } + size { + x: 426.0 + y: 190.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: "gui/green_long" + id: "rich_dec" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "progress" + 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: 20.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: "dec rich\n" + "" + font: "game" + id: "rich_dec_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.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "rich_dec" layer: "" inherit_alpha: true alpha: 1.0 diff --git a/example/example.gui.gui_script b/example/example.gui.gui_script index ec37096..1b4bc7a 100644 --- a/example/example.gui.gui_script +++ b/example/example.gui.gui_script @@ -4,52 +4,101 @@ local druid_settings = require("druid.settings") local lang = { locale_text = "Localized" } +local start_x = 300 +local page_width = 600 +local cur_page = 1 +local max_page = 2 + + + +local function log(self, params) + print(params) +end + local function setup_druid(self) - -- two different way of exernal component regesstration druid.comps["my_mega_test_comp"] = require "druid.base.text" druid.register("my_custom_component", {}) - + druid_settings.is_debug = true - druid_settings.play_sound = function(name) sound.play("sounds#" .. name) end - druid_settings.get_text = function(text_id) return lang[text_id] end end + +local function change_page(self, delta) + cur_page = cur_page + delta + cur_page = math.max(1, cur_page) + cur_page = math.min(cur_page, max_page) + + gui.animate(gui.get_node("center"), "position.x", + start_x - (page_width * (cur_page - 1)), gui.EASING_OUTSINE, 0.1) +end + +local function init_pages(self) + self.druid:new_button("prev", change_page, -1) + self.druid:new_button("next", change_page, 1) +end + + +local function init_buttons(self) + self.druid:new_button("button_1", log, "button 1") + + self.druid:new(druid.comps.button, "button_2", log, "button 2") +end + + +local function init_progress(self) + local val = 0.4 + local simple = self.druid:new_progress("simple_fill", "x", val) + local vert = self.druid:new_progress("simple_vert_fill", "y", val) + + simple:set_steps({0, 0.3, 0.6, 1}, function(self, step) + print("STEP:", step) + end) + + timer.delay(0.4, true, function() + val = val + 0.1 + if val > 1 then + simple:empty() + vert:empty() + val = 0 + end + simple:to(val) + vert:to(val) + end) + + + local rich = self.druid:new_progress_rich("rich_fill", "rich_red", "rich_green", "x") + + rich:set_to(0.3) + + local rich_val = 0.3 + self.druid:new_button("rich_add", function() + rich_val = rich_val + 0.1 + rich:to(rich_val) + end) + self.druid:new_button("rich_dec", function() + rich_val = rich_val - 0.1 + rich:to(rich_val) + end) +end + + function init(self) setup_druid(self) self.druid = druid.new(self) - self.druid:new_button("button_1", function() - print("On button 1") - end) - - --alternative way of component creation - self.druid:new(druid.comps.button, "button_2", function() - print("On button 2") - end) - - self.druid:new_button("button_3", function() - print("On button 3") - end) - - self.druid:new_android_back(function(self, params) - print("On android back", params) - end, 2) - - self.druid:new_text("text_2", "Simple text", false, 400) - self.druid:new_text("text_3", "locale_text", true) - - self.druid:new_timer("text_1", 5, 0, function() - print("On timer end") - end) + init_pages(self) + init_buttons(self) + init_progress(self) + self.druid:new_android_back(log, "some") end function update(self, dt) diff --git a/example/gui.atlas b/example/gui.atlas index 0170ec5..6cb5a3a 100644 --- a/example/gui.atlas +++ b/example/gui.atlas @@ -4,6 +4,21 @@ images { images { image: "/example/res/green_long.png" } -margin: 0 -extrude_borders: 0 +images { + image: "/example/res/progress_back.png" +} +images { + image: "/example/res/progress_green.png" +} +images { + image: "/example/res/progress_red.png" +} +images { + image: "/example/res/progress_yellow.png" +} +images { + image: "/example/res/empty.png" +} +margin: 2 +extrude_borders: 2 inner_padding: 0 diff --git a/example/res/custom.texture_profiles b/example/res/custom.texture_profiles new file mode 100644 index 0000000..5b0d776 --- /dev/null +++ b/example/res/custom.texture_profiles @@ -0,0 +1,18 @@ +path_settings { + path: "**" + profile: "Default" +} +profiles { + name: "Default" + platforms { + os: OS_ID_GENERIC + formats { + format: TEXTURE_FORMAT_RGBA + compression_level: BEST + compression_type: COMPRESSION_TYPE_DEFAULT + } + mipmaps: false + max_texture_size: 0 + premultiply_alpha: true + } +} diff --git a/example/res/empty.png b/example/res/empty.png new file mode 100755 index 0000000..5da9ec0 Binary files /dev/null and b/example/res/empty.png differ diff --git a/example/res/progress_back.png b/example/res/progress_back.png new file mode 100755 index 0000000..30a6652 Binary files /dev/null and b/example/res/progress_back.png differ diff --git a/example/res/progress_green.png b/example/res/progress_green.png new file mode 100755 index 0000000..93907f5 Binary files /dev/null and b/example/res/progress_green.png differ diff --git a/example/res/progress_red.png b/example/res/progress_red.png new file mode 100755 index 0000000..4f55b3a Binary files /dev/null and b/example/res/progress_red.png differ diff --git a/example/res/progress_yellow.png b/example/res/progress_yellow.png new file mode 100755 index 0000000..3e4e38d Binary files /dev/null and b/example/res/progress_yellow.png differ diff --git a/game.project b/game.project index adf34bf..c62a018 100644 --- a/game.project +++ b/game.project @@ -5,8 +5,8 @@ main_collection = /example/example.collectionc shared_state = 1 [display] -width = 400 -height = 400 +width = 600 +height = 900 [project] title = druid @@ -14,3 +14,6 @@ title = druid [library] include_dirs = druid +[graphics] +texture_profiles = /example/res/custom.texture_profiles +