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