Announcement

Collapse
No announcement yet.

Creating a Mouse Cursor in the HUD

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

  • replied
    @Matt Doyle

    I do believe this tutorial is broken in the 2013-07 UDK build. I've scoured the tutorial and triple checked all of the elements. No compile errors, and when I run the game, no errors in the Log. When I press Left Shift, the Mouse cursor appears in the top left corner of the screen and if I release Left Shift, it disappears (no log errors). However, the mouse cursor does not move at all. It would appear that in AS2, where I add the mouseListener, the code doesn't actually fire off any message when the onMouseMove event happens. I've included an ExternalInterface.call() from within that AS2 frame just to check if the code gets touched and it does in fact run and add the mouseListener, it's just that the onMouseMove does not ever get triggered. One interesting thing though is that when I use the Scaleform GFxPlayer Launcher from inside of Flash, that the UpdateMousePosition does receive a callback and appears to be working properly (showing updated mouse coordinates).

    My Flash document is AS2.0 running Flash Player 11.2.

    I've also tried a different method using onClipEvent (as suggested earlier in this thread), but that does not work either. I've had success using onClipEvent(mouseMove) in other flash files for my main menu, but for some reason when I extend Scaleform's default HUDWrapper class and try to do anything with the mouse, it doesn't seem to work.

    Lastly, I also searched my source code for any instances of bIgnoreMouseInput, but I did not find any that were relevant (I found 1 other instance but I tried flipping the boolean on it and it made no difference).

    Any help you could shine on this would be greatly appreciated.

    Thanks,
    Justin

    UPDATE1:
    I followed disReGard's instructions on how they implemented their mouse into the HUD and I was able to get it working, however, his method imports the mouse as a separate GFxMoviePlayer movie file. This creates it's own problems because of course I cannot click on buttons in 1 swf if the mouse is in the other swf. However, what is confusing to me is that if I copy/paste only a few changes so that the mouse is not loaded as a seperate GFxMovie, and I just place the mouse cursor directly into my HUD .swf file, it does not work. So basically I can get it working if I load the mouse as a new GFxMoviePlayer, however, if I just want the mouse to work directly inside my HUD it doesn't move. Really strange! PS - I've been a software developer for over 5 years now and before that I was a Ux developer so I am very familiar with Flash and have been working in UDK for about 6 months. I'm by far a novice still with UDK but why Flash won't provide a callback in 1 flash file, but it does from another is just mind boggling!

    Link to the tutorial on how to load mouse from a different swf
    http://forums.epicgames.com/threads/...1#post28319144

    UPDATE2 SOLVED:
    The reason why my Hud wrapper wasn't picking up the mouse input is because I was extending the GFxMinimapHud, and that by default has bAllowInput and bAllowFocus set to false. If you set those to true it works.

    Leave a comment:


  • replied
    Originally posted by Hex0n View Post
    This tutorial seems completely broken even at the time when it was written. How the hell is "MouseCursor = MouseContainer.GetObject("my_cursor");" supposed to works since following the tutorial we never assign "my_cursor" anywhere, nor in Unreal Script or Flash ?

    Does anyone has a working tutorial for mouse cursor in hud please ? I tried to put Skalamondre's AS code in MouseContainer but it haven't changed anything ! Mouse cursor won't move and the code to find the SWF size is broken too ! Everything is broken !
    Change the line to this:


    Code:
    MouseCursor = MouseContainer.GetObject("mouseCursor_mc");

    Leave a comment:


  • replied
    I can't really confirm whether or not the tutorial works but I can tell you that in script I don't really worry too much about where the mouse is at any given moments. I'm only worried about the mouse click call back events that happen when a button is pressed. So what I'm saying is that the onClipEvent(mouseMove) I mentioned earlier just makes sure that flash keeps the mouse icon updated so that it shows where it should as the player moves it.

    When you use .GetObject it actually will get the object in the movie by name. So if you have an object on the _root of the movie (not just in the library but on the stage) you name it and can then access it like this:

    (In this example I have an object on the _root of a movie called "MovieObject" and it has a child object called "MovieObjectChild." I use GetVariableObject instead of GetObject.)

    Code:
    //Sets up a var to reference the objects with from script
    var GfxObject MyObject;
    var GfxObject MyObjectChild;
    
    MyObject = getVariableObject("_root.MovieObject"); // Literally assigning the object in the movie to the var we setup.
    MyObjectChild = MyObject.getVariableObject("MovieObjectChild"); //Since we now assigned MyObjectChild we can use getObject on it directly to reference another object.
    
    //We could also have done:
    MyObjectChild = MyObject.getVariableObject("_root.MovieObject.MovieObjectChild");
    By the way - the objects don't have to be CLIK objects in flash or anything special for this to work. In fact if they were CLIK objects you wouldn't need to do this because those objects call back to an initialization routine. I use the method above for my HUD because those objects are lightweight objects. I use the CLIK objects for my menus and selection screens.


    Here's a real working routine that I used in a complete project:

    Code:
    class GFxHud extends GFxMoviePlayer;
    
    var GFxObject     ScreenMessageMC
    var GFxObject     ScreenMessageTF;
    
    ScreenMessageMC = GetVariableObject("_root.screenMessageMC");
    ScreenMessageTF = GetVariableObject("_root.screenMessageMC.centerText.textField");
    
    function SetMessageText(string message)
    {
    	ScreenMessageMC.SetText(message);
    	ScreenMessageTF.GotoAndPlay("on");
    }

    Leave a comment:


  • replied
    This tutorial seems completely broken even at the time when it was written. How the hell is "MouseCursor = MouseContainer.GetObject("my_cursor");" supposed to works since following the tutorial we never assign "my_cursor" anywhere, nor in Unreal Script or Flash ?

    Does anyone has a working tutorial for mouse cursor in hud please ? I tried to put Skalamondre's AS code in MouseContainer but it haven't changed anything ! Mouse cursor won't move and the code to find the SWF size is broken too ! Everything is broken !

    Leave a comment:


  • replied
    **** I never got to respond to this. Hope you got it by now. If not here's the answer in case you didn't.

    I believe you're missing the "onClipEvent" for the mouse pointer. Drop the pointer on the stage at 0,0. Basically it moves the mouse to the current system mouse position on every frame.

    Select it and put this in the AS code window:

    Code:
    onClipEvent(mouseMove)
    {
    	_x = _root._xmouse;
    	_y = _root._ymouse;
    }

    Leave a comment:


  • replied
    Hi guys,

    i follow this tutorial, and i can see the mouse cursor but, cursors position is not update....:S

    any idea???

    my udk version is "UDK-2013-07"

    thanks in advanced.....

    Leave a comment:


  • replied
    I got the mouse to toggle with the shift key. Now I also want to manipulate the menu that I created in the same Flash file. You can see the menu here. Can you please tell me how to make the mouse interact with the menu? Are there any tutorials that can help me do just that? DO I need to learn CLIK?

    Leave a comment:


  • replied
    Just wanted to say sorry for my website being down when people have been trying to access the flash cursor class. One of the drawbacks of being a bedroom coder is lack of money and my hosting costs me more than I can afford some months.

    I will endeavour to keep the site up as much as possible and again my apologies.

    Leave a comment:


  • replied
    Hey what about the rest of us! J/K, seriously though I assume this is a popup manager issue. Is there a fairly simple fix?

    Leave a comment:


  • replied
    Jump on IRC tonight #UDKC on irc.enterthegame.com ill help you out.

    Leave a comment:


  • replied
    The class from f00n.com is gone. Does anybody have it? I'm having a heck of a time getting my cursor to show up above the dropdown menus.

    Leave a comment:


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

    Leave a comment:


  • replied
    that didn't seem to help, but thanks anyways

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    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

    Leave a comment:

Working...
X