Show
Ignore:
Timestamp:
08/27/10 11:30:01 (21 months ago)
Author:
Carsten
Message:

Reintegrated branches/cafu_to_wx back into trunk!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/Games/DeathMatch/GUIs/MainMenu/MainMenu_main.cgui

    r36 r136  
    1919 
    2020    return ""; 
     21end 
     22 
     23-- Parses a string that describes a video mode. It returns the width, height, colour depth and refresh rate. 
     24function ParseModeStr(ModeStr) 
     25    -- For case-insensitive matching, translate the entire string to lower case. 
     26    ModeStr=ModeStr:lower(); 
     27 
     28    local width, height=ModeStr:match("(%d+)%s*x%s*(%d+)"); 
     29    local bpp          =ModeStr:match("(%d+)%s*bpp"); 
     30    local rate         =ModeStr:match("(%d+)%s*hz"); 
     31 
     32    if width  then width =tonumber(width);  end 
     33    if height then height=tonumber(height); end 
     34    if bpp    then bpp   =tonumber(bpp);    end 
     35    if rate   then rate  =tonumber(rate);   end 
     36 
     37    return width, height, bpp, rate; 
    2138end 
    2239 
     
    544561 
    545562function OptionsContextMenu.Frame.Video:OnMouseButtonUp() 
    546     -- Select the first screen resolution that is at least as wide as "dlg_clWindowSizeX" (1024*768 is used as a fall-back). 
    547     VideoOptionsDialog.Frame.ScreenResChoice:SetSelection(2);   -- Safety if the loop below fails for some reason. 
     563    -- Select the screen resolution that matches the one specified in the console variables. 
     564    VideoOptionsDialog.Frame.ScreenResChoice:SetSelection(0);   -- Safety if the loop below fails for some reason. 
    548565 
    549566    for ModeNr=0, VideoOptionsDialog.Frame.ScreenResChoice:GetNumChoices()-1 do 
    550         local ResX=tonumber(VideoOptionsDialog.Frame.ScreenResChoice:GetChoice(ModeNr):match("%d+")); 
    551  
    552         if (ResX>=ci.GetValue("dlg_clWindowSizeX")) then 
     567        local width, height, bpp, rate=ParseModeStr(VideoOptionsDialog.Frame.ScreenResChoice:GetChoice(ModeNr)); 
     568 
     569        if width==ci.GetValue("dlg_clWindowSizeX") and height==ci.GetValue("dlg_clWindowSizeY") then 
     570            -- The width and height match, select this mode. 
    553571            VideoOptionsDialog.Frame.ScreenResChoice:SetSelection(ModeNr); 
    554             break; 
     572 
     573            if bpp==ci.GetValue("dlg_clDisplayBPP") and rate==ci.GetValue("dlg_clDisplayRefresh") then 
     574                -- The color depth and refresh rate match, too - stop looking for a better match. 
     575                break; 
     576            end 
    555577        end 
    556578    end 
     
    11601182-- Move into OnInit()? 
    11611183VideoOptionsDialog.Frame.ScreenResChoice:Clear(); 
    1162 VideoOptionsDialog.Frame.ScreenResChoice:Append(" 640 x 480"); 
    1163 VideoOptionsDialog.Frame.ScreenResChoice:Append(" 800 x 600"); 
    1164 VideoOptionsDialog.Frame.ScreenResChoice:Append(" 1024 x 768"); 
    1165 VideoOptionsDialog.Frame.ScreenResChoice:Append(" 1152 x 864"); 
    1166 VideoOptionsDialog.Frame.ScreenResChoice:Append(" 1280 x 1024"); 
    1167 VideoOptionsDialog.Frame.ScreenResChoice:Append(" 1600 x 1200"); 
    1168 VideoOptionsDialog.Frame.ScreenResChoice:SetSelection(2);   -- Set again when the dialog is shown. 
     1184 
     1185-- For each video mode in console variable "VideoModes" (a multi-line string with one 
     1186-- video mode per line, separated by new-lines), append a choice to the choice window. 
     1187for ModeStr in ci.GetValue("VideoModes"):gmatch("[^\n]+") do 
     1188    VideoOptionsDialog.Frame.ScreenResChoice:Append(" "..ModeStr); 
     1189end 
     1190 
     1191-- It is possible (though normally not necessary) to add custom video modes here, 
     1192-- for example when your favorite video mode is not automatically detected and provided above. 
     1193-- There is no guarantee though that the graphics driver can set any custom modes 
     1194-- (or else the mode had been automatically included in the enumeration above). 
     1195-- Examples: 
     1196-- VideoOptionsDialog.Frame.ScreenResChoice:Append(" 1152 x 864"); 
     1197-- VideoOptionsDialog.Frame.ScreenResChoice:Append(" 1440 x 900, 32 bpp, 60 Hz"); 
     1198 
     1199-- The list of video modes above should never be totally empty, 
     1200-- but still just handle the case here to be totally sure. 
     1201if (VideoOptionsDialog.Frame.ScreenResChoice:GetNumChoices()==0) then 
     1202    Console.Warning("Console variable VideoModes is empty!\n"); 
     1203 
     1204    VideoOptionsDialog.Frame.ScreenResChoice:Append(" 640 x 480"); 
     1205    VideoOptionsDialog.Frame.ScreenResChoice:Append(" 800 x 600"); 
     1206    VideoOptionsDialog.Frame.ScreenResChoice:Append(" 1024 x 768"); 
     1207end 
     1208 
     1209VideoOptionsDialog.Frame.ScreenResChoice:SetSelection(0);   -- Set again when the dialog is shown. 
    11691210 
    11701211function VideoOptionsDialog.Frame.ScreenResChoice:OnSelectionChanged(SelNum) 
     
    12151256    local ModeStr=VideoOptionsDialog.Frame.ScreenResChoice:GetChoice(ModeNr); 
    12161257 
    1217     local ResX, ResY=ModeStr:match("(%d+)%s*x%s*(%d+)"); 
    1218  
    1219     ci.SetValue("dlg_clWindowSizeX",   ResX); 
    1220     ci.SetValue("dlg_clWindowSizeY",   ResY); 
     1258    local width, height, bpp, rate=ParseModeStr(ModeStr); 
     1259 
     1260    if width  then ci.SetValue("dlg_clWindowSizeX",    width ); end 
     1261    if height then ci.SetValue("dlg_clWindowSizeY",    height); end 
     1262    if bpp    then ci.SetValue("dlg_clDisplayBPP",     bpp   ); end 
     1263    if rate   then ci.SetValue("dlg_clDisplayRefresh", rate  ); end 
     1264 
    12211265    ci.SetValue("dlg_clFullScreen",    VideoOptionsDialog.Frame.FullScreenChoice:GetSelection()==1); 
    12221266    ci.SetValue("dlg_clTextureDetail", VideoOptionsDialog.Frame.TextureDetailChoice:GetSelection());