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