Bishop Posted April 27, 2019 Share Posted April 27, 2019 (edited) 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 May 1, 2019 by Bishop Quote Link to comment Share on other sites More sharing options...
Happenstance Posted April 27, 2019 Share Posted April 27, 2019 Just set it like any other variable: PlayGui::onRightMouseUp(%this, ...) { %this.noCursor = 0; } Quote Link to comment Share on other sites More sharing options...
Bishop Posted April 28, 2019 Author Share Posted April 28, 2019 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 isOn..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? Quote Link to comment Share on other sites More sharing options...
Happenstance Posted April 28, 2019 Share Posted April 28, 2019 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. Quote Link to comment Share on other sites More sharing options...
Bishop Posted April 30, 2019 Author Share Posted April 30, 2019 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. Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted April 30, 2019 Share Posted April 30, 2019 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.guiAdd 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(); } Quote Link to comment Share on other sites More sharing options...
Bishop Posted April 30, 2019 Author Share Posted April 30, 2019 Thanks Jason,....practically i have the same code as in your example...this in the playGui.csfunction 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 :) Quote Link to comment Share on other sites More sharing options...
Bishop Posted April 30, 2019 Author Share Posted April 30, 2019 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. Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted April 30, 2019 Share Posted April 30, 2019 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. Quote Link to comment Share on other sites More sharing options...
Bishop Posted April 30, 2019 Author Share Posted April 30, 2019 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. Quote Link to comment Share on other sites More sharing options...
Happenstance Posted May 1, 2019 Share Posted May 1, 2019 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#L653A 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(); } } Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted May 1, 2019 Share Posted May 1, 2019 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/104679So leave noCursor=1; in playGui.guiin 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); } Quote Link to comment Share on other sites More sharing options...
Bishop Posted May 1, 2019 Author Share Posted May 1, 2019 Thanks very much for help guys,....Yes, exactly this works great....the cursor is hidden at the start of the game now and appears only after pressing and holding RMB.Thanks Jason and Happenstance. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.