Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 23, 2010, 11:41:30 AM (14 years ago)
Author:
rgrieder
Message:

Eliminated all unnecessary global Lua variables and replaced them either with a local or a instance variable (P.myVar).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestates3/data/gui/scripts/GraphicsMenu.lua

    r6746 r6773  
    44
    55function P.onLoad()
    6     block = true
    7     file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
    8     search_mode = 0
    9     f = io.open(file, "r")
    10     firstline = f:read("*line")
    11     rendersystem = string.sub(firstline, 15)
     6    P.block = true
     7    P.file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
     8    P.search_mode = 0
     9    local f = io.open(P.file, "r")
     10    local firstline = f:read("*line")
     11    local rendersystem = string.sub(firstline, 15)
    1212    for line in f:lines() do
    13         if search_mode == 0 then
     13        if P.search_mode == 0 then
    1414            if string.find(line, rendersystem) ~= nil then
    15                 search_mode = 1
     15                P.search_mode = 1
    1616            end
    1717        end
    18         if search_mode == 1 then
     18        if P.search_mode == 1 then
    1919            if string.sub(line, 1, 11) == "Full Screen" then
    2020                if string.sub(line, 13) == "Yes" then
    21                     fullscreen = true
     21                    P.fullscreen = true
    2222                else
    23                     fullscreen = false
     23                    P.fullscreen = false
    2424                end
    2525            end
    2626            if string.sub(line, 1, 10) == "Video Mode" then
    2727                if string.match(line, "@") == "@" then
    28                     resolution = string.sub(line, 12, string.find(line, "@")-2)
     28                    P.resolution = string.sub(line, 12, string.find(line, "@")-2)
    2929                else
    30                     resolution = string.sub(line, 12)
     30                    P.resolution = string.sub(line, 12)
    3131                end
    3232                break
     
    3636    f:close()
    3737    local fullscreenwindow = tolua.cast(winMgr:getWindow("orxonox/FullscreenCheckbox"),"CEGUI::Checkbox")
    38     fullscreenwindow:setSelected(fullscreen)
    39     listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox")
     38    fullscreenwindow:setSelected(P.fullscreen)
     39    P.listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox")
    4040    local resolutionList = {}
    4141    table.insert(resolutionList, "640 x 480")
     
    5252    table.insert(resolutionList, "1440 x 900")
    5353    for k,v in pairs(resolutionList) do
    54         item = CEGUI.createListboxTextItem(v)
     54        local item = CEGUI.createListboxTextItem(v)
    5555        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    56         CEGUI.toListbox(listboxwindow):addItem(item)
     56        CEGUI.toListbox(P.listboxwindow):addItem(item)
    5757    end
    58     if resolution == "640 x 480" then
    59         listboxwindow:setItemSelectState(0,true)
    60     elseif resolution == "720 x 480" then
    61         listboxwindow:setItemSelectState(1,true)
    62     elseif resolution == "720 x 576" then
    63         listboxwindow:setItemSelectState(2,true)
    64     elseif resolution == "800 x 480" then
    65         listboxwindow:setItemSelectState(3,true)
    66     elseif resolution == "800 x 600" then
    67         listboxwindow:setItemSelectState(4,true)
    68     elseif resolution == "1024 x 480" then
    69         listboxwindow:setItemSelectState(5,true)
    70     elseif resolution == "1024 x 600" then
    71         listboxwindow:setItemSelectState(6,true)
    72     elseif resolution == "1024 x 768" then
    73         listboxwindow:setItemSelectState(7,true)
    74     elseif resolution == "1152 x 864" then
    75         listboxwindow:setItemSelectState(8,true)
    76     elseif resolution == "1280 x 720" then
    77         listboxwindow:setItemSelectState(9,true)
    78     elseif resolution == "1280 x 768" then
    79         listboxwindow:setItemSelectState(10,true)
    80     elseif resolution == "1440 x 900" then
    81         listboxwindow:setItemSelectState(11,true)
     58    if P.resolution == "640 x 480" then
     59        P.listboxwindow:setItemSelectState(0,true)
     60    elseif P.resolution == "720 x 480" then
     61        P.listboxwindow:setItemSelectState(1,true)
     62    elseif P.resolution == "720 x 576" then
     63        P.listboxwindow:setItemSelectState(2,true)
     64    elseif P.resolution == "800 x 480" then
     65        P.listboxwindow:setItemSelectState(3,true)
     66    elseif P.resolution == "800 x 600" then
     67        P.listboxwindow:setItemSelectState(4,true)
     68    elseif P.resolution == "1024 x 480" then
     69        P.listboxwindow:setItemSelectState(5,true)
     70    elseif P.resolution == "1024 x 600" then
     71        P.listboxwindow:setItemSelectState(6,true)
     72    elseif P.resolution == "1024 x 768" then
     73        P.listboxwindow:setItemSelectState(7,true)
     74    elseif P.resolution == "1152 x 864" then
     75        P.listboxwindow:setItemSelectState(8,true)
     76    elseif P.resolution == "1280 x 720" then
     77        P.listboxwindow:setItemSelectState(9,true)
     78    elseif P.resolution == "1280 x 768" then
     79        P.listboxwindow:setItemSelectState(10,true)
     80    elseif P.resolution == "1440 x 900" then
     81        P.listboxwindow:setItemSelectState(11,true)
    8282    end
    83     scrollbar_active = false
    84     block = false
     83    P.scrollbar_active = false
     84    P.block = false
    8585end
    8686
    8787function P.GraphicsResolutionListbox_changed(e)
    88     if listboxwindow:isItemSelected(0) then
    89         resolution = "640 x 480"
    90     elseif listboxwindow:isItemSelected(1) then
    91         resolution = "720 x 480"
    92     elseif listboxwindow:isItemSelected(2) then
    93         resolution = "720 x 576"
    94     elseif listboxwindow:isItemSelected(3) then
    95         resolution = "800 x 480"
    96     elseif listboxwindow:isItemSelected(4) then
    97         resolution = "800 x 600"
    98     elseif listboxwindow:isItemSelected(5) then
    99         resolution = "1024 x 480"
    100     elseif listboxwindow:isItemSelected(6) then
    101         resolution = "1024 x 600"
    102     elseif listboxwindow:isItemSelected(7) then
    103         resolution = "1024 x 768"
    104     elseif listboxwindow:isItemSelected(8) then
    105         resolution = "1152 x 864"
    106     elseif listboxwindow:isItemSelected(9) then
    107         resolution = "1280 x 720"
    108     elseif listboxwindow:isItemSelected(10) then
    109         resolution = "1280 x 768"
    110     elseif listboxwindow:isItemSelected(11) then
    111         resolution = "1440 x 900"
     88    if P.listboxwindow:isItemSelected(0) then
     89        P.resolution = "640 x 480"
     90    elseif P.listboxwindow:isItemSelected(1) then
     91        P.resolution = "720 x 480"
     92    elseif P.listboxwindow:isItemSelected(2) then
     93        P.resolution = "720 x 576"
     94    elseif P.listboxwindow:isItemSelected(3) then
     95        P.resolution = "800 x 480"
     96    elseif P.listboxwindow:isItemSelected(4) then
     97        P.resolution = "800 x 600"
     98    elseif P.listboxwindow:isItemSelected(5) then
     99        P.resolution = "1024 x 480"
     100    elseif P.listboxwindow:isItemSelected(6) then
     101        P.resolution = "1024 x 600"
     102    elseif P.listboxwindow:isItemSelected(7) then
     103        P.resolution = "1024 x 768"
     104    elseif P.listboxwindow:isItemSelected(8) then
     105        P.resolution = "1152 x 864"
     106    elseif P.listboxwindow:isItemSelected(9) then
     107        P.resolution = "1280 x 720"
     108    elseif P.listboxwindow:isItemSelected(10) then
     109        P.resolution = "1280 x 768"
     110    elseif P.listboxwindow:isItemSelected(11) then
     111        P.resolution = "1440 x 900"
    112112    end
    113     search_mode = 0
    114     f = io.open(file, "r")
    115     firstline = f:read("*line")
    116     text = firstline .. "\n"
    117     rendersystem = string.sub(firstline, 15)
     113    P.search_mode = 0
     114    local f = io.open(P.file, "r")
     115    local firstline = f:read("*line")
     116    local text = firstline .. "\n"
     117    local rendersystem = string.sub(firstline, 15)
    118118    for line in f:lines() do
    119         if search_mode == 0 then
     119        if P.search_mode == 0 then
    120120            if string.find(line, rendersystem) ~= nil then
    121                 search_mode = 1
     121                P.search_mode = 1
    122122            end
    123123        end
    124         if search_mode == 1 then
     124        if P.search_mode == 1 then
    125125            if string.sub(line, 1, 10) == "Video Mode" then
    126126                if string.match(line, "@") == "@" then
    127                     line = "Video Mode=" .. resolution .. string.sub(line, string.find(line, "@")-1)
     127                    line = "Video Mode=" .. P.resolution .. string.sub(line, string.find(line, "@")-1)
    128128                else
    129                     line = "Video Mode=" .. resolution
     129                    line = "Video Mode=" .. P.resolution
    130130                end
    131                 search_mode = 2
     131                P.search_mode = 2
    132132            end
    133133        end
     
    135135    end
    136136    f:close()
    137     f = io.open(file, "w")
     137    f = io.open(P.file, "w")
    138138    f:write(text)
    139139    f:close()
     
    141141
    142142function P.GraphicsBrightnessScrollbar_changed(e)
    143     if scrollbar_active == false then
     143    if P.scrollbar_active == false then
    144144        -- brightness
    145145        logMessage(0, "event: brightness")
     
    148148
    149149function P.GraphicsBrightnessScrollbar_started(e)
    150     scrollbar_active = true
     150    P.scrollbar_active = true
    151151end
    152152
     
    154154    -- brightness
    155155    logMessage(0, "event: brightness")
    156     scrollbar_active = false
     156    P.scrollbar_active = false
    157157end
    158158
    159159function P.GraphicsFullscreenCheckbox_clicked(e)
    160     if block == false then
    161         search_mode = 0
    162         f = io.open(file, "r")
    163         firstline = f:read("*line")
    164         text = firstline .. "\n"
    165         rendersystem = string.sub(firstline, 15)
     160    if P.block == false then
     161        P.search_mode = 0
     162        local f = io.open(P.file, "r")
     163        local firstline = f:read("*line")
     164        local text = firstline .. "\n"
     165        local rendersystem = string.sub(firstline, 15)
    166166        for line in f:lines() do
    167             if search_mode == 0 then
     167            if P.search_mode == 0 then
    168168                if string.find(line, rendersystem) ~= nil then
    169                     search_mode = 1
     169                    P.search_mode = 1
    170170                end
    171171            end
    172             if search_mode == 1 then
     172            if P.search_mode == 1 then
    173173                if string.sub(line, 1, 11) == "Full Screen" then
    174                     if fullscreen == true then
     174                    if P.fullscreen == true then
    175175                        line = "Full Screen=No"
    176                         fullscreen = false
     176                        P.fullscreen = false
    177177                    else
    178178                        line = "Full Screen=Yes"
    179                         fullscreen = true
     179                        P.fullscreen = true
    180180                    end
    181                     search_mode = 2
     181                    P.search_mode = 2
    182182                end
    183183            end
     
    185185        end
    186186        f:close()
    187         f = io.open(file, "w")
     187        f = io.open(P.file, "w")
    188188        f:write(text)
    189189        f:close()
Note: See TracChangeset for help on using the changeset viewer.