Commit 96ff51e0 authored by 魔大农's avatar 魔大农 🍀

Started on menu

parent c87d5cb4
......@@ -37,3 +37,7 @@ quatter
# Blender
*.blend*
# Settings
Resources/Settings.xml
os: linux
dist: trusty
compiler: gcc
language: cpp
sudo: false
cache:
apt: true
submodules: false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- build-essential
- make
- g++-4.9
- libx11-dev
- libxrandr-dev
- libasound2-dev
- git
before_script:
- wget --no-check-certificate https://cmake.org/files/v3.9/cmake-3.9.2-Linux-x86_64.tar.gz -O - | tar zx -C $HOME
- export PATH=$HOME/cmake-3.9.2-Linux-x86_64/bin:$PATH
script:
- git clone https://github.com/Urho3D/Urho3D
- cd Urho3D
- cmake . -Wno-dev -DURHO3D_SAMPLES=0 -DURHO3D_URHO2D=0 -DURHO3D_TOOLS=0 -DURHO3D_ANGELSCRIPT=0 -DURHO3D_LUA=0 && make
- cd ..
- qmake Quatter.pro -Wnone
- make
No preview for this file type
......@@ -27,7 +27,8 @@ SOURCES += \
effectmaster.cpp \
square.cpp \
yad.cpp \
indicator.cpp
indicator.cpp \
guimaster.cpp
HEADERS += \
luckey.h \
......@@ -40,7 +41,8 @@ HEADERS += \
effectmaster.h \
square.h \
yad.h \
indicator.h
indicator.h \
guimaster.h
unix {
isEmpty(PREFIX) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -58,33 +58,34 @@ void Board::OnNodeSet(Node *node)
void Board::CreateSquares()
{
for (int i{0}; i < BOARD_WIDTH; ++i)
for (int i{0}; i < BOARD_WIDTH; ++i) {
for (int j{0}; j < BOARD_HEIGHT; ++j) {
Node* squareNode{ node_->CreateChild("Square") };
Node* squareNode{ node_->CreateChild("Square", LOCAL) };
Square* square{ squareNode->CreateComponent<Square>() };
IntVector2 coords{ i, j };
square->coords_ = coords;
squareNode->SetPosition(CoordsToPosition(coords));
squares_[square->coords_] = square;
}
}
}
void Board::CreateIndicators()
{
for (int i{0}; i < 6; ++i) {
Node* indicatorNode{ node_->CreateChild("Indicator") };
Node* indicatorNode{ node_->CreateChild("Indicator", LOCAL) };
indicatorNode->SetPosition(GetThickness() * Vector3::UP);
Indicator* indicator{ indicatorNode->CreateComponent<Indicator>() };
indicator->Init(i);
indicators_.Push(SharedPtr<Indicator>(indicator));
indicators_.Push(indicator);
}
}
void Board::Reset()
{
for (Square* s: squares_.Values()) {
for (Square* s : squares_.Values()) {
s->free_ = true;
s->piece_ = nullptr;
......@@ -101,6 +102,7 @@ void Board::Refuse()
Material* glow{ selectedSquare_->slot_->GetMaterial() };
glow->SetShaderParameter("MatDiffColor", Color(1.0f, 0.0f, 0.0f, 1.0f));
if (selectedSquare_->free_)
FX->FadeTo(glow, COLOR_GLOW, 0.23f);
else
......@@ -122,7 +124,8 @@ bool Board::IsFull() const
{
for (Square* s : squares_.Values()) {
if (s->free_) return false;
if (s->free_)
return false;
}
return true;
......@@ -138,7 +141,7 @@ Vector3 Board::CoordsToPosition(IntVector2 coords)
void Board::HandleSceneUpdate(StringHash eventType, VariantMap& eventData)
{ (void)eventType; (void)eventData;
for (Square* s : squares_.Values()){
for (Square* s : squares_.Values()) {
s->slot_->SetMorphWeight(0, MC->Sine(2.3f, 0.0f, 1.0f));
......@@ -175,33 +178,45 @@ bool Board::PutPiece(Piece* piece, Square* square)
return true;
} else {
Refuse();
return false;
}
}
bool Board::PutPiece(Piece* piece) {
if (!selectedSquare_){
bool Board::PutPiece(Piece* piece)
{
if (!selectedSquare_) {
SelectLast();
return false;
} else
} else {
return PutPiece(piece, selectedSquare_);
}
}
bool Board::PutPiece(Square* square) {
bool Board::PutPiece(Square* square)
{
return PutPiece(MC->GetPickedPiece(), square);
}
bool Board::PutPiece(){
bool Board::PutPiece()
{
return PutPiece(MC->GetPickedPiece());
}
Square* Board::GetNearestSquare(Vector3 pos, bool free)
{
Square* nearest{};
for (Square* s : squares_.Values()){
if (!nearest ||
LucKey::Distance(s->node_->GetWorldPosition(), pos) <
for (Square* s : squares_.Values()) {
if (!nearest
|| LucKey::Distance(s->node_->GetWorldPosition(), pos) <
LucKey::Distance(nearest->node_->GetWorldPosition(), pos))
{
if (s->free_ || !free)
nearest = s;
}
}
return nearest;
}
......@@ -258,12 +273,18 @@ void Board::Deselect()
void Board::Step(IntVector2 step)
{
if (selectedSquare_){
IntVector2 newCoords{selectedSquare_->coords_ + step};
if (selectedSquare_) {
IntVector2 newCoords{ selectedSquare_->coords_ + step };
if (squares_.Contains(newCoords)){
Select(squares_[newCoords].Get());
Select(squares_[newCoords]);
}
} else SelectLast();
} else {
SelectLast();
}
}
bool Board::CheckQuatter()
......@@ -280,7 +301,7 @@ bool Board::CheckQuatter()
for (int i{0}; i < BOARD_WIDTH; ++i) {
IntVector2 coords(i, j);
Piece* piece{squares_[coords].Get()->piece_};
Piece* piece{squares_[coords]->piece_};
if (piece) {
......@@ -322,7 +343,7 @@ bool Board::CheckQuatter()
for (int j{0}; j < BOARD_HEIGHT; ++j) {
IntVector2 coords{ i, j };
Piece* piece{ squares_[coords].Get()->piece_ };
Piece* piece{ squares_[coords]->piece_ };
if (piece) {
......@@ -364,7 +385,7 @@ bool Board::CheckQuatter()
for (int i{0}; i < BOARD_WIDTH; ++i) {
IntVector2 coords{ i, direction ? i : (BOARD_WIDTH - i - 1) };
Piece* piece{ squares_[coords].Get()->piece_ };
Piece* piece{ squares_[coords]->piece_ };
if (piece) {
......@@ -409,7 +430,7 @@ bool Board::CheckQuatter()
for (int m : {0, 1}) for (int n : {0, 1}) {
IntVector2 coords{ k + m, l + n };
Piece* piece{ squares_[coords].Get()->piece_ };
Piece* piece{ squares_[coords]->piece_ };
if (piece) {
......@@ -446,6 +467,7 @@ bool Board::CheckQuatter()
//No Quatter
return false;
}
void Board::Indicate(IntVector2 first, IntVector2 last)
{
//Indicate single square (for keyboard selection)
......@@ -506,7 +528,7 @@ void Board::FadeInIndicator(Indicator* indicator, bool fast)
}
void Board::HideIndicators()
{
for (SharedPtr<Indicator> i : indicators_){
FX->FadeOut(i.Get()->glow_);
for (Indicator* i : indicators_){
FX->FadeOut(i->glow_);
}
}
......@@ -44,7 +44,7 @@ class Board : public LogicComponent
public:
Board(Context* context);
static void RegisterObject(Context* context);
void OnNodeSet(Node* node) override;
virtual void OnNodeSet(Node* node);
float GetThickness() const { return model_->GetBoundingBox().Size().y_; }
......@@ -56,7 +56,7 @@ public:
bool CheckQuatter();
void Step(IntVector2 step);
Vector<SharedPtr<Square>> GetSquares() const { return squares_.Values(); }
Vector<Square*> GetSquares() const { return squares_.Values(); }
Square* GetNearestSquare(Vector3 pos, bool free = true);
Square* GetSelectedSquare() const { return selectedSquare_; }
Square* GetLastSelectedSquare() const { return lastSelectedSquare_; }
......@@ -75,10 +75,10 @@ public:
private:
StaticModel* model_;
HashMap<IntVector2, SharedPtr<Square>> squares_;
HashMap<IntVector2, Square*> squares_;
Square* selectedSquare_;
Square* lastSelectedSquare_;
Vector<SharedPtr<Indicator>> indicators_;
Vector<Indicator*> indicators_;
Vector3 CoordsToPosition(IntVector2 coords);
void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
void Indicate(IntVector2 first, IntVector2 last = IntVector2(-1, -1));
......
/* Quatter
// Copyright (C) 2017 LucKey Productions (luckeyproductions.nl)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "quattercam.h"
#include "guimaster.h"
GUIMaster::GUIMaster(Context* context) : Master(context),
logoSprite_{},
activeSide_{0}
{
Init3DGUI();
CreateLogo();
SubscribeToEvent(E_UPDATE, URHO3D_HANDLER(GUIMaster, HandleUpdate));
}
void GUIMaster::Init3DGUI()
{
Node* tableNode_{ MC->world_.tableNode_ };
for (int s{0}; s < 4; ++s) {
faces_.Push(tableNode_->CreateChild("MenuPlane"));
faces_[s]->SetPosition(Quaternion(-90.0f * (s + 2), Vector3::UP) * Vector3(0.0f, -13.0f, 9.5f));
faces_[s]->SetRotation(Quaternion(-90.0f * (s + 2), Vector3::UP) * Quaternion(180.0f, Vector3::FORWARD) * Quaternion(90.0f, Vector3::RIGHT));
faces_[s]->SetScale({16.0f, 0.1f, 16.0f});
faces_[s]->CreateComponent<StaticModel>()->SetModel(MC->GetModel("Plane"));
UIComponent* uiComponent{ faces_[s]->CreateComponent<UIComponent>() };
uiComponent->GetMaterial()->SetTechnique(0, CACHE->GetResource<Technique>("Techniques/DiffAdd.xml"));
UIElement* uiRoot{ uiComponent->GetRoot() };
uiRoot->SetDefaultStyle(CACHE->GetResource<XMLFile>("UI/DefaultStyle.xml"));
switch (s) {
case 0: {
// Create the Window and add it to the UI's root node
uiRoot->SetSize(2048, 2048);
uiRoot->SetLayout(LM_FREE);
// Set Window size and layout settings
// window->SetMinWidth(1024);
// window->SetMinHeight(1024);
// window->SetLayout(LM_VERTICAL, 6, IntRect(6, 6, 6, 6));
// window->SetAlignment(HA_CENTER, VA_CENTER);
// window->SetName("Window");
// window->SetStyleAuto();
for (int b{0}; b < 5; ++b) {
Button* button{ new Button(context_) };
uiRoot->AddChild(button);
String name{};
switch (b) {
case 0:
name = "Multi";
break;
case 1:
name = "Local";
break;
case 2:
name = "Settings";
break;
case 3:
name = "Exit";
break;
case 4:
name = "AI";
break;
default:
break;
}
button->SetName(name);
button->SetTexture(CACHE->GetResource<Texture2D>("Textures/UI/" + name + ".png"));
button->SetAlignment(HA_CENTER, VA_CENTER);
button->SetPosition(IntVector2::RIGHT * uiRoot->GetWidth() / 23 + uiRoot->GetSize() * 0.5f + VectorFloorToInt(Vector2(1.0f, 0.8f) * LucKey::Rotate(Vector2::LEFT * uiRoot->GetHeight() * 0.34f, b * 360.0f / 5)));
button->SetSize(button->GetTexture()->GetWidth(), button->GetTexture()->GetHeight());
button->SetColor(C_TOPLEFT, COLOR_GLOW);
SubscribeToEvent(button, E_CLICK, URHO3D_HANDLER(GUIMaster, HandleClick));
}
} break;
default: {}
break;
}
// // Create Window 'titlebar' container
// UIElement* titleBar = new UIElement(context_);
// titleBar->SetMinSize(0, 24);
// titleBar->SetVerticalAlignment(VA_TOP);
// titleBar->SetLayoutMode(LM_HORIZONTAL);
// // Create the Window title Text
// Text* windowTitle = new Text(context_);
// windowTitle->SetName("WindowTitle");
// windowTitle->SetText("Hello GUI!");
// // Create the Window's close button
// Button* buttonClose = new Button(context_);
// buttonClose->SetName("CloseButton");
// // Add the controls to the title bar
// titleBar->AddChild(windowTitle);
// titleBar->AddChild(buttonClose);
// // Add the title bar to the Window
// window->AddChild(titleBar);
// windowTitle->SetStyleAuto();
// buttonClose->SetStyle("CloseButton");
}
}
void GUIMaster::CreateLogo()
{
Texture2D* logoTexture{ CACHE->GetResource<Texture2D>("Textures/Logo.png") };
if (!logoTexture)
return;
logoSprite_ = GUI->GetRoot()->CreateChild<Sprite>();
// Set logo sprite texture
logoSprite_->SetTexture(logoTexture);
int textureWidth{ logoTexture->GetWidth() };
int textureHeight{ logoTexture->GetHeight() };
logoSprite_->SetScale(Min(1.0f, (GRAPHICS->GetHeight() / static_cast<float>(textureHeight)) * 0.42f));
logoSprite_->SetSize(textureWidth, textureHeight);
logoSprite_->SetHotSpot(textureWidth / 2, 0);
logoSprite_->SetAlignment(HA_CENTER, VA_TOP);
logoSprite_->SetOpacity(0.99f);
logoSprite_->SetPriority(-100);
}
void GUIMaster::SetLogoVisible(bool enable)
{
logoSprite_->SetVisible(enable);
INPUT->SetMouseVisible(enable);
for (Node* face : faces_) {
face->SetEnabled(enable);
}
}
void GUIMaster::HandleUpdate(StringHash eventType, VariantMap& eventData)
{ (void)eventType;
for (Node* node : faces_) {
UIComponent* uiComponent{ node->GetComponent<UIComponent>() };
UIElement* uiRoot{ uiComponent->GetRoot() };
for (SharedPtr<UIElement> el : uiRoot->GetChildren()) {
for (int c{0}; c < 4; ++c)
el->SetColor(static_cast<Corner>(c), (el->GetColor(static_cast<Corner>(c)) + COLOR_GLOW * Random(0.23f, 2.3f)) * 0.5f);
}
}
}
void GUIMaster::HandleClick(StringHash eventType, VariantMap& eventData)
{ (void)eventType;
UIElement* element{ static_cast<UIElement*>(eventData[Click::P_ELEMENT].GetPtr()) };
if (!element)
return;
if (element->GetName() == "Exit")
MC->Exit();
else if (element->GetName() == "Settings")
activeSide_ = 1;
else if (element->GetName() == "Multi")
activeSide_ = 3;
else if (element->GetName() == "Local"){
MC->world_.camera_->TargetBoard();
MC->Reset();
}
}
/* Quatter
// Copyright (C) 2017 LucKey Productions (luckeyproductions.nl)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef GUIMASTER_H
#define GUIMASTER_H
#include <Urho3D/Urho3D.h>
#include "master.h"
class GUIMaster : public Master
{
URHO3D_OBJECT(GUIMaster, Master);
public:
GUIMaster(Context* context);
void EnterMenu();
int GetActiveSide() const { return activeSide_; }
void SetLogoVisible(bool enable);
private:
int activeSide_;
Sprite* logoSprite_;
void Init3DGUI();
void CreateLogo();
Vector<Node*> faces_;
void HandleUpdate(StringHash eventType, VariantMap& eventData);
void HandleClick(StringHash eventType, VariantMap& eventData);
};
#endif // GUIMASTER_H
......@@ -31,18 +31,20 @@ Indicator::Indicator(Context* context) : LogicComponent(context)
void Indicator::OnNodeSet(Node *node)
{ if (!node) return;
node_->AddTag("Indicator");
glow_ = MC->GetMaterial("Glow")->Clone();
//Create nodes and models
arrowNode1_ = node_->CreateChild("Arrow");
arrowNode1_ = node_->CreateChild("Arrow", LOCAL);
arrowNode1_->Rotate(Quaternion(-90.0f, Vector3::UP));
model1_ = arrowNode1_->CreateComponent<AnimatedModel>();
arrowNode2_ = node_->CreateChild("Arrow");
arrowNode2_ = node_->CreateChild("Arrow", LOCAL);
arrowNode2_->Rotate(Quaternion(90.0f, Vector3::UP));
model2_ = arrowNode2_->CreateComponent<AnimatedModel>();
//Create lights
Node* lightNode1{arrowNode1_->CreateChild("Light")};
Node* lightNode1{ arrowNode1_->CreateChild("Light", LOCAL) };
lightNode1->SetPosition(Vector3::UP * 0.23f);
light1_ = lightNode1->CreateComponent<Light>();
light1_->SetColor(COLOR_GLOW);
......@@ -50,7 +52,7 @@ void Indicator::OnNodeSet(Node *node)
light1_->SetRange(2.0f);
light1_->SetCastShadows(false);
Node* lightNode2{arrowNode2_->CreateChild("Light")};
Node* lightNode2{ arrowNode2_->CreateChild("Light", LOCAL) };
lightNode2->SetPosition(Vector3::UP * 0.23f);
light2_ = lightNode2->CreateComponent<Light>();
light2_->SetColor(COLOR_GLOW);
......
......@@ -31,7 +31,7 @@ class Indicator : public LogicComponent
public:
Indicator(Context* context);
static void RegisterObject(Context* context);
void OnNodeSet(Node* node) override;
virtual void OnNodeSet(Node* node);
private:
Node* arrowNode1_;
......
......@@ -62,17 +62,15 @@ void InputMaster::ConstructYad()
Node* yadNode{ MC->world_.scene_->CreateChild("Yad") };
yad_ = yadNode->CreateComponent<Yad>();
yad_->Hide();
}
void InputMaster::HandleUpdate(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
float t{ eventData[Update::P_TIMESTEP].GetFloat() };
idleTime_ += t;
mouseIdleTime_ += t;
sinceStep_ += t;
float timeStep{ eventData[Update::P_TIMESTEP].GetFloat() };
idleTime_ += timeStep;
mouseIdleTime_ += timeStep;
sinceStep_ += timeStep;
if (idleTime_ > IDLE_THRESHOLD)
SetIdle();
......@@ -80,12 +78,18 @@ void InputMaster::HandleUpdate(StringHash eventType, VariantMap &eventData)
if (mouseIdleTime_ > IDLE_THRESHOLD * 0.23f)
yad_->Hide();
HandleCameraMovement(t);
HandleCameraMovement(timeStep);
HandleKeys();
HandleJoystickButtons();
}
void InputMaster::AnyKey()
{
if (MC->GetGameState() == GameState::SPLASH)
MC->EnterMenu();
}
void InputMaster::HandleKeys()
{
for (int key : pressedKeys_) {
......@@ -123,12 +127,7 @@ void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
pressedKeys_.Insert(key);
switch (key) {
case KEY_ESCAPE:
if (!BOARD->IsEmpty() || MC->GetSelectedPiece() || MC->GetPickedPiece()) {
MC->Reset();
} else MC->Exit();
break;
case KEY_9:
MC->TakeScreenshot();
break;
......@@ -141,8 +140,19 @@ void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
case KEY_KP_MINUS:
MC->MusicGainDown(VOLUME_STEP);
break;
default: break;
case KEY_ESCAPE:
if (!BOARD->IsEmpty() || MC->GetSelectedPiece() || MC->GetPickedPiece()) {
MC->Reset();
} else {
MC->EnterMenu();
}
break;
default:
AnyKey();
break;
}
}
void InputMaster::HandleKeyUp(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
......@@ -175,8 +185,11 @@ void InputMaster::Step(Vector3 step)
if (sinceStep_ < STEP_INTERVAL)
return;
if (MC->InMenu()) {
//Send to menu
return;
if (MC->InPickState()) {
} else if (MC->InPickState()) {
sinceStep_ = 0.0f;
if (step == Vector3::RIGHT || step == Vector3::UP)
......@@ -219,6 +232,9 @@ void InputMaster::Step(Vector3 step)
void InputMaster::HandleMouseMove(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
if (MC->InMenu())
return;
UpdateMousePos();
mousePos_.x_ += eventData[MouseMove::P_DX].GetFloat() / GRAPHICS->GetWidth();
......@@ -248,7 +264,12 @@ void InputMaster::HandleMouseMove(StringHash eventType, VariantMap &eventData)
void InputMaster::HandleMouseButtonDown(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
int button{eventData[MouseButtonDown::P_BUTTON].GetInt()};
if (MC->InMenu()) {
AnyKey();
return;
}
int button{ eventData[MouseButtonDown::P_BUTTON].GetInt() };
pressedMouseButtons_.Insert(button);
mouseMoveSinceClick_ = Vector2::ZERO;
......@@ -265,7 +286,10 @@ void InputMaster::HandleMouseButtonDown(StringHash eventType, VariantMap &eventD
void InputMaster::HandleMouseButtonUp(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
int button{eventData[MouseButtonUp::P_BUTTON].GetInt()};
if (MC->InMenu())
return;
int button{ eventData[MouseButtonUp::P_BUTTON].GetInt() };
if (pressedMouseButtons_.Contains(button))
pressedMouseButtons_.Erase(button);
......@@ -305,11 +329,14 @@ void InputMaster::HandleMouseButtonUp(StringHash eventType, VariantMap &eventDat
void InputMaster::HandleMouseWheel(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
CAMERA->SetDistance(CAMERA->GetDistance() - eventData[MouseWheel::P_WHEEL].GetInt() * 2.3f);
CAMERA->Zoom(eventData[MouseWheel::P_WHEEL].GetInt() * 2.3f);
}
void InputMaster::UpdateYad()
{
if