Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8938


Ignore:
Timestamp:
Nov 16, 2011, 3:46:36 PM (13 years ago)
Author:
baermatt
Message:

Added some basic but yet static level configuration support.

Location:
code/branches/menue/data/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/menue/data/gui/layouts/SingleplayerConfigMenu.layout

    r8927 r8938  
    99        <Property Name="BackgroundEnabled" Value="False" />
    1010        <Window Type="MenuWidgets/StaticText" Name="orxonox/SingleplayerConfigMenu/ConfigWindow" >
    11             <Property Name="Text" Value="Miscellaneous" />
     11            <Property Name="Text" Value="Config" />
    1212            <Property Name="Alpha" Value="0.8" />
    1313            <Property Name="InheritsAlpha" Value="False" />
  • code/branches/menue/data/gui/scripts/SingleplayerConfigMenu.lua

    r8927 r8938  
    33local P = createMenuSheet("SingleplayerConfigMenu")
    44
     5P.commandList = {}
     6P.nameList = {}
     7P.linesList = {}
     8
     9P.sampleWindow = nil
     10
     11P.lineHeight = 0
     12P.commandWidth = 0
     13P.editboxWidth = 0
     14P.resetWidth = 0
     15P.spaceWidth = 0
     16
     17function P.onLoad()
     18    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/SingleplayerConfigMenu/MiscConfigPane/SampleWindow")
     19    P.sampleWindow:setText("SampleText")
     20
     21    P:setButton(1, 1, {
     22            ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigMenu/CancelButton"),
     23            ["callback"]  = P.SingleplayerConfigCancelButton_clicked
     24    })
     25   
     26    P:setButton(1, 2, {
     27            ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigMenu/OKButton"),
     28            ["callback"]  = P.SingleplayerConfigOKButton_clicked
     29    })
     30end
     31
     32function P.onHide()
     33   
     34end
     35
     36function P.loadConfig(level)
     37    P.commandList = {}
     38    table.insert(P.commandList, "Gametype initialStartCountdown_")
     39    table.insert(P.commandList, "Gametype bAutoStart_")
     40    table.insert(P.commandList, "Gametype numberOfBots_")
     41    table.insert(P.commandList, "UnderAttack gameTime_")
     42    table.insert(P.commandList, "TeamDeathmatch teams_")
     43
     44    P.nameList = {}
     45    table.insert(P.nameList, "Start countdown")
     46    table.insert(P.nameList, "Autostart")
     47    table.insert(P.nameList, "Number of Bots")
     48    table.insert(P.nameList, "UnderAttack: game time")
     49    table.insert(P.nameList, "TeamDeathmatch: Number of teams")
     50
     51    P.linesList = {}
     52   
     53    --Calculate design parameters:
     54    local size = getMinTextSize(P.sampleWindow)
     55    P.lineHeight = size[1]
     56
     57    P.commandWidth = 0
     58    for k,v in pairs(P.commandList) do
     59        P.sampleWindow:setText(P.nameList[k])
     60        size = getMinTextSize(P.sampleWindow)
     61        if size[2] > P.commandWidth then
     62            P.commandWidth = size[2]
     63        end
     64    end
     65
     66    P.sampleWindow:setText("reset")
     67    size = getMinTextSize(P.sampleWindow)
     68    P.resetWidth = size[2]+20
     69
     70    P.spaceWidth = 10
     71   
     72    local pane = tolua.cast(winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane")
     73    size = pane:getViewableArea()
     74    P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth
     75
     76    P.createLines()
     77end
     78
     79function P.createLine(k)
     80    local offset = 0
     81    local line = winMgr:createWindow("DefaultWindow", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k)
     82    line:setHeight(CEGUI.UDim(0, P.lineHeight))
     83    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
     84
     85    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
     86    command:setText(P.nameList[k])
     87    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
     88    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
     89    line:addChildWindow(command)
     90    offset = offset + P.commandWidth + P.spaceWidth
     91
     92    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
     93    configvalue:setProperty("ReadOnly", "set:False")
     94    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
     95    configvalue:setText(value)
     96    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
     97    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
     98    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".SingleplayerConfigEditbox_textAccepted")
     99    line:addChildWindow(configvalue)
     100    offset = offset + P.editboxWidth + P.spaceWidth
     101
     102    local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
     103    reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
     104    reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
     105    reset:setText("reset")
     106    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".SingleplayerConfigResetButton_clicked")
     107    line:addChildWindow(reset)
     108    reset:setEnabled(false)
     109    offset = offset + P.resetWidth + P.spaceWidth
     110
     111    line:setWidth(CEGUI.UDim(0, offset))
     112
     113    return line
     114end
     115
     116function P.createLines()
     117    local window = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane")
     118
     119    for k,v in pairs(P.commandList) do
     120        local line = P.createLine(k)
     121        table.insert(P.linesList, line)
     122        window:addChildWindow(line)
     123    end
     124
     125    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
     126    pane:setVerticalStepSize(getScrollingStepSize(window))
     127end
     128
     129function P.SingleplayerConfigOKButton_clicked(e)
     130    for k,v in pairs(P.commandList) do
     131        local editbox = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
     132        orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
     133        local resetButton = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
     134        resetButton:setEnabled(false)
     135    end
     136   
     137    hideMenuSheet("SingleplayerConfigMenu")
     138end
     139
     140function P.SingleplayerConfigCancelButton_clicked(e)
     141    hideMenuSheet("SingleplayerConfigMenu")
     142end
     143
     144function P.SingleplayerConfigEditbox_textAccepted(e)
     145    local we = CEGUI.toWindowEventArgs(e)
     146    local name = we.window:getName()
     147
     148    local match = string.gmatch(name, "%d+")
     149    local commandNr = tonumber(match())
     150
     151    local resetButton = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
     152    resetButton:setEnabled(true)
     153end
     154
     155function P.SingleplayerConfigResetButton_clicked(e)
     156    local we = CEGUI.toWindowEventArgs(e)
     157    local name = we.window:getName()
     158
     159    local match = string.gmatch(name, "%d+")
     160    local commandNr = tonumber(match())
     161
     162    local editbox = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
     163    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
     164    editbox:setText(value)
     165   
     166    we.window:setEnabled(false)
     167end
     168
    5169return P
  • code/branches/menue/data/gui/scripts/SingleplayerMenu.lua

    r8931 r8938  
    135135
    136136function P.SingleplayerConfigButton_clicked(e)
    137     showMenuSheet("SingleplayerConfigMenu", true)
     137    local level = P.SingleplayerGetSelectedLevel()
     138    if level ~= nil then
     139        local X = showMenuSheet("SingleplayerConfigMenu")
     140        X:loadConfig(level)
     141    end
    138142end
    139143
Note: See TracChangeset for help on using the changeset viewer.