Jump to content

Hide/Show mouse cursor by pressing RMB (SOLVED)


Bishop

Recommended Posts

Hi, .....In the playGui.gui I have a Dynamic Field ....noCursor 0 and I need to change this value in the game runtime by script in the scripts/gui/playGui.cs where I have the functions PlayGui::onRightMouseDown(%this, %screenPos, %cameraPos, %worldDir),

this function turns the cursor on and adjusts it to the center of the screen.

and vice versa...function PlayGui::onRightMouseUp(...).......turns off and hides the cursor.

.....so I need this dynamic field value option to set in these functions.

Thanks guys.

Edited by Bishop
Link to comment
Share on other sites

Thanks,....problem is in the playGui.gui where I have in the new GameTSCtrl(PlayGui) dynamic field variable noCursor = "1".....so when game start mouse cursor is off / hidden.....this is what I need when level is loaded and game start but then this fuctions in the playGui.cs do not work...

....what I need is when player push RightMouseDown then mouse cursor is

On..shown and when player release RightMouse button cursor is Off/ hidden and player control fps camera again...

.....but this dynamic field variable declared in the playGui.gui disables showing or hiding the cursor by mouse inputs....in other words, it will block those functions in the playGui.cs.....if i delete this variable from the dynamic fields it works but the cursor is just visible at the start of the game but until the player presses the right mouse button later then cursor disappears.

.... maybe choose a better place to control the cursor that has a higher priority than playGui.gui?

Link to comment
Share on other sites

Ah, I see what you're attempting to do. The issue is when the cursor is hidden mouse events are sent to ActionMap for processing, when it's shown they are sent through the GUI system. In your case PlayGui::onRightMouseDown() is never being called because those events are being handled (and ignored) by ActionMap.


In the old TGE days this would require a C++ change but it looks like T3D handles this case. Set Canvas.alwaysHandleMouseButtons to true and see if things work from there.

Link to comment
Share on other sites

Edit: Actually the below code makes it act strange. It seems to need another click to turn cursor off again. I think the showCursor and hideCursor functions might be the answer though.


I think this is what you are going for(read edit).


leave noCursor as zero in playGUI.gui



Add this to end of scripts/gui/playGUI.cs

 

function PlayGui::onRightMouseDown(%this, %screenPos,
%cameraPos, %worldDir)
{
 
  showCursor();
  Canvas.alwaysHandleMouseButtons = false;
 
}
function PlayGui::onRightMouseUp(%this, %screenPos,
%cameraPos, %worldDir)
{
 
  Canvas.alwaysHandleMouseButtons = true;
  hideCursor();
}
Link to comment
Share on other sites

Thanks Jason,....practically i have the same code as in your example...

this in the playGui.cs

function PlayGui::onRightMouseDown(%this, %screenPos, %cameraPos, %worldDir)
{
  showCursor();
  Canvas.alwaysHandleMouseButtons = false;
  Canvas.setCursorPos(840, 500); //set cursor on the center of the screen
} 
//----------------------------------------------------
function PlayGui::onRightMouseUp(%this, %screenPos, %cameraPos, %worldDir)
{
  Canvas.alwaysHandleMouseButtons = true;
  hideCursor();
  Canvas.setCursorPos(840, 500);
  ItemWindow.setHidden(true); //main window of the 3d Item_viewer
}
//-------------------------------------------------------
function PlayGui::onMouseDown(%this, %screenPos, %cameraPos, %worldDir)
{
  %cursorPos = Canvas.getCursorPos();
  %range = 5;
  %dirScaled = VectorScale (%worldDir, %range);
  %endPoint = VectorAdd (%cameraPos, %dirScaled);
  %result = containerRayCast(%cameraPos, %endPoint, $TypeMasks::Static Shape Object Type, 
  LocalClientConnection.getControlObject(), false);
 if (getWordCount (%result) > 0 && getWord(%result, 0) !$= "0")
 {
    %obj = getWord(%result, 0);
    if (%obj.getinternalName () $= "game_item")
    {
       ItemWindow.setHidden(false);
       Item_viewer.setVisible (true);
       showCursor();
       %obj = %result.getName();
       Item_text.setText(%obj.name);
       Item_viewer.setModel(%obj.shapeName);
     } 
     else
     {
        Item_viewer.setVisible (false);
        ItemWindow.setHidden(true);
     }
  }
}

....this code works fine what I need but one thing is that I don't want to display a mouse cursor when i start the game.

.....sorry for formatting the script in the post :)

Link to comment
Share on other sites

This mouse controls are for my Red611 project where the objects/items will be viewed....so player clicks on the item with LMB (cursor is hidden) >>> the window with model/item appears...mouse cursor appears too....fps camera is off....the player views and examines the model/item....and now the player has two options......

....close the model window with RMB anywhere on the screen outside the model window.....the window closes and the cursor also disappears....fps camera is On.

.....or clicks with LMB on the bottom half of the screen when he want to close the model window....or may not close the model window but in both cases it will stay the cursor on the screen so that when there are multiple models/items to examine on the screen....for example the individual books in the library.....will actually stay in the viewing item mode....until he presses RMB.

.....but only problem is cursor which is visible when the game begins.

Link to comment
Share on other sites

Thanks,.....exactly as wrote Happenstance in the post above.... "The issue is when the cursor is hidden mouse events are sent to ActionMap for processing, when it's shown they are sent through the GUI system. In your case PlayGui::onRightMouseDown() is never being called because those events are being handled (and ignored) by ActionMap."

......so when I try to set noCursor = "1" in the playGui.gui - GameTSCtrl(PlayGui)

....which I really need to make the cursor hidden at the start of the game...so then RMB input is blocked/ignored.

Link to comment
Share on other sites

It might be worth tracing the code from here to see what's happening with the mouse events:

https://github.com/GarageGames/Torque3D/blob/7daa243057073f0a7fcfa7d2a8b1c4f50abe73d8/Engine/source/gui/core/guiCanvas.cpp#L653


A workaround in script might be to also bind the right mouse button to a toggleCursor() function so that you're responding to the mouse event from both the GUI side (PlayGui::onRightMouseDown()) and the ActionMap side. You can find an example of how to do this in default.bind.cs but it'll look something like:

 

// button1 = Right Mouse Button
// binding to moveMap so that this only works in a level
moveMap.bind(mouse, button1, toggleCursor);
 
function toggleCursor(%val)
{
    if(%val)
    {
        showCursor();
    }
}
Link to comment
Share on other sites


A workaround in script might be to also bind the right mouse button to a toggleCursor() function so that you're responding to the mouse event from both the GUI side (PlayGui::onRightMouseDown()) and the ActionMap side. You can find an example of how to do this in default.bind.cs but it'll look something like:

 

 

Exactly and thanks to Joel Schilling, I think his name was, who came up with a fix to the ActionMap. It's GlobalActionMap.


edit: Here's the post from GG: https://www.garagegames.com/community/forums/viewthread/104679


So leave noCursor=1; in playGui.gui


in scripts/client/default.bind.cs


Find moveMap.bind( mouse, button1, mouseButtonZoom ); and comment it out.


add to bottom:

 

moveMap.bind( mouse, button1, toggleCursor );
 
 
function toggleCursor()
{
   if(Canvas.isCursorOn()) {
      hideCursor();
   }
   else
   {
      showCursor();
   }
}

 

In scripts/gui/playGui.cs add to bottom:

 

function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
   GlobalActionMap.bind(mouse, "button1", toggleMouse);
}
 
function PlayGui::onRightMouseUp(%this, %pos, %start, %ray)
{
   GlobalActionMap.unbind(mouse, "button1", toggleMouse);
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...