From 76c7bf45bd56289dd6ab0e29fb7b1d1e0c700958 Mon Sep 17 00:00:00 2001 From: BeniS Date: Sun, 22 Jul 2012 05:17:03 +1200 Subject: [PATCH] More on UITable and the Market. --- .../skins/default/styles/tables.otui | 8 +++- modules/corelib/ui/uitable.lua | 45 ++++++++++++------- modules/game_market/market.lua | 29 ++++++------ .../ui/marketoffers/itemoffers.otui | 6 ++- 4 files changed, 57 insertions(+), 31 deletions(-) diff --git a/modules/client_skins/skins/default/styles/tables.otui b/modules/client_skins/skins/default/styles/tables.otui index e1b3207e..700fa050 100644 --- a/modules/client_skins/skins/default/styles/tables.otui +++ b/modules/client_skins/skins/default/styles/tables.otui @@ -1,9 +1,13 @@ Table < UITable layout: verticalBox + column-style: TableColumn + row-style: TableRow -TableRow < UIScrollArea +TableRow < Label + id: defaultRow layout: horizontalBox height: 10 -TableColumn < UIScrollArea +TableColumn < Label + id: defaultColumn width: 30 diff --git a/modules/corelib/ui/uitable.lua b/modules/corelib/ui/uitable.lua index af640326..4340cb01 100644 --- a/modules/corelib/ui/uitable.lua +++ b/modules/corelib/ui/uitable.lua @@ -5,8 +5,9 @@ function UITable.create() local table = UITable.internalCreate() table.rows = {} table.rows.columns = {} - table.rowStyle = {} - table.columStyle = {} + table.rowBaseStyle = nil + table.columBaseStyle = nil + table.selectedRow = nil return table end @@ -22,23 +23,37 @@ function UITable:onStyleApply(styleName, styleNode) for name, value in pairs(styleNode) do if name == 'column-style' then addEvent(function() - self:setRowStyle(self:getParent():getChildById(value)) + self:setColumnStyle(value) end) elseif name == 'row-style' then addEvent(function() - self:setRowStyle(self:getParent():getChildById(value)) + self:setRowStyle(value) end) end end end -function UITable:addRow(columns, rowStyle, columStyle) - local row = g_ui.createWidget(rowStyle, self) +function UITable:addRow(columns) + if not columns or type(columns) ~= 'table' then + g_logger.error('UITable:addRow - table columns must be provided in a table') + end + + -- TODO: table header rows as buttons. + --[[if #self.rows < 1 then + g_ui.createWidget(self.rowBaseStyle, self) + end]] + + local row = g_ui.createWidget(self.rowBaseStyle, self) row.columns = {} - for k, data in pairs(columns) do - local col = g_ui.createWidget(columStyle, row) - col:setText(data) + for _, column in pairs(columns) do + local col = g_ui.createWidget(self.columBaseStyle, row) + if column[1] then + col:setText(column[1]) + end + if #column > 1 then + col:setWidth(column[2]) + end table.insert(row.columns, col) end row.onClick = function(row) self:selectRow(row) end @@ -72,15 +87,15 @@ function UITable:selectRow(selectedRow) end function UITable:setRowStyle(style) - self.rowStyle = style - for k, row in pairs(self.rows) do + self.rowBaseStyle = style + --[[for k, row in pairs(self.rows) do row:setStyle(style) - end + end]] end function UITable:setColumnStyle(style) - self.columStyle = style - for k, col in pairs(self.rows.columns) do + self.columBaseStyle = style + --[[for k, col in pairs(self.rows.columns) do col:setStyle(style) - end + end]] end \ No newline at end of file diff --git a/modules/game_market/market.lua b/modules/game_market/market.lua index 33dffef6..73ea6b48 100644 --- a/modules/game_market/market.lua +++ b/modules/game_market/market.lua @@ -256,23 +256,23 @@ function Market.updateOffers(offers) for k, offer in pairs(offers) do if offer and offer:getAction() == MarketAction.Buy then local data = { - offer:getPlayer(), - offer:getAmount(), - offer:getPrice()*offer:getAmount(), - offer:getPrice(), - offer:getTimeStamp() + {offer:getPlayer(), 80}, + {offer:getAmount(), 50}, + {offer:getPrice()*offer:getAmount(), 80}, + {offer:getPrice(), 60}, + {offer:getTimeStamp(), 80} } - local row = buyOfferTable:addRow(data, 'OfferTableRow', 'OfferTableColumn') + local row = buyOfferTable:addRow(data) table.insert(marketOffers[MarketAction.Buy], offer) else local data = { - offer:getPlayer(), - offer:getAmount(), - offer:getPrice()*offer:getAmount(), - offer:getPrice(), - offer:getTimeStamp() + {offer:getPlayer(), 80}, + {offer:getAmount(), 50}, + {offer:getPrice()*offer:getAmount(), 80}, + {offer:getPrice(), 60}, + {offer:getTimeStamp(), 80} } - local row = sellOfferTable:addRow(data, 'OfferTableRow', 'OfferTableColumn') + local row = sellOfferTable:addRow(data) table.insert(marketOffers[MarketAction.Sell], offer) end end @@ -323,7 +323,10 @@ function Market.onMarketEnter(depotItems, offers, balance) loadDepotItems(depotItems) -- TODO: if you are already viewing an item on market enter it must recheck the current item - if selectedItem and selectedItem:isChecked() then + print(selectedItem) + print(selectedItem:isChecked()) + if selectedItem then + print('in') selectedItem:setChecked(false) selectedItem:setChecked(true) end diff --git a/modules/game_market/ui/marketoffers/itemoffers.otui b/modules/game_market/ui/marketoffers/itemoffers.otui index 9606f1ab..1bbd2f11 100644 --- a/modules/game_market/ui/marketoffers/itemoffers.otui +++ b/modules/game_market/ui/marketoffers/itemoffers.otui @@ -4,7 +4,7 @@ OfferTableRow < TableRow text-offset: 2 0 focusable: true color: #cccccc - height: 25 + height: 15 $focus: background-color: #294f6d @@ -51,6 +51,8 @@ Panel border-width: 1 border-color: #191f27 vertical-scrollbar: sellingTableScrollBar + row-style: OfferTableRow + column-style: OfferTableColumn VerticalScrollBar id: sellingTableScrollBar @@ -91,6 +93,8 @@ Panel border-width: 1 border-color: #191f27 vertical-scrollbar: buyingTableScrollBar + row-style: OfferTableRow + column-style: OfferTableColumn VerticalScrollBar id: buyingTableScrollBar