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