Announcement

Collapse
No announcement yet.

Mouse Clicking on Buttons in the HUD During Gameplay (mouse and UI for RTS)

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

    Mouse Clicking on Buttons in the HUD During Gameplay (mouse and UI for RTS)

    mouse and user interface for RTS-style games.

    this were problem discussion:
    http://forums.epicgames.com/showthread.php?t=753021
    http://forums.epicgames.com/showthread.php?t=756008

    First, thanx to Matt Doyle for help and advices and ideas which come on them research and him solution.

    this is another ways to do mouse and UI for RTS.

    As we know, UDK and Scaleform can't propertly block only mouse. We can block all input with scaleform or do not block any input. If we do not block input and clicking to scaleform buttons, then click event will be captured twice: first time in flash And second time with UDK input. It means, you click on button but at same time you click on map.

    The best thing we need: it is ignore mouse click in UDK input when clicking on any buttons in flash. But it is not real, because UDK input being sent to flash when bCaptureInput = false, so UDK input is executed before flash input is executed, that is problem. To change it, i did bCaptureInput = true and all input is going to flash and only then from flash functions to UDK functions (not to UDK input). And with add AddFocusIgnoreKey(name KeyName), that key will be ignored by the Flash, and sent to UDK input. So we can do only mouse capture.

    To fix it id did some tests and here is one of the results.

    Solution 1

    Cons & pros:
    - click works propertly
    - all input going to flash and UDK input do not used (UDK bindings for game will not work)
    - need some specifics for flash movie creation (all input should be captured in AS2.0 and not in scaleform class)
    - separate classes for buttons and mouse

    1. Flash movie Mouse class
    Code:
    class X_COM_GFx_MouseCursor extends GFxMoviePlayer;
    
    var int MouseX;
    var int MouseY;
    
    var X_COM_PlayerController      xcPC;
    
    function Init(optional LocalPlayer LocPlay)
    {
    	super.Init(LocPlay);
    	Start();
    	Advance(0.f);
               AddIgnoreKeys();
    }
    
    function AddIgnoreKeys()
    {
                AddFocusIgnoreKey('W'); // and etc.. if needed
    }
    
    function  SetUpController(X_COM_PlayerController      aController)
    {
    	xcPC = aController;
    }
    
    function ReceiveMouseCoords( float x, float y )
    {
    	MouseX = x;
    	MouseY = y;
    }
    
    // Left mouse button
    function LeftBtn_Pressed()
    {
    	`log("LeftBtnClick_Pressed");
    	xcPC.StartFire();
    }
    
    function LeftBtn_Released()
    {
    	`log("LeftBtnClick_Released");
    	xcPC.StopFire();
    }
    
    // Right mouse button
    function RightBtn_Pressed()
    {
    	`log("RightBtnClick_Pressed");
    	xcPC.StartAltFire();
    }
    
    function RightBtn_Released()
    {
    	`log("RightBtnClick_Released");
    	xcPC.StopAltFire();
    }
    
    // Middle mouse button
    function MiddleBtn_Pressed()
    {
    	`log("MiddleBtnClick_Pressed");
    }
    
    function MiddleBtn_Released()
    {
    	`log("MiddleBtnClick_Released");
    }
    
    DefaultProperties
    {
    	bIgnoreMouseInput = false // SHOULD BE FALSE to not ignore mouse movement.
    	bCaptureInput = true // SHOULD BE TRUE to capture all keyboard and mouse input
    
    	bPauseGameWhileActive = False // do you want your game paused when this is open?
    
    	bDisplayWithHudOff = FALSE // do you want the HUD displayed while this is open?
    
    	// The path to the swf asset
    	MovieInfo = SwfMovie'X-COM_UI.MouseCursor'
    
    	TimingMode=TM_Real
    }
    2. Mouse Action script code
    Code:
    import flash.external.ExternalInterface;
    
    Mouse.hide();
    
    startDrag("CursorMC");
    
    var mouseListener:Object = new Object();
    
    mouseListener.onMouseMove = function ()
    {
        	// Tell UnrealScript about the new mouse coords.
    	ExternalInterface.call( "ReceiveMouseCoords", _root._xmouse, _root._ymouse );
    	updateAfterEvent();
    };
    
    mouseListener.onMouseDown = function(button, target) 
    {
    	if ( button == 1  ) //left click
    	{
    		ExternalInterface.call( "LeftBtn_Pressed" );
        }
    	else if ( button == 2  ) //right click
    	{
    		ExternalInterface.call( "RightBtn_Pressed" );
        }
    	else if ( button == 3  ) //middle click
    	{
    		ExternalInterface.call( "MiddleBtn_Pressed" );
        }	
    }
    
    mouseListener.onMouseUp = function(button, target) 
    {
    	if ( button == 1  ) //left click
    	{
    		ExternalInterface.call( "LeftBtn_Released" );
        }
    	else if ( button == 2  ) //right click
    	{
    		ExternalInterface.call( "RightBtn_Released" );
        }
    	else if ( button == 3  ) //middle click
    	{
    		ExternalInterface.call( "MiddleBtn_Released" );
        }	
    }
    
    Mouse.addListener(mouseListener);
    
    // get from Matt Doyle tutorial
    var keyboardInput:Object = new Object(); // creates a new object to hold keyboard input.
    Key.addListener(keyboardInput); // uses the object to listen for keyboard input.
    
    /* when a key is pressed, execute this function. */
    keyboardInput.onKeyDown = function() 
    {
        /* store the keyboard input ASCII code inside 'keyPressed'. */
        var keyPressed:Number = Key.getCode();
        trace("Key Pressed" + keyPressed);
    
        /* Call the UnrealScript function 'KeyPressed' and send it the 'keyPressed' value. */
        ExternalInterface.call("KeyPressed"), keyPressed);
    }
    3. Player controller class
    Code:
    class X_COM_PlayerController extends UDKPlayerController;
    
    var X_COM_GFx_MouseCursor		MouseCursor;
    var X_COM_GFx_HUD_Planet		HUD_Planet;
    
    var bool                        			bButtonClicked; //true if flash button clicked
    
    simulated function PostBeginPlay()
    {
    	super.PostBeginPlay();
    	CreateMouse();
    	ShowUserInterface_Planet();
    }
    
    function CreateMouse()
    {
    	MouseCursor = new class'X_COM_GFx_MouseCursor';
    	MouseCursor.SetViewScaleMode( SM_ShowAll );
    	MouseCursor.SetAlignment( Align_Center );
    	MouseCursor.Init( LocalPlayer(Player) );
    	MouseCursor.SetPriority(100);
    	MouseCursor.SetUpController(self);
    }
    
    function ShowUserInterface_Planet()
    {   
    	if (HUD_Planet == none)
    	{
    		HUD_Planet = new class'X_COM_GFx_HUD_Planet';
    		HUD_Planet.SetViewScaleMode( SM_ShowAll );
    		HUD_Planet.SetAlignment( Align_Center );
    		HUD_Planet.Init(LocalPlayer(self.player));
    		HUD_Planet.SetUpController(self);
    	}
    }
    
    exec function StopFire( optional byte FireModeNum )
    {
    	if (bButtonClicked) //if any button clicked then exit
    	{
    		bButtonClicked = false;
    		return;
    	}
    	
    	// if not any button clicked:
    	//here is your code for map click (traces, movem fire, other actions)
    }
    4. User Interface class (scaleform class with buttons) Action script code
    Code:
    import flash.external.ExternalInterface;
    _global.gfxExtensions=true;
    
    Mouse.hide();
    
    function handleButtonRelease()
    {
    	ExternalInterface.call( "BTN_NewBase_Released" );
    }
    BTN_NewBase.addEventListener("click", this, "handleButtonRelease");
    
    //BTN_NewBase - it is button with instanced name BTN_NewBase placed in scene
    5. User Interface class (scaleform class with buttons) Unreal script code
    Code:
    class X_COM_GFx_HUD_Planet extends GFxMoviePlayer;
    
    var X_COM_PlayerController      xcPC;
    
    function Init(optional LocalPlayer LocPlay)
    {
    	super.Init(LocPlay);
    	Start();
    	Advance(0.f);
    }
    
    function  SetUpController(X_COM_PlayerController      aController)
    {
    	xcPC = aController;
    }
    
    function BTN_NewBase_Released()
    {
    	xcPC.bButtonClicked = true;  //this tells to player controller to not execute regular click
    	xcPC.Call_some_fucntion_in_PC();
    }
    
    DefaultProperties
    {
    	bIgnoreMouseInput = TRUE // this determines whether the mouse is captured or not
               bCaptureInput = TRUE
    
    	bPauseGameWhileActive = FALSE // do you want your game paused when this is open?
    
               bDisplayWithHudOff = FALSE // do you want the HUD displayed while this is open?
    
    	// The path to the swf asset
    	MovieInfo = SwfMovie'X-COM_UI.GEO_Planet'
    
               TimingMode=TM_Real
    }


    --------------------------------------------------------------------------



    Solution 2

    Cons & pros:
    - click works propertly
    - all input going to UDK input except mouse
    - need some specifics for flash movie creation (mouse cursor and all menus and buttons should be in one SWF file)

    in GFxMoviePlayer class:
    and with using classes above
    Code:
    event bool FilterButtonInput(int ControllerId, name ButtonName, EInputEvent InputEvent)
    {
        if (ButtonName == 'LeftMouseButton')
        {
    		if (InputEvent == IE_Released)
    		{
    			if (xcPC.bButtonClicked) return true;
                                      else
                                      {
                                            xcPC.StopFire();
                                       }
    		}
    		return false;
        }
        return false;
    }



    --------------------------------------------------------------------------


    But all of thats solutions are not perfect and in ideal it should be done in other way


    Solution 3
    i hope it maybe coming soon from Epic Games

    #2
    Great post. This certainly provides a viable second method for accessing CLIK buttons on the HUD without firing your weapon etc.

    One typo. Check your function name and the external interface call:

    ExternalInterface.call( "BTN_NewBase_click" );
    function BTN_NewBase_Released()

    They don't match.

    Comment


      #3
      yes, right, coped wrong function, tnx, fixed

      Comment


        #4
        Написал бы на форуме анрил-левел на русском. Рускоязчное коммунити было бы благодарно...

        Would write in the forum "Unreal-Level" in Russian. Russian-speaking community would be grateful ...

        Comment

        Working...
        X