[11612] | 1 | -- Dialogue.lua |
---|
[11579] | 2 | |
---|
| 3 | local P = createMenuSheet("Dialog") |
---|
| 4 | |
---|
| 5 | P.wrapper = nil |
---|
[11612] | 6 | P.detailsWindows = {} |
---|
[11579] | 7 | P.showing = false |
---|
[11644] | 8 | P.choice = 0 |
---|
[11579] | 9 | |
---|
[11644] | 10 | function P.onLoad() --wird ausgefuert wenn Fenster geladen |
---|
[11579] | 11 | P.wrapper = nil |
---|
| 12 | end |
---|
| 13 | |
---|
[11644] | 14 | function P.onShow() --wird ausgefuert wenn Dialogfenster gezeigt |
---|
[11612] | 15 | |
---|
[11579] | 16 | orxonox.CommandExecutor:execute("setTimeFactor 0") |
---|
| 17 | P.createDialog() |
---|
| 18 | P.showing = true |
---|
| 19 | |
---|
| 20 | end |
---|
| 21 | |
---|
[11644] | 22 | function P.onHide() --aufgefuert wenn Fenster geschlossen wird |
---|
[11579] | 23 | orxonox.CommandExecutor:execute("setTimeFactor 1") |
---|
| 24 | P.showing = false |
---|
| 25 | P.cleanup(true) |
---|
| 26 | end |
---|
| 27 | |
---|
[11644] | 28 | function P.createDialog() -- initiallisiert das Dialog Fenster, setzt Namen sowie die erste Frage mit enstprechenden Antworten |
---|
[11579] | 29 | |
---|
[11612] | 30 | local manager = orxonox.DialogManager:getInstance() |
---|
[11579] | 31 | |
---|
| 32 | |
---|
[11642] | 33 | local personfield = winMgr:getWindow("orxonox/Dialog/Person") |
---|
| 34 | local person = manager:getPerson() |
---|
| 35 | personfield:setText(person) |
---|
| 36 | |
---|
| 37 | local questionfiled = winMgr:getWindow("orxonox/Dialog/Question") |
---|
| 38 | local question = manager:getQuestion() |
---|
| 39 | questionfiled:setText(question) |
---|
| 40 | |
---|
[11644] | 41 | local listboxwindow = winMgr:getWindow("orxonox/AnsListbox") |
---|
| 42 | CEGUI.toListbox(listboxwindow):resetList() |
---|
[11642] | 43 | |
---|
[11644] | 44 | local ansList = {} |
---|
[11642] | 45 | local anssize = manager:getSize() |
---|
[11612] | 46 | |
---|
[11642] | 47 | for index = 0, anssize -1, 1 do |
---|
[11644] | 48 | table.insert(ansList, manager:getAnswer(index)) |
---|
[11642] | 49 | end |
---|
| 50 | |
---|
[11644] | 51 | for k,v in pairs(ansList) do |
---|
[11642] | 52 | item = CEGUI.createListboxTextItem(v) |
---|
| 53 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 54 | CEGUI.toListbox(listboxwindow):addItem(item) |
---|
| 55 | end |
---|
[11579] | 56 | end |
---|
| 57 | |
---|
[11644] | 58 | function P.updateDialog() --updated den Dialog entsprechend der Ausgeaehlten option der letzten Frage, setzt Frage und Antwortmoeglichkeiten neu |
---|
[11642] | 59 | local manager = orxonox.DialogManager:getInstance() |
---|
[11644] | 60 | manager:update(P.choice) |
---|
[11642] | 61 | |
---|
| 62 | local questionfiled = winMgr:getWindow("orxonox/Dialog/Question") |
---|
| 63 | local question = manager:getQuestion() |
---|
| 64 | questionfiled:setText(question) |
---|
[11644] | 65 | |
---|
| 66 | local listboxwindow = winMgr:getWindow("orxonox/AnsListbox") |
---|
| 67 | listboxwindow:resetList() |
---|
| 68 | |
---|
| 69 | local ansList = {} |
---|
| 70 | local anssize = manager:getSize() |
---|
| 71 | |
---|
| 72 | for index = 0, anssize -1, 1 do |
---|
| 73 | table.insert(ansList, manager:getAnswer(index)) |
---|
| 74 | end |
---|
| 75 | |
---|
| 76 | for k,v in pairs(ansList) do |
---|
| 77 | item = CEGUI.createListboxTextItem(v) |
---|
| 78 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 79 | CEGUI.toListbox(listboxwindow):addItem(item) |
---|
| 80 | end |
---|
| 81 | |
---|
| 82 | P.choice = 0 |
---|
[11579] | 83 | end |
---|
| 84 | |
---|
[11644] | 85 | function P.answer_changed(e) --wird aufgerufen falls Auswahl geaendert wird und setzt enstprechenden Indexparameter |
---|
| 86 | listboxwindow = winMgr:getWindow("orxonox/AnsListbox") |
---|
| 87 | selection = listboxwindow:getFirstSelectedItem() |
---|
| 88 | if selection ~= nil then |
---|
| 89 | P.choice = listboxwindow:getItemIndex(selection) |
---|
| 90 | else |
---|
| 91 | P.choice = 0 |
---|
| 92 | end |
---|
[11642] | 93 | end |
---|
[11579] | 94 | |
---|
[11642] | 95 | |
---|
[11644] | 96 | function P.cleanup(destroyDetails) --loest Fenster wieder auf (!nicht selbst geschrieben, nur uebernommen, eventuell nicht noetiger code) |
---|
| 97 | |
---|
[11579] | 98 | if P.wrapper ~= nil then |
---|
| 99 | winMgr:destroyWindow(P.wrapper) |
---|
| 100 | end |
---|
| 101 | |
---|
| 102 | --Destroy details windows. |
---|
| 103 | if destroyDetails == false then |
---|
| 104 | return |
---|
| 105 | end |
---|
| 106 | for k,v in pairs(P.detailsWindows) do |
---|
| 107 | if v ~= nil then |
---|
| 108 | P.destroyDetailWindow(k) |
---|
| 109 | end |
---|
| 110 | end |
---|
| 111 | |
---|
| 112 | end |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | |
---|
[11644] | 116 | function P.Button_clicked(e) --wird bei click auf say knopf ausgeloest, entscheidet ob Dialog schliesst oder updated und fuert entsprechen aus |
---|
| 117 | local ending = orxonox.DialogManager:getInstance():endtest(P.choice) |
---|
[11579] | 118 | |
---|
[11642] | 119 | if ending then |
---|
[11579] | 120 | orxonox.CommandExecutor:execute("OrxonoxOverlay toggleVisibility Dialog") |
---|
[11642] | 121 | else |
---|
| 122 | P.updateDialog(index) |
---|
| 123 | end |
---|
[11579] | 124 | end |
---|
| 125 | |
---|
| 126 | return P |
---|