mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
* improve example gui. Add simple pages * return old progress bar with example * base progress with steps, there is bug with step? 1 ~= 1, small delta? * polish progress, check float error case * add callback on end of "to" function, value check * start of green/red in progress * add first version of rich progress bar * make green bar darker * rich bar fixes * add delay, before filling in rich progress * PR fixes * remove dublicate of 'progress_rich'
114 lines
2.4 KiB
Plaintext
114 lines
2.4 KiB
Plaintext
local druid = require("druid.druid")
|
|
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)
|
|
|
|
init_pages(self)
|
|
init_buttons(self)
|
|
init_progress(self)
|
|
|
|
self.druid:new_android_back(log, "some")
|
|
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 |