User:Maven/sandbox: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(attempting rewrite of vgui_screen article)
(more mucking about)
Line 11: Line 11:
*'''Panel Height in World''' = 32
*'''Panel Height in World''' = 32


Height and Width can be changed to whatever you need. Those values define the actual size of the screen in the world.
Height and width can be changed to whatever you need. Those values define the actual size of the screen in the world.


==Creating a VGUI script==
==Creating a VGUI screen==


==VGUI code modifications==
'''TODO:''' Can .res files be zipped into a BSP? If so, much of this section needs adjusted.


=== Getting it to load ===
VGUI screen files have a ''.res'' extension and should be placed in <code>''steamdir''\SourceMods\''yourmod''\scripts\screens\</code>.


1) Create a .res file in <codE>''steamdir''\SourceMods\''yourmod''\scripts\screens</code>. This example is called <code>vgui_test_screen.res</code>:
# <code>vgui_test_screen.res</code> is a good starting point for creating a VGUI screen file; it can be extracted from <code>source engine.gcf</code> at path <code>hl2/scripts/screens/</code> using [[GCFScape]].
 
"screen_basic.res"
{
    "Background"
    {
        "ControlName" "MaterialImage"
        "fieldName"  "Background"
        "xpos"  "0"
        "ypos"  "0"
        "zpos"  "-2"
        "wide"  "480"
        "tall"  "240"
        "material"  "vgui/screens/vgui_overlay"
    }
    "OwnerReadout"
    {
        "ControlName" "Label"
        "fieldName"  "OwnerReadout"
        "xpos"  "10"
        "ypos"  "20"
        "wide"  "240"
        "tall"  "34"
        "autoResize" "0"
        "pinCorner"  "0"
        "visible"  "1"
        "enabled"  "1"
        "tabPosition" "0"
        "labelText"  "No Owner"
        "textAlignment" "center"
        "dulltext"  "0"
        "paintBackground" "0"
    }
    "HealthReadout"
    {
        "ControlName" "Label"
        "fieldName"  "HealthReadout"
        "xpos"  "240"
        "ypos"  "20"
        "wide"  "240"
        "tall"  "34"
        "autoResize" "0"
        "pinCorner"  "0"
        "visible"  "1"
        "enabled"  "1"
        "tabPosition" "0"
        "labelText"  "Health: 100%"
        "textAlignment" "center"
        "dulltext"  "0"
        "paintBackground" "0"
    }
    "DismantleButton"
    {
        "ControlName" "MaterialButton"
        "fieldName"  "Dismantle"
        "xpos"  "78"
        "ypos"  "160"
        "wide"  "324"
        "tall"  "48"
        "autoResize" "0"
        "pinCorner"  "0"
        "visible"  "1"
        "enabled"  "1"
        "tabPosition" "2"
        "labelText"  "Dismantle"
        "textAlignment" "center"
        "dulltext"  "0"
        "brighttext" "0"
        "Default"  "0"
        "command"  "quit"
        "paintborder" "0"
        "enabledImage"
        {
            "material" "vgui/screens/vgui_button_enabled"
            "color" "255 255 255 255"
        }
        "mouseOverImage"
        {
            "material" "vgui/screens/vgui_button_hover"
            "color" "255 255 255 255"
        }
        "pressedImage"
        {
            "material" "vgui/screens/vgui_button_pushed"
            "color" "255 255 255 255"
        }
        "disabledImage"
        {
            "material" "vgui/screens/vgui_button_disabled"
            "color" "255 255 255 255"
        }
    }
}


2) The materials used in the .res file can be found in source material.gcf using [[GCFScape]]. Extract the files in hl2\materials\vgui\screens to ''steamdir''\SourceMods\''moddir''\materials\vgui\screens.
# The materials used in the ''.res'' file can be found in <code>source materials.gfc</code>. Extract the material files mentioned in the ''.res'' file to <code>''steamdir''\SourceMods\''moddir''\materials\vgui\screens</code>.


3) In ''steamdir''\SourceMods\''moddir''\scripts create or open the text file vgui_screens.txt and add a new entry for the screen.
# <code>In ''steamdir''\SourceMods\''moddir''\scripts</code> create or open the text file <code>vgui_screens.txt</code> and add a new entry. An example would be:
ex.


  "VGUI_Screens"
  "VGUI_Screens"
Line 138: Line 45:
  }
  }


==VGUI code modifications==
There is a problem with VGUI screens receiving input.
'''TODO''': what are the effects? Is it a crash bug?
<code>CInput::ExtraMouseSample</code> calls <code>g_pClientMode->CreateMove()</code> without initializing the button flags, thus the VGui screen is updated with bad button input.  Since <code>IN_VALIDVGUIINPUT</code> is only set from within <code>CInput::CreateMove</code>, the VGui screens only update when the button flags are valid.


=== Getting Input to work ===
There are two known fixes. They both involve code changes and therefore are only applicable to mods.
Here is the proper way of fixing vgui input:
 
=== Fix 1 ===


In '''in_buttons.h''', where the other flags are defined add:
In '''in_buttons.h''', where the other flags are defined add:
     #define IN_VALIDVGUIINPUT     (1 << 23) //bitflag for vgui fix
     #define IN_VALIDVGUIINPUT     (1 << 23) //bitflag for vgui fix


next, in '''in_main.cpp''' inside the method - CInput::CreateMove(...)
next, in '''in_main.cpp''' inside method <code>CInput::CreateMove( ''...'' )</code>
add:
add:
     cmd->buttons |= IN_VALIDVGUIINPUT;
     cmd->buttons |= IN_VALIDVGUIINPUT;
