| [5661] | 1 | -- PickupInventory.lua | 
|---|
| [5559] | 2 |  | 
|---|
| [6746] | 3 | local P = createMenuSheet("PickupInventory") | 
|---|
| [6711] | 4 |  | 
|---|
|  | 5 | P.carrierList = {} | 
|---|
|  | 6 | P.wrapper = nil | 
|---|
|  | 7 | P.detailsWindows = {} | 
|---|
| [5587] | 8 |  | 
|---|
| [6746] | 9 | function P.onLoad() | 
|---|
| [6711] | 10 | carrierList = {} | 
|---|
|  | 11 | end | 
|---|
| [6417] | 12 |  | 
|---|
| [6747] | 13 | function P.onShow() | 
|---|
| [6711] | 14 | P.createInventory() | 
|---|
| [5559] | 15 | end | 
|---|
|  | 16 |  | 
|---|
| [6747] | 17 | function P.onHide() | 
|---|
| [6711] | 18 | P.cleanup() | 
|---|
| [5559] | 19 | end | 
|---|
|  | 20 |  | 
|---|
| [6711] | 21 | function P.update() | 
|---|
|  | 22 | P.cleanup() | 
|---|
|  | 23 |  | 
|---|
|  | 24 | P.createInventory() | 
|---|
| [5559] | 25 | end | 
|---|
|  | 26 |  | 
|---|
| [6711] | 27 | function P.createInventory() | 
|---|
|  | 28 | local pickupManager = orxonox.PickupManager:getInstance() | 
|---|
|  | 29 | local carrier = pickupManager:getPawn() | 
|---|
|  | 30 |  | 
|---|
|  | 31 | local root = winMgr:getWindow("orxonox/PickupInventory/Inventory") | 
|---|
| [6750] | 32 | P.wrapper = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/PickupInventory/Inventory/Wrapper") | 
|---|
| [6711] | 33 | P.wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0))) | 
|---|
|  | 34 | root:addChildWindow(P.wrapper) | 
|---|
|  | 35 |  | 
|---|
|  | 36 | P.carrierList = {} | 
|---|
|  | 37 |  | 
|---|
|  | 38 | --Design parameters: | 
|---|
|  | 39 | local space = 15 | 
|---|
|  | 40 |  | 
|---|
|  | 41 | P.getCarrierList(carrier) | 
|---|
|  | 42 | local offset = 0 | 
|---|
|  | 43 | for k,v in pairs(P.carrierList) do | 
|---|
|  | 44 | local window = P.createCarrierBox(v,k) | 
|---|
|  | 45 | window:setYPosition(CEGUI.UDim(0,offset)) | 
|---|
|  | 46 | offset = offset + window:getHeight():asAbsolute(1) + space | 
|---|
|  | 47 | P.wrapper:addChildWindow(window) | 
|---|
|  | 48 | end | 
|---|
|  | 49 | end | 
|---|
| [6417] | 50 |  | 
|---|
| [6711] | 51 | function P.getCarrierList(carrier) | 
|---|
| [6417] | 52 |  | 
|---|
| [6711] | 53 | -- TODO: Test for nil or 0? | 
|---|
|  | 54 | if carrier == nil then | 
|---|
|  | 55 | return | 
|---|
| [5587] | 56 | end | 
|---|
| [6711] | 57 |  | 
|---|
|  | 58 | table.insert(P.carrierList, carrier) | 
|---|
|  | 59 |  | 
|---|
|  | 60 | local numCarriers = orxonox.PickupManager:getInstance():getNumCarrierChildren(carrier) | 
|---|
|  | 61 | if numCarriers == 0 then | 
|---|
|  | 62 | return | 
|---|
|  | 63 | end | 
|---|
|  | 64 |  | 
|---|
|  | 65 | for i=0,numCarriers-1,1 do | 
|---|
|  | 66 | local child = orxonox.PickupManager:getInstance():getCarrierChild(i, carrier) | 
|---|
|  | 67 | if child ~= nil then | 
|---|
|  | 68 | P.getCarrierList(child) | 
|---|
|  | 69 | end | 
|---|
|  | 70 | end | 
|---|
|  | 71 | end | 
|---|
| [6417] | 72 |  | 
|---|
| [6711] | 73 | function P.createCarrierBox(carrier, index) | 
|---|
|  | 74 |  | 
|---|
|  | 75 | local name = "orxonox/PickupInventory/Carrier" .. index | 
|---|
| [6906] | 76 |  | 
|---|
| [6711] | 77 | --Design parameters: | 
|---|
|  | 78 | local imageHeight = 50 | 
|---|
|  | 79 | local textHeight = 30 | 
|---|
|  | 80 | local horizontalOffset = 20 | 
|---|
|  | 81 | local buttonWidth = 85 | 
|---|
|  | 82 |  | 
|---|
|  | 83 | local offset = 0 | 
|---|
|  | 84 |  | 
|---|
| [6750] | 85 | local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Box") | 
|---|
| [6711] | 86 | box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horizontalOffset), CEGUI.UDim(0, 0))) | 
|---|
|  | 87 | box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -horizontalOffset), CEGUI.UDim(1, 0))) | 
|---|
|  | 88 |  | 
|---|
|  | 89 | local numPickups = orxonox.PickupManager:getInstance():getNumPickups(carrier) | 
|---|
|  | 90 | for i=0,numPickups-1,1 do | 
|---|
|  | 91 | local pickup = orxonox.PickupManager:getInstance():getPickupRepresentation(i, carrier) | 
|---|
|  | 92 |  | 
|---|
| [6750] | 93 | local item = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Box/Pickup" .. i) | 
|---|
| [6711] | 94 | item:setSize(CEGUI.UVector2(CEGUI.UDim(1, -horizontalOffset), CEGUI.UDim(0, imageHeight))) | 
|---|
|  | 95 | item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horizontalOffset), CEGUI.UDim(0, offset))) | 
|---|
|  | 96 | box:addChildWindow(item) | 
|---|
|  | 97 | offset = offset + imageHeight+5 | 
|---|
|  | 98 |  | 
|---|
| [6750] | 99 | local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Box/Pickup" .. i .. "/Image") | 
|---|
| [6711] | 100 | image:setProperty("Image", "set:PickupInventory image:" .. pickup:getInventoryRepresentation()) | 
|---|
|  | 101 | image:setProperty("BackgroundEnabled", "set:False") | 
|---|
|  | 102 | image:setProperty("FrameEnabled", "set:True") | 
|---|
|  | 103 | image:setSize(CEGUI.UVector2(CEGUI.UDim(0, imageHeight), CEGUI.UDim(0, imageHeight))) | 
|---|
|  | 104 | item:addChildWindow(image) | 
|---|
|  | 105 |  | 
|---|
| [6750] | 106 | local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Box/Pickup" .. i .. "/Title") | 
|---|
| [6711] | 107 | title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageHeight+5), CEGUI.UDim(0, (imageHeight-textHeight)/2))) | 
|---|
|  | 108 | title:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(0, textHeight))) | 
|---|
|  | 109 | title:setText(pickup:getPickupName()) | 
|---|
|  | 110 | title:setProperty("FrameEnabled", "set:False") | 
|---|
|  | 111 | item:addChildWindow(title) | 
|---|
|  | 112 |  | 
|---|
| [6750] | 113 | local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/UseButton") | 
|---|
| [6711] | 114 | useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+10),CEGUI.UDim(0, (imageHeight-textHeight)/2))) | 
|---|
|  | 115 | useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight))) | 
|---|
|  | 116 | useButton:setText("use") | 
|---|
| [6746] | 117 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked") | 
|---|
| [6711] | 118 | item:addChildWindow(useButton) | 
|---|
|  | 119 |  | 
|---|
| [6750] | 120 | local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/DropButton") | 
|---|
| [6711] | 121 | dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+15+buttonWidth),CEGUI.UDim(0, (imageHeight-textHeight)/2))) | 
|---|
|  | 122 | dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight))) | 
|---|
|  | 123 | dropButton:setText("drop") | 
|---|
| [6746] | 124 | orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked") | 
|---|
| [6711] | 125 | item:addChildWindow(dropButton) | 
|---|
|  | 126 |  | 
|---|
| [6750] | 127 | local detailsButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/DetailsButton") | 
|---|
| [6711] | 128 | detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+20+2*buttonWidth),CEGUI.UDim(0, (imageHeight-textHeight)/2))) | 
|---|
|  | 129 | detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight))) | 
|---|
|  | 130 | detailsButton:setText("details") | 
|---|
| [6746] | 131 | orxonox.GUIManager:subscribeEventHelper(detailsButton, "Clicked", P.name .. ".InventoryDetailsButton_clicked") | 
|---|
| [6711] | 132 | item:addChildWindow(detailsButton) | 
|---|
|  | 133 | end | 
|---|
|  | 134 |  | 
|---|
|  | 135 | box:setHeight(CEGUI.UDim(0,offset)) | 
|---|
|  | 136 |  | 
|---|
|  | 137 | return box | 
|---|
|  | 138 | end | 
|---|
|  | 139 |  | 
|---|
|  | 140 | function P.cleanup() | 
|---|
|  | 141 | if P.wrapper ~= nil then | 
|---|
|  | 142 | winMgr:destroyWindow(P.wrapper) | 
|---|
|  | 143 | end | 
|---|
|  | 144 |  | 
|---|
|  | 145 | --Destroy details windows. | 
|---|
|  | 146 | for k,v in pairs(P.detailsWindows) do | 
|---|
|  | 147 | if v ~= nil then | 
|---|
|  | 148 | winMgr:destroyWindow(v) | 
|---|
| [5587] | 149 | end | 
|---|
|  | 150 | end | 
|---|
|  | 151 | end | 
|---|
|  | 152 |  | 
|---|
| [6711] | 153 | function P.windowToCarrierHelper(e) | 
|---|
|  | 154 | local we = CEGUI.toWindowEventArgs(e) | 
|---|
|  | 155 | local name = we.window:getName() | 
|---|
| [6417] | 156 |  | 
|---|
| [6711] | 157 | local match = string.gmatch(name, "%d+") | 
|---|
|  | 158 | local carrierNr = tonumber(match()) | 
|---|
|  | 159 | local pickupNr = tonumber(match()) | 
|---|
|  | 160 |  | 
|---|
|  | 161 | local arguments = {} | 
|---|
|  | 162 | arguments[1] = carrierNr | 
|---|
|  | 163 | arguments[2] = pickupNr | 
|---|
|  | 164 | return arguments | 
|---|
| [5587] | 165 | end | 
|---|
|  | 166 |  | 
|---|
| [6711] | 167 | function P.createDetailsWindow(pickupIndex, carrierIndex) | 
|---|
|  | 168 | local carrier = P.carrierList[carrierIndex] | 
|---|
|  | 169 | local pickup = orxonox.PickupManager:getInstance():getPickupRepresentation(pickupIndex, carrier) | 
|---|
|  | 170 |  | 
|---|
|  | 171 | local headerOffset = 35 | 
|---|
|  | 172 | --Design parameters | 
|---|
|  | 173 | local titleHeight = 30 | 
|---|
|  | 174 | local imageSize = 100 | 
|---|
|  | 175 | local buttonWidth = 85 | 
|---|
|  | 176 |  | 
|---|
|  | 177 | local name = "orxonox/PickupInventory/Carrier" .. carrierIndex .. "/Pickup" .. pickupIndex .. "/Details" .. P.getNewDetailNumber() | 
|---|
|  | 178 |  | 
|---|
| [6750] | 179 | local window = winMgr:createWindow("MenuWidgets/FrameWindow", name) | 
|---|
| [6711] | 180 | window:setSize(CEGUI.UVector2(CEGUI.UDim(0.5,0),CEGUI.UDim(0.4,0))) | 
|---|
| [6746] | 181 | orxonox.GUIManager:subscribeEventHelper(window, "CloseClicked", P.name .. ".closeDetailWindow") | 
|---|
| [6711] | 182 |  | 
|---|
|  | 183 | local root = winMgr:getWindow("orxonox/PickupInventory/Background") | 
|---|
|  | 184 | root:addChildWindow(window) | 
|---|
|  | 185 |  | 
|---|
|  | 186 | local wrapper = winMgr:createWindow("DefaultWindow", name .. "/Wrapper") | 
|---|
|  | 187 | wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1, -20),CEGUI.UDim(1, -50))) | 
|---|
|  | 188 | wrapper:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10),CEGUI.UDim(0, 40))) | 
|---|
|  | 189 | window:addChildWindow(wrapper) | 
|---|
|  | 190 |  | 
|---|
| [6750] | 191 | local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title") | 
|---|
| [6711] | 192 | title:setText(pickup:getPickupName()) | 
|---|
|  | 193 | title:setHeight(CEGUI.UDim(0, titleHeight)) | 
|---|
|  | 194 | title:setProperty("FrameEnabled", "set:False") | 
|---|
|  | 195 | title:setProperty("BackgroundEnabled", "set:False") | 
|---|
|  | 196 | wrapper:addChildWindow(title) | 
|---|
|  | 197 |  | 
|---|
| [6750] | 198 | local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image") | 
|---|
| [6711] | 199 | image:setProperty("Image", "set:PickupInventory image:" .. pickup:getInventoryRepresentation()) | 
|---|
|  | 200 | image:setProperty("BackgroundEnabled", "set:False") | 
|---|
|  | 201 | image:setProperty("FrameEnabled", "set:True") | 
|---|
|  | 202 | image:setSize(CEGUI.UVector2(CEGUI.UDim(0, imageSize), CEGUI.UDim(0, imageSize))) | 
|---|
|  | 203 | image:setYPosition(CEGUI.UDim(0, titleHeight + 5)) | 
|---|
|  | 204 | wrapper:addChildWindow(image) | 
|---|
|  | 205 |  | 
|---|
| [6750] | 206 | local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Description") | 
|---|
| [6711] | 207 | box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -1*(imageSize + 10)),CEGUI.UDim(1, -(titleHeight + 5 + titleHeight + 20)))) | 
|---|
|  | 208 | box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize + 10),CEGUI.UDim(0, titleHeight + 5))) | 
|---|
|  | 209 | local description = winMgr:createWindow("TaharezLook/StaticText", name .. "/Description/Text") | 
|---|
|  | 210 | description:setText(pickup:getPickupDescription()) | 
|---|
|  | 211 | description:setProperty("HorzFormatting", "WordWrapLeftAligned") | 
|---|
|  | 212 | description:setProperty("VertFormatting", "TopAligned") | 
|---|
|  | 213 | box:addChildWindow(description) | 
|---|
|  | 214 | wrapper:addChildWindow(box) | 
|---|
|  | 215 |  | 
|---|
| [6750] | 216 | local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton") | 
|---|
| [6711] | 217 | useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize+10),CEGUI.UDim(1, -40))) | 
|---|
|  | 218 | useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, titleHeight))) | 
|---|
|  | 219 | useButton:setText("use") | 
|---|
| [6746] | 220 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked") | 
|---|
| [6711] | 221 | wrapper:addChildWindow(useButton) | 
|---|
|  | 222 |  | 
|---|
| [6750] | 223 | local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton") | 
|---|
| [6711] | 224 | dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize+10+buttonWidth+10),CEGUI.UDim(1, -40))) | 
|---|
|  | 225 | dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, titleHeight))) | 
|---|
|  | 226 | dropButton:setText("drop") | 
|---|
| [6746] | 227 | orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked") | 
|---|
| [6711] | 228 | wrapper:addChildWindow(dropButton) | 
|---|
|  | 229 |  | 
|---|
|  | 230 | table.insert(P.detailsWindows, window) | 
|---|
|  | 231 |  | 
|---|
|  | 232 | end | 
|---|
|  | 233 |  | 
|---|
|  | 234 | function P.getNewDetailNumber() | 
|---|
|  | 235 | local number = table.getn(P.detailsWindows) | 
|---|
|  | 236 | for k,v in pairs(P.detailsWindows) do | 
|---|
|  | 237 | if v == nil then | 
|---|
|  | 238 | number = k-1 | 
|---|
|  | 239 | end | 
|---|
|  | 240 | end | 
|---|
|  | 241 | return number | 
|---|
|  | 242 | end | 
|---|
|  | 243 |  | 
|---|
|  | 244 | function P.InventoryUseButton_clicked(e) | 
|---|
|  | 245 | local arguments = P.windowToCarrierHelper(e) | 
|---|
|  | 246 | orxonox.PickupManager:getInstance():usePickup(arguments[2], P.carrierList[arguments[1]], true) | 
|---|
|  | 247 | end | 
|---|
|  | 248 |  | 
|---|
|  | 249 | function P.InventoryDropButton_clicked(e) | 
|---|
|  | 250 | local arguments = P.windowToCarrierHelper(e) | 
|---|
|  | 251 | orxonox.PickupManager:getInstance():dropPickup(arguments[2], P.carrierList[arguments[1]]) | 
|---|
|  | 252 | end | 
|---|
|  | 253 |  | 
|---|
|  | 254 | function P.InventoryDetailsButton_clicked(e) | 
|---|
|  | 255 | local arguments = P.windowToCarrierHelper(e) | 
|---|
|  | 256 | P.createDetailsWindow(arguments[2], arguments[1]) | 
|---|
|  | 257 | end | 
|---|
|  | 258 |  | 
|---|
|  | 259 | function P.closeDetailWindow(e) | 
|---|
|  | 260 | --Get some numbers from the window | 
|---|
|  | 261 | local we = CEGUI.toWindowEventArgs(e) | 
|---|
|  | 262 | local name = we.window:getName() | 
|---|
|  | 263 | local match = string.gmatch(name, "%d+") | 
|---|
|  | 264 | local carrierNr = tonumber(match()) | 
|---|
|  | 265 | local pickupNr = tonumber(match()) | 
|---|
|  | 266 | local detailNr = tonumber(match()) | 
|---|
|  | 267 |  | 
|---|
|  | 268 | local window = P.detailsWindows[detailNr+1] | 
|---|
|  | 269 | winMgr:destroyWindow(window) | 
|---|
|  | 270 | P.detailsWindows[detailNr+1] = nil | 
|---|
|  | 271 | end | 
|---|
|  | 272 |  | 
|---|
|  | 273 | function P.InventoryBackButton_clicked(e) | 
|---|
| [6750] | 274 | orxonox.CommandExecutor:execute("OrxonoxOverlay toggleVisibility PickupInventory") | 
|---|
| [6711] | 275 | end | 
|---|
|  | 276 |  | 
|---|
| [5661] | 277 | return P | 
|---|