Some performance fixes, added UITable widget for easy tables (needs more work still), Worked on Market order displaying.
This commit is contained in:
		
							parent
							
								
									3461761739
								
							
						
					
					
						commit
						9c8134c8a6
					
				|  | @ -28,7 +28,8 @@ local skin = { | ||||||
|     'splitters.otui', |     'splitters.otui', | ||||||
|     'miniwindow.otui', |     'miniwindow.otui', | ||||||
|     'items.otui', |     'items.otui', | ||||||
|     'creatures.otui' |     'creatures.otui', | ||||||
|  |     'tables.otui' | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   particles = { |   particles = { | ||||||
|  |  | ||||||
|  | @ -0,0 +1,9 @@ | ||||||
|  | Table < UITable | ||||||
|  |   layout: verticalBox | ||||||
|  | 
 | ||||||
|  | TableRow < UIScrollArea | ||||||
|  |   layout: horizontalBox | ||||||
|  |   height: 10 | ||||||
|  | 
 | ||||||
|  | TableColumn < UIScrollArea | ||||||
|  |   width: 30 | ||||||
|  | @ -0,0 +1,86 @@ | ||||||
|  | -- @docclass | ||||||
|  | UITable = extends(UIScrollArea) | ||||||
|  | 
 | ||||||
|  | function UITable.create() | ||||||
|  |   local table = UITable.internalCreate() | ||||||
|  |   table.rows = {} | ||||||
|  |   table.rows.columns = {} | ||||||
|  |   table.rowStyle = {} | ||||||
|  |   table.columStyle = {} | ||||||
|  |   return table | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function UITable:destroy() | ||||||
|  |   for k,row in pairs(self.rows) do | ||||||
|  |     row.onClick = nil | ||||||
|  |   end | ||||||
|  |   self.rows = {} | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function UITable:onStyleApply(styleName, styleNode) | ||||||
|  |   UIScrollArea.onStyleApply(self, styleName, styleNode) | ||||||
|  |   for name, value in pairs(styleNode) do | ||||||
|  |     if name == 'column-style' then | ||||||
|  |       addEvent(function() | ||||||
|  |         self:setRowStyle(self:getParent():getChildById(value)) | ||||||
|  |       end) | ||||||
|  |     elseif name == 'row-style' then | ||||||
|  |       addEvent(function() | ||||||
|  |         self:setRowStyle(self:getParent():getChildById(value)) | ||||||
|  |       end) | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function UITable:addRow(columns, rowStyle, columStyle) | ||||||
|  |   local row = g_ui.createWidget(rowStyle, self) | ||||||
|  |   row.columns = {} | ||||||
|  | 
 | ||||||
|  |   for k, data in pairs(columns) do | ||||||
|  |     local col = g_ui.createWidget(columStyle, row) | ||||||
|  |     col:setText(data) | ||||||
|  |     table.insert(row.columns, col) | ||||||
|  |   end | ||||||
|  |   row.onClick = function(row) self:selectRow(row) end | ||||||
|  |   table.insert(self.rows, row) | ||||||
|  |   return row | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function UITable:removeRow(row) | ||||||
|  |   if self.selectedRow == row then | ||||||
|  |     self:selectRow(nil) | ||||||
|  |   end | ||||||
|  |   row.onClick = nil | ||||||
|  |   table.removevalue(self.rows, row) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function UITable:selectRow(selectedRow) | ||||||
|  |   if selectedRow == self.selectedRow then return end | ||||||
|  | 
 | ||||||
|  |   local previousSelectedRow = self.selectedRow | ||||||
|  |   self.selectedRow = selectedRow | ||||||
|  | 
 | ||||||
|  |   if previousSelectedRow then | ||||||
|  |     previousSelectedRow:setChecked(false) | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   if selectedRow then | ||||||
|  |     selectedRow:setChecked(true) | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   signalcall(self.onSelectionChange, self, selectedRow, previousSelectedRow) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function UITable:setRowStyle(style) | ||||||
|  |   self.rowStyle = style | ||||||
|  |   for k, row in pairs(self.rows) do | ||||||
|  |     row:setStyle(style) | ||||||
|  |   end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function UITable:setColumnStyle(style) | ||||||
|  |   self.columStyle = style | ||||||
|  |   for k, col in pairs(self.rows.columns) do | ||||||
|  |     col:setStyle(style) | ||||||
|  |   end | ||||||
|  | end | ||||||
|  | @ -62,15 +62,15 @@ local function initMarketItems() | ||||||
|   -- populate all market items |   -- populate all market items | ||||||
|   marketItems = {} |   marketItems = {} | ||||||
|   local types = g_things.findThingTypeByAttr(ThingAttrMarket) |   local types = g_things.findThingTypeByAttr(ThingAttrMarket) | ||||||
|   for idx = 1, #types do |   for i = 1, #types do | ||||||
|     local t = types[idx] |     local t = types[i] | ||||||
|     local newItem = Item.create(t:getId()) |     local newItem = Item.create(t:getId()) | ||||||
|     if newItem then |     if newItem then | ||||||
|       local item = { |       local item = { | ||||||
|         ptr = newItem, |         ptr = newItem, | ||||||
|         marketData = t:getMarketData() |         marketData = t:getMarketData() | ||||||
|       } |       } | ||||||
|       table.insert(marketItems, item) |       marketItems[#marketItems+1] = item | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  | @ -92,7 +92,8 @@ local function updateItemsWidget() | ||||||
|   end |   end | ||||||
|   radioItemSet = UIRadioGroup.create() |   radioItemSet = UIRadioGroup.create() | ||||||
| 
 | 
 | ||||||
|   for _, item in pairs(currentItems) do |   for i = 1, #currentItems do | ||||||
|  |     local item = currentItems[i] | ||||||
|     local itemBox = g_ui.createWidget('MarketItemBox', itemsPanel) |     local itemBox = g_ui.createWidget('MarketItemBox', itemsPanel) | ||||||
|     local itemWidget = itemBox:getChildById('item') |     local itemWidget = itemBox:getChildById('item') | ||||||
| 
 | 
 | ||||||
|  | @ -108,7 +109,8 @@ end | ||||||
| 
 | 
 | ||||||
| local function loadDepotItems(depotItems) | local function loadDepotItems(depotItems) | ||||||
|   information.depotItems = {} |   information.depotItems = {} | ||||||
|   for _, data in pairs(depotItems) do |   for i = 1, #depotItems do | ||||||
|  |     local data = depotItems[i] | ||||||
|     local item = Item.create(data[1]) |     local item = Item.create(data[1]) | ||||||
|     if not item then |     if not item then | ||||||
|       break |       break | ||||||
|  | @ -229,8 +231,9 @@ function Market.loadMarketItems(_category) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   currentItems = {} |   currentItems = {} | ||||||
|   for _, item in pairs(marketItems) do |   for i = 1, #marketItems do | ||||||
|     -- filter items here |     -- filter items here | ||||||
|  |     local item = marketItems[i] | ||||||
|     local category = item.marketData.category |     local category = item.marketData.category | ||||||
|     if category == _category or _category == MarketCategory[0] then |     if category == _category or _category == MarketCategory[0] then | ||||||
|       table.insert(currentItems, item) |       table.insert(currentItems, item) | ||||||
|  | @ -244,20 +247,32 @@ function Market.updateOffers(offers) | ||||||
|   marketOffers[MarketAction.Buy] = {} |   marketOffers[MarketAction.Buy] = {} | ||||||
|   marketOffers[MarketAction.Sell] = {} |   marketOffers[MarketAction.Sell] = {} | ||||||
| 
 | 
 | ||||||
|   local buyOfferList = marketWindow:recursiveGetChildById('buyingList') |   local buyOfferTable = marketWindow:recursiveGetChildById('buyingTable') | ||||||
|   buyOfferList:destroyChildren() |   buyOfferTable:destroyChildren() | ||||||
| 
 | 
 | ||||||
|   local sellOfferList = marketWindow:recursiveGetChildById('sellingList') |   local sellOfferTable = marketWindow:recursiveGetChildById('sellingTable') | ||||||
|   sellOfferList:destroyChildren() |   sellOfferTable:destroyChildren() | ||||||
| 
 | 
 | ||||||
|   for k, offer in pairs(offers) do |   for k, offer in pairs(offers) do | ||||||
|     if offer and offer:getAction() == MarketAction.Buy then |     if offer and offer:getAction() == MarketAction.Buy then | ||||||
|       local label = g_ui.createWidget('OfferListLabel', buyOfferList) |       local data = { | ||||||
|       label:setText(offer:getPlayer()..'                  '..offer:getAmount()..'                  '..(offer:getPrice()*offer:getAmount())..'                  '..offer:getPrice()..'                  '..offer:getTimeStamp()) |         offer:getPlayer(), | ||||||
|  |         offer:getAmount(), | ||||||
|  |         offer:getPrice()*offer:getAmount(), | ||||||
|  |         offer:getPrice(), | ||||||
|  |         offer:getTimeStamp() | ||||||
|  |       } | ||||||
|  |       local row = buyOfferTable:addRow(data, 'OfferTableRow', 'OfferTableColumn') | ||||||
|       table.insert(marketOffers[MarketAction.Buy], offer) |       table.insert(marketOffers[MarketAction.Buy], offer) | ||||||
|     else |     else | ||||||
|       local label = g_ui.createWidget('OfferListLabel', sellOfferList) |       local data = { | ||||||
|       label:setText(offer:getPlayer()..'                  '..offer:getAmount()..'                  '..(offer:getPrice()*offer:getAmount())..'                  '..offer:getPrice()..'                  '..offer:getTimeStamp()) |         offer:getPlayer(), | ||||||
|  |         offer:getAmount(), | ||||||
|  |         offer:getPrice()*offer:getAmount(), | ||||||
|  |         offer:getPrice(), | ||||||
|  |         offer:getTimeStamp() | ||||||
|  |       } | ||||||
|  |       local row = sellOfferTable:addRow(data, 'OfferTableRow', 'OfferTableColumn') | ||||||
|       table.insert(marketOffers[MarketAction.Sell], offer) |       table.insert(marketOffers[MarketAction.Sell], offer) | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  | @ -1,14 +1,22 @@ | ||||||
| OfferListLabel < Label | OfferTableRow < TableRow | ||||||
|   font: verdana-11px-monochrome |   font: verdana-11px-monochrome | ||||||
|   background-color: alpha |   background-color: alpha | ||||||
|   text-offset: 2 0 |   text-offset: 2 0 | ||||||
|   focusable: true |   focusable: true | ||||||
|   color: #cccccc |   color: #cccccc | ||||||
|  |   height: 25 | ||||||
| 
 | 
 | ||||||
|   $focus: |   $focus: | ||||||
|     background-color: #294f6d |     background-color: #294f6d | ||||||
|     color: #ffffff |     color: #ffffff | ||||||
| 
 | 
 | ||||||
|  | OfferTableColumn < TableColumn | ||||||
|  |   font: verdana-11px-monochrome | ||||||
|  |   background-color: alpha | ||||||
|  |   text-offset: 2 0 | ||||||
|  |   color: #cccccc | ||||||
|  |   width: 80 | ||||||
|  | 
 | ||||||
| Panel | Panel | ||||||
|   background-color: #22283399 |   background-color: #22283399 | ||||||
|   margin: 1 |   margin: 1 | ||||||
|  | @ -28,8 +36,8 @@ Panel | ||||||
|     margin-top: 44 |     margin-top: 44 | ||||||
|     margin-left: 6 |     margin-left: 6 | ||||||
| 
 | 
 | ||||||
|   TextList |   Table | ||||||
|     id: sellingList |     id: sellingTable | ||||||
|     anchors.top: prev.bottom |     anchors.top: prev.bottom | ||||||
|     anchors.left: prev.left |     anchors.left: prev.left | ||||||
|     anchors.right: parent.right |     anchors.right: parent.right | ||||||
|  | @ -39,10 +47,13 @@ Panel | ||||||
|     margin-right: 6 |     margin-right: 6 | ||||||
|     padding: 1 |     padding: 1 | ||||||
|     focusable: false |     focusable: false | ||||||
|     vertical-scrollbar: sellingListScrollBar |     background-color: #222833 | ||||||
|  |     border-width: 1 | ||||||
|  |     border-color: #191f27 | ||||||
|  |     vertical-scrollbar: sellingTableScrollBar | ||||||
| 
 | 
 | ||||||
|   VerticalScrollBar |   VerticalScrollBar | ||||||
|     id: sellingListScrollBar |     id: sellingTableScrollBar | ||||||
|     anchors.top: prev.top |     anchors.top: prev.top | ||||||
|     anchors.bottom: prev.bottom |     anchors.bottom: prev.bottom | ||||||
|     anchors.right: prev.right |     anchors.right: prev.right | ||||||
|  | @ -65,8 +76,8 @@ Panel | ||||||
|     margin-top: 9 |     margin-top: 9 | ||||||
|     margin-left: 6 |     margin-left: 6 | ||||||
| 
 | 
 | ||||||
|   TextList |   Table | ||||||
|     id: buyingList |     id: buyingTable | ||||||
|     anchors.top: prev.bottom |     anchors.top: prev.bottom | ||||||
|     anchors.left: prev.left |     anchors.left: prev.left | ||||||
|     anchors.right: parent.right |     anchors.right: parent.right | ||||||
|  | @ -76,10 +87,13 @@ Panel | ||||||
|     height: 120 |     height: 120 | ||||||
|     padding: 1 |     padding: 1 | ||||||
|     focusable: false |     focusable: false | ||||||
|     vertical-scrollbar: buyingListScrollBar |     background-color: #222833 | ||||||
|  |     border-width: 1 | ||||||
|  |     border-color: #191f27 | ||||||
|  |     vertical-scrollbar: buyingTableScrollBar | ||||||
| 
 | 
 | ||||||
|   VerticalScrollBar |   VerticalScrollBar | ||||||
|     id: buyingListScrollBar |     id: buyingTableScrollBar | ||||||
|     anchors.top: prev.top |     anchors.top: prev.top | ||||||
|     anchors.bottom: prev.bottom |     anchors.bottom: prev.bottom | ||||||
|     anchors.right: prev.right |     anchors.right: prev.right | ||||||
|  |  | ||||||
|  | @ -111,9 +111,10 @@ local function updateOutfit() | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   outfit.addons = 0 |   outfit.addons = 0 | ||||||
|   for k, addon in pairs(prevAddons) do |   for i = 1, #prevAddons do | ||||||
|     if addon and addons[k].widget:isEnabled() then |     local addon = prevAddons[i] | ||||||
|       addons[k].widget:setChecked(true) |     if addon and addons[i].widget:isEnabled() then | ||||||
|  |       addons[i].widget:setChecked(true) | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  | @ -185,7 +186,7 @@ function Outfit.create(creatureOutfit, outfitList, creatureMount, mountList) | ||||||
|     [3] = {widget = outfitWindow:getChildById('addon3'), value = 4} |     [3] = {widget = outfitWindow:getChildById('addon3'), value = 4} | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   for k, addon in pairs(addons) do |   for _, addon in pairs(addons) do | ||||||
|     addon.widget.onCheckChange = function(self) onAddonCheckChange(self, addon.value) end |     addon.widget.onCheckChange = function(self) onAddonCheckChange(self, addon.value) end | ||||||
|   end |   end | ||||||
|    |    | ||||||
|  | @ -216,7 +217,7 @@ function Outfit.create(creatureOutfit, outfitList, creatureMount, mountList) | ||||||
|         colorBox:setChecked(true) |         colorBox:setChecked(true) | ||||||
|       end |       end | ||||||
|       colorBox.onCheckChange = onColorCheckChange |       colorBox.onCheckChange = onColorCheckChange | ||||||
|       table.insert(colorBoxes, colorBox) |       colorBoxes[#colorBoxes+1] = colorBox | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  | @ -260,10 +261,10 @@ function Outfit.randomize() | ||||||
|     outfitWindow:getChildById('detail') |     outfitWindow:getChildById('detail') | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   for k, section in pairs(outfitTemplate) do |   for i = 1, #outfitTemplate do | ||||||
|     section:setChecked(true) |     outfitTemplate[i]:setChecked(true) | ||||||
|     colorBoxes[math.random(1, #colorBoxes)]:setChecked(true) |     colorBoxes[math.random(1, #colorBoxes)]:setChecked(true) | ||||||
|     section:setChecked(false) |     outfitTemplate[i]:setChecked(false) | ||||||
|   end |   end | ||||||
|   outfitTemplate[1]:setChecked(true) |   outfitTemplate[1]:setChecked(true) | ||||||
| end | end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 BeniS
						BeniS