Hide/Show mouse cursor by pressing RMB (SOLVED)

There are no stupid questions, just stupid answers.
  • 1
  • 2
13 posts Page 1 of 2
Bishop
Posts: 78
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Sat Apr 27, 2019 8:19 pm
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.
Last edited by Bishop on Wed May 01, 2019 6:21 pm, edited 1 time in total.
Happenstance
Posts: 90
Joined: Sat Apr 11, 2015 9:08 pm
by Happenstance » Sun Apr 28, 2019 12:16 am
Just set it like any other variable:

Code: Select all

PlayGui::onRightMouseUp(%this, ...) { %this.noCursor = 0; }
Bishop
Posts: 78
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Sun Apr 28, 2019 2:19 pm
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?
Happenstance
Posts: 90
Joined: Sat Apr 11, 2015 9:08 pm
by Happenstance » Sun Apr 28, 2019 4:34 pm
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.
Bishop
Posts: 78
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Tue Apr 30, 2019 12:16 pm
Thanks....I tried alwaysHandleMouseButtons but not working ....mouse event are still blocked when noCursor is set to "1" when the game starts.
.....I have to find some other solution.
Jason Campbell
Posts: 335
Joined: Fri Feb 13, 2015 2:51 am
 
by Jason Campbell » Tue Apr 30, 2019 1:25 pm
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();
}
Bishop
Posts: 78
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Tue Apr 30, 2019 4:05 pm
Thanks Jason,....practically i have the same code as in your example...
this in the playGui.cs

Code: Select all

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 :)
Bishop
Posts: 78
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Tue Apr 30, 2019 4:50 pm
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.
Jason Campbell
Posts: 335
Joined: Fri Feb 13, 2015 2:51 am
 
by Jason Campbell » Tue Apr 30, 2019 7:50 pm
I was in a rush, I thought the cursor was hidden until I right clicked. Oh well, I think this was covered in the simple rpg paper doll inventory resource. I'm at work but I can try to help tonight.
Bishop
Posts: 78
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Tue Apr 30, 2019 11:59 pm
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.
  • 1
  • 2
13 posts Page 1 of 2

Who is online

Users browsing this forum: No registered users and 3 guests