mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 03:24:55 +02:00
modules changes
* speedup widget destruction checks * rework outfit module using grid layout and the new design * fixes in console, terminal, textmessage modules
This commit is contained in:
@@ -2,16 +2,16 @@ UIComboBox = extends(UIWidget)
|
||||
|
||||
function UIComboBox.create()
|
||||
local combobox = UIComboBox.internalCreate()
|
||||
combobox.m_options = {}
|
||||
combobox.m_currentIndex = -1
|
||||
combobox.options = {}
|
||||
combobox.currentIndex = -1
|
||||
return combobox
|
||||
end
|
||||
|
||||
function UIComboBox:setCurrentOption(text)
|
||||
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
|
||||
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
|
||||
self:setText(text)
|
||||
self:onOptionChange(text, v.data)
|
||||
return
|
||||
@@ -20,24 +20,24 @@ function UIComboBox:setCurrentOption(text)
|
||||
end
|
||||
|
||||
function UIComboBox:setCurrentIndex(index)
|
||||
if index >= 1 and index <= #self.m_options then
|
||||
local v = self.m_options[index]
|
||||
self.m_currentIndex = index
|
||||
if index >= 1 and index <= #self.options then
|
||||
local v = self.options[index]
|
||||
self.currentIndex = index
|
||||
self:setText(v.text)
|
||||
self:onOptionChange(v.text, v.data)
|
||||
end
|
||||
end
|
||||
|
||||
function UIComboBox:addOption(text, data)
|
||||
table.insert(self.m_options, { text = text, data = data })
|
||||
local index = #self.m_options
|
||||
table.insert(self.options, { text = text, data = data })
|
||||
local index = #self.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.m_options) do
|
||||
for i,v in ipairs(self.options) do
|
||||
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
|
||||
end
|
||||
menu:setWidth(self:getWidth())
|
||||
@@ -48,10 +48,10 @@ function UIComboBox:onMousePress(mousePos, mouseButton)
|
||||
end
|
||||
|
||||
function UIComboBox:onMouseWheel(mousePos, direction)
|
||||
if direction == MouseWheelUp and self.m_currentIndex > 1 then
|
||||
self:setCurrentIndex(self.m_currentIndex - 1)
|
||||
elseif direction == MouseWheelDown and self.m_currentIndex < #self.m_options then
|
||||
self:setCurrentIndex(self.m_currentIndex + 1)
|
||||
if direction == MouseWheelUp and self.currentIndex > 1 then
|
||||
self:setCurrentIndex(self.currentIndex - 1)
|
||||
elseif direction == MouseWheelDown and self.currentIndex < #self.options then
|
||||
self:setCurrentIndex(self.currentIndex + 1)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
@@ -4,23 +4,23 @@ function UIProgressBar.create()
|
||||
local progressbar = UIProgressBar.internalCreate()
|
||||
progressbar:setFocusable(false)
|
||||
progressbar:setPhantom(true)
|
||||
progressbar.m_percent = 0
|
||||
progressbar.percent = 0
|
||||
progressbar:updateBackground()
|
||||
return progressbar
|
||||
end
|
||||
|
||||
function UIProgressBar:setPercent(percent)
|
||||
self.m_percent = math.max(math.min(percent, 100), 0)
|
||||
self.percent = math.max(math.min(percent, 100), 0)
|
||||
self:updateBackground()
|
||||
end
|
||||
|
||||
|
||||
function UIProgressBar:getPercent()
|
||||
return self.m_percent
|
||||
return self.percent
|
||||
end
|
||||
|
||||
function UIProgressBar:updateBackground()
|
||||
local width = math.max((self.m_percent * self:getWidth())/100, 1)
|
||||
local width = math.max((self.percent * self:getWidth())/100, 1)
|
||||
local height = self:getHeight()
|
||||
self:setBackgroundSize({width=width, height=height})
|
||||
end
|
||||
|
@@ -3,54 +3,54 @@ UISpinBox = extends(UILineEdit)
|
||||
function UISpinBox.create()
|
||||
local spinbox = UISpinBox.internalCreate()
|
||||
spinbox:setValidCharacters('0123456789')
|
||||
spinbox.m_minimum = 0
|
||||
spinbox.m_maximum = 0
|
||||
spinbox.minimum = 0
|
||||
spinbox.maximum = 0
|
||||
spinbox:setCurrentIndex(0)
|
||||
spinbox:setText("0")
|
||||
return spinbox
|
||||
end
|
||||
|
||||
function UISpinBox:setCurrentIndex(index)
|
||||
if index >= self.m_minimum and index <= self.m_maximum then
|
||||
if index >= self.minimum and index <= self.maximum then
|
||||
if self:getText():len() > 0 then
|
||||
self:setText(index)
|
||||
end
|
||||
self.m_currentIndex = index
|
||||
self.currentIndex = index
|
||||
self:onIndexChange(index)
|
||||
end
|
||||
end
|
||||
|
||||
function UISpinBox:setMinimum(minimum)
|
||||
if minimum > self.m_maximum then
|
||||
if minimum > self.maximum then
|
||||
print("[UISpinBox:setMinimum]: minimum value cant be greater than maximum")
|
||||
return false
|
||||
end
|
||||
if self.m_currentIndex < minimum then
|
||||
if self.currentIndex < minimum then
|
||||
self:setCurrentIndex(minimum)
|
||||
end
|
||||
self.m_minimum = minimum
|
||||
self.minimum = minimum
|
||||
end
|
||||
|
||||
function UISpinBox:setMaximum(maximum)
|
||||
if maximum < self.m_minimum then
|
||||
if maximum < self.minimum then
|
||||
print("[UISpinBox:setMaximum]: maximum value cant be lower than minimum")
|
||||
return false
|
||||
end
|
||||
if self.m_currentIndex > maximum then
|
||||
if self.currentIndex > maximum then
|
||||
self:setCurrentIndex(maximum)
|
||||
end
|
||||
self.m_maximum = maximum
|
||||
self.maximum = maximum
|
||||
end
|
||||
|
||||
function UISpinBox:getCurrentIndex()
|
||||
return self.m_currentIndex
|
||||
return self.currentIndex
|
||||
end
|
||||
|
||||
function UISpinBox:onMouseWheel(mousePos, direction)
|
||||
if direction == MouseWheelUp then
|
||||
self:setCurrentIndex(self.m_currentIndex + 1)
|
||||
self:setCurrentIndex(self.currentIndex + 1)
|
||||
elseif direction == MouseWheelDown then
|
||||
self:setCurrentIndex(self.m_currentIndex - 1)
|
||||
self:setCurrentIndex(self.currentIndex - 1)
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -58,12 +58,12 @@ end
|
||||
function UISpinBox:onTextChange(text, oldText)
|
||||
|
||||
if text:len() == 0 then
|
||||
self:setCurrentIndex(self.m_minimum)
|
||||
self:setCurrentIndex(self.minimum)
|
||||
return
|
||||
end
|
||||
|
||||
local number = tonumber(text)
|
||||
if not number or number > self.m_maximum or number < self.m_minimum then
|
||||
if not number or number > self.maximum or number < self.minimum then
|
||||
self:setText(oldText)
|
||||
return
|
||||
end
|
||||
|
Reference in New Issue
Block a user