Commit 2d2493b1 authored by 魔大农's avatar 魔大农 🍀

Moved some Yad logic to Yad component

parent cafc775e
......@@ -63,7 +63,7 @@ void InputMaster::ConstructYad()
Node* yadNode{ MC->world_.scene_->CreateChild("Yad") };
yad_ = yadNode->CreateComponent<Yad>();
HideYad();
yad_->Hide();
}
void InputMaster::HandleUpdate(StringHash eventType, VariantMap &eventData)
......@@ -78,7 +78,7 @@ void InputMaster::HandleUpdate(StringHash eventType, VariantMap &eventData)
SetIdle();
if (mouseIdleTime_ > IDLE_THRESHOLD * 0.23f)
HideYad();
yad_->Hide();
HandleCameraMovement(t);
......@@ -223,7 +223,7 @@ void InputMaster::HandleMouseMove(StringHash eventType, VariantMap &eventData)
{
drag_ = true;
INPUT->SetMouseMode(MM_WRAP);
HideYad();
yad_->Hide();
}
MC->SetSelectionMode(SM_YAD);
......@@ -269,10 +269,10 @@ void InputMaster::HandleMouseButtonUp(StringHash eventType, VariantMap &eventDat
if (!drag_){
if (MC->InPickState() && MC->GetSelectedPiece()){
MC->GetSelectedPiece()->Pick();
RestoreYad();
yad_->Restore();
} else if (MC->InPutState() && BOARD->GetSelectedSquare()){
BOARD->PutPiece(MC->GetPickedPiece(), BOARD->GetSelectedSquare());
RestoreYad();
yad_->Restore();
//Zoom
} else if (boardClick_ && RaycastToBoard()){
CAMERA->ZoomToBoard();
......@@ -303,21 +303,10 @@ void InputMaster::UpdateYad()
if (mouseIdleTime_ > IDLE_THRESHOLD * 0.5f
|| hide)
{
HideYad();
yad_->Hide();
}
}
}
void InputMaster::HideYad()
{
yad_->hidden_ = true;
FX->FadeOut(yad_->light_);
FX->FadeOut(yad_->material_, 0.1f);
}
void InputMaster::RevealYad()
{
yad_->hidden_ = false;
RestoreYad();
}
Vector3 InputMaster::YadRaycast(bool& none)
{
bool square{false};
......@@ -330,7 +319,7 @@ Vector3 InputMaster::YadRaycast(bool& none)
if (MC->InPickState()){
MC->SelectPiece(rayPiece_);
if (!yad_->hidden_)
HideYad();
yad_->Hide();
return yad_->node_->GetPosition(); //return
}
//Select square and dim yad when hovering over a square in a put state
......@@ -339,9 +328,9 @@ Vector3 InputMaster::YadRaycast(bool& none)
if (MC->InPutState()){
BOARD->Select(raySquare_);
if (yad_->hidden_)
RevealYad();
yad_->Reveal();
else if (!yad_->dimmed_)
DimYad();
yad_->Dim();
}
}
}
......@@ -360,10 +349,10 @@ Vector3 InputMaster::YadRaycast(bool& none)
{
BOARD->Deselect();
if (yad_->dimmed_)
RestoreYad();
yad_->Restore();
}
if (yad_->hidden_ && !drag_)
RevealYad();
yad_->Reveal();
if (!r.node_->HasTag("Piece")
&& !r.node_->HasTag("Square")
&& !r.node_->HasTag("Yad"))
......@@ -372,15 +361,6 @@ Vector3 InputMaster::YadRaycast(bool& none)
none = true;
return Vector3::ZERO; //return
}
void InputMaster::DimYad()
{
FX->FadeTo(yad_->light_, YAD_DIMMED);
}
void InputMaster::RestoreYad()
{
FX->FadeTo(yad_->light_, YAD_FULLBRIGHT);
FX->FadeTo(yad_->material_, COLOR_GLOW, 0.1f);
}
void InputMaster::SelectionButtonPressed()
{
......
......@@ -27,8 +27,6 @@
#define DEADZONE 0.34f
#define MOUSESPEED 0.23f
#define YAD_FULLBRIGHT 0.5f
#define YAD_DIMMED 0.1f
#define DRAG_THRESHOLD 0.023f
class Square;
......@@ -67,8 +65,6 @@ private:
void ResetIdle();
void SetIdle();
Ray MouseRay();
void HideYad();
void RevealYad();
Piece* RaycastToPiece();
Square* RaycastToSquare();
......@@ -104,8 +100,6 @@ private:
void HandleRightArrowPressed();
void HandleLeftArrowPressed();
bool CorrectJoystickId(int joystickId);
void DimYad();
void RestoreYad();
void SelectionButtonPressed();
};
......
......@@ -17,8 +17,7 @@
*/
#include "yad.h"
#define YAD_FULLBRIGHT 0.5f
#include "effectmaster.h"
void Yad::RegisterObject(Context *context)
{
......@@ -53,7 +52,26 @@ void Yad::OnNodeSet(Node *node)
light_->SetBrightness(YAD_FULLBRIGHT);
}
void Yad::Dim()
{
FX->FadeTo(light_, YAD_DIMMED);
}
void Yad::Hide()
{
hidden_ = true;
FX->FadeOut(light_);
FX->FadeOut(material_, 0.1f);
}
void Yad::Reveal()
{
hidden_ = false;
Restore();
}
void Yad::Restore()
{
FX->FadeTo(light_, YAD_FULLBRIGHT);
FX->FadeTo(material_, COLOR_GLOW, 0.1f);
}
......@@ -24,6 +24,10 @@
#include "mastercontrol.h"
#include "luckey.h"
#define YAD_FULLBRIGHT 0.5f
#define YAD_DIMMED 0.1f
class Yad : public LogicComponent
{
friend class InputMaster;
......@@ -38,6 +42,11 @@ private:
SharedPtr<Light> light_;
bool hidden_;
bool dimmed_;
void Dim();
void Hide();
void Reveal();
void Restore();
};
#endif // YAD_H
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