Some minor fixes

* UISpinBox bug with minimum/maximum
* Some fixes to UITable
* Fixed force exit bug.
* Added new next/previous ui buttons.
This commit is contained in:
BeniS 2012-07-26 22:19:34 +12:00
parent 36c029fc69
commit 5419eece66
5 changed files with 54 additions and 34 deletions

View File

@ -39,3 +39,23 @@ TabButton < UIButton
$on: $on:
image-clip: 0 40 20 20 image-clip: 0 40 20 20
color: #80c7f8 color: #80c7f8
BrowseButton < Button
size: 20 29
icon-clip: 0 0 12 21
$hover !disabled:
icon-clip: 0 21 12 21
$pressed:
icon-clip: 0 22 12 21
$disabled:
image-color: #ffffff55
icon-color: #ffffff55
NextButton < BrowseButton
icon-source: /images/arrow_right.png
PreviousButton < BrowseButton
icon-source: /images/arrow_left.png

View File

@ -27,9 +27,17 @@ function UISpinBox:onTextChange(text, oldText)
end end
local number = tonumber(text) local number = tonumber(text)
if not number or number > self.maximum or number < self.minimum then if not number then
self:setText(oldText) self:setText(number)
return return
else
if number < self.minimum then
self:setText(self.minimum)
return
elseif number > self.maximum then
self:setText(self.maximum)
return
end
end end
self:setValue(number) self:setValue(number)
@ -42,9 +50,11 @@ end
function UISpinBox:onStyleApply(styleName, styleNode) function UISpinBox:onStyleApply(styleName, styleNode)
for name, value in pairs(styleNode) do for name, value in pairs(styleNode) do
if name == 'maximum' then if name == 'maximum' then
self:setMaximum(value) addEvent(function() self:setMaximum(value)
end)
elseif name == 'minimum' then elseif name == 'minimum' then
self:setMinimum(value) addEvent(function() self:setMinimum(value)
end)
end end
end end
end end
@ -61,6 +71,9 @@ end
function UISpinBox:setMinimum(minimum) function UISpinBox:setMinimum(minimum)
self.minimum = minimum self.minimum = minimum
if self.minimum > self.maximum then
self.maximum = self.minimum
end
if self.value < minimum then if self.value < minimum then
self:setValue(minimum) self:setValue(minimum)
end end
@ -73,4 +86,6 @@ function UISpinBox:setMaximum(maximum)
end end
end end
function UISpinBox:getValue() return self.value end function UISpinBox:getValue()
return self.value
end

View File

@ -11,19 +11,14 @@ local HEADER_ID = 'row0'
function UITable.create() function UITable.create()
local table = UITable.internalCreate() local table = UITable.internalCreate()
table.headerRow = nil table.headerRow = nil
table.dataSpace = nil table.dataSpace = nil
table.rows = {} table.rows = {}
table.rowBaseStyle = nil table.rowBaseStyle = nil
table.columns = {} table.columns = {}
table.columBaseStyle = nil table.columBaseStyle = nil
table.headerRowBaseStyle = nil table.headerRowBaseStyle = nil
table.headerColumnBaseStyle = nil table.headerColumnBaseStyle = nil
table.selectedRow = nil table.selectedRow = nil
return table return table
end end
@ -119,7 +114,7 @@ function UITable:removeHeaderRow()
self.headerRow = nil self.headerRow = nil
end end
function UITable:addRow(data, height) function UITable:addRow(data, ref, height)
if not self.dataSpace then if not self.dataSpace then
g_logger.error('UITable:addRow - table data space has not been set, cannot add rows.') g_logger.error('UITable:addRow - table data space has not been set, cannot add rows.')
return return
@ -130,11 +125,11 @@ function UITable:addRow(data, height)
end end
local row = g_ui.createWidget(self.rowBaseStyle, self.dataSpace) local row = g_ui.createWidget(self.rowBaseStyle, self.dataSpace)
if ref then row.ref = ref end
if height then row:setHeight(height) end if height then row:setHeight(height) end
local rowId = #self.rows local rowId = #self.rows
while rowId < 1 do rowId = rowId + 1 end row:setId('row'..(rowId < 1 and 1 or rowId))
rowId = 'row'..rowId
row:setId(rowId)
for _, column in pairs(data) do for _, column in pairs(data) do
local col = g_ui.createWidget(self.columBaseStyle, row) local col = g_ui.createWidget(self.columBaseStyle, row)
@ -149,7 +144,10 @@ function UITable:addRow(data, height)
end end
self.columns[rowId] = col self.columns[rowId] = col
end end
row.onClick = function(row) self:selectRow(row) end
row.onFocusChange = function(row, focused)
if focused then self:selectRow(row) end
end
table.insert(self.rows, row) table.insert(self.rows, row)
return row return row
end end

View File

@ -113,7 +113,7 @@ function hide()
Background.show() Background.show()
end end
function exit() function forceExit()
if g_game.isOnline() then if g_game.isOnline() then
g_game.forceLogout() g_game.forceLogout()
scheduleEvent(exit, 10) scheduleEvent(exit, 10)
@ -131,7 +131,7 @@ function tryExit()
local cancelButton = exitWindow:getChildById('buttonCancel') local cancelButton = exitWindow:getChildById('buttonCancel')
local exitFunc = function() local exitFunc = function()
exit() forceExit()
end end
local logoutFunc = function() local logoutFunc = function()
logout() logout()

View File

@ -1,26 +1,13 @@
BrowseButton < Button NextOutfitButton < NextButton
size: 20 29
icon-clip: 0 0 12 21
$hover !disabled:
icon-clip: 0 21 12 21
$pressed:
icon-clip: 0 22 12 21
$disabled:
color: #f0ad4d88
NextOutfitButton < BrowseButton
icon-source: /images/arrow_right.png icon-source: /images/arrow_right.png
PrevOutfitButton < BrowseButton PrevOutfitButton < PreviousButton
icon-source: /images/arrow_left.png icon-source: /images/arrow_left.png
NextMountButton < BrowseButton NextMountButton < NextButton
icon-source: /images/arrow_right.png icon-source: /images/arrow_right.png
PrevMountButton < BrowseButton PrevMountButton < PreviousButton
icon-source: /images/arrow_left.png icon-source: /images/arrow_left.png
Window Window