Skip to content

Commit

Permalink
aplicado muchos fixes y emprolijado la lista para joinear partidas. f…
Browse files Browse the repository at this point in the history
…ixeados bugs de botones que seguian captando señales fuera de sus escenas. cambiados algunos colores de botones. testeado todos los posibles bugs, que pueden pasar mientras se joinea a una partida.
  • Loading branch information
nrsanchezfiuba committed Jun 25, 2024
1 parent 634948f commit 77ac104
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 122 deletions.
37 changes: 24 additions & 13 deletions client/menu_objects/match_selector.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
#include "match_selector.h"

MatchSelectorButton::MatchSelectorButton(SDL_Renderer* renderer,
std::shared_ptr<engine::ResourcePool> resource_pool,
SDL_Rect& d_rect, std::atomic<bool>& match_select_running,
std::atomic<bool>& caracter_select_running,
const std::string& label_info, uint16_t& selected_id,
uint16_t& id_match):
engine::Button(std::make_unique<engine::Label>(engine::Label(
resource_pool->get_font(FONT), d_rect, {255, 255, 255, 255},
{0, 0, 0, 255}, label_info, renderer)),
d_rect, {0, 0, 0, 255}, {255, 255, 255, 255}),
MatchSelector::MatchSelector(SDL_Renderer* renderer,
std::shared_ptr<engine::ResourcePool> resource_pool, int x, int y,
std::atomic<bool>& match_select_running,
std::atomic<bool>& caracter_select_running,
std::atomic<bool>& is_joinning, const std::string& label_info,
uint16_t id_match, uint16_t& selected_id):
engine::Button(std::make_unique<engine::Label>(
engine::Label(resource_pool->get_font(FONT), {x, y + 5, 280, 30},
{0, 0, 0, 255}, {0, 0, 0, 255}, label_info, renderer)),
{x, y, 330, 40}, get_random_color(), get_random_color()),
match_select_running(match_select_running),
caracter_select_running(caracter_select_running),
is_joinning(is_joinning),
selected_id(selected_id),
id_match(id_match) {}


void MatchSelectorButton::on_click() {
void MatchSelector::on_click() {
#ifdef LOG
std::cout << "Clicked Join match." << std::endl;
#endif
std::cout << "match button id: " << id_match << std::endl;
selected_id = id_match;
std::cout << "selected id: " << selected_id << std::endl;
is_joinning.store(true);
caracter_select_running.store(true);
match_select_running.store(false);
}

MatchSelectorButton::~MatchSelectorButton() = default;
SDL_Color MatchSelector::get_random_color() {
const Uint8 minBrightValue = 128;
Uint8 r = minBrightValue + rand() % (256 - minBrightValue);
Uint8 g = minBrightValue + rand() % (256 - minBrightValue);
Uint8 b = minBrightValue + rand() % (256 - minBrightValue);
return SDL_Color{r, g, b, 255};
}

MatchSelector::~MatchSelector() = default;
17 changes: 10 additions & 7 deletions client/menu_objects/match_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
#include "../../game_engine/gui/widgets/label.h"
#include "../protocol/client_message_handler.h"

class MatchSelectorButton: public engine::Button {
class MatchSelector: public engine::Button {
private:
std::atomic<bool>& match_select_running;
std::atomic<bool>& caracter_select_running;
std::atomic<bool>& is_joinning;
uint16_t& selected_id;
uint16_t& id_match;
uint16_t id_match;

public:
MatchSelectorButton(SDL_Renderer* renderer, std::shared_ptr<engine::ResourcePool> resource_pool,
SDL_Rect& d_rect, std::atomic<bool>& match_select_running,
std::atomic<bool>& caracter_select_running, const std::string& label_info,
uint16_t& selected_id, uint16_t& id_match);
MatchSelector(SDL_Renderer* renderer, std::shared_ptr<engine::ResourcePool> resource_pool,
int x, int y, std::atomic<bool>& match_select_running,
std::atomic<bool>& caracter_select_running, std::atomic<bool>& is_joinning,
const std::string& label_info, uint16_t id_match, uint16_t& selected_id);

void on_click() override;

~MatchSelectorButton() override;
SDL_Color get_random_color();

~MatchSelector() override;
};


Expand Down
19 changes: 10 additions & 9 deletions client/menu_objects/receive_matches_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

ReceiveMatchesButton::ReceiveMatchesButton(SDL_Renderer* renderer,
std::shared_ptr<engine::ResourcePool> resource_pool,
ClientMessageHandler& message_handler,
std::atomic<bool>& game_running,
std::atomic<bool>& match_select_running,
SDL_Rect& d_rect):
ClientMessageHandler& message_handler, SDL_Rect& d_rect,
std::atomic<bool>& match_requested):
engine::Button(std::make_unique<engine::Label>(engine::Label(
resource_pool->get_font(FONT), d_rect, {255, 255, 255, 255},
{0, 0, 0, 255}, "Find Online Matches", renderer)),
d_rect, {0, 0, 0, 255}, {255, 255, 255, 255}),
game_running(game_running),
match_select_running(match_select_running),
{255, 255, 255, 255}, "Refresh", renderer)),
{d_rect.x, d_rect.y, d_rect.w + 15, d_rect.h}, {0, 150, 0, 255},
{0, 0, 40, 255}),
match_requested(match_requested),
message_handler(message_handler) {}

void ReceiveMatchesButton::on_click() { message_handler.send_match_list_request(); }
void ReceiveMatchesButton::on_click() {
message_handler.send_match_list_request();
match_requested.store(true);
}

