home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 January / Gamestar_69_2005-01_dvd.iso / Dema / theprojectv1-0.exe / FCData / Scripts.pak / Scripts / UIScreens / BenchmarkSetup.lua < prev    next >
Encoding:
Text File  |  2004-10-28  |  12.4 KB  |  522 lines

  1.  
  2. -- get the list of videofiles
  3. szScriptFolder = "Scripts/UIScreens/";
  4.  
  5. -- Load Configuration
  6. Script:LoadScript(szScriptFolder.."UISystemCfg.lua", 1);                -- Load Configuration File
  7.  
  8. -- Load the skin
  9. Script:LoadScript(UI.szSkinPath, 1);
  10.  
  11. UI.PageOptions=
  12. {    
  13.     GUI=
  14.     {
  15.     
  16.         background=
  17.         {
  18.             classname = "static",
  19.             left = 40, top = 150,
  20.             width = 720, height = 300,
  21.             
  22.             color = UI.szMessageBoxScreenColor,
  23.             
  24.             zorder = -1,    -- must be above all
  25.         },
  26.         
  27. -- ///////////////////////// Resolution /////////////////////////
  28.  
  29.         Resolution_text =
  30.         {
  31.             skin = UI.skins.Label,
  32.             left = 45, top = 200,
  33.             width = 150,
  34.             
  35.             fontname = "UI_Default_Bold",
  36.  
  37.             text = "Resolution",
  38.         },
  39.  
  40.         Resolution =
  41.         {
  42.             left = 200, top = 200,
  43.             skin = UI.skins.ComboBox, -- edit the skill to change the appearance. Skin.lua
  44.             
  45.             --buttoncolor = UI.szBorderColor,
  46.     
  47.             tabstop = 2,
  48.             
  49.             vscrollbar =
  50.             {
  51.                 skin = UI.skins.VScrollBar,
  52.             },
  53.             
  54.             fontname = "UI_Default",
  55.             
  56.             user =
  57.             {
  58.                 -- data
  59.                 lScreenResolutionAndBpp = nil,
  60.  
  61.                 -- code (implemented below)
  62.                 Initialize = nil,
  63.                 ApplySelection = nil,
  64.             },
  65.             
  66.             OnChanged = function(self)
  67.                 if (self:GetSelection()) then
  68.                     System:Log("you've just selected: "..self:GetSelection());    
  69.                 end
  70.             end,
  71.         },
  72.         
  73. -- ///////////////////////// FSAA /////////////////////////
  74.         
  75.         FSAA_text =
  76.         {
  77.             skin = UI.skins.Label,
  78.             left = 45, top = 242,
  79.             width = 150,
  80.                         
  81.             fontname = "UI_Default_Bold",
  82.  
  83.             text = "Anti Aliasing",
  84.         },
  85.  
  86.         FSAA =
  87.         {
  88.             left = 200, top = 242,
  89.             skin = UI.skins.ComboBox, -- edit the skill to change the appearance. Skin.lua
  90.     
  91.             tabstop = 3,
  92.             
  93.             fontname = "UI_Default",
  94.             
  95.             vscrollbar =
  96.             {
  97.                 skin = UI.skins.VScrollBar,
  98.             },
  99.             
  100.             OnChanged = function(self)
  101.                 if (self:GetSelection()) then
  102.                     System:Log("you've just selected: "..self:GetSelection());    
  103.                 end
  104.             end,
  105.             
  106.             user =
  107.             {
  108.                 -- data
  109.                 initialSelectionIndex = 0,
  110.  
  111.                 -- code (implemented below)
  112.                 Initialize = nil,
  113.                 UpdateAssignedGlobals = nil,
  114.             },
  115.         },
  116.         
  117. -- ///////////////////////// Fullscreen /////////////////////////
  118.         
  119.         Fullscreen_text =
  120.         {
  121.             skin = UI.skins.Label,
  122.             left = 45, top = 284,
  123.             width = 150,
  124.  
  125.             fontname = "UI_Default_Bold",
  126.  
  127.             text = "Fullscreen Mode",
  128.         },
  129.  
  130.         Fullscreen =
  131.         {
  132.             skin = UI.skins.CheckBox,
  133.             left = 200, top = 284,
  134.  
  135.             tabstop = 4,
  136.  
  137.             -- code specific for "Full Screen" check box (separated in user table)
  138.             user =
  139.             {
  140.                 -- code (implemented below)
  141.                 UpdateAssignedGlobals = nil,
  142.             },
  143.         },
  144.         
  145. -- ///////////////////////// 3Dc Texture Compression /////////////////////////
  146.         
  147.         TDCTexture_text =
  148.         {
  149.             skin = UI.skins.Label,
  150.             left = 45, top = 326,
  151.             width = 150,
  152.  
  153.             fontname = "UI_Default_Bold",
  154.             text = "3Dc Texture Compression",
  155.         },
  156.  
  157.         TDCTexture =
  158.         {
  159.             skin = UI.skins.CheckBox,
  160.             left = 200, top = 326,
  161.  
  162.             tabstop = 5,
  163.  
  164.             user =
  165.             {
  166.                 -- code (implemented below)
  167.                 UpdateAssignedGlobals = nil,
  168.             },
  169.         },
  170.         
  171. -- ///////////////////////// VSync /////////////////////////
  172.         
  173.         VSync_text =
  174.         {
  175.             skin = UI.skins.Label,
  176.             left = 45, top = 368,
  177.             width = 152,
  178.  
  179.             fontname = "UI_Default_Bold",
  180.             text = "Vertical Sync",
  181.         },
  182.  
  183.         VSync =
  184.         {
  185.             skin = UI.skins.CheckBox,
  186.             left = 200, top = 368,
  187.  
  188.             tabstop = 6,
  189.  
  190.             user =
  191.             {
  192.                 -- code (implemented below)
  193.                 UpdateAssignedGlobals = nil,
  194.             },
  195.         },
  196.         
  197. -- ///////////////////////// Sound Volume /////////////////////////
  198.  
  199.         SoundOnOff_text =
  200.         {
  201.             skin = UI.skins.Label,
  202.             left = 360, top = 200,
  203.             width = 150,
  204.  
  205.             fontname = "UI_Default_Bold",
  206.             text = "Enable sound",
  207.         },
  208.  
  209.         SoundOnOff =
  210.         {
  211.             skin = UI.skins.CheckBox,
  212.             left = 515, top = 200,
  213.     
  214.             tabstop = 7,
  215.             
  216.             user =
  217.             {
  218.                 -- code (implemented below)
  219.                 UpdateAssignedGlobals = nil,
  220.             },
  221.         },
  222.         
  223. -- ///////////////////////// Sound Volume /////////////////////////
  224.  
  225.         SoundVolume_text =
  226.         {
  227.             skin = UI.skins.Label,
  228.             left = 360, top = 242,
  229.             width = 150,
  230.  
  231.             fontname = "UI_Default_Bold",
  232.             text = "Sound Volume",
  233.         },
  234.  
  235.         SoundVolume =
  236.         {
  237.             left = 515, top = 242,
  238.             skin = UI.skins.HScrollBar, -- edit the skill to change the appearance. Skin.lua
  239.     
  240.             tabstop = 8,
  241.             
  242.             user =
  243.             {
  244.                 soundSfxCue = Sound:LoadSound( "Sounds/Menu/Click.wav",SOUND_UNSCALABLE),
  245.             },
  246.  
  247.             OnChanged = function( Sender )
  248.                 setglobal( "s_SFXVolume", Sender:GetValue() );    -- 0..1
  249.                 local sound = UI.PageOptions.GUI.SoundVolume.user.soundSfxCue;
  250.                 if( sound ~= nil ) then
  251.                     Sound:SetSoundVolume( sound, getglobal( "s_SFXVolume" ) * 255.0 );
  252.                     Sound:SetSoundLoop( sound, 0 );
  253.                     Sound:PlaySound( sound );
  254.                 end;
  255.             end,
  256.         },
  257.  
  258. -- ------------------------- Apply -------------------------
  259.         
  260.         DoBenchmark=
  261.         {
  262.             skin = UI.skins.ActionButton,    -- skin is like a template. it will inherit everything from it. Skin.lua
  263.     
  264.             left = 405, top = 540,
  265.             tabstop = 1,
  266.             
  267.             fontname = "UI_Control",
  268.             --fontsize = 14
  269.             text = "Run Benchmark",
  270.             
  271.             OnCommand = function(self)
  272.                 local newValue = 0;
  273.                 local curValue = tonumber( getglobal( "r_Fullscreen" ) );
  274.  
  275.                 if ( UI.PageOptions.GUI.Fullscreen:GetChecked() ) then
  276.                     newValue = 1;
  277.                 end
  278.                 if( newValue ~= curValue ) then
  279.                     setglobal( "r_Fullscreen", newValue );
  280.                 end
  281.                 
  282.                 newValue = 0;
  283.                 curValue = tonumber( getglobal( "r_Tex3DC" ) );
  284.  
  285.                 if ( UI.PageOptions.GUI.TDCTexture:GetChecked() ) then
  286.                     newValue = 1;
  287.                 end
  288.                 if( newValue ~= curValue ) then
  289.                     setglobal( "r_Tex3DC", newValue );
  290.                 end
  291.                 
  292.                 newValue = 0;
  293.                 curValue = tonumber( getglobal( "r_VSync" ) );
  294.  
  295.                 if ( UI.PageOptions.GUI.VSync:GetChecked() ) then
  296.                     newValue = 1;
  297.                 end
  298.                 if( newValue ~= curValue ) then
  299.                     setglobal( "r_VSync", newValue );
  300.                 end
  301.                 
  302.                 newValue = 0;
  303.                 curValue = tonumber( getglobal( "s_SoundEnable" ) );
  304.  
  305.                 if ( UI.PageOptions.GUI.SoundOnOff:GetChecked() ) then
  306.                     newValue = 1;
  307.                 end
  308.                 if( newValue ~= curValue ) then
  309.                     setglobal( "s_SoundEnable", newValue );
  310.                 end
  311.                 
  312.                 UI.PageOptions.GUI.Resolution.user.ApplySelection();
  313.                 UI.PageOptions.GUI.FSAA.user.UpdateAssignedGlobals();
  314.                 
  315.                 TechDemo:GoToScreen( "Benchmark" );
  316.             end,
  317.         },
  318.         
  319.         Quit =
  320.         {
  321.             skin = UI.skins.ActionButton,    -- skin is like a template. it will inherit everything from it. Skin.lua
  322.     
  323.             left = 580, top = 540,
  324.             tabstop = 1,
  325.             
  326.             fontname = "UI_Control",
  327.             --fontsize = 14
  328.             text = "Quit",
  329.             
  330.             OnCommand = function(self)
  331.                 TechDemo:Quit();
  332.             end,
  333.         },
  334.         
  335.         OnInit = function(self)
  336.         end,    
  337.                     
  338.         OnActivate= function(self) -- this will be called everytime you activate this screen
  339.             -- here populate the screen
  340.             self.Resolution:Clear();
  341.             self.Resolution:AddItem("Blah"); -- there are lots of parameters you can add, such as background color, texture, etc.. etc..
  342.             
  343.             local curValue = tonumber( getglobal( "r_Fullscreen" ) );
  344.             UI.PageOptions.GUI.Fullscreen:SetChecked( curValue ~= 0 );
  345.             
  346.             curValue = tonumber( getglobal( "r_VSync" ) );
  347.             UI.PageOptions.GUI.VSync:SetChecked( curValue ~= 0 );
  348.             
  349.             curValue = tonumber( getglobal( "r_Tex3DC" ) );
  350.             UI.PageOptions.GUI.TDCTexture:SetChecked( curValue ~= 0 );
  351.             
  352.             UI.PageOptions.GUI.SoundVolume:SetValue( getglobal("s_SFXVolume") );
  353.             
  354.             UI.PageOptions.GUI.Resolution.user.Initialize();
  355.             UI.PageOptions.GUI.FSAA.user.Initialize();
  356.         end,
  357.     },
  358. };
  359.  
  360. UI.PageOptions.GUI.Fullscreen.user.UpdateAssignedGlobals = function( self )
  361.     local newValue = 0;
  362.     local curValue = tonumber( getglobal( "r_Fullscreen" ) );
  363.  
  364.     if UI.PageOptions.GUI.Fullscreen:GetChecked() then
  365.         newValue = 1;
  366.     end
  367.     if( newValue ~= curValue ) then
  368.         setglobal( "r_Fullscreen", newValue );
  369.     end
  370. end
  371.  
  372.  
  373.  
  374. UI.PageOptions.GUI.TDCTexture.user.UpdateAssignedGlobals = function( self )
  375.     local newValue = 0;
  376.     local curValue = tonumber( getglobal( "r_Tex3DC" ) );
  377.  
  378.     if UI.PageOptions.GUI.TDCTexture:GetChecked() then
  379.         newValue = 1;
  380.     end
  381.     if( newValue ~= curValue ) then
  382.         setglobal( "r_Tex3DC", newValue );
  383.     end
  384. end
  385.  
  386.  
  387.  
  388. UI.PageOptions.GUI.VSync.user.UpdateAssignedGlobals = function( self )
  389.     local newValue = 0;
  390.     local curValue = tonumber( getglobal( "r_VSync" ) );
  391.  
  392.     if UI.PageOptions.GUI.VSync:GetChecked() then
  393.         newValue = 1;
  394.     end
  395.     if( newValue ~= curValue ) then
  396.         setglobal( "r_VSync", newValue );
  397.     end
  398. end
  399.  
  400.  
  401. UI.PageOptions.GUI.Resolution.user.Initialize = function( self )
  402.     -- initalize widget
  403.     UI.PageOptions.GUI.Resolution:Clear();
  404.  
  405.     UI.PageOptions.GUI.Resolution.user.ScreenResolutionAndBpp = {};
  406.     local lTmpScreenResolutionAndBpp = System:EnumDisplayFormats();
  407.  
  408.     local ref = UI.PageOptions.GUI.Resolution.user.ScreenResolutionAndBpp;
  409.     local j = 1;
  410.     for i, DispFmt in lTmpScreenResolutionAndBpp do
  411.         if( DispFmt.bpp == 32 and DispFmt.width >= 1024 and DispFmt.height >= 768 ) then
  412.             ref[ j ] = DispFmt;
  413.             j = j + 1;
  414.         end
  415.     end
  416.  
  417.     for i, DispFmt in ref do
  418.         UI.PageOptions.GUI.Resolution:AddItem( DispFmt.width.."x"..DispFmt.height.."x"..DispFmt.bpp );
  419.     end
  420.  
  421.     -- let widget reflect state of globals
  422.     local bpp = tonumber( getglobal( "r_ColorBits" ) );
  423.     local sCurrentRes = tonumber( getglobal( "r_Width" ) ).."x"..tonumber( getglobal( "r_Height" ) ).."x"..bpp;
  424.     UI.PageOptions.GUI.Resolution:Select( sCurrentRes );
  425. end
  426.  
  427. UI.PageOptions.GUI.Resolution.user.ApplySelection = function( self )
  428.  
  429.     local index = UI.PageOptions.GUI.Resolution:GetSelectionIndex();
  430.     local newRes = UI.PageOptions.GUI.Resolution.user.ScreenResolutionAndBpp[ index ];
  431.  
  432.     if( tostring( r_Width ) ~= tostring( newRes.width ) or
  433.             tostring( r_Height )~= tostring( newRes.height ) or
  434.             tostring( r_ColorBits ) ~= tostring( newRes.bpp ) ) then
  435.  
  436.         setglobal( "r_Width", newRes.width );
  437.         setglobal( "r_Height", newRes.height );
  438.         setglobal( "r_ColorBits", newRes.bpp );
  439.  
  440.     end
  441. end
  442.  
  443.  
  444. UI.PageOptions.GUI.FSAA.user.Initialize = function( self )
  445.     -- initalize widget
  446.     UI.PageOptions.GUI.FSAA:Clear();
  447.     
  448.     FSAAModes = System:EnumAAFormats();
  449.     
  450.     UI.PageOptions.GUI.FSAA:AddItem("None");
  451.     
  452.     UI.PageOptions.GUI.FSAA.user.FSAAModes = {};
  453.     
  454.     for n, mode in FSAAModes do
  455.         local i = UI.PageOptions.GUI.FSAA:AddItem(mode.desc);
  456.         
  457.         UI.PageOptions.GUI.FSAA.user.FSAAModes[i] = mode;
  458.     end
  459.     
  460.     -- let widget reflect state of globals
  461.     local fsaa = tonumber(getglobal("r_FSAA" ));
  462.     local fsaaSamples = tonumber(getglobal("r_FSAA_samples"));
  463.     local fsaaQuality = tonumber(getglobal("r_FSAA_quality"));
  464.     if(fsaa ~= 0) then    
  465.         -- find the correct match
  466.         for n, mode in UI.PageOptions.GUI.FSAA.user.FSAAModes do
  467.             if ((fsaaSamples == tonumber(mode.samples)) and (fsaaQuality == tonumber(mode.quality))) then
  468.                 UI.PageOptions.GUI.FSAA:SelectIndex(n);
  469.                 break;
  470.             end            
  471.         end
  472.     else
  473.         UI.PageOptions.GUI.FSAA:SelectIndex(1);
  474.     end;
  475.  
  476.     -- save initial selection state
  477.     UI.PageOptions.GUI.FSAA.user.initialSelectionIndex =
  478.         UI.PageOptions.GUI.FSAA:GetSelectionIndex();
  479.  
  480.     -- disable widget when game is running as FSAA can't be adjusted right now
  481.     if( ClientStuff ) then
  482.         UI:DisableWidget( UI.PageOptions.GUI.FSAA );
  483.     end;
  484. end
  485.  
  486. UI.PageOptions.GUI.FSAA.user.UpdateAssignedGlobals = function( self )
  487.     local curSelectionIndex = UI.PageOptions.GUI.FSAA:GetSelectionIndex();
  488.  
  489.     -- has selection changed
  490.     if( curSelectionIndex ~= UI.PageOptions.GUI.FSAA.user.initialSelectionIndex ) then
  491.         if( curSelectionIndex == 1 ) then
  492.             setglobal( "r_FSAA", 0 );            -- no fsaa
  493.             setglobal( "r_FSAA_samples", 1 );
  494.             setglobal( "r_FSAA_quality", 0 );
  495.         else
  496.             local mode = UI.PageOptions.GUI.FSAA.user.FSAAModes[curSelectionIndex];
  497.             setglobal( "r_FSAA", 1 );            -- no fsaa
  498.             setglobal( "r_FSAA_samples", mode.samples );
  499.             setglobal( "r_FSAA_quality", mode.quality );
  500.         end
  501.         --System:LogToConsole( "FSAA mode and number of FSAA samples changed, relaunch necessary..." );
  502.         --UI.PageOptions.GUI.relaunchNeeded = 1;
  503.         UI.PageOptions.GUI.FSAA.user.initialSelectionIndex = curSelectionIndex;
  504.     end
  505. end
  506.  
  507. UI.PageOptions.GUI.SoundOnOff.user.UpdateAssignedGlobals = function( self )
  508.     local newValue = 0;
  509.     local curValue = tonumber( getglobal( "s_SoundEnable" ) );
  510.  
  511.     if UI.PageOptions.GUI.SoundOnOff:GetChecked() then
  512.         newValue = 1;
  513.     end
  514.     if( newValue ~= curValue ) then
  515.         setglobal( "s_SoundEnable", newValue );
  516.     end
  517. end
  518.  
  519. szScreen = "Options";
  520. UI:CreateScreenFromTable(szScreen, UI.PageOptions.GUI);
  521. Script:LoadScript("Scripts/UIScreens/UISystem.lua", 1);
  522.