local druid = require("druid.druid")
local druid_const = require("druid.const")
local lang = require("example.lang")


local function refresh_lang_text(self)
	self.text_current:format(lang.get_locale("ui_lang"))
end


function init(self)
	self.druid = druid.new(self)

	self.text_current = self.druid:new_lang_text("text_current_lang", "ui_current_lang")
	self.text_example_1 = self.druid:new_lang_text("text_example_1", "ui_example_1")
	self.text_example_2 = self.druid:new_lang_text("text_example_2", "ui_example_2")
	self.text_example_3 = self.druid:new_lang_text("text_example_3", "ui_example_3")
	self.text_example_3:format(10, 20, 30)

	refresh_lang_text(self)

	self.current_lang = lang.get_locale()
	self.druid:new_button("button_change_lang/button", lang.toggle_locale)
end


function final(self)
	self.druid:final()
end


function update(self, dt)
	self.druid:update(dt)
end


function on_message(self, message_id, message, sender)
	-- If we have localized text in text formatting, we should update it manually
	-- If we have non localized text, the lang_text:format or :translate will update text manually again
	if message_id == hash(druid_const.ON_LANGUAGE_CHANGE) then
		refresh_lang_text(self)
	end

	self.druid:on_message(message_id, message, sender)
end


function on_input(self, action_id, action)
	return self.druid:on_input(action_id, action)
end