ReceiveMatchesButton::~ReceiveMatchesButton() = default;
7 changes: 3 additions & 4 deletions client/menu_objects/receive_matches_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

class ReceiveMatchesButton: public engine::Button {
private:
std::atomic<bool>& game_running;
std::atomic<bool>& match_select_running;
std::atomic<bool>& match_requested;
ClientMessageHandler& message_handler;

public:
ReceiveMatchesButton(SDL_Renderer* renderer,
std::shared_ptr<engine::ResourcePool> resource_pool,
ClientMessageHandler& message_handler, std::atomic<bool>& game_running,
std::atomic<bool>& match_select_running, SDL_Rect& d_rect);
ClientMessageHandler& message_handler, SDL_Rect& d_rect,
std::atomic<bool>& match_requested);

void on_click() override;

Expand Down
22 changes: 22 additions & 0 deletions client/menu_objects/return_to_menu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "return_to_menu.h"

ReturnToMenuButton::ReturnToMenuButton(SDL_Renderer* renderer,
std::shared_ptr<engine::ResourcePool> resource_pool,
SDL_Rect& d_rect, std::atomic<bool>& menu_running,
std::atomic<bool>& match_select_running):
engine::Button(std::make_unique<engine::Label>(engine::Label(
resource_pool->get_font(FONT), {d_rect.x, d_rect.y, 50, d_rect.h},
{255, 255, 255, 255}, {0, 0, 0, 255}, "Return to menu", renderer)),
d_rect, {0, 0, 0, 255}, {255, 255, 255, 255}),
menu_running(menu_running),
match_select_running(match_select_running) {}

void ReturnToMenuButton::on_click() {
#ifdef LOG
std::cout << "Clicked Return to menu." << std::endl;
#endif
menu_running.store(true);
match_select_running.store(false);
}

ReturnToMenuButton::~ReturnToMenuButton() {}
31 changes: 31 additions & 0 deletions client/menu_objects/return_to_menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef TP_FINAL_RETURN_TO_MENU_H
#define TP_FINAL_RETURN_TO_MENU_H

#include <atomic>
#include <memory>

#include <SDL2/SDL.h>

#include "../../common/assets.h"
#include "../../game_engine/gui/basic/resource_pool.h"
#include "../../game_engine/gui/widgets/button.h"
#include "../../game_engine/gui/widgets/label.h"
#include "../protocol/client_message_handler.h"

class ReturnToMenuButton: public engine::Button {
private:
std::atomic<bool>& menu_running;
std::atomic<bool>& match_select_running;

public:
ReturnToMenuButton(SDL_Renderer* renderer, std::shared_ptr<engine::ResourcePool> resource_pool,
SDL_Rect& d_rect, std::atomic<bool>& menu_running,
std::atomic<bool>& match_select_running);

void on_click() override;

~ReturnToMenuButton() override;
};


#endif
1 change: 1 addition & 0 deletions client/protocol/client_message_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void ClientMessageHandler::handle_connected_to_match(const ClientHasConnectedToM
}

void ClientMessageHandler::handle_recv_active_games(const MatchInfoDTO& dto) {
std::cout << "Received active games" << std::endl;
match_select_q.push(std::make_shared<MatchInfoDTO>(dto));
#ifdef LOG
std::cout << "Received active games" << std::endl;
Expand Down
12 changes: 11 additions & 1 deletion client/scenes/character_select_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CharacterSelectScene::CharacterSelectScene(engine::Window& window, EventLoop* ev
std::shared_ptr<engine::SoundManager> sound_manager,
std::atomic<bool>& game_running,
std::atomic<bool>& character_select_running,
std::atomic<bool>& is_joinning,
uint16_t& match_selected_id,
ClientMessageHandler& message_handler):
window(window),
renderer(window.get_renderer()),
Expand All @@ -18,6 +20,8 @@ CharacterSelectScene::CharacterSelectScene(engine::Window& window, EventLoop* ev
title_background(SDL_Color{0, 122, 16, 255}, SDL_Rect{0, 90, 800, 85}),
game_running(game_running),
character_select_running(character_select_running),
match_selected_id(match_selected_id),
is_joinning(is_joinning),
message_handler(message_handler),
selected_character(JAZZ_CHARACTER) {
auto texture = resource_pool->get_texture(CHARACTER_SELECT_FILE);
Expand Down Expand Up @@ -84,8 +88,14 @@ void CharacterSelectScene::start(uint16_t selected_map_id) {
frame_start += rate;
it++;
}
if (game_running) {

std::cout << "is joinning: " << (int)is_joinning << std::endl;
std::cout << "with id: " << match_selected_id << std::endl;
if (game_running && !is_joinning) {
message_handler.create_match(selected_character, selected_map_id, MAX_PLAYERS);
} else {
message_handler.join_match(match_selected_id, selected_character);
is_joinning = false;
}
}

Expand Down
3 changes: 3 additions & 0 deletions client/scenes/character_select_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CharacterSelectScene {

std::atomic<bool>& game_running;
std::atomic<bool>& character_select_running;
uint16_t& match_selected_id;
std::atomic<bool>& is_joinning;

ClientMessageHandler& message_handler;

Expand All @@ -48,6 +50,7 @@ class CharacterSelectScene {
std::shared_ptr<engine::SoundManager> sound_manager,
std::atomic<bool>& game_running,
std::atomic<bool>& character_select_running,
std::atomic<bool>& is_joinning, uint16_t& match_selected_id,
ClientMessageHandler& message_handler);

// cant copy
Expand Down
Loading

0 comments on commit 77ac104

Please sign in to comment.