Skip to content

Commit

Permalink
Merge branch 'developing' into music
Browse files Browse the repository at this point in the history
  • Loading branch information
niki4smirn authored Jun 4, 2022
2 parents e0674aa + b611eca commit 42e6471
Show file tree
Hide file tree
Showing 26 changed files with 603 additions and 23 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ add_executable(server
src/Server/Models/RoomModel/room_model.cpp
src/Server/Models/GameModel/game_model.cpp
src/Server/Games/AbstractMinigame/abstract_minigame.cpp
src/Server/Games/SampleMinigame/sample_minigame.cpp
src/Server/Games/TerminalMinigame/terminal_minigame.cpp
)

if (WIN32)
Expand Down Expand Up @@ -87,6 +87,7 @@ add_executable(client
src/Client/View/FinalScreen/final_screen.cpp
src/Client/View/NetworkProblemWidget/network_problem_widget.cpp
Resources/Sound/Sound.qrc
src/Client/Games/TerminalMinigameView/terminal_minigame_view.cpp
)

set(REQUIRED_QT_PARTS
Expand Down
5 changes: 5 additions & 0 deletions Protobuf/minigame_actions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ message SampleMinigame {
string str = 1;
}

message TerminalMinigame {
uint64 key_id = 1;
}

message MinigameAction {
uint64 minigame_id = 1;
oneof minigame {
SampleMinigame sample_minigame = 2;
TerminalMinigame terminal_minigame = 3;
}
}
11 changes: 11 additions & 0 deletions Protobuf/minigame_responses.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ message SampleResponse {
Role role = 2;
}

message InitialTerminalResponse {
repeated uint64 available_buttons_id = 1;
string text = 2;
}

message TerminalResponse {
string entered_text = 1;
}

message MinigameResponse {
enum Result {
kCompleted = 0;
Expand All @@ -21,5 +30,7 @@ message MinigameResponse {
oneof type {
Result result = 2;
SampleResponse sample_response = 3;
InitialTerminalResponse initial_terminal_respone = 4;
TerminalResponse terminal_response = 5;
}
}
Binary file added Resources/Fonts/Fairfax.ttf
Binary file not shown.
35 changes: 34 additions & 1 deletion src/Client/Controller/client_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void ClientController::Handle(const events::EventWrapper& event) {
++minigame_menu_pos;
}
view_->UpdateProgress(game_info.progress());
view_->ResetAllBulbs();
for (const auto& minigame_info : game_info.minigames_info()) {
auto minigame_pos = MinigamePosById(minigame_info.id());
if (minigame_pos) {
Expand All @@ -81,6 +82,10 @@ void ClientController::Handle(const events::EventWrapper& event) {
view_->ShowFinalScreen(game_result.score() != 0);
break;
}
case server_events::ServerEventWrapper::kGameResponse: {
const auto& game_response = server_event.game_response();
view_->UpdateMinigame(game_response);
}
default: {}
}
break;
Expand Down Expand Up @@ -135,7 +140,7 @@ void ClientController::ConnectView() {
if (minigame_id != 0) {
SendJoinMinigame(minigame_id);
}
});
});
connect(view_,
&ClientView::LeaveMinigame,
this,
Expand Down Expand Up @@ -216,6 +221,34 @@ void ClientController::SendStartGameEvent() {

void ClientController::SendKeyEvent(input::Name key) {
LOG << input::InputNameToString(key);

auto minigame = view_->IsMinigameStarted();
if (!minigame.has_value()) {
return;
}

switch (minigame.value()) {
case MinigameType::kTerminal: {
auto* terminal_minigame = new minigame_actions::TerminalMinigame();

terminal_minigame->set_key_id(static_cast<uint64_t>(key));

auto* game_action = new minigame_actions::MinigameAction;
game_action->set_allocated_terminal_minigame(terminal_minigame);
game_action->set_minigame_id(static_cast<uint64_t>(minigame.value()));

auto* game_event = new client_events::EventToGame;
game_event->set_allocated_minigame_action(game_action);

auto* client_event = new client_events::ClientEventWrapper;
client_event->set_allocated_event_to_game(game_event);

events::EventWrapper event;
event.set_allocated_client_event(client_event);

AddEventToSend(event);
}
}
}

void ClientController::SendMouseMoveEvent(const QPoint& pos) {
Expand Down
95 changes: 95 additions & 0 deletions src/Client/Games/TerminalMinigameView/terminal_minigame_view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "terminal_minigame_view.h"

#include <QFontDatabase>

#include "src/Client/InputController/input_names.h"

TerminalMinigameView::TerminalMinigameView(QWidget* parent)
: QWidget(parent),
static_text_(new QLabel(this)),
needed_text_(new QLabel(this)),
entered_text_(new QLabel(this)),
available_keys_(new QLabel(this)),
layout_(new QGridLayout(this)) {
QString family =
QFontDatabase::applicationFontFamilies(QFontDatabase::addApplicationFont(
"../Resources/Fonts/Fairfax.ttf")).at(0);
auto font = QFont(family);
font.setPointSize(36);

static_text_->setStyleSheet("QLabel {color : #20C20E; }");
static_text_->setFont(font);
needed_text_->setStyleSheet("QLabel {color : lightgray; }");
needed_text_->setFont(font);
entered_text_->setStyleSheet("QLabel {color : #20C20E; }");
entered_text_->setFont(font);
available_keys_->setStyleSheet("QLabel {color : #20C20E; }");
available_keys_->setFont(font);

layout_->addWidget(static_text_, 0, 0, Qt::AlignBottom | Qt::AlignLeft);
layout_->addWidget(needed_text_, 1, 0, Qt::AlignBottom | Qt::AlignLeft);
layout_->addWidget(entered_text_, 1, 0, Qt::AlignBottom | Qt::AlignLeft);
layout_->addWidget(available_keys_, 2, 0, Qt::AlignBottom | Qt::AlignLeft);

layout_->setRowStretch(0, 1);
layout_->setRowStretch(1, 1);
layout_->setRowStretch(2, 12);

setLayout(layout_);
repaint();
}

void TerminalMinigameView::PaintBackground(QPainter* painter) {
painter->save();

auto width = size().width();
auto height = size().width();

painter->setBrush(QColorConstants::Black);
painter->setPen(QColorConstants::Black);
painter->drawRect(0, 0, width, height);

painter->setBrush(QColor(32, 194, 14));
painter->drawRect(0, 0, width * (remaining_time_ * 1.0 / total_time_), 10);

painter->restore();
}

void TerminalMinigameView::paintEvent(QPaintEvent* event) {
QPainter painter(this);
PaintBackground(&painter);
}

void TerminalMinigameView::InitializeView(
const minigame_responses::MinigameResponse& response) {
auto& initial_response = response.initial_terminal_respone();
total_time_ = response.remaining_time();
remaining_time_ = total_time_;

needed_text_->setText(
text_prefix_ + QString::fromStdString(initial_response.text()));

QString available_keys = "Available keys: ";

for (const auto& id : initial_response.available_buttons_id()) {
QString temp = input::InputNameToString(static_cast<input::Name>(id));
temp.remove(0, 1);
available_keys += "\"" + temp + "\",";
}
available_keys.remove(available_keys.size() - 1, 1);

available_keys_->setText(available_keys);

repaint();
}

void TerminalMinigameView::UpdateView(
const minigame_responses::MinigameResponse& response) {
remaining_time_ = response.remaining_time();

auto& game_response = response.terminal_response();
entered_text_->setText(
text_prefix_ + QString::fromStdString(game_response.entered_text()));

repaint();
}
33 changes: 33 additions & 0 deletions src/Client/Games/TerminalMinigameView/terminal_minigame_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <QWidget>
#include <QPainter>
#include <QLabel>
#include <QGridLayout>

#include "Protobuf/minigame_responses.pb.h"

class TerminalMinigameView : public QWidget{
Q_OBJECT
public:
explicit TerminalMinigameView(QWidget* parent = nullptr);

void InitializeView(const minigame_responses::MinigameResponse& response);
void UpdateView(const minigame_responses::MinigameResponse& response);

private:
QLabel* static_text_;
QLabel* needed_text_;
QLabel* entered_text_;
QLabel* available_keys_;

QGridLayout* layout_;

const QString text_prefix_ = "user@spaceship:~/ ";

uint64_t total_time_ = 1;
uint64_t remaining_time_ = 1;

void PaintBackground(QPainter* painter);
void paintEvent(QPaintEvent* event) override;
};
2 changes: 1 addition & 1 deletion src/Client/Games/minigames_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using MinigameId = uint64_t;
enum class MinigameType {
kNone = 0,

kSample = 1,
kTerminal = 1,

kLast
};
72 changes: 72 additions & 0 deletions src/Client/View/FinalGameWidget/game_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,75 @@ void GameWidget::SetBulbsCount(int minigame_pos, int count) {
default: {}
}
}

void GameWidget::TurnOffGreen() {
QPixmap pixmap_red(":Bulbs/red_bulb_off.png");
pixmap_red = pixmap_red.scaled(red_bulb_green_->size());
red_bulb_green_->setPixmap(pixmap_red);

QPixmap pixmap_yellow(":Bulbs/yellow_bulb_off.png");
pixmap_yellow = pixmap_yellow.scaled(yellow_bulb_green_->size());
yellow_bulb_green_->setPixmap(pixmap_yellow);

QPixmap pixmap_green(":Bulbs/green_bulb_off.png");
pixmap_green = pixmap_green.scaled(green_bulb_green_->size());
green_bulb_green_->setPixmap(pixmap_green);

QPixmap pixmap_blue(":Bulbs/blue_bulb_off.png");
pixmap_blue = pixmap_blue.scaled(blue_bulb_green_->size());
blue_bulb_green_->setPixmap(pixmap_blue);
}

void GameWidget::TurnOffRed() {
QPixmap pixmap_red(":Bulbs/red_bulb_off.png");
pixmap_red = pixmap_red.scaled(red_bulb_green_->size());
red_bulb_red_->setPixmap(pixmap_red);

QPixmap pixmap_yellow(":Bulbs/yellow_bulb_off.png");
pixmap_yellow = pixmap_yellow.scaled(yellow_bulb_green_->size());
yellow_bulb_red_->setPixmap(pixmap_yellow);

QPixmap pixmap_green(":Bulbs/green_bulb_off.png");
pixmap_green = pixmap_green.scaled(green_bulb_green_->size());
green_bulb_red_->setPixmap(pixmap_green);

QPixmap pixmap_blue(":Bulbs/blue_bulb_off.png");
pixmap_blue = pixmap_blue.scaled(blue_bulb_green_->size());
blue_bulb_red_->setPixmap(pixmap_blue);
}

void GameWidget::TurnOffPurple() {
QPixmap pixmap_red(":Bulbs/red_bulb_off.png");
pixmap_red = pixmap_red.scaled(red_bulb_green_->size());
red_bulb_purple_->setPixmap(pixmap_red);

QPixmap pixmap_yellow(":Bulbs/yellow_bulb_off.png");
pixmap_yellow = pixmap_yellow.scaled(yellow_bulb_green_->size());
yellow_bulb_purple_->setPixmap(pixmap_yellow);

QPixmap pixmap_green(":Bulbs/green_bulb_off.png");
pixmap_green = pixmap_green.scaled(green_bulb_green_->size());
green_bulb_purple_->setPixmap(pixmap_green);

QPixmap pixmap_blue(":Bulbs/blue_bulb_off.png");
pixmap_blue = pixmap_blue.scaled(blue_bulb_green_->size());
blue_bulb_purple_->setPixmap(pixmap_blue);
}

void GameWidget::TurnOffBlue() {
QPixmap pixmap_red(":Bulbs/red_bulb_off.png");
pixmap_red = pixmap_red.scaled(red_bulb_green_->size());
red_bulb_blue_->setPixmap(pixmap_red);

QPixmap pixmap_yellow(":Bulbs/yellow_bulb_off.png");
pixmap_yellow = pixmap_yellow.scaled(yellow_bulb_green_->size());
yellow_bulb_blue_->setPixmap(pixmap_yellow);

QPixmap pixmap_green(":Bulbs/green_bulb_off.png");
pixmap_green = pixmap_green.scaled(green_bulb_green_->size());
green_bulb_blue_->setPixmap(pixmap_green);

QPixmap pixmap_blue(":Bulbs/blue_bulb_off.png");
pixmap_blue = pixmap_blue.scaled(blue_bulb_green_->size());
blue_bulb_blue_->setPixmap(pixmap_blue);
}
5 changes: 5 additions & 0 deletions src/Client/View/FinalGameWidget/game_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class GameWidget : public QWidget {

void SetProgress(int progress, int max_progress);
void SetBulbsCount(int minigame_pos, int count);
void TurnOffGreen();
void TurnOffRed();
void TurnOffPurple();
void TurnOffBlue();


signals:
void JoinMinigame(int minigame_index_pos);
Expand Down
11 changes: 11 additions & 0 deletions src/Client/View/FinalScreen/final_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ FinalScreen::FinalScreen(QWidget* parent) : QWidget(parent) {
SetLayout();
UpdateInfo();
Connect();
setMouseTracking(true);
background_->setMouseTracking(true);
to_lobby_button_->setMouseTracking(true);
to_menu_button_->setMouseTracking(true);
info_->setMouseTracking(true);
game_name_->setMouseTracking(true);
}

void FinalScreen::SetSize() {
Expand Down Expand Up @@ -89,3 +95,8 @@ void FinalScreen::SetResult(bool victory) {
victory_ = victory;
UpdateInfo();
}

void FinalScreen::mouseMoveEvent(QMouseEvent* event) {
QWidget::mouseMoveEvent(event);
background_->SetCenterPos(event->pos());
}
2 changes: 2 additions & 0 deletions src/Client/View/FinalScreen/final_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class FinalScreen : public QWidget {

~FinalScreen() override = default;

void mouseMoveEvent(QMouseEvent* event) override;

void SetResult(bool victory);

private:
Expand Down
8 changes: 0 additions & 8 deletions src/Client/View/MainMenu/Background/background_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ void BackgroundWidget::paintEvent(QPaintEvent*) {
Paint(&painter);
}

void BackgroundWidget::mousePressEvent(QMouseEvent*) {
SetLightEffect(true);
}

void BackgroundWidget::mouseReleaseEvent(QMouseEvent*) {
SetLightEffect(false);
}

void BackgroundWidget::mouseMoveEvent(QMouseEvent* event) {
SetCenterPos(event->pos());
}
Expand Down
Loading

0 comments on commit 42e6471

Please sign in to comment.