#include "StdAfx.h" #include "inputsystem.h" #include "ShortcutManager.h" #include "Application.h" //#include "RenderSystem.h" #include "StageManager.h" #include "ObjectManager.h" #include "Hero.h" #include "CameraManager.h" #include "UICursor.h" #include "UINode.h" #include "SkillExecuter.h" cInputSystem* cInputSystem::mpSingleton = 0; cInputSystem::cInputSystem() { assert( mpSingleton == 0 && "bad singleton!" ); mpSingleton = this; } cInputSystem::~cInputSystem() { Exit(); mpSingleton = 0; } bool cInputSystem::Init( NiInstanceRef hi, NiWindowRef hwnd ) { HRESULT hr; /// ÀåÄ¡ »ý¼º hr = DirectInput8Create( hi, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&mpDI, NULL ); if( FAILED( hr ) ) { return false; } /// Űº¸µå »ý¼º hr |= mKeyboard.Create( hwnd, mpDI ); if( FAILED( hr ) ) { return false; } /// ¸¶¿ì½º »ý¼º if( !mMouse.Create( hwnd ) ) { return false; } return true; } void cInputSystem::Exit() { mMouse.Release(); mKeyboard.Release(); SAFE_RELEASE( mpDI ); } /// ÁÖÀÇ»çÇ× : Űº¸µå¿Í ¸¶¿ì½ºÀÇ Ã³¸® ¼ø¼­´Â º¯°æÇÏÁö ¸»°Í!! void cInputSystem::Process( unsigned long deltaTime ) { /// OBJECTMAN->ClearPickObject(); bool keyMoveUpdate = false; /// Keyboard ó¸® mKeyboard.UpdateKeyboardState(); if( THEAPP->IsActive() == false ) { mKeyboard.ClearKeyState(); } else { /// Æ÷Ä¿½º ³ëµå°¡ Àְųª, ¸ð´Þ ´ÙÀ̾ó·Î±×°¡ ¶°ÀÖÀ¸¸é ó¸® ¾ÈÇÔ. if( UIMAN->GetFocusedNode() || UIMAN->IsShowModalBox() ) { mKeyboard.ClearKeyState(); } else { /// ÃÖ»óÀ§ ÄÁÅ×À̳ʿ¡ À̺¥Æ®¸¦ Àü´ÞÇÑ´Ù.. /// À̰÷Àº ½ºÅ×ÀÌÁö¿¡ µû¶ó¼­ ¸·¾Æ ³õÀÚ!! /// °ÔÀÓ»ó ŰÀԷ ó¸®µé... // mKeyboard.StartGetKeyState(); // while( mKeyboard.GetNextKeyState() ) if( mKeyboard.GetDirectInput() ) { mKeyboard.GetNextKeyState(); /// °ÔÀÓ»ó ŰÀԷ ó¸®µé... STAGEMAN->ProcessKeyUpDown( deltaTime, &mKeyboard ); ////////////////////////////////////////////////////////////////////////// /// key move check if( mKeyboard.GetKeyDown(KEY_MOVE_UP) || mKeyboard.GetKeyDown(KEY_MOVE_LEFT) || mKeyboard.GetKeyDown(KEY_MOVE_RIGHT) || mKeyboard.GetKeyDown(KEY_MOVE_DOWN) || mKeyboard.GetKeyDown(KEY_AUTO_RUN) || mKeyboard.GetKeyUp(KEY_MOVE_UP) || mKeyboard.GetKeyUp(KEY_MOVE_LEFT) || mKeyboard.GetKeyUp(KEY_MOVE_RIGHT) || mKeyboard.GetKeyUp(KEY_MOVE_DOWN) ) { keyMoveUpdate = true; } ////////////////////////////////////////////////////////////////////////// } STAGEMAN->ProcessKeyPressed( &mKeyboard ); } } /// Mouse ó¸® do { mMouse.GetNextMouseEvent(); if( mMouse.LButtonDoubleClick() || mMouse.LButtonDown() ) { /// ±âº» Ä¿¼­¿´À» °æ¿ì¿¡¸¸ Ŭ¸¯½Ã Ŭ¸¯ Ä¿¼­·Î º¯°æ CURSOR->SetCursor( eCURSOR_CLICK ); } else if( mMouse.LButtonUp() ) { CURSOR->SetCursor( eCURSOR_UNCLICK ); } /// UI ÀÎDz ó¸® if( UseMouseEventByUIMgr() ) { /// UI°¡ ¸Þ¼¼Áö¸¦ ó¸®Çß´Ù¸é... if( mMouse.RButtonDown() || mMouse.LButtonDown() ) { if( STAGEMAN->GetCurrentStage() == eStage_Game ) { if( HERO ) { if( SKILLEXECUTER->IsSkillCharge() || SKILLEXECUTER->IsFieldSkillCharge() ) { sChargeInfo chargeInfo = SKILLEXECUTER->GetChargeSkill(); SKILLEXECUTER->ChargeOff( chargeInfo.mSkillIdx, chargeInfo.mSkillStep ); } } } } continue; } /// Ä«¸Þ¶ó¿¡ ´ëÇÑ ÀÎDz ó¸® ( WM_MOUSEMOVE ) if( STAGEMAN->GetCurrentStage() == eStage_Game ) { CAMERAMAN->ProcessMouse( deltaTime ); if( UIMAN->IsVisibleDrag() || UIMAN->IsVisibleUnionDrag() ) { CURSOR->SetCursor( eCURSOR_CLICK ); continue; } cUINode* node = UIMAN->GetHoverNode(); if( node ) { if( node->IsSetCursorDefault() == true ) CURSOR->SetCursor( eCURSOR_DEFAULT ); continue; } } /// °ÔÀÓ»ó ¸¶¿ì½º À̺¥Æ® 󸮵é... STAGEMAN->ProcessMouseEvent( deltaTime, &mMouse ); if( mMouse.RButtonDown() || mMouse.RButtonUp() ) { if( HERO && HERO->IsReadyUseSkill() ) keyMoveUpdate = true; } } while( !mMouse.IsEmptyMouseEvent() ); if( keyMoveUpdate == true ) { if( HERO && STAGEMAN->GetCurrentStage() == eStage_Game ) HERO->UpdateKeyState(); } } bool cInputSystem::UseMouseEventByUIMgr() { cUIEvent event; event.mControl = mMouse.ControlPressed(); event.mShift = mMouse.ShiftPressed(); event.mAlt = mMouse.AltPressed(); if( THEAPP->IsActive() ) { if( mMouse.LButtonDown() ) { event.mType = eUIEVENT_LBUTTON_DOWN; event.mPos.mX = mMouse.GetMouseEventX();//mMouse.GetMouseX(); event.mPos.mY = mMouse.GetMouseEventY();//mMouse.GetMouseY(); return UIMAN->PostEventFromUser( event ); } else if( mMouse.LButtonUp() ) { event.mType = eUIEVENT_LBUTTON_UP; event.mPos.mX = mMouse.GetMouseEventX();//mMouse.GetMouseX(); event.mPos.mY = mMouse.GetMouseEventY();//mMouse.GetMouseY(); return UIMAN->PostEventFromUser( event ); } else if( mMouse.RButtonDown() ) { event.mType = eUIEVENT_RBUTTON_DOWN; event.mPos.mX = mMouse.GetMouseEventX();//mMouse.GetMouseX(); event.mPos.mY = mMouse.GetMouseEventY();//mMouse.GetMouseY(); return UIMAN->PostEventFromUser( event ); } else if( mMouse.RButtonUp() ) { event.mType = eUIEVENT_RBUTTON_UP; event.mPos.mX = mMouse.GetMouseEventX();//mMouse.GetMouseX(); event.mPos.mY = mMouse.GetMouseEventY();//mMouse.GetMouseY(); return UIMAN->PostEventFromUser( event ); } else if( mMouse.LButtonDoubleClick() ) { event.mType = eUIEVENT_LBUTTON_DBLCLK; event.mPos.mX = mMouse.GetMouseEventX();//mMouse.GetMouseX(); event.mPos.mY = mMouse.GetMouseEventY();//mMouse.GetMouseY(); return UIMAN->PostEventFromUser( event ); } } if( mMouse.GetWheel() ) { event.mType = eUIEVENT_MOUSE_WHEEL; event.mPos.mX = mMouse.GetMouseX(); event.mPos.mY = mMouse.GetMouseY(); event.mWheel = mMouse.GetWheel(); return UIMAN->PostEventFromUser( event ); } /// WM_MOUSE_MOVE¿¡ ´ëÇÑ Ã³¸®´Â À©µµ¿ì Ȱ¼º/ºñȰ¼º°ú ¹«°üÇÑ´Ù. if( mMouse.IsDrag() ) { event.mType = eUIEVENT_MOUSE_MOVE; //event.mPos.mX = (float)mMouse.GetMouseX() / (float)RENDERSYS->GetScreenWidth(); //event.mPos.mY = (float)mMouse.GetMouseY() / (float)RENDERSYS->GetScreenHeight(); event.mPos.mX = mMouse.GetMouseX(); event.mPos.mY = mMouse.GetMouseY(); return UIMAN->PostEventFromUser( event ); } return false; } bool cInputSystem::WindowMessageParser( HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam ) { /// ¸¶¿ì½º¿¡¼­ 󸮵Ǵ À̺¥Æ®³Ä!! if( mMouse.GetWindowMessage( wnd, msg, wparam, lparam ) ) return false; /// UI À̺¥Æ® cUIEvent event; /// UI ¿¡µðÆ® °è¿­¿¡ Æ÷Ä¿½º°¡ ÀÖ´Â °æ¿ì ó¸® if( UIMAN == 0 ) return false; if( UIMAN->IsShowModalBox() == false && UIMAN->IsShowModalessBox() == false ) { if( !UIMAN->GetFocusedNode() ) return false; } else { /// modal ÀÌ ¶ç¿öÁ® ÀÖÀ»°æ¿ì¿¡µµ ó¸®ÇØ¾ß ÇÒ °æ¿ì. mKeyboard.UpdateKeyboardState(); if( mKeyboard.GetDirectInput() ) { mKeyboard.GetNextKeyState(); if( mKeyboard.GetKeyDown( KEY_SCREENSHOT ) == true ) THEAPP->SetSaveScreenShot( true ); } } /// Űº¸µå À̺¥Æ®¿¡ ´ëÇÑ Ã³¸®!! switch( msg ) { /* BYTE keys[256]; WORD asc = 0; GetKeyboardState( keys ); ToAscii( wparam, lparam, keys, &asc, 0 ); event.mShift = (keys[VK_SHIFT] & 0x80) != 0; event.mControl = (keys[VK_CONTROL] & 0x80) != 0; event.mAscii = asc >= 0 ? asc : 0; */ /// 1. KEY DOWN/UP ó¸® case WM_KEYDOWN: { event.mType = eUIEVENT_KEY_DOWN; event.mCode = (eKeyCode)wparam; UIMAN->PostEventFromUser( event ); } return true; case WM_KEYUP: { event.mType = eUIEVENT_KEY_UP; event.mCode = (eKeyCode)wparam; UIMAN->PostEventFromUser( event ); // /// ½ºÅ©¸°¼¦.. // if( event.mCode == eKEY_F12 ) // THEAPP->SetSaveScreenShot( true ); } return true; /// 2. WM_CHAR Message ó¸® case WM_CHAR: { event.mType = eUIEVENT_CHAR; event.mWparam = (TCHAR)wparam; UIMAN->PostEventFromUser( event ); } //return true; break; /// 3. IME Message ó¸® //case WM_INPUTLANGCHANGE: // { // int a= 0; // a=1; // } // //return true; // break; case WM_IME_NOTIFY: { switch( wparam ) { case IMN_OPENCANDIDATE: break; case IMN_SETCONVERSIONMODE: { event.mType = eUIEVENT_IME_NOTIFY; event.mWparam = wparam; UIMAN->PostEventFromUser( event ); } break; } } break; case WM_IME_STARTCOMPOSITION: { event.mType = eUIEVENT_IME_STARTCOMPOSITION; event.mCode = (eKeyCode)wparam; UIMAN->PostEventFromUser( event ); } //return true; break; case WM_IME_COMPOSITION: { /// ÇÑ±Û Á¶ÇÕÁß event.mType = eUIEVENT_IME_COMPOSITION; event.mWparam = (BYTE)wparam; event.mLparam = lparam; UIMAN->PostEventFromUser( event ); } //return true; break; case WM_IME_ENDCOMPOSITION: { event.mType = eUIEVENT_IME_ENDCOMPOSITION; UIMAN->PostEventFromUser( event ); } //return true; break; } return false; } void cInputSystem::InputInfoClearAll() { mKeyboard.UpdateKeyboardState(); mKeyboard.ClearKeyState(); mMouse.ClearAllInfo(); } void cInputSystem::KeyInfoClear() { mKeyboard.UpdateKeyboardState(); mKeyboard.ClearKeyState(); }