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