mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
implement API to save lists in configs file and terminal history
This commit is contained in:
@@ -2,16 +2,16 @@ UIComboBox = extends(UIWidget)
|
||||
|
||||
function UIComboBox.create()
|
||||
local combobox = UIComboBox.internalCreate()
|
||||
combobox.options = {}
|
||||
combobox.currentIndex = -1
|
||||
combobox.m_options = {}
|
||||
combobox.m_currentIndex = -1
|
||||
return combobox
|
||||
end
|
||||
|
||||
function UIComboBox:setCurrentOption(text)
|
||||
if not self.options then return end
|
||||
for i,v in ipairs(self.options) do
|
||||
if v.text == text and self.currentIndex ~= i then
|
||||
self.currentIndex = i
|
||||
if not self.m_options then return end
|
||||
for i,v in ipairs(self.m_options) do
|
||||
if v.text == text and self.m_currentIndex ~= i then
|
||||
self.m_currentIndex = i
|
||||
self:setText(text)
|
||||
self:onOptionChange(text, data)
|
||||
return
|
||||
@@ -20,15 +20,15 @@ function UIComboBox:setCurrentOption(text)
|
||||
end
|
||||
|
||||
function UIComboBox:addOption(text, data)
|
||||
table.insert(self.options, { text = text, data = data })
|
||||
local index = #self.options
|
||||
table.insert(self.m_options, { text = text, data = data })
|
||||
local index = #self.m_options
|
||||
if index == 1 then self:setCurrentOption(text) end
|
||||
return index
|
||||
end
|
||||
|
||||
function UIComboBox:onMousePress(mousePos, mouseButton)
|
||||
local menu = createWidget(self:getStyleName() .. 'PopupMenu', self)
|
||||
for i,v in ipairs(self.options) do
|
||||
for i,v in ipairs(self.m_options) do
|
||||
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
|
||||
end
|
||||
menu:setWidth(self:getWidth())
|
||||
|
23
modules/core_widgets/uimessagebox.lua
Normal file
23
modules/core_widgets/uimessagebox.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
UIMessageBox = extends(UIWindow)
|
||||
|
||||
function UIMessageBox.create(title, message)
|
||||
local messagebox = UIMessageBox.internalCreate()
|
||||
|
||||
messagebox:setText(title)
|
||||
local messageLabel = self:getChildById('messageLabel')
|
||||
label:setText(message)
|
||||
label:resizeToText()
|
||||
|
||||
window:setWidth(math.max(label:getWidth() + self:getPaddingLeft() + self:getPaddingRight(), self:getWidth()))
|
||||
window:setHeight(label:getHeight() + self:getPaddingTop() + self:getPaddingBottom())
|
||||
|
||||
return messagebox
|
||||
end
|
||||
|
||||
function UIMessageBox:setTitle(title)
|
||||
end
|
||||
|
||||
function UIMessageBox:setMessage(message)
|
||||
end
|
||||
|
||||
function
|
@@ -4,19 +4,28 @@ function UIProgressBar.create()
|
||||
local progressbar = UIProgressBar.internalCreate()
|
||||
progressbar:setFocusable(false)
|
||||
progressbar:setPhantom(true)
|
||||
progressbar.percent = 0
|
||||
progressbar:setBackgroundSize({width = 1, height = 1})
|
||||
progressbar.m_percent = 0
|
||||
progressbar:updateBackground()
|
||||
return progressbar
|
||||
end
|
||||
|
||||
function UIProgressBar:setPercent(percent)
|
||||
self:setBackgroundHeight(self:getHeight())
|
||||
local width = (percent * self:getWidth())/100
|
||||
if width == 0 then width = 1 end
|
||||
self:setBackgroundWidth(width)
|
||||
self.percent = percent
|
||||
self.m_percent = percent
|
||||
self:updateBackground()
|
||||
end
|
||||
|
||||
|
||||
function UIProgressBar:getPercent()
|
||||
return self.percent
|
||||
return self.m_percent
|
||||
end
|
||||
|
||||
function UIProgressBar:updateBackground()
|
||||
local width = math.max((self.m_percent * self:getWidth())/100, 1)
|
||||
local height = self:getHeight()
|
||||
self:setBackgroundSize({width=width, height=height})
|
||||
end
|
||||
|
||||
|
||||
function UIProgressBar:onGeometryChange(oldRect, newRect)
|
||||
self:updateBackground()
|
||||
end
|
||||
|
Reference in New Issue
Block a user