Line 152: Line 67:




next, in '''c_baseplayer.cpp''' inside the method - C_BasePlayer::CreateMove( ... )
next, in '''c_baseplayer.cpp''' inside method <code>C_BasePlayer::CreateMove( ''...'' )</code>
add:
add:
     if(pCmd->buttons & IN_VALIDVGUIINPUT)
     if(pCmd->buttons & IN_VALIDVGUIINPUT)
right above:
right above:
     DetermineVguiInputMode( pCmd );
     DetermineVguiInputMode( pCmd );
''(So it only calls DetermineVguiInputMode if the buttons include our flag)''
''(So it only calls <code>DetermineVguiInputMode</code> if the buttons include our flag)''


and finally, inside the method - C_BasePlayer::DetermineVguiInputMode(...)
and finally, inside method <code>C_BasePlayer::DetermineVguiInputMode( ''...'' )</code>
change '''''both''''' instances of:
change '''both''' instances of:
     pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2);
     pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2);
to read:
to read:
     pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2 | IN_VALIDVGUIINPUT);
     pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2 | IN_VALIDVGUIINPUT);


=== Fix 2 ===


The reason we do this is because <code>CInput::ExtraMouseSample</code> calls <code>g_pClientMode->CreateMove()</code> without initializing the button flags, thus the VGui screen is updated with bad button input.  Since IN_VALIDVGUIINPUT is only set from within <code>CInput::CreateMove</code>, the VGui screens only update when the button flags are valid.
An alternative fix would be to add a new boolean variable to <code>CUserCmd</code> such as <code>bButtonFlagsValid</code> that can be set depending on the validity of the button flags.  This would allow the structure to internally store this information for its whole lifetime while freeing up that extra button bit.
 
=== Alternative Fix ===
 
An alternative fix would be to add a new variable to '''CUserCmd''' such as bButtonFlagsValid that can be set to either '''true''' or '''false''' depending on the validity of the button flags.  This would allow the structure to internally store this information for its whole lifetime while freeing up that extra button bit.
 
=== Further Possibilities ===
1) Make it so that when a player is viewing the screen, all input is sent to the screen, including movement keys. The player will not be able to move again, until they look outside the bounds of the screen.


== External links ==
== External links ==
* [http://www.jakoavain.net/helk/granted.jpg Screenshot of working panels in the mod Hostile Planet]
* [http://www.jakoavain.net/helk/granted.jpg Screenshot of working panels in the mod Hostile Planet]

Revision as of 13:43, 23 September 2005

This is my personal sandbox area.


Adding a VGUI screen to a map

Create a vgui_screen with the following properties:

  • Panel Name = vgui_test_screen
  • Panel Width in World = 64
  • Panel Height in World = 32

Height and width can be changed to whatever you need. Those values define the actual size of the screen in the world.

Creating a VGUI screen

TODO: Can .res files be zipped into a BSP? If so, much of this section needs adjusted.

VGUI screen files have a .res extension and should be placed in steamdir\SourceMods\yourmod\scripts\screens\.

  1. vgui_test_screen.res is a good starting point for creating a VGUI screen file; it can be extracted from source engine.gcf at path hl2/scripts/screens/ using GCFScape.
  1. The materials used in the .res file can be found in source materials.gfc. Extract the material files mentioned in the .res file to steamdir\SourceMods\moddir\materials\vgui\screens.
  1. In steamdir\SourceMods\moddir\scripts create or open the text file vgui_screens.txt and add a new entry. An example would be:
"VGUI_Screens"
{
   "vgui_test_screen"
   {
       // This is our example screen
       "type"		"vgui_screen_panel"
       "pixelswide"	480
       "pixelshigh"	240
       // This must be the file you created in step 1
       "resfile"	"scripts/screens/vgui_test_screen.res"
   } 
   "teleport_countdown_screen"
   {
       "type"		"teleport_countdown_screen"
       "pixelswide"	480
       "pixelshigh"	240
       "resfile"	"scripts/screens/teleport_countdown_screen.res"
   }
}

VGUI code modifications

There is a problem with VGUI screens receiving input.

TODO: what are the effects? Is it a crash bug?

CInput::ExtraMouseSample calls g_pClientMode->CreateMove() without initializing the button flags, thus the VGui screen is updated with bad button input. Since IN_VALIDVGUIINPUT is only set from within CInput::CreateMove, the VGui screens only update when the button flags are valid.

There are two known fixes. They both involve code changes and therefore are only applicable to mods.

Fix 1

In in_buttons.h, where the other flags are defined add:

   #define IN_VALIDVGUIINPUT		    (1 << 23) //bitflag for vgui fix

next, in in_main.cpp inside method CInput::CreateMove( ... ) add:

   cmd->buttons |= IN_VALIDVGUIINPUT;

right above:

   g_pClientMode->CreateMove( input_sample_frametime, cmd );


next, in c_baseplayer.cpp inside method C_BasePlayer::CreateMove( ... ) add:

   if(pCmd->buttons & IN_VALIDVGUIINPUT)

right above:

   DetermineVguiInputMode( pCmd );

(So it only calls DetermineVguiInputMode if the buttons include our flag)

and finally, inside method C_BasePlayer::DetermineVguiInputMode( ... ) change both instances of:

   pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2);

to read:

   pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2 | IN_VALIDVGUIINPUT);

Fix 2

An alternative fix would be to add a new boolean variable to CUserCmd such as bButtonFlagsValid that can be set depending on the validity of the button flags. This would allow the structure to internally store this information for its whole lifetime while freeing up that extra button bit.

External links