[11235] | 1 | -- HighscoreMenu.lua |
---|
| 2 | |
---|
| 3 | local P = createMenuSheet("HighscoreMenu") |
---|
| 4 | |
---|
| 5 | P.scrollbarWidth = 13 |
---|
| 6 | P.nameList = {} |
---|
| 7 | P.scoreList = {} |
---|
| 8 | P.linesList = {} |
---|
| 9 | |
---|
| 10 | P.sampleWindow = nil |
---|
| 11 | |
---|
| 12 | P.lineHeight = 0 |
---|
| 13 | P.playerWidth = 0 |
---|
| 14 | P.editboxWidth = 0 |
---|
| 15 | P.resetWidth = 0 |
---|
| 16 | P.spaceWidth = 0 |
---|
| 17 | |
---|
| 18 | function P.onLoad() |
---|
| 19 | P.nameList = {} |
---|
| 20 | table.insert(P.nameList, "firsttestPlayer") |
---|
| 21 | table.insert(P.nameList, "secondtestPlayer") |
---|
| 22 | P.scoreList = {} |
---|
| 23 | table.insert(P.scoreList, 120) |
---|
| 24 | table.insert(P.scoreList, 20) |
---|
| 25 | |
---|
| 26 | P.linesList = {} |
---|
| 27 | |
---|
| 28 | --Calculate design parameters: |
---|
| 29 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") |
---|
| 30 | P.sampleWindow:setText("SampleText") |
---|
| 31 | |
---|
| 32 | local size = getMinTextSize(P.sampleWindow) |
---|
| 33 | P.lineHeight = size[1] |
---|
| 34 | |
---|
| 35 | P.playerWidth = 0 |
---|
| 36 | for k,v in pairs(P.scoreList) do |
---|
| 37 | P.sampleWindow:setText(P.nameList[k]) |
---|
| 38 | size = getMinTextSize(P.sampleWindow) |
---|
| 39 | if size[2] > P.playerWidth then |
---|
| 40 | P.playerWidth = size[2] |
---|
| 41 | end |
---|
| 42 | end |
---|
| 43 | |
---|
| 44 | P.sampleWindow:setText("reset") |
---|
| 45 | size = getMinTextSize(P.sampleWindow) |
---|
| 46 | P.resetWidth = size[2]+20 |
---|
| 47 | |
---|
| 48 | P.spaceWidth = 10 |
---|
| 49 | |
---|
| 50 | local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") |
---|
| 51 | size = pane:getViewableArea() |
---|
| 52 | |
---|
| 53 | P.editboxWidth = size:getWidth() - P.playerWidth - P.resetWidth - 5*P.spaceWidth |
---|
| 54 | |
---|
| 55 | P.createLines() |
---|
| 56 | |
---|
| 57 | P:setButton(1, 1, { |
---|
| 58 | ["button"] = winMgr:getWindow("orxonox/HighscoreBackButton"), |
---|
| 59 | ["callback"] = P.HighscoreBackButton_clicked |
---|
| 60 | }) |
---|
| 61 | end |
---|
| 62 | |
---|
| 63 | function P.onShow() |
---|
| 64 | --local description = winMgr:getWindow("orxonox/HighscoreText") |
---|
| 65 | |
---|
| 66 | --height = getStaticTextWindowHeight(description) |
---|
| 67 | --description:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(0.0, height))) |
---|
| 68 | end |
---|
| 69 | function P.createLine(k) |
---|
| 70 | -- content window for the entire line |
---|
| 71 | local line = winMgr:createWindow("DefaultWindow", "orxonox/HighscoreMenuPane/Score" .. k) |
---|
| 72 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
| 73 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
| 74 | |
---|
| 75 | local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") |
---|
| 76 | local half = (pane:getViewableArea()):getWidth() * 0.5 |
---|
| 77 | local offset = half * 0.01 |
---|
| 78 | -- config name |
---|
| 79 | local player = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/HighscoreMenuPane/Score" .. k .. "/Player") |
---|
| 80 | player:setText(P.nameList[k]) |
---|
| 81 | player:setSize(CEGUI.UVector2(CEGUI.UDim(0, half-offset), CEGUI.UDim(1, 0))) |
---|
| 82 | player:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
| 83 | line:addChildWindow(player) |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | -- config value (editable) |
---|
| 87 | |
---|
| 88 | local playerValue = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/HighscoreMenuPane/Score" .. k .. "/Value") |
---|
| 89 | --playerValue:setProperty("ReadOnly", "set:False") |
---|
| 90 | --local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])SS |
---|
| 91 | playerValue:setText(P.scoreList[k]) |
---|
| 92 | playerValue:setSize(CEGUI.UVector2(CEGUI.UDim(0, half-offset), CEGUI.UDim(1, 0))) |
---|
| 93 | playerValue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, half+offset), CEGUI.UDim(0, 0))) |
---|
| 94 | -- enable the reset button if the value changed |
---|
| 95 | orxonox.GUIManager:subscribeEventHelper(playerValue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted") |
---|
| 96 | line:addChildWindow(playerValue) |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | line:setWidth(CEGUI.UDim(0, 2*half)) |
---|
| 101 | |
---|
| 102 | return line |
---|
| 103 | end |
---|
| 104 | |
---|
| 105 | function P.createLines() |
---|
| 106 | local window = winMgr:getWindow("orxonox/HighscoreMenuPane") |
---|
| 107 | |
---|
| 108 | for k,v in pairs(P.scoreList) do |
---|
| 109 | local line = P.createLine(k) |
---|
| 110 | table.insert(P.linesList, line) |
---|
| 111 | window:addChildWindow(line) |
---|
| 112 | end |
---|
| 113 | |
---|
| 114 | local pane = tolua.cast(window, "CEGUI::ScrollablePane") |
---|
| 115 | pane:setVerticalStepSize(getScrollingStepSize(window)) |
---|
| 116 | end |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | function P.HighscoreBackButton_clicked(e) |
---|
| 120 | hideMenuSheet(P.name) |
---|
| 121 | end |
---|
| 122 | |
---|
| 123 | return P |
---|
| 124 | |
---|