Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2011, 3:22:46 PM (13 years ago)
Author:
baermatt
Message:

Cleaned up the miscellaneous menu and added possibility to cancel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/menue/data/gui/scripts/MiscConfigMenu.lua

    r8729 r8964  
    1111P.lineHeight = 0
    1212P.commandWidth = 0
    13 P.configWidth = 0
     13P.editboxWidth = 0
    1414P.resetWidth = 0
    1515P.spaceWidth = 0
     
    7575    end
    7676
    77     P.sampleWindow:setText("configure")
    78     size = getMinTextSize(P.sampleWindow)
    79     P.configWidth = size[2]+20
    80 
    8177    P.sampleWindow:setText("reset")
    8278    size = getMinTextSize(P.sampleWindow)
    8379    P.resetWidth = size[2]+20
    8480
    85     P.spaceWidth = math.floor(1/8*P.configWidth)
     81    P.spaceWidth = 10
     82   
     83    local pane = tolua.cast(winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane")
     84    size = pane:getViewableArea()
     85    P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth
    8686
    8787    P.createLines()
    8888
    8989    P:setButton(1, 1, {
    90             ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"),
    91             ["callback"]  = P.MiscConfigBackButton_clicked
     90            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"),
     91            ["callback"]  = P.MiscConfigCancelButton_clicked
     92    })
     93   
     94    P:setButton(1, 2, {
     95            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"),
     96            ["callback"]  = P.MiscConfigOKButton_clicked
    9297    })
    9398end
     
    95100function P.createLine(k)
    96101    local offset = 0
     102    -- content window for the entire line
    97103    local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k)
    98104    line:setHeight(CEGUI.UDim(0, P.lineHeight))
    99105    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
    100106
     107    -- config name
    101108    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
    102109    command:setText(P.nameList[k])
     
    106113    offset = offset + P.commandWidth + P.spaceWidth
    107114
     115    -- config value (editable)
    108116    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
    109117    configvalue:setProperty("ReadOnly", "set:False")
    110118    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
    111119    configvalue:setText(value)
    112     P.sampleWindow:setText(value)
    113     local size = getMinTextSize(P.sampleWindow)
    114     local configvalueWidth = 2*size[2]
    115     configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0)))
     120    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
    116121    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
     122    -- enable the reset button if the value changed
     123    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted")
    117124    line:addChildWindow(configvalue)
    118     offset = offset + configvalueWidth + P.spaceWidth
     125    offset = offset + P.editboxWidth + P.spaceWidth
    119126
    120     local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config")
    121     config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0)))
    122     config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
    123     config:setText("configure")
    124     orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked")
    125     line:addChildWindow(config)
    126     offset = offset + P.configWidth + P.spaceWidth
    127 
     127    -- reset button (only available when value changed)
    128128    local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
    129129    reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
    130130    reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
    131131    reset:setText("reset")
    132     orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked")
     132    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked")
    133133    line:addChildWindow(reset)
    134134    reset:setEnabled(false)
     
    153153end
    154154
    155 function P.MiscConfigReset_clicked(e)
     155function P.MiscConfigOKButton_clicked(e)
     156    for k,v in pairs(P.commandList) do
     157        -- save the changes
     158        local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
     159        orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
     160        local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
     161        resetButton:setEnabled(false)
     162    end
     163   
     164    hideMenuSheet("MiscConfigMenu")
     165end
     166
     167function P.MiscConfigCancelButton_clicked(e)
     168    hideMenuSheet("MiscConfigMenu")
     169end
     170
     171function P.MiscConfigEditbox_textAccepted(e)
    156172    local we = CEGUI.toWindowEventArgs(e)
    157173    local name = we.window:getName()
     
    160176    local commandNr = tonumber(match())
    161177
    162     -- TODO: Implement reset.
     178    local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
     179    resetButton:setEnabled(true)
    163180end
    164181
    165 function P.MiscConfigConfigure_clicked(e)
     182function P.MiscConfigResetButton_clicked(e)
    166183    local we = CEGUI.toWindowEventArgs(e)
    167184    local name = we.window:getName()
     
    170187    local commandNr = tonumber(match())
    171188
    172     local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
    173 
    174     orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText())
     189    -- reload the old value
     190    local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
    175191    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
    176     window:setText(value)
    177 end
    178 
    179 function P.MiscConfigBackButton_clicked(e)
    180     hideMenuSheet("MiscConfigMenu")
     192    editbox:setText(value)
     193   
     194    we.window:setEnabled(false)
    181195end
    182196
Note: See TracChangeset for help on using the changeset viewer.