afxTSCtrl.cpp
Engine/source/afx/ui/afxTSCtrl.cpp
Public Functions
ConsoleDocClass(afxTSCtrl , "@brief A customized variation of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GameTSCtrl.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxGUI\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
DefineEngineMethod(afxTSCtrl , getMouse3DPos , Point3F , () , "Get the 3D position of the mouse <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cursor.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , getMouse3DVec , Point3F , () , "Get the 3D direction vector <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the mouse <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cursor.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , getTargetingMode , S32 , () , "Get the current targeting-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">mode.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , popTargetingMode , void , () , "Pop the targeting-<a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> off <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> statck of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">modes.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , pushTargetingMode , void , (U32 mode, U32 checkMethod) , ((U32) arcaneFX::TARGETING_OFF,(U32) arcaneFX::TARGET_CHECK_POLL) , "Push <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> targeting-<a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> onto <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> statck of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">modes.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , setSpellBook , void , (afxSpellBook *spellbook) , "Associate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> spellbook with an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxTSCtrl.\n\n</a>" "@ingroup AFX" )
Detailed Description
Public Functions
ConsoleDocClass(afxTSCtrl , "@brief A customized variation of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GameTSCtrl.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxGUI\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
DefineEngineMethod(afxTSCtrl , getMouse3DPos , Point3F , () , "Get the 3D position of the mouse <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cursor.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , getMouse3DVec , Point3F , () , "Get the 3D direction vector <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the mouse <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cursor.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , getTargetingMode , S32 , () , "Get the current targeting-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">mode.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , popTargetingMode , void , () , "Pop the targeting-<a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> off <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> statck of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">modes.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , pushTargetingMode , void , (U32 mode, U32 checkMethod) , ((U32) arcaneFX::TARGETING_OFF,(U32) arcaneFX::TARGET_CHECK_POLL) , "Push <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> targeting-<a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> onto <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> statck of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">modes.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxTSCtrl , setSpellBook , void , (afxSpellBook *spellbook) , "Associate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> spellbook with an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxTSCtrl.\n\n</a>" "@ingroup AFX" )
IMPLEMENT_CONOBJECT(afxTSCtrl )
1 2 3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 5// Copyright (C) 2015 Faust Logic, Inc. 6// 7// Permission is hereby granted, free of charge, to any person obtaining a copy 8// of this software and associated documentation files (the "Software"), to 9// deal in the Software without restriction, including without limitation the 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11// sell copies of the Software, and to permit persons to whom the Software is 12// furnished to do so, subject to the following conditions: 13// 14// The above copyright notice and this permission notice shall be included in 15// all copies or substantial portions of the Software. 16// 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23// IN THE SOFTWARE. 24// 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 26 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 28// Some of the object selection code in this file is based on functionality described 29// in the following resource: 30// 31// Object Selection in Torque by Dave Myers 32// http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7335 33// 34//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 35 36#include "afx/arcaneFX.h" 37 38#include "console/engineAPI.h" 39#include "gui/core/guiCanvas.h" 40#include "T3D/gameBase/gameConnection.h" 41#include "T3D/gameFunctions.h" 42 43#include "afx/ui/afxTSCtrl.h" 44#include "afx/afxSpellBook.h" 45 46//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 47 48IMPLEMENT_CONOBJECT(afxTSCtrl); 49 50ConsoleDocClass( afxTSCtrl, 51 "@brief A customized variation of GameTSCtrl.\n\n" 52 53 "@ingroup afxGUI\n" 54 "@ingroup AFX\n" 55); 56 57afxTSCtrl::afxTSCtrl() 58{ 59 mMouse3DVec.zero(); 60 mMouse3DPos.zero(); 61 mouse_dn_timestamp = 0; 62 spellbook = NULL; 63 64 clearTargetingMode(); 65} 66 67bool afxTSCtrl::processCameraQuery(CameraQuery *camq) 68{ 69 GameUpdateCameraFov(); 70 return GameProcessCameraQuery(camq); 71} 72 73void afxTSCtrl::renderWorld(const RectI &updateRect) 74{ 75 GameRenderWorld(); 76} 77 78void afxTSCtrl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent) 79{ 80 Parent::getCursor(cursor, showCursor, lastGuiEvent); 81 82 GameConnection* conn = GameConnection::getConnectionToServer(); 83 if (!conn || !conn->getRolloverObj()) 84 return; 85 86 GuiCanvas *pRoot = getRoot(); 87 if( !pRoot ) 88 return; 89 90 PlatformWindow* pWindow = pRoot->getPlatformWindow(); 91 AssertFatal(pWindow != NULL, "GuiControl without owning platform window! This should not be possible."); 92 PlatformCursorController* pController = pWindow->getCursorController(); 93 AssertFatal(pController != NULL, "PlatformWindow without an owned CursorController!"); 94 95 if(pRoot->mCursorChanged != PlatformCursorController::curHand) 96 { 97 // We've already changed the cursor, so set it back before we change it again. 98 if(pRoot->mCursorChanged != -1) 99 pController->popCursor(); 100 101 // Now change the cursor shape 102 pController->pushCursor(PlatformCursorController::curHand); 103 pRoot->mCursorChanged = PlatformCursorController::curHand; 104 } 105 else if(pRoot->mCursorChanged != -1) 106 { 107 // Restore the cursor we changed 108 pController->popCursor(); 109 pRoot->mCursorChanged = -1; 110 } 111} 112 113//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 114 115void afxTSCtrl::onMouseDown(const GuiEvent &evt) 116{ 117 //Con::printf("#### afxTSCtrl::onLeftMouseDown() ####"); 118 119 // save a timestamp so we can measure how long the button is down 120 mouse_dn_timestamp = Platform::getRealMilliseconds(); 121 122 GuiCanvas* Canvas = getRoot(); 123 124 // clear button down status because the ActionMap is going to capture 125 // the mouse and the button up will never happen 126 Canvas->clearMouseButtonDown(); 127 128 // indicate that processing of event should continue (pass down to ActionMap) 129 Canvas->setConsumeLastInputEvent(false); 130} 131 132void afxTSCtrl::onRightMouseDown(const GuiEvent& evt) 133{ 134 //Con::printf("#### afxTSCtrl::onRightMouseDown() ####"); 135 136 GuiCanvas* Canvas = getRoot(); 137 138 // clear right button down status because the ActionMap is going to capture 139 // the mouse and the right button up will never happen 140 Canvas->clearMouseRightButtonDown(); 141 142 // indicate that processing of event should continue (pass down to ActionMap) 143 Canvas->setConsumeLastInputEvent(false); 144} 145 146void afxTSCtrl::onMouseMove(const GuiEvent& evt) 147{ 148 AssertFatal(!targeting_mode.empty(), "Error, undefined targeting mode."); 149 150 Targeting targeting = targeting_mode.last(); 151 if (targeting.mode == arcaneFX::TARGETING_OFF || targeting.check != arcaneFX::TARGET_CHECK_ON_MOUSE_MOVE) 152 return; 153 154 performTargeting(evt.mousePoint, targeting.mode); 155} 156 157void afxTSCtrl::onRender(Point2I offset, const RectI &updateRect) 158{ 159 GameConnection* con = GameConnection::getConnectionToServer(); 160#if defined(BROKEN_DAMAGEFLASH_WHITEOUT_BLACKOUT) 161 bool skipRender = (!con); 162#else 163 bool skipRender = (!con || 164 (con->getWhiteOut() >= 1.f) || 165 (con->getDamageFlash() >= 1.f) || 166 (con->getBlackOut() >= 1.f)); 167#endif 168 169 if (!skipRender) 170 Parent::onRender(offset, updateRect); 171 172 GFX->setViewport(updateRect); 173} 174 175void afxTSCtrl::advanceTime(F32 dt) 176{ 177 AssertFatal(!targeting_mode.empty(), "Error, undefined targeting mode."); 178 179 Targeting targeting = targeting_mode.last(); 180 if (targeting.mode == arcaneFX::TARGETING_OFF || targeting.check != arcaneFX::TARGET_CHECK_POLL) 181 return; 182 183 GuiCanvas* Canvas = getRoot(); 184 185 Point2I cursor_pos; 186 if (Canvas && Canvas->getLastCursorPoint(cursor_pos)) 187 { 188 performTargeting(cursor_pos, targeting.mode); 189 } 190}; 191 192void afxTSCtrl::performTargeting(const Point2I& mousePoint, U8 mode) 193{ 194 GuiCanvas* Canvas = getRoot(); 195 196 if (mode != arcaneFX::TARGETING_FREE && !Canvas->isCursorON()) 197 return; 198 199 MatrixF cam_xfm; 200 Point3F dummy_pt; 201 if (GameGetCameraTransform(&cam_xfm, &dummy_pt)) 202 { 203 // get cam pos 204 Point3F cameraPoint; cam_xfm.getColumn(3,&cameraPoint); 205 206 // construct 3D screen point from mouse coords 207 Point3F screen_pt((F32)mousePoint.x, (F32)mousePoint.y, 1.0f); 208 209 // convert screen point to world point 210 bool bad_cam = mIsZero(mLastCameraQuery.farPlane); 211 Point3F world_pt; 212 if (!bad_cam && unproject(screen_pt, &world_pt)) 213 { 214 Point3F mouseVec = world_pt - cameraPoint; 215 mouseVec.normalizeSafe(); 216 217 mMouse3DPos = cameraPoint; 218 mMouse3DVec = mouseVec; 219 220 F32 selectRange = arcaneFX::sTargetSelectionRange; 221 Point3F mouseScaled = mouseVec*selectRange; 222 Point3F rangeEnd = cameraPoint + mouseScaled; 223 224 if (mode == arcaneFX::TARGETING_STANDARD) 225 arcaneFX::rolloverRayCast(cameraPoint, rangeEnd, arcaneFX::sTargetSelectionMask); 226 else if (mode == arcaneFX::TARGETING_FREE) 227 arcaneFX::freeTargetingRayCast(cameraPoint, rangeEnd, arcaneFX::sFreeTargetSelectionMask); 228 } 229 } 230} 231 232void afxTSCtrl::onMouseEnter(const GuiEvent& evt) 233{ 234 //Con::printf("#### afxTSCtrl::onMouseEnter() ####"); 235} 236 237void afxTSCtrl::onMouseDragged(const GuiEvent& evt) 238{ 239 //Con::printf("#### afxTSCtrl::onMouseDragged() ####"); 240} 241 242 243void afxTSCtrl::onMouseLeave(const GuiEvent& evt) 244{ 245 //Con::printf("#### afxTSCtrl::onMouseLeave() ####"); 246} 247 248bool afxTSCtrl::onMouseWheelUp(const GuiEvent& evt) 249{ 250 //Con::printf("#### afxTSCtrl::onMouseWheelUp() ####"); 251 Con::executef(this, "onMouseWheelUp"); 252 return true; 253} 254 255bool afxTSCtrl::onMouseWheelDown(const GuiEvent& evt) 256{ 257 //Con::printf("#### afxTSCtrl::onMouseWheelDown() ####"); 258 Con::executef(this, "onMouseWheelDown"); 259 return true; 260} 261 262//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 263 264void afxTSCtrl::setSpellBook(afxSpellBook* book) 265{ 266 if (book != spellbook) 267 { 268 spellbook = book; 269 Con::executef(this, "onSpellbookChange", (spellbook) ? spellbook->getIdString() : ""); 270 } 271} 272 273void afxTSCtrl::clearTargetingMode() 274{ 275 targeting_mode.clear(); 276 pushTargetingMode(arcaneFX::TARGETING_OFF, arcaneFX::TARGET_CHECK_POLL); 277} 278 279void afxTSCtrl::pushTargetingMode(U8 mode, U8 check) 280{ 281 switch (mode) 282 { 283 case arcaneFX::TARGETING_OFF: 284 case arcaneFX::TARGETING_STANDARD: 285 case arcaneFX::TARGETING_FREE: 286 break; 287 default: 288 Con::errorf("afxTSCtrl::setTargetingMode() -- unknown targeting mode [%d].", mode); 289 return; 290 } 291 292 switch (check) 293 { 294 case arcaneFX::TARGET_CHECK_POLL: 295 case arcaneFX::TARGET_CHECK_ON_MOUSE_MOVE: 296 break; 297 default: 298 Con::errorf("afxTSCtrl::setTargetingMode() -- unknown targeting check method [%d].", check); 299 return; 300 } 301 302 Targeting targeting = { mode, check }; 303 targeting_mode.push_back(targeting); 304} 305 306void afxTSCtrl::popTargetingMode() 307{ 308 if (targeting_mode.size() <= 1) 309 return ; 310 311 targeting_mode.pop_back(); 312} 313 314U8 afxTSCtrl::getTargetingMode() 315{ 316 return (targeting_mode.size() > 0) ? targeting_mode.last().mode : arcaneFX::TARGETING_OFF; 317} 318 319U8 afxTSCtrl::getTargetingCheckMethod() 320{ 321 return (targeting_mode.size() > 0) ? targeting_mode.last().check : arcaneFX::TARGET_CHECK_POLL; 322} 323 324//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 325 326DefineEngineMethod(afxTSCtrl, setSpellBook, void, (afxSpellBook* spellbook),, 327 "Associate a spellbook with an afxTSCtrl.\n\n" 328 "@ingroup AFX") 329{ 330 object->setSpellBook(spellbook); 331} 332 333DefineEngineMethod(afxTSCtrl, pushTargetingMode, void, (U32 mode, U32 checkMethod), ((U32)arcaneFX::TARGETING_OFF, (U32)arcaneFX::TARGET_CHECK_POLL), 334 "Push a new targeting-mode onto a statck of modes.\n\n" 335 "@ingroup AFX") 336{ 337 object->pushTargetingMode((U8)mode, (U8)checkMethod); 338} 339 340DefineEngineMethod(afxTSCtrl, popTargetingMode, void, (),, 341 "Pop the targeting-mode off a statck of modes.\n\n" 342 "@ingroup AFX") 343{ 344 object->popTargetingMode(); 345} 346 347DefineEngineMethod(afxTSCtrl, getTargetingMode, S32, (),, 348 "Get the current targeting-mode.\n\n" 349 "@ingroup AFX") 350{ 351 return object->getTargetingMode(); 352} 353 354DefineEngineMethod(afxTSCtrl, getMouse3DVec, Point3F, (),, 355 "Get the 3D direction vector for the mouse cursor.\n\n" 356 "@ingroup AFX") 357{ 358 return object->getMouse3DVec(); 359} 360 361DefineEngineMethod(afxTSCtrl, getMouse3DPos, Point3F, (),, 362 "Get the 3D position of the mouse cursor.\n\n" 363 "@ingroup AFX") 364{ 365 return object->getMouse3DPos(); 366} 367 368//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 369