home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 January / Gamestar_69_2005-01_dvd.iso / Dema / theprojectv1-0.exe / FCData / Scripts.pak / Scripts / OldUI / MenuScreens / Options.lua.bak < prev    next >
Encoding:
Text File  |  2004-08-27  |  10.2 KB  |  410 lines

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