2024-10-17 01:24:15 +03:00

63 lines
2.1 KiB
Lua

local lang = require("lang.lang")
local component = require("druid.component")
local container = require("example.components.container.container")
local lang_text = require("druid.extended.lang_text")
local rich_text = require("druid.custom.rich_text.rich_text")
---@class panel_information: druid.base_component
---@field root druid.container
---@field text_header druid.lang_text
---@field rich_text druid.rich_text
---@field druid druid_instance
local PanelInformation = component.create("panel_information")
---@param template string
---@param nodes table<hash, node>
function PanelInformation:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.root = self.druid:new(container, "root") --[[@as druid.container]]
self.root:add_container("text_header")
self.root:add_container("scroll_view")
self.root:add_container("S_Anchor")
self.root:add_container("NE_Anchor")
self.druid:new(lang_text, "text_header", "ui_information")
self.druid:new(lang_text, "button_profiler/text", "ui_profiler")
--self.text_description = self.druid:new(lang_text, "text_description", "") --[[@as druid.lang_text]]
self.rich_text = self.druid:new(rich_text, "text_description")
self.button_profiler = self.druid:new_button("button_profiler/root", self.on_profiler_click)
self.button_profiler:set_key_trigger("key_p")
self.button_view_code = self.druid:new_button("button_view_code/root")
-- Disable profiler button for HTML5
gui.set_enabled(self.button_profiler.node, not html5)
end
function PanelInformation:set_text(text_id)
local text = lang.txt(text_id)
self.rich_text:set_text(text)
end
function PanelInformation:on_profiler_click()
if self._profiler_mode == nil then
self._profiler_mode = profiler.VIEW_MODE_MINIMIZED
profiler.enable_ui(true)
profiler.set_ui_view_mode(self._profiler_mode)
elseif self._profiler_mode == profiler.VIEW_MODE_MINIMIZED then
self._profiler_mode = profiler.VIEW_MODE_FULL
profiler.enable_ui(true)
profiler.set_ui_view_mode(self._profiler_mode)
else
self._profiler_mode = nil
profiler.enable_ui(false)
end
end
return PanelInformation