Commit db1eedf0 authored by 魔大农's avatar 魔大农

Added Quatter indicators and worked on mouse input

parent 8fc587b0
No preview for this file type
......@@ -28,6 +28,7 @@ template <> unsigned MakeHash(const IntVector2& value)
}
Board::Board(): Object(MC->GetContext()),
indicateSingle_{false},
squares_{},
selectedSquare_{nullptr},
lastSelectedSquare_{nullptr}
......@@ -63,7 +64,7 @@ Board::Board(): Object(MC->GetContext()),
Node* lightNode{slotNode->CreateChild("Light")};
lightNode->SetPosition(Vector3::UP * 0.23f);
square->light_ = lightNode->CreateComponent<Light>();
square->light_->SetColor(COLOR_GLOW);
square->light_->SetColor(0.5f * COLOR_GLOW);
square->light_->SetBrightness(0.023f);
square->light_->SetRange(2.0f);
square->light_->SetCastShadows(false);
......@@ -72,6 +73,62 @@ Board::Board(): Object(MC->GetContext()),
}
//Create Quatter indicators
for (int i{0}; i < 6; ++i){
//Create base
Indicator* indicator{new Indicator};
indicator->rootNode_ = rootNode_->CreateChild("Indicator");
indicator->rootNode_->SetPosition(GetThickness() * Vector3::UP);
if (i == 1)
indicator->rootNode_->Rotate(Quaternion(90.0f, Vector3::UP));
else if (i == 2)
indicator->rootNode_->Rotate(Quaternion(45.0f, Vector3::UP));
else if (i == 3)
indicator->rootNode_->Rotate(Quaternion(-45.0f, Vector3::UP));
else if (i == 5)
indicator->rootNode_->Rotate(Quaternion(90.0f, Vector3::UP));
indicator->glow_ = MC->GetMaterial("Glow")->Clone();
//Create models
Node* arrowNode1{indicator->rootNode_->CreateChild("Arrow")};
arrowNode1->SetPosition(Vector3::LEFT * (2.3f + 0.95f * (i == 2 || i == 3)) + Vector3::FORWARD * (i >= 4));
arrowNode1->Rotate(Quaternion(-90.0f, Vector3::UP));
indicator->model1_ = arrowNode1->CreateComponent<AnimatedModel>();
if (i < 4)
indicator->model1_->SetModel(MC->GetModel("Arrow"));
else
indicator->model1_->SetModel(MC->GetModel("BlockIndicator"));
indicator->model1_->SetMaterial(indicator->glow_);
Node* arrowNode2{indicator->rootNode_->CreateChild("Arrow")};
arrowNode2->SetPosition(Vector3::RIGHT * (2.3f + 0.95f * (i == 2 || i == 3)));
arrowNode2->Rotate(Quaternion(90.0f, Vector3::UP));
indicator->model2_ = arrowNode2->CreateComponent<AnimatedModel>();
if (i < 4)
indicator->model2_->SetModel(MC->GetModel("Arrow"));
else
indicator->model2_->SetModel(MC->GetModel("BlockIndicator"));
indicator->model2_->SetMaterial(indicator->glow_);
indicator->model2_->GetMaterial()->SetShaderParameter("MatDiffColor", Color(0.0f, 0.0f, 0.0f, 0.0f));
//Create light
Node* lightNode1{arrowNode1->CreateChild("Light")};
lightNode1->SetPosition(Vector3::UP * 0.23f);
indicator->light1_ = lightNode1->CreateComponent<Light>();
indicator->light1_->SetColor(COLOR_GLOW);
indicator->light1_->SetBrightness(0.023f);
indicator->light1_->SetRange(2.0f);
indicator->light1_->SetCastShadows(false);
Node* lightNode2{arrowNode2->CreateChild("Light")};
lightNode2->SetPosition(Vector3::UP * 0.23f);
indicator->light2_ = lightNode2->CreateComponent<Light>();
indicator->light2_->SetColor(COLOR_GLOW);
indicator->light2_->SetBrightness(0.023f);
indicator->light2_->SetRange(2.0f);
indicator->light2_->SetCastShadows(false);
indicators_.Push(SharedPtr<Indicator>(indicator));
}
SubscribeToEvent(E_SCENEUPDATE, URHO3D_HANDLER(Board, HandleSceneUpdate));
}
void Board::Reset()
......@@ -166,16 +223,16 @@ bool Board::CheckQuatter()
bool checkBlocks{true};
//Check rows
for (int i{0}; i < BOARD_WIDTH; ++i){
for (int j{0}; j < BOARD_HEIGHT; ++j){
Piece::Attributes matching{};
matching.flip();
Piece::Attributes first{};
for (int j{0}; j < BOARD_HEIGHT; ++j){
for (int i{0}; i < BOARD_WIDTH; ++i){
IntVector2 coords(i, j);
Piece* piece{squares_[coords].Get()->piece_};
if (piece){
Piece::Attributes attributes{piece->GetAttributes()};
if (j == 0) {
Piece::Attributes attributes(piece->GetAttributes());
if (i == 0) {
first = attributes;
} else {
for (int a{0}; a < NUM_ATTRIBUTES; ++a)
......@@ -190,21 +247,22 @@ bool Board::CheckQuatter()
}
//Quatter!
if (matching.any()){
Indicate(IntVector2(0, j), IntVector2(BOARD_WIDTH - 1, j));
return true;
}
}
//Check columns
for (int j{0}; j < BOARD_HEIGHT; ++j){
for (int i{0}; i < BOARD_WIDTH; ++i){
Piece::Attributes matching{};
matching.flip();
Piece::Attributes first{};
for (int i{0}; i < BOARD_WIDTH; ++i){
for (int j{0}; j < BOARD_HEIGHT; ++j){
IntVector2 coords(i, j);
Piece* piece{squares_[coords].Get()->piece_};
if (piece){
Piece::Attributes attributes(piece->GetAttributes());
if (i == 0) {
Piece::Attributes attributes{piece->GetAttributes()};
if (j == 0) {
first = attributes;
} else {
for (int a{0}; a < NUM_ATTRIBUTES; ++a)
......@@ -219,6 +277,7 @@ bool Board::CheckQuatter()
}
//Quatter!
if (matching.any()){
Indicate(IntVector2(i, 0), IntVector2(i, BOARD_HEIGHT - 1));
return true;
}
}
......@@ -247,6 +306,8 @@ bool Board::CheckQuatter()
}
//Quatter!
if (matching.any()){
Indicate(IntVector2(0, direction * (BOARD_HEIGHT - 1)),
IntVector2(BOARD_WIDTH - 1, !direction * (BOARD_HEIGHT - 1)));
return true;
}
}
......@@ -277,6 +338,8 @@ bool Board::CheckQuatter()
}
//Quatter!
if (matching.any()){
Indicate(IntVector2(k, l),
IntVector2(k + 1, l + 1));
return true;
}
}
......@@ -336,10 +399,13 @@ void Board::Select(Square* square)
Color(1.0f, 0.8f, 0.0f, 0.5f));
}
Indicate(square->coords_);
FX->FadeTo(square->light_, 0.42f);
}
void Board::Deselect(Square* square)
{
HideIndicators();
if (!square) return;
if (selectedSquare_ == square){
......@@ -369,3 +435,48 @@ void Board::Step(IntVector2 step)
}
} else SelectLast();
}
void Board::Indicate(IntVector2 first, IntVector2 last)
{
//Indicate single square
if (last == IntVector2(-1, -1)){
if (indicateSingle_){
FX->FadeTo(indicators_[0]->glow_, COLOR_GLOW);
FX->TransformTo(indicators_[0]->rootNode_,
CoordsToPosition(first) * Vector3(0.0f, 1.0f, 1.0f),
indicators_[0]->rootNode_->GetRotation(),
0.23f);
FX->FadeTo(indicators_[1]->glow_, COLOR_GLOW);
FX->TransformTo(indicators_[1]->rootNode_,
CoordsToPosition(first) * Vector3(1.0f, 1.0f, 0.0f),
indicators_[1]->rootNode_->GetRotation(),
0.23f);
}
//Indicate row
} else if (first.y_ == last.y_){
FX->FadeTo(indicators_[0]->glow_, COLOR_GLOW);
indicators_[0]->rootNode_->SetPosition(CoordsToPosition(first) * Vector3(0.0f, 1.0f, 1.0f));
//Indicate column
} else if (first.x_ == last.x_){
FX->FadeTo(indicators_[1]->glow_, COLOR_GLOW);
indicators_[1]->rootNode_->SetPosition(CoordsToPosition(first) * Vector3(1.0f, 1.0f, 0.0f));
//Indicate first diagonal
} else if (first.x_ == 0 && last.y_ == 0){
FX->FadeTo(indicators_[3]->glow_, COLOR_GLOW);
//Indicate 2x2 blocks
} else if (last.x_ - first.x_ == 1) {
FX->FadeTo(indicators_[4]->glow_, COLOR_GLOW);
indicators_[4]->rootNode_->SetPosition(CoordsToPosition(first) * Vector3(0.0f, 1.0f, 1.0f));
FX->FadeTo(indicators_[5]->glow_, COLOR_GLOW);
indicators_[5]->rootNode_->SetPosition(CoordsToPosition(first) * Vector3(1.0f, 1.0f, 0.0f));
//Indicate other diagonal
} else
FX->FadeTo(indicators_[2]->glow_, COLOR_GLOW);
}
void Board::HideIndicators()
{
for (SharedPtr<Indicator> i: indicators_){
FX->FadeOut(i.Get()->glow_);
}
}
......@@ -47,6 +47,18 @@ public:
bool selected_;
}Square;
typedef class Indicator : public Object{
URHO3D_OBJECT(Indicator, Object);
public:
Indicator() : Object(MC->GetContext()) {}
SharedPtr<Node> rootNode_;
SharedPtr<Material> glow_;
SharedPtr<AnimatedModel> model1_;
SharedPtr<AnimatedModel> model2_;
SharedPtr<Light> light1_;
SharedPtr<Light> light2_;
}Indicator;
class Board : public Object
{
URHO3D_OBJECT(Board, Object);
......@@ -90,15 +102,19 @@ public:
bool IsEmpty() const;
bool IsFull() const;
void HideIndicators();
private:
bool indicateSingle_;
SharedPtr<Node> rootNode_;
StaticModel* model_;
HashMap<IntVector2, SharedPtr<Square>> squares_;
Square* selectedSquare_;
Square* lastSelectedSquare_;
Vector<SharedPtr<Indicator>> indicators_;
Vector3 CoordsToPosition(IntVector2 coords);
void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
void Indicate(IntVector2 first, IntVector2 last = IntVector2(-1, -1));
};
#endif // BOARD_H
......@@ -34,7 +34,7 @@ public:
void FadeTo(Light* light, float brightness, float duration = 0.23f);
void FadeTo(SoundSource* soundSource, float gain, float duration = 2.3f);
void FadeOut(Material* material) {FadeTo(material, material->GetShaderParameter("MatDiffColor").GetColor() * 0.0f); }
void FadeOut(Material* material, float duration = 0.23f) {FadeTo(material, material->GetShaderParameter("MatDiffColor").GetColor() * 0.0f, duration); }
void FadeOut(Light* light) { FadeTo(light, 0.0f); }
void FadeOut(SoundSource* soundSource, float duration = 5.0f);
......
......@@ -24,8 +24,8 @@
InputMaster::InputMaster() : Master(),
input_{GetSubsystem<Input>()},
idleTime_{-IDLE_THRESHOLD * 0.5f},
idle_{true},
idleTime_{IDLE_THRESHOLD},
idle_{false},
mousePos_{},
mouseIdleTime_{0.0f},
sinceStep_{STEP_INTERVAL},
......@@ -48,15 +48,18 @@ InputMaster::InputMaster() : Master(),
void InputMaster::ConstructYad()
{
//Construct yad
yad_->node_ = MC->world_.scene_->CreateChild("Yad");
Node* lightNode{yad_->node_->CreateChild("Light")};
lightNode->SetPosition(Vector3::UP * 0.23f);
yad_->model_ = yad_->node_->CreateComponent<AnimatedModel>();
yad_->model_->SetModel(MC->GetModel("Yad"));
yad_->material_ = MC->GetMaterial("Glow")->Clone();
yad_->model_->SetMaterial(yad_->material_);
yad_->light_ = lightNode->CreateComponent<Light>();
yad_->light_->SetLightType(LIGHT_POINT);
yad_->light_->SetColor(COLOR_GLOW);
yad_->light_->SetRange(1.0f);
yad_->light_->SetBrightness(3.0f);
yad_->light_->SetBrightness(YAD_FULLBRIGHT);
HideYad();
}
......@@ -84,7 +87,9 @@ void InputMaster::UpdateYad()
{
Vector3 yadPos{YadRaycast()};
if (yadPos.Length())
yad_->node_->SetPosition(yadPos);
yad_->node_->SetPosition(Vector3(0.5f * (yadPos.x_ + yad_->node_->GetPosition().x_),
yadPos.y_,
0.5f * (yadPos.z_ + yad_->node_->GetPosition().z_)));
if (!yad_->hidden_
&& mouseIdleTime_ > IDLE_THRESHOLD * 0.5f ){
HideYad();
......@@ -94,11 +99,12 @@ void InputMaster::HideYad()
{
yad_->hidden_ = true;
FX->FadeOut(yad_->light_);
FX->FadeOut(yad_->material_, 0.1f);
}
void InputMaster::RevealYad()
{
yad_->hidden_ = false;
FX->FadeTo(yad_->light_, 1.0f);
RestoreYad();
}
Vector3 InputMaster::YadRaycast()
{
......@@ -109,7 +115,9 @@ Vector3 InputMaster::YadRaycast()
MC->world_.scene_->GetComponent<Octree>()->Raycast(query);
bool square{false};
if (RaycastToPiece()){
if (RaycastToPiece()
&& (rayPiece_->GetState() == PieceState::FREE
|| rayPiece_->GetState() == PieceState::SELECTED)){
if (MC->InPickState()){
MC->SelectPiece(rayPiece_);
if (!yad_->hidden_)
......@@ -122,6 +130,8 @@ Vector3 InputMaster::YadRaycast()
BOARD->Select(raySquare_);
if (yad_->hidden_)
RevealYad();
else
DimYad();
}
}
......@@ -131,12 +141,22 @@ Vector3 InputMaster::YadRaycast()
MC->DeselectPiece();
} else if (MC->InPutState() && !square){
BOARD->Deselect();
RestoreYad();
}
if (yad_->hidden_)
RevealYad();
return r.position_;
}
}
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::HandleKeys()
{
......@@ -424,8 +444,9 @@ void InputMaster::HandleActionButtonPressed()
selectedPiece->Pick();
BOARD->SelectNearestFreeSquare();
} else if (MC->selectionMode_ == SM_STEP)
MC->SelectLastPiece();
} else if (MC->selectionMode_ == SM_STEP || MC->selectionMode_ == SM_YAD)
if (!MC->SelectLastPiece())
MC->CameraSelectPiece();
else if (MC->selectionMode_ == SM_CAMERA)
MC->CameraSelectPiece();
......
......@@ -27,6 +27,9 @@
#define DEADZONE 0.34f
#define MOUSESPEED 0.23f
#define YAD_FULLBRIGHT 0.5f
#define YAD_DIMMED 0.1f
class Square;
typedef class Yad : public Object{
......@@ -35,7 +38,7 @@ public:
Yad() : Object(MC->GetContext()) {}
SharedPtr<Node> node_;
SharedPtr<AnimatedModel> model_;
SharedPtr<AnimatedModel> material_;
SharedPtr<Material> material_;
SharedPtr<Light> light_;
bool hidden_{true};
}Yad;
......@@ -111,6 +114,8 @@ private:
void HandleRightArrowPressed();
void HandleLeftArrowPressed();
bool CorrectJoystickId(int joystickId);
void DimYad();
void RestoreYad();
};
#endif // INPUTMASTER_H
......@@ -121,6 +121,13 @@ void MasterControl::CreateScene()
tableModel->SetMaterial(GetMaterial("Table"));
tableModel->GetMaterial()->SetShaderParameter("MatDiffColor", Vector4(0.32f, 0.40f, 0.42f, 1.0f));
tableModel->SetCastShadows(true);
Node* hitNode{world_.scene_->CreateChild("HitPlane")};
hitNode->SetPosition(Vector3::DOWN * 1.23f);
hitNode->SetScale(42.0f);
StaticModel* hitPlane{hitNode->CreateComponent<StaticModel>()};
hitPlane->SetModel(MC->GetModel("Plane"));
hitPlane->SetMaterial(MC->GetMaterial("Invisible"));
//Create board and pieces
world_.board_ = new Board();
......
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