Advertisement
Guest User

WRI

a guest
Oct 15th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // WindowReplicationInfo.
  3. //
  4. // The WRI is used to popup UWindow classes on the client.  Most likely you will
  5. // want to expand this actor in to a child.  It has no built in functionality
  6. // other than making the window appear.
  7. //
  8. //=============================================================================
  9.  
  10. class WRI expands ReplicationInfo;
  11.  
  12. // Replicated Server->Client Variables
  13.  
  14. // What type of Window to open
  15. var() class <UWindowWindow> Window${1}< ${3} >
  16.  
  17. // Dims of the window
  18. var() int WinLeft,WinTop,WinWidth,WinHeight;
  19.  
  20. // Whether the WRI should destroy itself when the window closes
  21. // - default is true
  22. // - should be set to false if you plan to open/close the window repeatedly
  23. var() bool DestroyOnClose;
  24.  
  25. // Client Side Variables
  26.  
  27. // Holds a pointer to the window
  28. var UWindowWindow TheWindow;
  29.  
  30. // Ticks passed since the creation of the uwindows root (counts up to two)
  31. var int TicksPassed;
  32.  
  33. replication
  34. {
  35.    // Functions that Server calls on the Client
  36.    reliable if ( Role == ROLE_Authority)
  37.       OpenWindow, CloseWindow;
  38.  
  39.    // Function the Client calls on the Server
  40.    reliable if ( Role < ROLE_Authority )
  41.       DestroyWRI;
  42. }
  43.  
  44. // Post(Net)BeginPlay - This is a simulated function that is called everywhere, and creates a window on the appropriate machine.
  45. // Intended for the user attempting to create the window
  46.  
  47. // The OpenWindow should only be called from one place: the owner's machine.
  48. // To detect when we are on the owner's machine, we check the playerpawn's Player var, and their console.
  49. // Since these only exist on the machine for which they are used,
  50. //   their existence ensures we are running on the owner's machine.
  51. // Once that has been validated, we call OpenWindow.
  52.  
  53. // The reason for BOTH the PostNetBeginPlay and PostBeginPlay is slightly strange.
  54. // PostBeginPlay is called on the client if it is simulated, but it is before the variables have been replicated
  55. //   Thus, Owner is not replicated yet, and the WRI is unable to spawn the window
  56. // PostNetBeginPlay is called after the variables have been replicated, and so is appropriate
  57. //   It is not called on the server machine (NM_Standalone or NM_Listen) because no variables are replicated to that machine
  58. //   And so, PostBeginPlay is needed for those types of servers
  59.  
  60. event PostBeginPlay()
  61. {
  62.    Super.PostBeginPlay();
  63.    OpenIfNecessary();
  64. }
  65.  
  66. simulated event PostNetBeginPlay ()
  67. {
  68.    Super.PostBeginPlay();
  69.    OpenIfNecessary();
  70. }
  71.  
  72. simulated function OpenIfNecessary ()
  73. {
  74.    local PlayerPawn P;
  75.    if (Owner!=None)
  76.    {
  77.       P = PlayerPawn(Owner);
  78.       if (P!=None && P.Player!=None && P.Player.Console !=None)
  79.       {
  80.          OpenWindow();
  81.       }
  82.    }
  83. }
  84.  
  85. // OpenWindow - This is a client-side function who's job is to open on the window on the client.
  86. // Intended for the user attempting to create the window
  87.  
  88. // This first does a lot of checking to make sure the player has a console.
  89. // Then it creates and sets up UWindows if it has not been set up yet.
  90. // This can take a long period of time, but only happens if you join from GameSpy.
  91. //   (eg: connect to a server without using the uwindows stuff to do it)
  92. // Then it sets up bQuickKeyEnable so that the menu/status bar don't show up.
  93. // And finally, says to launch the window two ticks from the call to OpenWindow.
  94. // If the Root could have been created this tick, then it does not contain the height and width
  95. //   vars that are necessary to position the window correctly.
  96.  
  97. simulated function bool OpenWindow()
  98. {
  99.  
  100.    local PlayerPawn P;
  101.    local WindowConsole C;
  102.  
  103.    P = PlayerPawn(Owner);
  104.    if (P==None)
  105.    {
  106.       log("#### -- Attempted to open a window on something other than a PlayerPawn");
  107.  
  108.       DestroyWRI();
  109.       return false;
  110.    }
  111.  
  112.    C = WindowConsole(P.Player.Console);
  113.    if (C==None)
  114.    {
  115.       Log("#### -- No Console");
  116.       DestroyWRI();
  117.       return false;
  118.    }
  119.  
  120.    if (!C.bCreatedRoot || C.Root==None)
  121.    {
  122.       // Tell the console to create the root
  123.       C.CreateRootWindow(None);
  124.    }
  125.  
  126.    // Hide the status and menu bars and all other windows, so that our window alone will show
  127.    C.bQuickKeyEnable = true;
  128.  
  129.    C.LaunchUWindow();
  130.  
  131.    //tell tick() to create the window in 2 ticks from now, to allow time to get the uwindow size set up
  132.    TicksPassed = 1;
  133.  
  134.    return true;
  135.  
  136. }
  137.  
  138. // Tick - Counts down ticks in TickPassed until they hit 0, at which point it really creates the window
  139. // Also destroys the WRI when they close the window if DestroyOnClose == true
  140. // Intended for the user attempting to create the window, or close the window
  141.  
  142. // See the description for OpenWindow for the reasoning behind this Tick.
  143. // After two ticks, it creates the window in the base Root, and sets it up to work with bQuickKeyEnable.
  144.  
  145. // This also calls DestroyWRI if the WRI is setup to DestroyOnClose, and the window is closed
  146. simulated function Tick(float DeltaTime)
  147. {
  148.    if (TicksPassed != 0)
  149.    {
  150.       if (TicksPassed++ == 2)
  151.       {
  152.          SetupWindow();
  153.          // Reset TicksPassed to 0
  154.          TicksPassed = 0;
  155.       }
  156.    }
  157.    if (DestroyOnClose && TheWindow != None && !TheWindow.bWindowVisible)
  158.    {
  159.       DestroyWRI();
  160.    }
  161. }
  162.  
  163. simulated function bool SetupWindow ()
  164. {
  165.    local WindowConsole C;
  166.  
  167.    C = WindowConsole(PlayerPawn(Owner).Player.Console);
  168.  
  169.    TheWindow = C.Root.CreateWindow(WindowClass, WinLeft, WinTop, WinWidth, WinHeight);
  170.  
  171.    if (TheWindow==None)
  172.    {
  173.       Log("#### -- CreateWindow Failed");
  174.       DestroyWRI();
  175.       return false;
  176.    }
  177.  
  178.    if ( C.bShowConsole )
  179.       C.HideConsole();
  180.  
  181.    // Make it show even when everything else is hidden through bQuickKeyEnable
  182.    TheWindow.bLeaveOnScreen = True;
  183.  
  184.    // Show the window
  185.    TheWindow.ShowWindow();
  186.  
  187.    return true;
  188. }
  189.  
  190. // CloseWindow -- This is a client side function that can be used to close the window.
  191. // Intended for the user attempting to create the window
  192.  
  193. // Undoes the bQuickKeyEnable stuff just in case
  194. // Then turns off the Uwindow mode, and closes the window.
  195.  
  196. simulated function CloseWindow()
  197. {
  198.    local WindowConsole C;
  199.  
  200.    C = WindowConsole(PlayerPawn(Owner).Player.Console);
  201.  
  202.    C.bQuickKeyEnable = False;
  203.    C.CloseUWindow();
  204.  
  205.    if (TheWindow!=None)
  206.    {
  207.       TheWindow.Close();
  208.    }
  209.  
  210. }
  211.  
  212. // ==========================================================================
  213. // These functions happen on the server side
  214. // ==========================================================================
  215.  
  216. // DestoryWRI - Gets rid of the WRI and cleans up.
  217. // Intended for the server or authority, which *could* be the user that had the window (in a listen server or standalone game)
  218.  
  219. // Should be called from the client when the user closes the window.
  220. // Subclasses should override it and do any last minute processing of the data here.
  221.  
  222. function DestroyWRI()
  223. {
  224.    Destroy();
  225. }
  226.  
  227. // Make sure any changes to the WindowClass get replicated in the first Tick of it's lifetime
  228. // Ahead of everything else (UT uses a max of 3)
  229. // Use SimulatedProxy so that the Tick() calls are executed
  230.  
  231. defaultproperties
  232. {
  233.     DestroyOnClose=True
  234.     RemoteRole=ROLE_SimulatedProxy
  235.     NetPriority=10.00
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement