[11401] | 1 | --[[local P = createMenuSheet("Dialogue Window") |
---|
| 2 | |
---|
| 3 | function P.onLoad() |
---|
| 4 | P.createWindow() |
---|
| 5 | P.showing = true |
---|
| 6 | end |
---|
| 7 | function function_name( ... ) |
---|
| 8 | -- body |
---|
| 9 | end |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | function P.createWindow() |
---|
| 15 | |
---|
| 16 | local question = orxonox.DialogueManager:getInstance():getquestion() |
---|
| 17 | local default = (winMgr:createWindow("DefaultWindow")) |
---|
| 18 | default:setText(question) |
---|
| 19 | default:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
| 20 | default:setProperty("UnifiedAreaRect", "{{0,0},{0,0},{1,0},{1,0}}") |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | end |
---|
| 27 | local numOptions = DialogueManager:getnumOptions() |
---|
| 28 | local counter = 1 |
---|
| 29 | local offset = 0 |
---|
| 30 | --create and name buttons while there are still options |
---|
| 31 | while counter <= numOptions do |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | end]] |
---|
| 35 | -- Dialogue.lua |
---|
| 36 | |
---|
| 37 | local P = createMenuSheet("PickupInventory") |
---|
| 38 | |
---|
| 39 | P.wrapper = nil |
---|
| 40 | P.detailsWindows = {} |
---|
| 41 | P.detailPickups = {} |
---|
| 42 | P.pickupsList = {} |
---|
| 43 | |
---|
| 44 | P.showing = false |
---|
| 45 | |
---|
| 46 | -- Design parameters |
---|
| 47 | P.imageHeight = 50 |
---|
| 48 | P.detailImageSize = 100 |
---|
| 49 | P.textHeight = 30 |
---|
| 50 | P.buttonWidth = 85 |
---|
| 51 | |
---|
| 52 | function P.onLoad() |
---|
| 53 | orxout("loading") |
---|
| 54 | P.wrapper = nil |
---|
| 55 | P.detailsWindows = {} |
---|
| 56 | P.detailPickups = {} |
---|
| 57 | P.pickupsList = {} |
---|
| 58 | end |
---|
| 59 | |
---|
| 60 | function P.onShow() |
---|
| 61 | orxout("showing") |
---|
| 62 | P.createInventory() |
---|
| 63 | P.showing = true |
---|
| 64 | end |
---|
| 65 | |
---|
| 66 | function P.onHide() |
---|
| 67 | P.showing = false |
---|
| 68 | P.cleanup(true) |
---|
| 69 | end |
---|
| 70 | |
---|
| 71 | function P.update() |
---|
| 72 | if P.showing == false then |
---|
| 73 | return |
---|
| 74 | end |
---|
| 75 | |
---|
| 76 | -- Update opened detail windows. |
---|
| 77 | for k,v in pairs(P.detailsWindows) do |
---|
| 78 | if v ~= nil then |
---|
| 79 | local pickup = P.detailPickups[k] |
---|
| 80 | if pickup ~= nil and pickup ~= 0 then |
---|
| 81 | local useButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/UseButton") |
---|
| 82 | local dropButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/DropButton") |
---|
| 83 | if orxonox.PickupManager:getInstance():isValidPickup(pickup.pickup) == false then |
---|
| 84 | useButton:setEnabled(false) |
---|
| 85 | dropButton:setEnabled(false) |
---|
| 86 | P.detailPickups[k] = nil |
---|
| 87 | else |
---|
| 88 | useButton:setEnabled(true) |
---|
| 89 | if pickup.inUse == true then |
---|
| 90 | useButton:setText("unuse") |
---|
| 91 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked") |
---|
| 92 | if pickup.usable == false then |
---|
| 93 | useButton:setEnabled(false) |
---|
| 94 | end |
---|
| 95 | else |
---|
| 96 | useButton:setText("use") |
---|
| 97 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked") |
---|
| 98 | if pickup.unusable == false then |
---|
| 99 | useButton:setEnabled(false) |
---|
| 100 | end |
---|
| 101 | end |
---|
| 102 | |
---|
| 103 | if pickup.pickedUp == false then |
---|
| 104 | useButton:setEnabled(false) |
---|
| 105 | dropButton:setEnabled(false) |
---|
| 106 | P.detailPickups[k] = nil |
---|
| 107 | end |
---|
| 108 | end |
---|
| 109 | end |
---|
| 110 | end |
---|
| 111 | end |
---|
| 112 | |
---|
| 113 | -- Update main inventory. |
---|
| 114 | P.cleanup(false) |
---|
| 115 | P.createInventory() |
---|
| 116 | -- TODO: Recover scrolling position |
---|
| 117 | |
---|
| 118 | end |
---|
| 119 | |
---|
| 120 | function P.createInventory() |
---|
| 121 | local pickupManager = orxonox.PickupManager:getInstance() |
---|
| 122 | |
---|
| 123 | local root = winMgr:getWindow("orxonox/PickupInventory/Inventory") |
---|
| 124 | P.wrapper = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/PickupInventory/Inventory/Wrapper") |
---|
| 125 | P.wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0))) |
---|
| 126 | root:addChildWindow(P.wrapper) |
---|
| 127 | |
---|
| 128 | P.pickupsList = {} |
---|
| 129 | |
---|
| 130 | local numPickups = pickupManager:getNumPickups() |
---|
| 131 | local counter = 1 |
---|
| 132 | local offset = 0 |
---|
| 133 | while counter <= numPickups do |
---|
| 134 | local pickup = pickupManager:popPickup() |
---|
| 135 | table.insert(P.pickupsList, pickup) |
---|
| 136 | local window = P.createPickupEntry(counter, pickup) |
---|
| 137 | window:setYPosition(CEGUI.UDim(0,offset)) |
---|
| 138 | offset = offset + window:getHeight():asAbsolute(1) |
---|
| 139 | P.wrapper:addChildWindow(window) |
---|
| 140 | counter = counter + 1 |
---|
| 141 | end |
---|
| 142 | |
---|
| 143 | end |
---|
| 144 | |
---|
| 145 | function P.createPickupEntry(index, pickup) |
---|
| 146 | local representation = orxonox.PickupManager:getInstance():getRepresentation(pickup.representationName) |
---|
| 147 | |
---|
| 148 | local name = "orxonox/PickupInventory/Box/Pickup" .. index |
---|
| 149 | |
---|
| 150 | local item = winMgr:createWindow("MenuWidgets/StaticText", name) |
---|
| 151 | item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, P.imageHeight))) |
---|
| 152 | item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
| 153 | |
---|
| 154 | local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image") |
---|
| 155 | image:setProperty("Image", "set:PickupInventory image:" .. representation:getInventoryRepresentation()) |
---|
| 156 | image:setProperty("BackgroundEnabled", "set:False") |
---|
| 157 | image:setProperty("FrameEnabled", "set:True") |
---|
| 158 | image:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.imageHeight), CEGUI.UDim(0, P.imageHeight))) |
---|
| 159 | item:addChildWindow(image) |
---|
| 160 | |
---|
| 161 | local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title") |
---|
| 162 | title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.imageHeight+5), CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2))) |
---|
| 163 | title:setSize(CEGUI.UVector2(CEGUI.UDim(0.3, 0), CEGUI.UDim(0, P.textHeight))) |
---|
| 164 | title:setText(representation:getPickupName()) |
---|
| 165 | title:setProperty("FrameEnabled", "set:False") |
---|
| 166 | item:addChildWindow(title) |
---|
| 167 | |
---|
| 168 | local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton") |
---|
| 169 | useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+10),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2))) |
---|
| 170 | useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight))) |
---|
| 171 | if pickup.inUse == false then |
---|
| 172 | useButton:setText("use") |
---|
| 173 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked") |
---|
| 174 | if pickup.usable == false then |
---|
| 175 | useButton:setEnabled(false) |
---|
| 176 | end |
---|
| 177 | else |
---|
| 178 | useButton:setText("unuse") |
---|
| 179 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked") |
---|
| 180 | if pickup.unusable == false then |
---|
| 181 | useButton:setEnabled(false) |
---|
| 182 | end |
---|
| 183 | end |
---|
| 184 | item:addChildWindow(useButton) |
---|
| 185 | |
---|
| 186 | local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton") |
---|
| 187 | dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+15+P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2))) |
---|
| 188 | dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight))) |
---|
| 189 | dropButton:setText("drop") |
---|
| 190 | orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked") |
---|
| 191 | item:addChildWindow(dropButton) |
---|
| 192 | |
---|
| 193 | local detailsButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DetailsButton") |
---|
| 194 | detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+20+2*P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2))) |
---|
| 195 | detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight))) |
---|
| 196 | detailsButton:setText("details") |
---|
| 197 | orxonox.GUIManager:subscribeEventHelper(detailsButton, "Clicked", P.name .. ".InventoryDetailsButton_clicked") |
---|
| 198 | item:addChildWindow(detailsButton) |
---|
| 199 | |
---|
| 200 | return item |
---|
| 201 | end |
---|
| 202 | |
---|
| 203 | function P.cleanup(destroyDetails) |
---|
| 204 | if P.wrapper ~= nil then |
---|
| 205 | winMgr:destroyWindow(P.wrapper) |
---|
| 206 | end |
---|
| 207 | |
---|
| 208 | --Destroy details windows. |
---|
| 209 | if destroyDetails == false then |
---|
| 210 | return |
---|
| 211 | end |
---|
| 212 | for k,v in pairs(P.detailsWindows) do |
---|
| 213 | if v ~= nil then |
---|
| 214 | P.destroyDetailWindow(k) |
---|
| 215 | end |
---|
| 216 | end |
---|
| 217 | end |
---|
| 218 | |
---|
| 219 | function P.windowToPickupHelper(e) |
---|
| 220 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 221 | local name = we.window:getName() |
---|
| 222 | |
---|
| 223 | local match = string.gmatch(name, "%d+") |
---|
| 224 | local pickupIndex = tonumber(match()) |
---|
| 225 | |
---|
| 226 | return pickupIndex |
---|
| 227 | end |
---|
| 228 | |
---|
| 229 | function P.createDetailsWindow(pickupIndex) |
---|
| 230 | local pickup = P.pickupsList[pickupIndex] |
---|
| 231 | local representation = orxonox.PickupManager:getInstance():getRepresentation(pickup.representationName) |
---|
| 232 | |
---|
| 233 | local index = P.getNewDetailNumber() |
---|
| 234 | local name = "orxonox/PickupInventory/Details" .. index |
---|
| 235 | |
---|
| 236 | local window = winMgr:createWindow("MenuWidgets/FrameWindow", name) |
---|
| 237 | window:setSize(CEGUI.UVector2(CEGUI.UDim(0.5,0),CEGUI.UDim(0.4,0))) |
---|
| 238 | orxonox.GUIManager:subscribeEventHelper(window, "CloseClicked", P.name .. ".closeDetailWindow") |
---|
| 239 | |
---|
| 240 | local root = winMgr:getWindow("orxonox/PickupInventory/Background") |
---|
| 241 | root:addChildWindow(window) |
---|
| 242 | |
---|
| 243 | local wrapper = winMgr:createWindow("DefaultWindow", name .. "/Wrapper") |
---|
| 244 | wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1, -20),CEGUI.UDim(1, -50))) |
---|
| 245 | wrapper:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10),CEGUI.UDim(0, 40))) |
---|
| 246 | window:addChildWindow(wrapper) |
---|
| 247 | |
---|
| 248 | local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title") |
---|
| 249 | title:setText(representation:getPickupName()) |
---|
| 250 | title:setHeight(CEGUI.UDim(0, P.textHeight)) |
---|
| 251 | title:setProperty("FrameEnabled", "set:False") |
---|
| 252 | title:setProperty("BackgroundEnabled", "set:False") |
---|
| 253 | wrapper:addChildWindow(title) |
---|
| 254 | |
---|
| 255 | local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image") |
---|
| 256 | image:setProperty("Image", "set:PickupInventory image:" .. representation:getInventoryRepresentation()) |
---|
| 257 | image:setProperty("BackgroundEnabled", "set:False") |
---|
| 258 | image:setProperty("FrameEnabled", "set:True") |
---|
| 259 | image:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize), CEGUI.UDim(0, P.detailImageSize))) |
---|
| 260 | image:setYPosition(CEGUI.UDim(0, P.textHeight + 5)) |
---|
| 261 | wrapper:addChildWindow(image) |
---|
| 262 | |
---|
| 263 | local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Description") |
---|
| 264 | box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -1*(P.detailImageSize + 10)),CEGUI.UDim(1, -(P.textHeight + 5 + P.textHeight + 20)))) |
---|
| 265 | box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize + 10),CEGUI.UDim(0, P.textHeight + 5))) |
---|
| 266 | local description = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Description/Text") |
---|
| 267 | description:setText(representation:getPickupDescription()) |
---|
| 268 | description:setProperty("HorzFormatting", "WordWrapLeftAligned") |
---|
| 269 | description:setProperty("VertFormatting", "TopAligned") |
---|
| 270 | box:addChildWindow(description) |
---|
| 271 | wrapper:addChildWindow(box) |
---|
| 272 | |
---|
| 273 | local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton") |
---|
| 274 | useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize+10),CEGUI.UDim(1, -40))) |
---|
| 275 | useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight))) |
---|
| 276 | if pickup.inUse == false then |
---|
| 277 | useButton:setText("use") |
---|
| 278 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked") |
---|
| 279 | if pickup.usable == false then |
---|
| 280 | useButton:setEnabled(false) |
---|
| 281 | end |
---|
| 282 | else |
---|
| 283 | useButton:setText("unuse") |
---|
| 284 | orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked") |
---|
| 285 | if pickup.unusable == false then |
---|
| 286 | useButton:setEnabled(false) |
---|
| 287 | end |
---|
| 288 | end |
---|
| 289 | wrapper:addChildWindow(useButton) |
---|
| 290 | |
---|
| 291 | local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton") |
---|
| 292 | dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize+10+P.buttonWidth+10),CEGUI.UDim(1, -40))) |
---|
| 293 | dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight))) |
---|
| 294 | dropButton:setText("drop") |
---|
| 295 | orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropDetailButton_clicked") |
---|
| 296 | wrapper:addChildWindow(dropButton) |
---|
| 297 | |
---|
| 298 | P.detailsWindows[index] = window |
---|
| 299 | P.detailPickups[index] = pickup |
---|
| 300 | |
---|
| 301 | end |
---|
| 302 | |
---|
| 303 | function P.getNewDetailNumber() |
---|
| 304 | local number = table.getn(P.detailsWindows) |
---|
| 305 | for k,v in pairs(P.detailsWindows) do |
---|
| 306 | if v == nil then |
---|
| 307 | number = k-1 |
---|
| 308 | end |
---|
| 309 | end |
---|
| 310 | return number+1 |
---|
| 311 | end |
---|
| 312 | |
---|
| 313 | function P.InventoryUseButton_clicked(e) |
---|
| 314 | local pickupIndex = P.windowToPickupHelper(e) |
---|
| 315 | local pickup = P.pickupsList[pickupIndex] |
---|
| 316 | orxonox.PickupManager:getInstance():usePickup(pickup.pickup, true) |
---|
| 317 | end |
---|
| 318 | |
---|
| 319 | function P.InventoryUnuseButton_clicked(e) |
---|
| 320 | local pickupIndex = P.windowToPickupHelper(e) |
---|
| 321 | local pickup = P.pickupsList[pickupIndex] |
---|
| 322 | orxonox.PickupManager:getInstance():usePickup(pickup.pickup, false) |
---|
| 323 | end |
---|
| 324 | |
---|
| 325 | function P.InventoryDropButton_clicked(e) |
---|
| 326 | local pickupIndex = P.windowToPickupHelper(e) |
---|
| 327 | local pickup = P.pickupsList[pickupIndex] |
---|
| 328 | orxonox.PickupManager:getInstance():dropPickup(pickup.pickup) |
---|
| 329 | end |
---|
| 330 | |
---|
| 331 | function P.InventoryDetailsButton_clicked(e) |
---|
| 332 | local pickupIndex = P.windowToPickupHelper(e) |
---|
| 333 | P.createDetailsWindow(pickupIndex) |
---|
| 334 | end |
---|
| 335 | |
---|
| 336 | function P.InventoryUseDetailButton_clicked(e) |
---|
| 337 | local pickupIndex = P.windowToPickupHelper(e) |
---|
| 338 | local pickup = P.detailPickups[pickupIndex] |
---|
| 339 | orxonox.PickupManager:getInstance():usePickup(pickup.pickup, true) |
---|
| 340 | end |
---|
| 341 | |
---|
| 342 | function P.InventoryUnuseDetailButton_clicked(e) |
---|
| 343 | local pickupIndex = P.windowToPickupHelper(e) |
---|
| 344 | local pickup = P.detailPickups[pickupIndex] |
---|
| 345 | orxonox.PickupManager:getInstance():usePickup(pickup.pickup, false) |
---|
| 346 | end |
---|
| 347 | |
---|
| 348 | function P.InventoryDropDetailButton_clicked(e) |
---|
| 349 | local pickupIndex = P.windowToPickupHelper(e) |
---|
| 350 | local pickup = P.detailPickups[pickupIndex] |
---|
| 351 | orxonox.PickupManager:getInstance():dropPickup(pickup.pickup) |
---|
| 352 | end |
---|
| 353 | |
---|
| 354 | function P.closeDetailWindow(e) |
---|
| 355 | --Get some numbers from the window |
---|
| 356 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 357 | local name = we.window:getName() |
---|
| 358 | local match = string.gmatch(name, "%d+") |
---|
| 359 | local detailNr = tonumber(match()) |
---|
| 360 | |
---|
| 361 | P.destroyDetailWindow(detailNr) |
---|
| 362 | end |
---|
| 363 | |
---|
| 364 | function P.destroyDetailWindow(detailNr) |
---|
| 365 | local window = P.detailsWindows[detailNr] |
---|
| 366 | winMgr:destroyWindow(window) |
---|
| 367 | P.detailsWindows[detailNr] = nil |
---|
| 368 | P.detailPickups[detailNr] = nil |
---|
| 369 | end |
---|
| 370 | |
---|
| 371 | function P.InventoryBackButton_clicked(e) |
---|
| 372 | orxonox.CommandExecutor:execute("OrxonoxOverlay toggleVisibility PickupInventory") |
---|
| 373 | end |
---|
| 374 | |
---|
| 375 | return P |
---|