Announcement

Collapse
No announcement yet.

Creating a Mouse Cursor in the HUD

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #46
    No. I've just gone through the tutorial again to be sure it's still working, and it is. If it's not working for you, then you've possibly missed something or not done something correctly as stated. My best advice to you is to go through each step again, and ensure you follow it to the letter. Everything you need to know is written in the tut.

    Comment


      #47
      Thanks for mentioning the Cursor class I made.

      I did have plans to update it and release all the other nice little scaleform components I made but I have been away from the scene since last November due to family issues.

      It made my day to see my class being pimped out as a possible solution

      Thanks !

      Comment


        #48
        How are exec functions run from the hudwrapper? When I try to run an exec function that is in a class extending the wrapper it says "command not recognized". I can only run an exec function from the playercontroller. Is there something that I am supposed to do to enable exec functions to run in classes other than my playercontroller?

        Thank you very much.

        Comment


          #49
          ConsoleCommand ...

          Comment


            #50
            console command

            That is the problem that I am having. When I run a console command with the name of the exec function it won't run. I get an error(Command Not Recognized) and nothing happens. It says that it can't recognize the command. When I run the exec function from the GamePlayerController, however, it works fine, but I can't access the functions from that class.

            Comment


              #51
              Code:
              ConsoleCommand("open BT-Test?game=BetterTech.BTGame?NumPlay=8?name=EnderWiggins");
              Works fine from a movie player.

              Comment


                #52
                error

                When I try to run this console command that is an exec function it says "command not recognized" only when the exec function is in "game player controller" does it work.

                What could I be doing wrong?

                Thank you very much

                Comment


                  #53
                  I figured out what it was, I was not updating the class as the used hud in my gameinfo class. The command could not be found because it was not part of the build.

                  Comment


                    #54
                    Matt, is it still possible to do this comment thing that you wrote about a year ago? Neither I nor visual studio can find this line in any of the .ini files.

                    Comment


                      #55
                      When I try to compile this part

                      simulated function PostBeginPlay()
                      {
                      super.PostBeginPlay();

                      // Your HUD instantiation code here...

                      // Stage.originalRect contains the original width and height of the SWF file.
                      // Replace HudMovie with the name of your instantiated HUD.
                      HudMovieSize = HudMovie.GetVariableObject("Stage.originalRect");

                      MouseInterfacePlayerInput = MouseInterfacePlayerInput(PlayerOwner.PlayerInput) ;
                      }
                      An error is given "Missing ';' before'('

                      ????

                      What is causing this?

                      Comment


                        #56
                        You've not ended a line of code with a semi-colon somewhere. You need to crawl through your code checking each line for semi-colons if no line number is given.

                        Comment


                          #57
                          Hey Matt,
                          I've been working through your tutorial, and I've hit a brick wall. I'm 12 hours into trying to solve me problem and, needless to say, it's not going well. I'm using the September 2011 version of UDK.

                          When I don't include the mouse cursor movie clip, and it's child movie clip, my dynamic text box still appears in the HUD. However, after including them; nothing appears, even when pressing/holding Left Shift. I'm really racking my brain at this; any ideas?

                          Player Controller class
                          Code:
                          class PSTestPlayerController extends UTPlayerController;
                          
                          var float Energy;
                          var float EnergyMax;
                          var float EnergyDelta;
                          var float Lives;
                          var bool setup;
                          var int Min;
                          var int Sec;
                          var string Message;
                          var bool GameOver;
                          
                          DefaultProperties
                          {
                          	bForceBehindView=false
                          	Energy = 100.0
                          	EnergyMax = 100.0
                          	EnergyDelta = -0.5
                          	Lives = 3.0
                          	Sec = 0;
                          	Min = 0;
                          	setup = false;
                          	Message = "";
                          	GameOver = false;
                          	//cursor support
                          	InputClass=class'MouseInterfacePlayerInput'
                          }
                          
                          public function AddEnergy(SeqAct_GiveEnergy action)
                          {
                          	//whether the button has been touched, or is empty, set the delta value for the energy
                          	if(!GameOver)
                          	{
                          		EnergyDelta = action.Amount;
                          	}
                          }
                          
                          simulated function PlayerTick(float DeltaTime)
                          {
                          	super.PlayerTick(DeltaTime);
                          	if(!GameOver)
                          	{
                          		if(!setup)
                          		{
                          			//start the timer for the end game (seen in green)
                          			setTimer(1.0, false, 'UpdateTimer');
                          			setup = true;
                          		}
                          		if(((Energy + EnergyDelta) <= EnergyMax) && ( (Energy + EnergyDelta) >= 0.0))
                          		{
                          			//update the energy (may be positive or negative)
                          			Energy += EnergyDelta;
                          		}
                          		if((Energy + EnergyDelta) > EnergyMax)
                          		{
                          			//makes the energy cap pretty
                          			Energy = 100.0;
                          		}
                          		if( (Energy + EnergyDelta) <= 0.0)
                          		{
                          			//deduct a life if energy falls to, or below, 0
                          			Lives -= 1.0;
                          			Energy = 100.0;
                          		}
                          		if(Lives <= 0.0)
                          		{
                          			//player loses
                          			endGame(0);
                          		}
                          	}
                          	else
                          	{
                          		Energy = 0.0;
                          	}
                          }
                          
                          simulated event UpdateTimer()
                          {
                          	//update the timer
                          	Sec++;
                          	if(Sec == 60)
                          	{
                          		Min++;
                          		Sec = 0;
                          	}
                          	if(Min == 4)
                          	{
                          		//player wins
                          		EndGame(1);
                          	}
                          	if(!GameOver)
                          	{
                          		setTimer(1.0, false, 'UpdateTimer');
                          	}
                          }
                          
                          public function EndGame(int type)
                          {
                          	//end the game (type = 0 fail, type = 1 success)
                          	if(type == 1)
                          	{
                          		Message = "Player Wins!";
                          		GameOver = true;
                          	}
                          	else
                          	{
                          		Message = "Player Loses :(";
                          		GameOver = true;
                          	}
                          }
                          Player HUD Wrapper class
                          Code:
                          class PSTestHUD extends UTHUDBase;
                          
                          //reference the actual SWF container
                          var PSGFxHUD HudMovie;
                          //for mouse support
                          var GFxObject HudMovieSize;
                          var MouseInterfacePlayerInput MouseInterfacePlayerInput;
                          var float MouseX, MouseY;
                          
                          DefaultProperties
                          {
                          }
                          
                          //called when this is destoryed
                          singular event Destroyed(){
                          	if (HudMovie != none){
                          		//get rid of the memory usage of HudMovie
                          		HudMovie.Close(true);
                          		HudMovie = none;
                          	}
                          	//super.Destroyed(); //not needed?
                          }
                          
                          //called after game loaded, init things
                          simulated function PostBeginPlay(){
                          	super.PostBeginPlay();
                          	
                          	//create a PSGFxHUD for HudMovie
                          	HudMovie = new class'PSGFxHUD';
                          	//set the HudMovie's player owner
                          	HudMovie.PlayerOwner = PSTestPlayerController(PlayerOwner);
                          	//set the timing mode to TM_Real - otherwise things get paused in menus
                          	HudMovie.SetTimingMode(TM_Real);
                          	//call HudMovie's init function
                          	HudMovie.loadASElements(HudMovie.GetPC());
                          	
                          	//cursor support
                          	HudMovieSize = HudMovie.GetVariableObject("Stage.originalRect");
                          	MouseInterfacePlayerInput = MouseInterfacePlayerInput(PlayerOwner.PlayerInput);
                          }
                          
                          exec function SetShowCursor(bool showCursor){
                          	HudMovie.ToggleCursor(showCursor, MouseX, MouseY);
                          }
                          
                          event PostRender(){	
                          	super.PostRender();
                              MouseX = MouseInterfacePlayerInput.MousePosition.X;
                              MouseY = MouseInterfacePlayerInput.MousePosition.Y;
                          
                              // Tick HUD
                              if (HudMovie != none){
                          		HudMovie.TickHud();
                              }
                          }
                          
                          //////////////////////////////////////////old, 3 rows of bars HUD
                          /*
                          function DrawGameHud()
                          {
                          	local PSTestPlayerController PC;
                          	PC = PSTestPlayerController(PlayerOwner);
                          
                              if ( !PlayerOwner.IsDead() && !UTPlayerOwner.IsInState('Spectating'))
                              {
                                  DrawBar("Health", PlayerOwner.Pawn.Health, PlayerOwner.Pawn.HealthMax,20,20,200,80,80);
                          		DrawBar("Ammo",(UTWeapon(PawnOwner.Weapon).AmmoCount), (UTWeapon(PawnOwner.Weapon).MaxAmmoCount) ,20,40,80,80,200);
                          		DrawBar("Energy", PC.Energy, PC.EnergyMax, 20, 60, 255, 255, 0);
                          		Canvas.SetPos(20, 80);
                          		Canvas.SetDrawColor(255, 255, 0);
                          		Canvas.Font = class'Engine'.static.getSmallFont();
                          		Canvas.DrawText("Energy:"$PC.Energy);
                          		Canvas.SetPos(130, 80);
                          		Canvas.DrawText("Max:"$PC.EnergyMax);
                          		Canvas.SetPos(230, 80);
                          		Canvas.DrawText("Lives:"$PC.Lives);
                          		Canvas.SetPos(20, 100);
                          		Canvas.SetDrawColor(0, 255, 0);
                          		Canvas.DrawText("Time:"$PC.Min$":"$PC.Sec);
                          		Canvas.SetPos(220, 220);
                          		Canvas.SetDrawColor(0, 0, 255);
                          		Canvas.DrawText(PC.Message);
                          	}
                          
                          }	
                          
                          
                          function DrawBar(String Title, float Value, float MaxValue,int X, int Y, int R, int G, int B)
                          {
                              local int PosX,NbCases,i;
                          
                              PosX = X; // Where we should draw the next rectangle
                              NbCases = 10 * Value / MaxValue;	 // Number of active rectangles to draw
                              i=0; // Number of rectangles already drawn
                          
                              /* Displays active rectangles */
                              while(i < NbCases && i < 10)
                              {
                                  Canvas.SetPos(PosX,Y);
                                  Canvas.SetDrawColor(R,G,B,200);
                                  Canvas.DrawRect(8,12);
                          
                                  PosX += 10;
                                  i++;
                          
                              }
                          
                              /* Displays deactived rectangles */
                              while(i < 10)
                              {
                                  Canvas.SetPos(PosX,Y);
                                  Canvas.SetDrawColor(255,255,255,80);
                                  Canvas.DrawRect(8,12);
                          
                                  PosX += 10;
                                  i++;
                          
                              }
                          
                              /* Displays a title ( "VARIABLE: [boxes]" */
                              Canvas.SetPos(PosX + 5,Y);
                              Canvas.SetDrawColor(R,G,B,200);
                              Canvas.Font = class'Engine'.static.GetSmallFont();
                              Canvas.DrawText(Title);
                          }
                          */
                          Player GFxHud class
                          Code:
                          class PSGFxHUD extends GFxMoviePlayer;
                          
                          //create variables to hold references to the Flash MovieClips and Text Fields that will be modified
                          var GFxObject ChatTF;
                          var bool update; //if the chat should be updated, do so
                          var int counter; //for debuging
                          //for mouse cursor support
                          var GFxObject RootMC, MouseContainer, MouseCursor;
                          var array<ASValue> args;
                          var bool bRollOver; //is the mouse over a button?
                          var string focusedButton; //what is the name of the button the mouse is over?
                          
                          var PSTestPlayerController PlayerOwner;
                          
                          function Init(optional LocalPlayer player)
                          {
                              super.Init(player);
                          	
                              Start();
                              Advance(0);
                          	
                          	RootMC = GetVariableObject("_root");
                          	AddFocusIgnoreKey('LeftShift'); //change to left Alt?
                          }
                          
                          //called from PSHud's PostBeginPlay()
                          function loadASElements(PlayerController PC)
                          {
                          	//start and load the SWF Movie
                          	//Start();
                          	//Advance(0.f);
                          	
                          	//chat dynamic text field
                          	ChatTF = GetVariableObject("_root.chatbox_txt");
                          }
                          
                          event UpdateMousePosition(float X, float Y)
                          {
                              local MouseInterfacePlayerInput MouseInterfacePlayerInput;
                          
                              MouseInterfacePlayerInput = MouseInterfacePlayerInput(GetPC().PlayerInput);
                          
                              if (MouseInterfacePlayerInput != None)
                              {
                                  MouseInterfacePlayerInput.SetMousePosition(X, Y);
                              }
                          }
                          
                          //called every update Tick
                          function TickHUD(){
                          	local UTPawn UTP;
                          	
                          	//create a reference and check if Pawn exists
                          	UTP = UTPawn(PlayerOwner.Pawn);
                          	if(UTP == None){
                          		return;
                          	}
                          	
                          	//if the cached value for the Health percent isn't equal to the current...
                          	if(update){
                          		//update chat field
                          		counter++;
                          		ChatTF.SetString("text", "Counted to: "$counter);
                          		update = false;
                          	}
                          }
                          
                          function GFxObject CreateMouseCursor()
                          {
                              return RootMC.AttachMovie("MouseContainer", "MouseCursor");
                          }
                          
                          /** Toggles mouse cursor on/off */
                          function ToggleCursor(bool showCursor, float mx, float my)
                          {	
                              if (showCursor)
                              {
                          	MouseContainer = CreateMouseCursor();
                          	MouseCursor = MouseContainer.GetObject("my_cursor");
                          	MouseCursor.SetPosition(mx,my);
                          	MouseContainer.SetBool("topmostLevel", true);
                              }
                              else
                              {
                          	MouseContainer.Invoke("removeMovieClip", args);
                          	MouseContainer = none;	
                              }
                          	
                              self.bIgnoreMouseInput = !showCursor;		
                          }
                          
                          DefaultProperties
                          {
                          	//this is the HUD. if the HUD is off, then this should be off
                          	bDisplayWithHudOff=false
                          	//the path to the .swf asset
                          	MovieInfo=SwfMovie'PSTestAssets.HUD.chatHud'
                          	//bGammaCorrection = false //unrecognized, depricated?
                          	update = true
                          	counter = 0
                          	//for toggleable mouse cursor support
                          	bIgnoreMouseInput = true
                          }
                          MouseInterfacePlayerInput class
                          Code:
                          class MouseInterfacePlayerInput extends PlayerInput;
                          
                          // Stored mouse position. Set to private write as we don't want other classes to modify it, but still allow other classes to access it.
                          var PrivateWrite IntPoint MousePosition; 
                          var PSTestHud PSTestHud;
                          var float HudX, HudY;
                          
                          event PlayerInput(float DeltaTime)
                          {
                              GetHudSize();
                          	
                              if (myHUD != None){
                          		// Add the aMouseX to the mouse position and clamp it within the viewport width
                          		MousePosition.X = Clamp(MousePosition.X + aMouseX, 0, HudX); 
                          		// Add the aMouseY to the mouse position and clamp it within the viewport height
                          		MousePosition.Y = Clamp(MousePosition.Y - aMouseY, 0, HudY); 
                              }
                              Super.PlayerInput(DeltaTime);
                          }
                          
                          // This function gets the original width and height of the HUD SWF and stores those values in HudX and HudY.
                          function GetHudSize()
                          {
                              // First store a reference to our HUD Wrapper and get the resolution of the HUD
                              PSTestHud = PSTestHud(myHUD);
                              HudX = PSTestHud.HudMovieSize.GetFloat("width");
                              HudY = PSTestHud.HudMovieSize.GetFloat("height");
                          }
                          
                          function SetMousePosition(int X, int Y)
                          {
                              GetHudSize();
                          	
                              if (MyHUD != None){
                          		MousePosition.X = Clamp(X, 0, HudX);
                          		MousePosition.Y = Clamp(Y, 0, HudY);
                              }
                          }
                          
                          defaultproperties
                          {
                          }
                          Thank you

                          Comment


                            #58
                            With a quick glance I can already tell you that you want to have the DefaultProperties as the very last block in your classes.
                            Doing otherwise might cause unwanted behaviour.

                            Other than that, I've got nothing atm.

                            Comment


                              #59
                              that didn't seem to help, but thanks anyways

                              Comment


                                #60
                                found my problem- I had 2 sets of the same AS script code, and one set had an error in it :P

                                Comment

                                Working...
                                X