Commit 4cece505 authored by 魔大农's avatar 魔大农

Improved mouse behaviour and registered MasterControl as SubSystem

parent 3d5b5dbe
......@@ -235,7 +235,7 @@ void Board::SelectLast()
if (lastSelectedSquare_ && lastSelectedSquare_ != selectedSquare_)
Select(lastSelectedSquare_);
else if (!selectedSquare_)
SelectNearestFreeSquare();
SelectNearestFreeSquare(CAMERA->GetPosition());
}
void Board::Select(Square* square)
{
......
......@@ -37,6 +37,8 @@ using namespace Urho3D;
class Piece;
class Indicator;
#define BOARD MC->world_.board_
class Board : public LogicComponent
{
URHO3D_OBJECT(Board, LogicComponent);
......@@ -62,8 +64,8 @@ public:
Square* GetLastSelectedSquare() const { return lastSelectedSquare_; }
void Select(Square* square);
void Deselect();
void SelectNearestSquare(Vector3 pos = CAMERA->GetPosition());
void SelectNearestFreeSquare(Vector3 pos = CAMERA->GetPosition());
void SelectNearestSquare(Vector3 pos);
void SelectNearestFreeSquare(Vector3 pos);
void SelectLast();
void Reset();
void Refuse();
......
......@@ -235,22 +235,20 @@ void InputMaster::HandleMouseMove(StringHash eventType, VariantMap &eventData)
if (MC->InMenu())
return;
UpdateMousePos();
if (INPUT->GetMouseMode() != MM_WRAP) {
mousePos_.x_ += eventData[MouseMove::P_DX].GetFloat() / GRAPHICS->GetWidth();
mousePos_.y_ += eventData[MouseMove::P_DY].GetFloat() / GRAPHICS->GetHeight();
mousePos_.x_ = eventData[MouseMove::P_X].GetFloat() / GRAPHICS->GetWidth();
mousePos_.y_ = eventData[MouseMove::P_Y].GetFloat() / GRAPHICS->GetHeight();
}
mouseMoveSinceClick_.x_ += eventData[MouseMove::P_DX].GetFloat() / GRAPHICS->GetWidth();
mouseMoveSinceClick_.y_ += eventData[MouseMove::P_DY].GetFloat() / GRAPHICS->GetHeight();
if (!drag_
&& mouseMoveSinceClick_.Length() > DRAG_THRESHOLD
&& (pressedMouseButtons_.Contains(MOUSEB_LEFT)
|| pressedMouseButtons_.Contains(MOUSEB_MIDDLE)
|| pressedMouseButtons_.Contains(MOUSEB_RIGHT)))
&& pressedMouseButtons_.Size())
{
drag_ = true;
INPUT->SetMouseMode(MM_WRAP);
yad_->Hide();
}
......@@ -274,7 +272,6 @@ void InputMaster::HandleMouseButtonDown(StringHash eventType, VariantMap &eventD
mouseMoveSinceClick_ = Vector2::ZERO;
MC->SetSelectionMode(SM_YAD);
UpdateMousePos();
boardClick_ = RaycastToBoard();
tableClick_ = RaycastToTable();
......@@ -282,6 +279,8 @@ void InputMaster::HandleMouseButtonDown(StringHash eventType, VariantMap &eventD
UpdateYad();
mouseIdleTime_ = 0.0f;
ResetIdle();
INPUT->SetMouseMode(MM_WRAP);
}
void InputMaster::HandleMouseButtonUp(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
......@@ -295,7 +294,6 @@ void InputMaster::HandleMouseButtonUp(StringHash eventType, VariantMap &eventDat
pressedMouseButtons_.Erase(button);
MC->SetSelectionMode(SM_YAD);
UpdateMousePos();
UpdateYad();
mouseIdleTime_ = 0.0f;
......@@ -324,7 +322,9 @@ void InputMaster::HandleMouseButtonUp(StringHash eventType, VariantMap &eventDat
}
drag_ = false;
INPUT->SetMouseMode(MM_FREE);
INPUT->SetMousePosition(VectorRoundToInt(Vector2(GRAPHICS->GetSize()) * mousePos_));
}
void InputMaster::HandleMouseWheel(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
......@@ -342,7 +342,7 @@ void InputMaster::UpdateYad()
if (!yad_->hidden_) {
if (yadPos.Length()) {
if (INPUT->GetMouseMode() == MM_FREE) {
yad_->node_->SetPosition(Vector3(0.5f * (yadPos.x_ + yad_->node_->GetPosition().x_),
yadPos.y_,
......@@ -422,12 +422,13 @@ void InputMaster::SelectionButtonPressed()
if (MC->InPickState())
MC->SetSelectionMode(SM_CAMERA);
else if (MC->InPutState())
BOARD->SelectNearestFreeSquare();
BOARD->SelectNearestFreeSquare(CAMERA->GetPosition());
}
void InputMaster::HandleJoystickButtons()
{
for(int joystickId: {0, 1}) {
for(int joystickId : {0, 1}) {
HashSet<int>& buttons = pressedJoystickButtons_[joystickId];
if (buttons.Size())
......@@ -546,7 +547,7 @@ void InputMaster::ActionButtonPressed()
Piece* selectedPiece{ MC->GetSelectedPiece() };
if (selectedPiece){
selectedPiece->Pick();
BOARD->SelectNearestFreeSquare();
BOARD->SelectNearestFreeSquare(CAMERA->GetPosition());
} else if (MC->selectionMode_ == SM_STEP || MC->selectionMode_ == SM_YAD){
if (!MC->SelectLastPiece())
MC->CameraSelectPiece();
......@@ -747,7 +748,7 @@ Square* InputMaster::RaycastToSquare()
}
bool InputMaster::RaycastToBoard()
{
Ray cameraRay{MouseRay()};
Ray cameraRay{ MouseRay() };
PODVector<RayQueryResult> results;
RayOctreeQuery query(results, cameraRay, RAY_TRIANGLE, 1000.0f, DRAWABLE_GEOMETRY);
......@@ -780,13 +781,7 @@ bool InputMaster::RaycastToTable()
}
Ray InputMaster::MouseRay()
{
Ray mouseRay{CAMERA->GetScreenRay(mousePos_.x_, mousePos_.y_)};
Ray mouseRay{ CAMERA->GetScreenRay(mousePos_.x_, mousePos_.y_) };
return mouseRay;
}
void InputMaster::UpdateMousePos()
{
IntVector2 mousePos{INPUT->GetMousePosition()};
mousePos_.x_ = Clamp(static_cast<float>(mousePos.x_) / GRAPHICS->GetWidth(), 0.0f, 1.0f);
mousePos_.y_ = Clamp(static_cast<float>(mousePos.y_) / GRAPHICS->GetHeight(), 0.0f, 1.0f);
}
......@@ -40,6 +40,7 @@ public:
InputMaster(Context* context);
bool IsIdle() const noexcept { return idle_; }
void ConstructYad();
void UpdateYad();
private:
HashSet<int> pressedKeys_;
......@@ -74,7 +75,6 @@ private:
void HandleUpdate(StringHash eventType, VariantMap &eventData);
void UpdateMousePos();
void UpdateYad();
Vector3 YadRaycast(bool& none);
void HandleKeyDown(StringHash eventType, VariantMap &eventData);
......
......@@ -93,6 +93,8 @@
#define FILES GetSubsystem<FileSystem>()
#define GUI GetSubsystem<UI>()
#define FX GetSubsystem<EffectMaster>()
namespace Urho3D {
class Drawable;
class Node;
......
......@@ -29,13 +29,6 @@
URHO3D_DEFINE_APPLICATION_MAIN(MasterControl);
MasterControl* MasterControl::instance_ = NULL;
MasterControl* MasterControl::GetInstance()
{
return MasterControl::instance_;
}
MasterControl::MasterControl(Context *context):
Application(context),
musicGain_{1.0f},
......@@ -51,8 +44,6 @@ MasterControl::MasterControl(Context *context):
pickedPiece_{},
lastReset_{0.0f}
{
instance_ = this;
QuatterCam::RegisterObject(context_);
Piece::RegisterObject(context_);
Board::RegisterObject(context_);
......@@ -90,12 +81,10 @@ void MasterControl::Setup()
engineParameters_[EP_RESOURCE_PATHS] = resourcePaths;
LoadSettings();
// engineParameters_["borderless"] = true;
}
void MasterControl::Start()
{
context_->RegisterSubsystem(this);
context_->RegisterSubsystem(new InputMaster(context_));
context_->RegisterSubsystem(new EffectMaster(context_));
......
......@@ -49,10 +49,8 @@ typedef struct GameWorld
Vector< Piece* > pieces_;
} GameWorld;
#define MC MasterControl::GetInstance()
#define FX GetSubsystem<EffectMaster>()
#define CAMERA MC->world_.camera_
#define BOARD MC->world_.board_
#define MC GetSubsystem<MasterControl>()
#define NUM_PIECES 16
#define TABLE_DEPTH 0.21f
#define RESET_DURATION 1.23f
......@@ -66,7 +64,6 @@ class MasterControl : public Application
public:
MasterControl(Context* context);
static MasterControl* GetInstance();
String GetResourceFolder() const { return resourceFolder_; }
GameWorld world_;
......@@ -118,7 +115,6 @@ public:
void Reset();
private:
static MasterControl* instance_;
String resourceFolder_;
Node* leafyLightNode_;
......
......@@ -110,6 +110,11 @@ String Piece::GetCodon(int length) const
return codon;
}
float Piece::GetAngle() const
{
return MC->AttributesToAngle(ToInt());
}
void Piece::Select()
{
if ((MC->GetGameState() == GameState::PLAYER1PICKS ||
......
......@@ -52,7 +52,7 @@ public:
bool GetPieceAttribute(int index) const { return attributes_[index]; }
PieceAttributes GetPieceAttributes() const { return attributes_; }
String GetCodon(int length = NUM_ATTRIBUTES) const;
float GetAngle() const { return MC->AttributesToAngle(ToInt()); }
float GetAngle() const;
void Select();
void Deselect();
PieceState GetState() const noexcept { return state_; }
......
......@@ -17,9 +17,9 @@
*/
#include "guimaster.h"
#include "inputmaster.h"
#include "quattercam.h"
//#include <initializer_list>
void QuatterCam::RegisterObject(Context *context)
{
......@@ -92,6 +92,8 @@ void QuatterCam::UpdateFov()
void QuatterCam::Update(float timeStep)
{
Vector3 oldPos{ node_->GetPosition() };
if (effectRenderPath_->GetShaderParameter("BloomHDRMix").GetVector2().y_ != 0.7f)
effectRenderPath_->SetShaderParameter("BloomHDRMix", Vector2(Clamp(TIME->GetElapsedTime() * 0.5f - 1.0f, 0.0f, 1.0f), Max(0.7f, 2.3f - TIME->GetElapsedTime() * 0.25f)));
......@@ -136,6 +138,9 @@ void QuatterCam::Update(float timeStep)
//Spin pockets
UpdatePockets(timeStep);
if (oldPos != node_->GetPosition())
GetSubsystem<InputMaster>()->UpdateYad();
}
void QuatterCam::UpdatePockets(float timeStep)
......
......@@ -45,6 +45,8 @@ using namespace Urho3D;
#define ZOOM_EDGE 7.0f
#define ZOOM_MENU 21.0f
#define CAMERA MC->world_.camera_
class QuatterCam : public LogicComponent
{
URHO3D_OBJECT(QuatterCam, LogicComponent);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment