[11401] | 1 | |
---|
| 2 | -- Dialogue.lua |
---|
| 3 | |
---|
[11406] | 4 | local P = createMenuSheet("Dialogue") |
---|
[11401] | 5 | |
---|
| 6 | P.wrapper = nil |
---|
| 7 | P.detailsWindows = {} |
---|
| 8 | P.detailPickups = {} |
---|
| 9 | P.pickupsList = {} |
---|
| 10 | |
---|
| 11 | P.showing = false |
---|
| 12 | |
---|
| 13 | -- Design parameters |
---|
| 14 | P.imageHeight = 50 |
---|
| 15 | P.detailImageSize = 100 |
---|
| 16 | P.textHeight = 30 |
---|
| 17 | P.buttonWidth = 85 |
---|
| 18 | |
---|
| 19 | function P.onLoad() |
---|
| 20 | P.wrapper = nil |
---|
| 21 | P.detailsWindows = {} |
---|
| 22 | P.detailPickups = {} |
---|
| 23 | P.pickupsList = {} |
---|
[11612] | 24 | |
---|
[11401] | 25 | end |
---|
| 26 | |
---|
| 27 | function P.onShow() |
---|
[11433] | 28 | orxonox.CommandExecutor:execute("setTimeFactor 0") |
---|
[11401] | 29 | P.createInventory() |
---|
| 30 | P.showing = true |
---|
| 31 | end |
---|
| 32 | |
---|
[11612] | 33 | |
---|
[11401] | 34 | function P.onHide() |
---|
[11433] | 35 | orxonox.CommandExecutor:execute("setTimeFactor 1") |
---|
[11401] | 36 | P.showing = false |
---|
| 37 | P.cleanup(true) |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | function P.update() |
---|
[11422] | 41 | P.updateInventory() |
---|
[11401] | 42 | if P.showing == false then |
---|
| 43 | return |
---|
| 44 | end |
---|
| 45 | |
---|
| 46 | -- Update opened detail windows. |
---|
[11406] | 47 | |
---|
[11401] | 48 | |
---|
| 49 | -- Update main inventory. |
---|
| 50 | P.cleanup(false) |
---|
| 51 | P.createInventory() |
---|
| 52 | -- TODO: Recover scrolling position |
---|
| 53 | |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | function P.createInventory() |
---|
[11433] | 57 | |
---|
[11406] | 58 | local pickupManager = orxonox.DialogueManager:getInstance() |
---|
[11401] | 59 | |
---|
[11422] | 60 | root = winMgr:getWindow("orxonox/Dialogue/Inventory") |
---|
[11406] | 61 | local question = orxonox.DialogueManager:getInstance():getquestion() |
---|
| 62 | root:setText(question) |
---|
| 63 | P.wrapper = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/Dialogue/Inventory/Wrapper") |
---|
[11401] | 64 | P.wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0))) |
---|
| 65 | root:addChildWindow(P.wrapper) |
---|
| 66 | |
---|
[11413] | 67 | |
---|
[11422] | 68 | detailsButton = winMgr:createWindow("MenuWidgets/Button", "/DetailsButton") |
---|
[11413] | 69 | local a1 = orxonox.DialogueManager:getInstance():getanswers1() |
---|
[11435] | 70 | detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.1, 0),CEGUI.UDim(0.25, (P.imageHeight-P.textHeight)/2))) |
---|
| 71 | detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0.8, 0), CEGUI.UDim(0, P.textHeight))) |
---|
[11413] | 72 | detailsButton:setText(a1) |
---|
| 73 | orxonox.GUIManager:subscribeEventHelper(detailsButton, "Clicked", P.name ..".a1Button_clicked") |
---|
[11415] | 74 | P.wrapper:addChildWindow(detailsButton) |
---|
[11401] | 75 | |
---|
[11422] | 76 | a2Button = winMgr:createWindow("MenuWidgets/Button", "/a2Button") |
---|
[11413] | 77 | local a2 = orxonox.DialogueManager:getInstance():getanswers2() |
---|
[11435] | 78 | a2Button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.1, 0),CEGUI.UDim(0.4, (P.imageHeight-P.textHeight)/2))) |
---|
| 79 | a2Button:setSize(CEGUI.UVector2(CEGUI.UDim(0.8, 0), CEGUI.UDim(0, P.textHeight))) |
---|
[11413] | 80 | a2Button:setText(a2) |
---|
| 81 | orxonox.GUIManager:subscribeEventHelper(a2Button, "Clicked", P.name ..".a2Button_clicked") |
---|
[11415] | 82 | P.wrapper:addChildWindow(a2Button) |
---|
[11413] | 83 | |
---|
| 84 | |
---|
[11401] | 85 | end |
---|
| 86 | |
---|
[11422] | 87 | function P.updateInventory() |
---|
| 88 | local questionn = orxonox.DialogueManager:getInstance():getquestion() |
---|
| 89 | root:setText(questionn) |
---|
| 90 | local a1n = orxonox.DialogueManager:getInstance():getanswers1() |
---|
| 91 | detailsButton:setText(a1n) |
---|
| 92 | local a2n = orxonox.DialogueManager:getInstance():getanswers2() |
---|
| 93 | a2Button:setText(a2n) |
---|
[11401] | 94 | |
---|
[11422] | 95 | end |
---|
[11401] | 96 | |
---|
[11422] | 97 | |
---|
[11401] | 98 | function P.cleanup(destroyDetails) |
---|
[11432] | 99 | |
---|
[11401] | 100 | if P.wrapper ~= nil then |
---|
| 101 | winMgr:destroyWindow(P.wrapper) |
---|
| 102 | end |
---|
| 103 | |
---|
| 104 | --Destroy details windows. |
---|
| 105 | if destroyDetails == false then |
---|
| 106 | return |
---|
| 107 | end |
---|
| 108 | for k,v in pairs(P.detailsWindows) do |
---|
| 109 | if v ~= nil then |
---|
| 110 | P.destroyDetailWindow(k) |
---|
| 111 | end |
---|
| 112 | end |
---|
[11435] | 113 | |
---|
[11401] | 114 | end |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | |
---|
[11413] | 118 | function P.a1Button_clicked(e) |
---|
[11428] | 119 | local ending = orxonox.DialogueManager:getInstance():theEnd() |
---|
| 120 | |
---|
| 121 | if ending then |
---|
| 122 | orxonox.CommandExecutor:execute("OrxonoxOverlay toggleVisibility Dialogue") |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | else |
---|
| 126 | orxonox.DialogueManager:getInstance():a1clicked() |
---|
| 127 | P.update() |
---|
| 128 | end |
---|
[11401] | 129 | end |
---|
| 130 | |
---|
[11413] | 131 | function P.a2Button_clicked(e) |
---|
[11428] | 132 | local ending = orxonox.DialogueManager:getInstance():theEnd() |
---|
| 133 | |
---|
| 134 | if ending then |
---|
| 135 | orxonox.CommandExecutor:execute("OrxonoxOverlay toggleVisibility Dialogue") |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | else |
---|
| 139 | orxonox.DialogueManager:getInstance():a2clicked() |
---|
| 140 | P.update() |
---|
| 141 | end |
---|
| 142 | |
---|
[11413] | 143 | end |
---|
| 144 | |
---|
[11401] | 145 | return P |
---|