diff --git a/Controllers/Enums.h b/Controllers/Enums.h new file mode 100644 index 0000000..cd2eb48 --- /dev/null +++ b/Controllers/Enums.h @@ -0,0 +1,95 @@ +#ifndef ENUMS_H +#define ENUMS_H + +struct CountInEnums +{ + int resources() { return 10; } +}; + + +enum class Contents +{ + Resource, + Unit, + Building +}; + + +enum class MainLandscapes +{ + Plain, + Mountain, + Tundra, + Snow, + Ice, + Coast, + Desert, + Ocean +}; + + +enum class OtherLandscapes +{ + Nothing, + Forest, + Jungles, + Hills, + ForestAndHills, + JunglesAndHills +}; + + +enum class Units +{ + Bowman, + Citizen, + Swordsman, + Worker, +}; + + +enum class Resources +{ + Fish, + Oil, + Aluminum, + Coal, + Horses, + Gold, + Iron, + Silver, + Stone, + Uranium, +}; + + +enum class Buildings +{ + Farm, + FishingBoat, + Fort, + LumberMill, + Mine, + OilWell, + Pasture, + Quarry, + Town, + TradingPost +}; + + +enum class Countries +{ + Nothing, + Russia, + America, + China, + England +}; + +enum class Mod{ + Show, + Play +}; + +#endif // ENUMS_H diff --git a/Controllers/FindUnitWay.cpp b/Controllers/FindUnitWay.cpp new file mode 100644 index 0000000..0e85439 --- /dev/null +++ b/Controllers/FindUnitWay.cpp @@ -0,0 +1,67 @@ +#include "FindUnitWay.h" +#include "iostream" + + +void OneMove::add_move(Position pos) +{ + minimove.push_back(pos); + end = pos; +} + +OneMove Way::get_move_in_way(size_t num_move) const{ + if(num_move > way.size()) + throw std::runtime_error("get_move_in_way(): The path has fewer moves"); + return way[num_move]; +} + +size_t Way::get_count_moves_in_way() const +{ + return way.size(); +} + +void Way::add_move(OneMove move) +{ + way.push_back(move); +} + +Way FindUnitWay::get_way(class Unit *unit, IMapForFind *map, Position start, Position end) +{ + Position go{start}; + Way way; + OneMove onemove{start}; + + int movement_points = unit->get_movement(); + if (!movement_points) + movement_points = unit->get_max_movement(); + while(go != end) + { + std::vector neighbors = map->adjacent_cells(go); + Position min_distance{neighbors[0]}; + for(size_t i{1}; i < neighbors.size(); ++i) + { + Position temp{neighbors[i]}; + if(abs(int(temp.y) - int(end.y)) < abs(int(min_distance.y) - int(end.y))) + min_distance = temp; + if(abs(int(temp.y) - int(end.y)) == abs(int(min_distance.y) - int(end.y))) + if(abs(int(temp.x) - int(end.x)) < abs(int(min_distance.x) - int(end.x))) + min_distance = temp; + } + onemove.add_move(min_distance); + onemove.spent_movement_points++; + go = min_distance; + --movement_points; + if(!movement_points) + { + movement_points = unit->get_max_movement(); + way.add_move(onemove); + onemove = OneMove{min_distance}; + } + } + way.add_move(onemove); + return way; +} + +OneMove FindUnitWay::get_first_move(class Unit* unit, IMapForFind* map, Position start, Position end) +{ + return get_way(unit, map, start, end).get_move_in_way(0); +} diff --git a/Controllers/FindUnitWay.h b/Controllers/FindUnitWay.h new file mode 100644 index 0000000..e7b5419 --- /dev/null +++ b/Controllers/FindUnitWay.h @@ -0,0 +1,55 @@ +#ifndef FINDUNITWAY_H +#define FINDUNITWAY_H + +#include + +#include "../Graphics/Map/IMap.h" +#include "../Graphics/Units/Unit.h" +#include "../IObject.h" + + +struct OneMove +{ + Position start; + Position end; + int spent_movement_points = 0; + + /* + * массив который хранит подперемещения в одном перемещении + * первый элемент равняется start + * последний элемент равняется end + */ + std::vector minimove; + + OneMove(Position _start, Position _end, + int _spent_movement_points, std::vector _minimove) + :start{_start}, end{_end}, spent_movement_points{_spent_movement_points}, + minimove{_minimove} + {} + OneMove(Position _start) + :start{_start}, end{_start} + { minimove.push_back(start); } + + void add_move(Position pos); +}; + + +class Way : public IObject +{ + std::vector way; +public: + /// number_move с нуля + OneMove get_move_in_way(size_t number_move) const; + size_t get_count_moves_in_way() const; + void add_move(OneMove move); +}; + + +class FindUnitWay : public IObject +{ +public: + Way get_way(class Unit* unit, IMapForFind* map, Position start, Position end); + OneMove get_first_move(class Unit* unit, IMapForFind* map, Position start, Position end); +}; + +#endif // FINDUNITWAY_H diff --git a/Controllers/FindVision.cpp b/Controllers/FindVision.cpp new file mode 100644 index 0000000..c4460e9 --- /dev/null +++ b/Controllers/FindVision.cpp @@ -0,0 +1,56 @@ +#include "FindVision.h" +#include + + +std::vector FindVision::unit_vision(class Unit* unit, Position pos_unit, IMapForFind* map) const +{ + std::vector res; + + std::queue> queue; + queue.push({pos_unit, unit->get_vision()}); + while(!queue.empty()){ + std::pair pair = queue.front(); + queue.pop(); + if(std::find(res.begin(), res.end(), pair.first) == res.end()) + res.push_back(pair.first); + + if(pair.second != 0) + for(Position pos : map->adjacent_cells(pair.first)) + queue.push({pos, pair.second-1}); + } + return res; +} + +std::vector FindVision::town_vision(PlayerTown* town, IMapForFind* map) const +{ + std::vector res; + + std::queue> queue; + queue.push({town->position_town(), 3}); + while(!queue.empty()){ + std::pair pair = queue.front(); + queue.pop(); + if(std::find(res.begin(), res.end(), pair.first) == res.end()) + { + Countries country_cell = map->get_cell_country(pair.first); + bool is_visible = false; + + if(town->get_country() == country_cell) + is_visible = true; + + for(auto pos : map->adjacent_cells(pair.first)) + { + country_cell = map->get_cell_country(pos); + if(town->get_country() == country_cell) + is_visible = true; + } + if(is_visible) + res.push_back(pair.first); + } + + if(pair.second != 0) + for(Position pos : map->adjacent_cells(pair.first)) + queue.push({pos, pair.second-1}); + } + return res; +} diff --git a/Controllers/FindVision.h b/Controllers/FindVision.h new file mode 100644 index 0000000..46652e7 --- /dev/null +++ b/Controllers/FindVision.h @@ -0,0 +1,20 @@ +#ifndef FINDUNITVISION_H +#define FINDUNITVISION_H + +#include +#include + +#include "Player/PlayerTown.h" +#include "../IObject.h" +#include "../Graphics/Map/IMap.h" +#include "../Graphics/Units/Unit.h" + + +class FindVision : public IObject +{ +public: + std::vector unit_vision(class Unit* unit, Position pos_unit, IMapForFind* map) const; + std::vector town_vision(PlayerTown* town, IMapForFind* map) const; +}; + +#endif // FINDUNITVISION_H diff --git a/Controllers/Game.cpp b/Controllers/Game.cpp new file mode 100644 index 0000000..e9e8de8 --- /dev/null +++ b/Controllers/Game.cpp @@ -0,0 +1,121 @@ +#include "Game.h" +#include + +Game::Game(QApplication* app, size_t count_cell_x, size_t count_cell_y, size_t count_players, Mod _mod) + :_graphics_controller {new GraphicsController(this)}, mod{_mod} +{ + _count_cell_x = count_cell_x; + _count_cell_y = count_cell_y; + _count_players = count_players; + QSize size_screen = app->primaryScreen()->size(); + _width_win = size_screen.width(); + _height_win = size_screen.height(); +} + +void Game::start() +{ + _graphics_controller->do_start_menu(); + _graphics_controller->get_imenu_start_full()->start_game(); +} + +void Game::start_game() +{ + _graphics_controller->create_elements(); + if (_count_players < 1) + throw std::runtime_error("There can't be less than 1 players"); + do_players(_count_players); + _current_player = players[0].get(); + + _current_player->draw_my_map(); + _graphics_controller->get_iplayer_gc()->update_res_inform(_current_player); + do_start_inform(); +} + +size_t Game::count_cell_x() const +{ + return _count_cell_x; +} + +size_t Game::count_cell_y() const +{ + return _count_cell_y; +} + +int Game::width_win() const +{ + return _width_win; +} + +int Game::height_win() const +{ + return _height_win; +} + +void Game::next_move() +{ + if(!_current_player->is_finish()) + { + _current_player->start_move(); + return; + } + _current_player->end_move(); + size_t num_player = num_curr_player(); + if(++num_player == players.size()) + num_player = 0; + _current_player = players[num_player].get(); + _current_player->draw_my_map(); + do_start_inform(); + _graphics_controller->window()->update(); +} + +IPlayer* Game::current_player() const +{ + return _current_player; +} + +IGameForWidget* Game::igame_for_widget() +{ + return this; +} + +IPlayerGraphicsController* Game::graphics_controller() const +{ + return _graphics_controller->get_iplayer_gc(); +} + +void Game::start_move() +{ + std::cout << "new move" << std::endl; + _graphics_controller->del_start_inform(); + _current_player->start_move(); +} + +QWidget* Game::window() const +{ + return _graphics_controller->window(); +} + +void Game::do_players(size_t count_players) +{ + players.clear(); + auto create_map = CreateMap{_graphics_controller.get()->get_imap_gc_full()}; + auto positions = create_map.initial_pos_player(int(count_players), _graphics_controller->get_imap_gc_full()->get_map()); + for(size_t i{0}; i < count_players; ++i) + { + players.push_back(std::unique_ptr{new Player(this, Countries(i+1), mod)}); + players[i]->set_initial_units(positions[i]); + } +} + +size_t Game::num_curr_player() +{ + for(size_t i{0}; i < players.size(); ++i) + if(players[i].get() == _current_player) + return i; + throw std::runtime_error("Cann't find current player"); +} + +void Game::do_start_inform() +{ + _graphics_controller->do_start_inform("Все хорошо.\n Следующий ход.\n"); +} diff --git a/Controllers/Game.h b/Controllers/Game.h new file mode 100644 index 0000000..025d29d --- /dev/null +++ b/Controllers/Game.h @@ -0,0 +1,52 @@ +#ifndef GAME_H +#define GAME_H + +#include +#include + +#include + +#include "IGame.h" +#include "Player/Player.h" +#include "../Graphics/GraphicsController/GraphicsController.h" + + +class Game : public IGameForGraphic, public IGameForPlayer, public IGameForWidget +{ +public: + Game(QApplication* app, size_t count_cell_x, size_t count_cell_y, size_t count_players, Mod mod); + void start(); + virtual void start_game() override; + + virtual size_t count_cell_x() const override; + virtual size_t count_cell_y() const override; + virtual int width_win() const override; + virtual int height_win() const override; + virtual void exit() override {} + virtual void next_move() override; + virtual IPlayer* current_player() const override; + virtual IGameForWidget* igame_for_widget() override; + + virtual IPlayerGraphicsController* graphics_controller() const override; + + virtual void start_move() override; + virtual QWidget* window() const override; +private: + void do_players(size_t count_player); + size_t num_curr_player(); + void do_start_inform(); + + std::unique_ptr _graphics_controller; + std::vector> players; + Player* _current_player; + + size_t _count_cell_x; + size_t _count_cell_y; + size_t _count_players; + int _width_win; + int _height_win; + + Mod mod; +}; + +#endif // GAME_H diff --git a/Controllers/IGame.h b/Controllers/IGame.h new file mode 100644 index 0000000..8c754ce --- /dev/null +++ b/Controllers/IGame.h @@ -0,0 +1,42 @@ +#ifndef IGAME_H +#define IGAME_H + +#include "Player/IPlayer.h" +#include "../IObject.h" +#include "../Graphics/GraphicsController/IPlayerGraphicsController.h" +#include "../Graphics/GraphicsController/IWindowGraphicsController.h" + + +class IGameForWidget : public IObject +{ +public: + virtual void start_move() = 0; + virtual QWidget* window() const = 0; +}; + + +class IGameForGraphic : public IObject +{ +public: + virtual void start_game() = 0; + virtual size_t count_cell_x() const = 0; + virtual size_t count_cell_y() const = 0; + virtual int width_win() const = 0; + virtual int height_win() const = 0; + virtual void exit() = 0; + virtual void next_move() = 0; + virtual IPlayer* current_player() const = 0; + virtual IGameForWidget* igame_for_widget() = 0; + virtual void start_move() = 0; +}; + + +class IGameForPlayer : public IObject +{ +public: + virtual IPlayerGraphicsController* graphics_controller() const = 0; + virtual size_t count_cell_x() const = 0; + virtual size_t count_cell_y() const = 0; +}; + +#endif // IGAME_H diff --git a/Controllers/Player/BuildInTown.cpp b/Controllers/Player/BuildInTown.cpp new file mode 100644 index 0000000..3c967b1 --- /dev/null +++ b/Controllers/Player/BuildInTown.cpp @@ -0,0 +1,20 @@ +#include "BuildInTown.h" + +double BuildInTown::build(double town_production) +{ + if(need_production > town_production) + { + need_production -= town_production; + return 0.; + } + else{ + double remains = town_production - need_production; + need_production = 0; + return remains; + } +} + +void BuildInTown::build_next_level() +{ + need_production = TownBuildNeeds().get_build_need_production(building, level+1); +} diff --git a/Controllers/Player/BuildInTown.h b/Controllers/Player/BuildInTown.h new file mode 100644 index 0000000..f485d2b --- /dev/null +++ b/Controllers/Player/BuildInTown.h @@ -0,0 +1,39 @@ +#ifndef BUILDINTOWN_H +#define BUILDINTOWN_H + +#include "../TownBuildings.h" +#include "../TownBuildNeeds.h" + + +struct BuildInTown +{ + enum TypeBuild{ + Unit, + Building + }; + + TypeBuild type_build; + TownBuildings building; + int level = 0; + Units unit; + double need_production; + + BuildInTown(Units type_unit) + :type_build{TypeBuild::Unit}, unit{type_unit} + { + need_production = TownBuildNeeds().get_build_need_production(type_unit); + } + + BuildInTown(TownBuildings type_building) + :type_build{TypeBuild::Building}, building{type_building} + { + need_production = TownBuildNeeds().get_build_need_production(type_building, 1); + } + + //возвращает остаток + double build(double town_production); + + void build_next_level(); +}; + +#endif // BUILDINTOWN_H diff --git a/Controllers/Player/IMenuTownPlayer.h b/Controllers/Player/IMenuTownPlayer.h new file mode 100644 index 0000000..9ebd367 --- /dev/null +++ b/Controllers/Player/IMenuTownPlayer.h @@ -0,0 +1,20 @@ +#ifndef IMENUTOWNPLAYER_H +#define IMENUTOWNPLAYER_H + +#include "IObject.h" +#include "PlayerRes.h" +#include "PlayerScience.h" + + +class IMenuTownPlayer : public IObject +{ +public: + virtual PlayerScience* player_science() const = 0; + + virtual double get_gold() const = 0; + virtual double get_gold_per_turn() const = 0; + virtual double get_science_per_turn() const = 0; + virtual PlayerRes* get_player_res() const = 0; +}; + +#endif // IMENUTOWNPLAYER_H diff --git a/Controllers/Player/IPlayer.h b/Controllers/Player/IPlayer.h new file mode 100644 index 0000000..841763a --- /dev/null +++ b/Controllers/Player/IPlayer.h @@ -0,0 +1,21 @@ +#ifndef IPLAYER_H +#define IPLAYER_H + +#include "PlayerScience.h" +#include "../../Graphics/GraphicsController/EventsStructures.h" +#include "../../Graphics/Units/Unit.h" +#include "../../IObject.h" + + +class IPlayer : public IObject +{ +public: + virtual void click_unit(class Unit* unit) = 0; + virtual void click_town(class Town* town) = 0; + virtual void del_menu_town() = 0; + virtual void set_initial_units(Position initial_cell) = 0; + virtual void menu_event(class Unit* unit, Event* event) = 0; + virtual PlayerScience* player_science() const = 0; +}; + +#endif // IPLAYER_H diff --git a/Controllers/Player/ITownPlayer.h b/Controllers/Player/ITownPlayer.h new file mode 100644 index 0000000..1afc342 --- /dev/null +++ b/Controllers/Player/ITownPlayer.h @@ -0,0 +1,19 @@ +#ifndef ITOWNPLAYER_H +#define ITOWNPLAYER_H + +#include "PlayerRes.h" +#include "PlayerScience.h" +#include "../Enums.h" +#include "../../IObject.h" + + +class ITownPlayer : public IObject +{ +public: + virtual PlayerScience* player_science() const = 0; + virtual PlayerRes* get_player_res() const = 0; + virtual void add_unit(Units type_unit, Position pos_cell) = 0; + virtual Countries get_country() const = 0; +}; + +#endif // ITOWNPLAYER_H diff --git a/Controllers/Player/Player.cpp b/Controllers/Player/Player.cpp new file mode 100644 index 0000000..8f924d4 --- /dev/null +++ b/Controllers/Player/Player.cpp @@ -0,0 +1,552 @@ +#include "Player.h" +#include + +Player::Player(IGameForPlayer* _game_controller, Countries _country, Mod _mod) + :game_controller{_game_controller}, country{_country}, mod{_mod}, + player_map{new PlayerMap({_game_controller->count_cell_x(), _game_controller->count_cell_y()}, _mod)}, + player_res{new PlayerRes(_mod)}, _player_science{new PlayerScience(_mod)} +{} + +Player::~Player() +{ + for(size_t i{0}; i < my_units.size(); ++i) + del_unit(my_units[i].get()); +} + +void Player::click_unit(class Unit* unit) +{ + PlayerUnit* my_unit = get_my_unit(unit); + if (my_unit) + unit_move(my_unit); +} + +void Player::click_town(class Town* town) +{ + PlayerTown* my_town = get_my_town(town); + if (my_town) + { + set_vision(false); + set_town_vision(my_town, true); + draw_my_map(); + + game_controller->graphics_controller()->centering_by_cell(my_town->position_town()); + game_controller->graphics_controller()->do_menu_town(this, my_town); + + } +} + +void Player::del_menu_town() +{ + set_vision(true); + draw_my_map(); +} + +void Player::set_initial_units(Position initial_cell) +{ + // add_unit(Units::Worker, initial_cell); +// add_unit(Units::Worker, initial_cell); + add_unit(Units::Citizen, initial_cell); + // build_town(&my_units[0]); + // click_town(my_towns[0]->town()); +// add_unit(Units::Bowman, initial_cell); +// add_unit(Units::Swordsman, initial_cell); + set_vision(true); +} + +PlayerUnit* Player::get_my_unit(class Unit* unit) +{ + for(size_t i{0}; i < my_units.size(); ++i) + if(my_units[i]->unit == unit) + return my_units[i].get(); + return nullptr; +} + +size_t Player::get_ind_my_unit(PlayerUnit* unit) +{ + for(size_t i{0}; i < my_units.size(); ++i) + if(my_units[i].get() == unit) + return i; + return my_units.size(); +} + +PlayerTown* Player::get_my_town(class Town* town) +{ + for(size_t i{0}; i < my_towns.size(); ++i) + if(my_towns[i]->town() == town) + return my_towns[i].get(); + return nullptr; +} + +void Player::menu_event(class Unit* unit, Event* event) +{ + // std::cout << "menu_event_ok" << std::endl; + + PlayerUnit* my_unit = get_my_unit(unit); + if(my_unit) + { + if(event->event == Events::Move) + { + MoveEvent* move_event = static_cast(event); + move_unit_event(my_unit, move_event); + return; + } + + if(unit->what_unit_I() == Units::Citizen) + event_for_citizen(my_unit, event); + else if(unit->what_unit_I() == Units::Worker) + event_for_worker(my_unit, event); + else + set_event_to_unit(my_unit, event); + } + else + throw std::runtime_error("set_event_to_unit: It's not my unit"); +} + +bool Player::is_finish() +{ + + do_events_unit(); + do_build_towns(); + for(size_t i{0}; i < my_units.size(); ++i) + { + if(my_units[i]->event->event != Events::NoEvent) + continue; + if(my_units[i]->unit->get_movement() == 0) + continue; + return false; + } + + for(size_t i{0}; i < my_towns.size(); ++i) + if(!my_towns[i]->get_build_queue().size()) + if(my_towns[i]->get_count_can_build()) + return false; + + if(player_science()->get_queue_science().size() == 0) + return false; + + return true; +} + +void Player::start_move() +{ + game_controller->graphics_controller()->update_res_inform(this); + for(size_t i{0}; i < my_units.size(); ++i) + if(my_units[i]->event->event == Events::NoEvent and my_units[i]->unit->get_movement() != 0) + { + unit_move(my_units[i].get()); + return; + } + for(size_t i{0}; i < my_towns.size(); ++i) + if(!my_towns[i]->get_build_queue().size()) + if(my_towns[i]->get_count_can_build()) + { + click_town(my_towns[i].get()->town()); + return; + } + + if(player_science()->get_queue_science().size() == 0) + game_controller->graphics_controller()->do_menu_science(); + + same_centering(); +} + +void Player::end_move() +{ + set_movement_to_max_unit(); + set_new_move_to_towns(); + player_science()->study(get_science_per_turn()); + gold += get_gold_per_turn(); + if(gold < 0.) + gold = 0.; +} + +void Player::draw_my_map() +{ + game_controller->graphics_controller()->draw_playermap(player_map.get(), _player_science.get()); +} + +PlayerScience* Player::player_science() const +{ + return _player_science.get(); +} + +void Player::set_event_to_unit(PlayerUnit* my_unit, Event* event) +{ + my_unit->event.reset(event); +} + + +void Player::event_for_citizen(PlayerUnit* my_unit, Event* event) +{ + if(event->event == Events::Build) + { + BuildEvent* build_event = static_cast(event); + if(build_event->building != Buildings::Town) + std::runtime_error("Citizen can build only town"); + set_vision(false); + build_town(my_unit); + set_vision(true); + draw_my_map(); + } + else + set_event_to_unit(my_unit, event); +} + +void Player::event_for_worker(PlayerUnit* my_unit, Event* event) +{ + if(event->event == Events::Build) + { + BuildEvent* build_event = static_cast(event); + my_unit->event.reset(event); + add_build(my_unit, build_event->building); + my_unit->unit->set_movement(0); + } + else + { + stop_build(my_unit); + set_event_to_unit(my_unit, event); + } +} + +void Player::move_unit_event(PlayerUnit* my_unit, MoveEvent* event) +{ + if(my_unit->unit->what_unit_I() == Units::Worker) + stop_build(my_unit); + + IMapForFind* map = game_controller->graphics_controller()->mapforfind(); + OneMove move = FindUnitWay().get_first_move(my_unit->unit, map, my_unit->pos, event->cell_move); + + for(size_t i{1}; i < move.minimove.size(); ++i) + { + int unit_movement = my_unit->unit->get_movement(); + if(unit_movement == 0) + break; + my_unit->unit->set_movement(unit_movement - 1); + + set_vision(false); + + Position move_cell = move.minimove[i]; + game_controller->graphics_controller()->move_unit( + my_unit->unit, my_unit->pos, move_cell); + my_unit->pos = move_cell; + + if(my_unit->unit->what_my_type() != Unit::Peaceful) + capture_cell(my_unit->pos); + set_vision(true); + } + + if(my_unit->pos == event->cell_move || my_unit->unit->get_movement() != 0) + { + delete event; + my_unit->event.reset(new struct NoEvent()); + } + else + { + my_unit->event.reset(event); + } + + draw_my_map(); +} + +void Player::set_vision(bool vision) +{ + for(size_t i{0}; i < my_units.size(); ++i) + { + IMapForFind* map = game_controller->graphics_controller()->mapforfind(); + std::vector unit_vision = + FindVision().unit_vision(my_units[i]->unit, my_units[i]->pos, map); + + for(Position pos : unit_vision) + if(vision) + player_map->set_show_cell(pos); + else + player_map->set_notvisible_cell(pos); + } + + for(auto& town : my_towns) + set_town_vision(town.get(), vision); +} + +void Player::set_town_vision(PlayerTown* town, bool vision) +{ + IMapForFind* map = game_controller->graphics_controller()->mapforfind(); + std::vector town_vision = FindVision().town_vision(town, map); + for(Position pos : town_vision) + if(vision) + player_map->set_show_cell(pos); + else + player_map->set_notvisible_cell(pos); +} + +void Player::set_movement_to_max_unit() +{ + for(size_t i{0}; i < my_units.size(); ++i) + my_units[i]->unit->set_movement(my_units[i]->unit->get_max_movement()); +} + +void Player::set_new_move_to_towns() +{ + for(size_t i{0}; i < my_towns.size(); ++i) + my_towns[i]->new_move(); +} + +void Player::do_events_unit() +{ + for(size_t i{0}; i < my_units.size(); ++i) + { + if(my_units[i]->event->event == Events::Move) + { + MoveEvent* move_event = static_cast(my_units[i]->event->copy()); + move_unit_event(my_units[i].get(), move_event); + } + } + + for(size_t i{0}; i < unit_build.size(); ++i) + { + PlayerUnit* unit = unit_build[i].unit; + if(!unit) + continue; + + if(unit->unit->get_movement() == 0) + continue; + + class Worker* worker = static_cast(unit->unit); + class Building* building = unit_build[i].building; + int phase = building->get_build_phase(); + building->set_build_phase(phase + worker->get_build_speed()); + + if(building->get_build_phase() == building->get_end_build_phase()) + { + add_res(unit_build[i].pos); + unit_build.erase(unit_build.begin() + i); + i--; + unit->event.reset(new struct NoEvent()); + } + unit->unit->set_movement(0); + } +} + +void Player::do_build_towns() +{ + for(size_t i{0}; i < my_towns.size(); ++i) + my_towns[i]->move_build(); +} + +void Player::build_town(PlayerUnit* my_unit) +{ + Position pos = my_unit->pos; + game_controller->graphics_controller()->centering_by_cell(pos); + class Building* building = game_controller-> + graphics_controller()->build(Buildings::Town, pos); + class Town* town = static_cast(building); + my_towns.push_back(std::unique_ptr{new PlayerTown{town, this, pos, mod}}); + del_unit(my_unit); + + auto map = game_controller->graphics_controller()->mapforfind(); + map->set_cell_country(pos, country); + + auto adjacent = map->adjacent_cells(pos); + for(auto cell_pos : adjacent) + if(map->get_cell_country(cell_pos) == Countries::Nothing) + map->set_cell_country(cell_pos, country); + // add_unit(Units::Worker, pos); + game_controller->graphics_controller()->update_res_inform(this); +} + +void Player::add_unit(Units type_unit, Position pos_cell) +{ + class Unit* unit = game_controller->graphics_controller()->add_unit(type_unit, pos_cell); + + unit->set_standard_charaterichtics(); + unit->set_country(country); + + my_units.push_back(std::unique_ptr{new PlayerUnit(unit, pos_cell)}); + + capture_cell(pos_cell); +} + +double Player::get_gold_per_turn() const +{ + double count = 0; + for(auto& town : my_towns) + count += town->get_gold_per_turn(); + return count; +} + +double Player::get_gold() const +{ + return gold; +} + +double Player::get_science_per_turn() const +{ + double count = 0; + for(auto& town : my_towns) + count += town->get_science_per_turn(); + return count; +} + +PlayerRes* Player::get_player_res() const +{ + return player_res.get(); +} + +Countries Player::get_country() const +{ + return country; +} + +void Player::del_unit(PlayerUnit* unit) +{ + game_controller->graphics_controller()->del_unit(unit->unit, unit->pos); + my_units.erase(my_units.begin() + get_ind_my_unit(unit)); +} + +void Player::unit_move(PlayerUnit* unit) +{ + game_controller->graphics_controller()->centering_by_cell(unit->pos); + game_controller->graphics_controller()->do_menu_unit(unit); + game_controller->graphics_controller()->highlight_unit(unit->unit, unit->pos); +} + +void Player::capture_cell(Position pos) +{ + auto map = game_controller->graphics_controller()->mapforfind(); + map->set_cell_country(pos, country); +} + +void Player::add_build(PlayerUnit* unit, Buildings type_building) +{ + for(size_t i{0}; i < unit_build.size(); ++i) + if(unit_build[i].pos == unit->pos) + { + if(unit_build[i].building->what_building_I() == type_building) + { + unit_build[i].unit = unit; + if(unit->unit->get_movement() != 0) + { + class Worker* worker = static_cast(unit->unit); + unit_build[i].building->set_build_phase(unit_build[i].building->get_build_phase() + worker->get_build_speed()); + } + } + return; + } + + class Building* building = game_controller->graphics_controller()->build(type_building, unit->pos); + + building->set_standard_charaterichtics(); + + if(unit->unit->get_movement() != 0) + { + class Worker* worker = static_cast(unit->unit); + building->set_build_phase(worker->get_build_speed()); + } + unit_build.push_back({unit, building, unit->pos}); + if(building->get_end_build_phase() == building->get_build_phase()) + { + unit->event.reset(new struct NoEvent()); + add_res(unit->pos); + } +} + +void Player::stop_build(PlayerUnit* unit) +{ + for(size_t i{0}; i < unit_build.size(); ++i) + if(unit_build[i].unit == unit) + { + std::cout << "1243" << std::endl; + unit_build[i].unit = nullptr; + std::cout << unit_build[i].unit << std::endl; + return; + } +} + +void Player::add_res(Position pos) +{ + IPlayerGraphicsController* gc = game_controller->graphics_controller(); + int count_res = gc->count_cell_resource(pos); + if(count_res && gc->has_cell_building(pos)) + { + Resources res = gc->cell_resource(pos); + Buildings building = gc->cell_building(pos); + + if(building == Buildings::Town) + { + player_res->add_resource(res, count_res); + return; + } + + if(res == Resources::Aluminum || res == Resources::Gold || + res == Resources::Iron || res == Resources::Silver || + res == Resources::Uranium || res == Resources::Coal) + if(building != Buildings::Mine) + return; + + if(res == Resources::Stone) + if(building != Buildings::Quarry) + return; + + if(res == Resources::Horses) + if(building != Buildings::Pasture) + return; + + if(res == Resources::Oil) + if(building != Buildings::OilWell) + return; + + if(res == Resources::Fish) + return; + + player_res->add_resource(res, count_res); + } + game_controller->graphics_controller()->update_res_inform(this); +} + +void Player::del_res(Position pos) +{ + IPlayerGraphicsController* gc = game_controller->graphics_controller(); + int count_res = gc->count_cell_resource(pos); + if(count_res && gc->has_cell_building(pos)) + { + Resources res = gc->cell_resource(pos); + Buildings building = gc->cell_building(pos); + + if(building == Buildings::Town) + { + player_res->del_resource(res, count_res); + return; + } + + if(res == Resources::Aluminum || res == Resources::Gold || + res == Resources::Iron || res == Resources::Silver || + res == Resources::Uranium || res == Resources::Coal) + if(building != Buildings::Mine) + return; + + if(res == Resources::Stone) + if(building != Buildings::Quarry) + return; + + if(res == Resources::Horses) + if(building != Buildings::Pasture) + return; + + if(res == Resources::Oil) + if(building != Buildings::OilWell) + return; + + if(res == Resources::Fish) + return; + + player_res->del_resource(res, count_res); + } + game_controller->graphics_controller()->update_res_inform(this); +} + +void Player::same_centering() +{ + if(my_units.size()) + game_controller->graphics_controller()->centering_by_cell(my_units[0]->pos); + else if(my_towns.size()) + game_controller->graphics_controller()->centering_by_cell(my_towns[0]->position_town()); +} diff --git a/Controllers/Player/Player.h b/Controllers/Player/Player.h new file mode 100644 index 0000000..7bbd090 --- /dev/null +++ b/Controllers/Player/Player.h @@ -0,0 +1,91 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include + +#include "IMenuTownPlayer.h" +#include "IPlayer.h" +#include "ITownPlayer.h" +#include "PlayerBuild.h" +#include "PlayerMap.h" +#include "PlayerTown.h" +#include "PlayerRes.h" +#include "PlayerUnit.h" +#include "../FindVision.h" +#include "../FindUnitWay.h" +#include "../IGame.h" +#include "../../Graphics/Buildings/Building.h" +#include "../../Graphics/GraphicsController/EventsStructures.h" +#include "../../Graphics/Units/Unit.h" +#include "../../Graphics/Units/Worker.h" + + +class Player : public IPlayer, public IMenuTownPlayer, public ITownPlayer +{ +public: + Player(IGameForPlayer* game_controller, Countries country, Mod mod); + virtual ~Player() override; + + virtual void click_unit(class Unit* unit) override; + virtual void click_town(class Town* town) override; + virtual void del_menu_town() override; + virtual void set_initial_units(Position initial_cell) override; + + virtual void menu_event(class Unit* unit, Event* event) override; + + virtual bool is_finish(); + virtual void start_move(); + virtual void end_move(); + virtual void draw_my_map(); + + virtual PlayerScience* player_science() const override; + virtual void add_unit(Units type_unit, Position pos_cell) override; + + virtual double get_gold_per_turn() const override; + virtual double get_gold() const override; + virtual double get_science_per_turn() const override; + virtual PlayerRes* get_player_res() const override; + virtual Countries get_country() const override; + +private: + PlayerUnit* get_my_unit(class Unit* unit); + size_t get_ind_my_unit(PlayerUnit* unit); + PlayerTown* get_my_town(class Town* town); + void set_event_to_unit(PlayerUnit* my_unit, Event* event); + void event_for_citizen(PlayerUnit* my_unit, Event* event); + void event_for_worker(PlayerUnit* my_unit, Event* event); + void move_unit_event(PlayerUnit* my_unit, MoveEvent* event); + void set_vision(bool vision); + void set_town_vision(PlayerTown* town, bool vision); + void set_movement_to_max_unit(); + void set_new_move_to_towns(); + + void do_events_unit(); + void do_build_towns(); + + void build_town(PlayerUnit* my_unit); + void del_unit(PlayerUnit* unit); + void unit_move(PlayerUnit* unit); + void capture_cell(Position pos); + + void add_build(PlayerUnit* unit, Buildings type_building); + void stop_build(PlayerUnit* unit); + void add_res(Position pos); + void del_res(Position pos); + + void same_centering(); + + IGameForPlayer* game_controller; + Countries country; + Mod mod; + double gold = 0; + + std::vector> my_units; + std::vector> my_towns; + std::vector unit_build; + std::unique_ptr player_map; + std::unique_ptr player_res; + std::unique_ptr _player_science; +}; + +#endif // PLAYER_H diff --git a/Controllers/Player/PlayerBuild.h b/Controllers/Player/PlayerBuild.h new file mode 100644 index 0000000..66d3772 --- /dev/null +++ b/Controllers/Player/PlayerBuild.h @@ -0,0 +1,19 @@ +#ifndef PLAYERBUILD_H +#define PLAYERBUILD_H + +#include "PlayerUnit.h" +#include "../../Graphics/Buildings/Building.h" + + +struct PlayerBuild +{ + PlayerUnit* unit; + class Building* building; + Position pos; + + PlayerBuild(PlayerUnit* _unit, class Building* _building, Position _pos) + :unit{_unit}, building{_building}, pos{_pos} + {} +}; + +#endif // PLAYERBUILD_H diff --git a/Controllers/Player/PlayerMap.cpp b/Controllers/Player/PlayerMap.cpp new file mode 100644 index 0000000..7a9cc71 --- /dev/null +++ b/Controllers/Player/PlayerMap.cpp @@ -0,0 +1,29 @@ +#include "PlayerMap.h" + +PlayerMap::PlayerMap(Position count_cell, Mod _mod) + :mod{_mod} +{ + for(size_t i{0}; i < count_cell.x; ++i) + { + map.push_back(std::vector{}); + for(size_t j{0}; j < count_cell.y; ++j) + map[i].push_back(ICell::FogOfWar); + } +} + +ICell::ShowCell PlayerMap::get_show_cell(Position pos_cell) const +{ + if(mod == Mod::Show) + return ICell::Show; + return map[pos_cell.x][pos_cell.y]; +} + +void PlayerMap::set_show_cell(Position pos_cell) +{ + map[pos_cell.x][pos_cell.y] = ICell::Show; +} + +void PlayerMap::set_notvisible_cell(Position pos_cell) +{ + map[pos_cell.x][pos_cell.y] = ICell::NotVisible; +} diff --git a/Controllers/Player/PlayerMap.h b/Controllers/Player/PlayerMap.h new file mode 100644 index 0000000..0bdcac6 --- /dev/null +++ b/Controllers/Player/PlayerMap.h @@ -0,0 +1,24 @@ +#ifndef PLAYERMAP_H +#define PLAYERMAP_H + +#include + +#include "../Enums.h" +#include "../../Graphics/Map/ICell.h" +#include "../../IObject.h" + + +class PlayerMap : public IObject +{ +public: + PlayerMap(Position count_cell, Mod mod); + ICell::ShowCell get_show_cell(Position pos_cell) const; + void set_show_cell(Position pos_cell); + void set_notvisible_cell(Position pos_cell); + +private: + std::vector> map; + Mod mod; +}; + +#endif // PLAYERMAP_H diff --git a/Controllers/Player/PlayerRes.cpp b/Controllers/Player/PlayerRes.cpp new file mode 100644 index 0000000..b236790 --- /dev/null +++ b/Controllers/Player/PlayerRes.cpp @@ -0,0 +1,33 @@ +#include "PlayerRes.h" + +PlayerRes::PlayerRes(Mod _mod) + :mod{_mod} +{ + int a = 3; + if(mod == Mod::Play) + a = 0; + for(int i{0}; i < CountInEnums().resources(); ++i) + player_resources.insert({Resources(i), a}); +} + +void PlayerRes::add_resource(Resources type_res, int count) +{ + player_resources.at(type_res) += count; +} + +void PlayerRes::del_resource(Resources type_res, int count) +{ + player_resources.at(type_res) -= count; + if(player_resources.at(type_res) < 0) + player_resources.at(type_res) = 0; +} + +void PlayerRes::set_resource(Resources type_res, int count) +{ + player_resources.at(type_res) = count; +} + +int PlayerRes::get_resource(Resources type_res) +{ + return player_resources.at(type_res); +} diff --git a/Controllers/Player/PlayerRes.h b/Controllers/Player/PlayerRes.h new file mode 100644 index 0000000..4e61f52 --- /dev/null +++ b/Controllers/Player/PlayerRes.h @@ -0,0 +1,33 @@ +#ifndef PLAYERRES_H +#define PLAYERRES_H + +#include + +#include "../Enums.h" +#include "../../IObject.h" + + +class PlayerRes : public IObject +{ + std::map player_resources; + +public: + PlayerRes(Mod mod); + + ///Добавляет к уже имеющимся + void add_resource(Resources type_res, int count); + + ///Убирает, если нужно убрать больше чем есть убирет все. + void del_resource(Resources type_res, int count); + + ///Заменяет на новое количество + void set_resource(Resources type_res, int count); + + /// Возвращает количество ресурса + int get_resource(Resources type_res); + +private: + Mod mod; +}; + +#endif // PLAYERRES_H diff --git a/Controllers/Player/PlayerScience.cpp b/Controllers/Player/PlayerScience.cpp new file mode 100644 index 0000000..1b53844 --- /dev/null +++ b/Controllers/Player/PlayerScience.cpp @@ -0,0 +1,232 @@ +#include "PlayerScience.h" +#include + +PlayerScience::PlayerScience(Mod _mod) + :mod{_mod} +{ + // building.push_back(TownBuildings::Walls); + // building.push_back(TownBuildings::Aqueduct); + // building.push_back(TownBuildings::Market); + // building.push_back(TownBuildings::PublicSchool); + // building.push_back(TownBuildings::University); + // building.push_back(TownBuildings::Bank); + // building.push_back(TownBuildings::MedicalLab); + // building.push_back(TownBuildings::ResearchLab); + // building.push_back(TownBuildings::Factory); + // building.push_back(TownBuildings::Monument); + // building.push_back(TownBuildings::Shrine); + // building.push_back(TownBuildings::Windmill); + // building.push_back(TownBuildings::Museum); + // building.push_back(TownBuildings::Hospital); + // building.push_back(TownBuildings::Stadium); + // building.push_back(TownBuildings::Workshop); + // building.push_back(TownBuildings::Library); + // building.push_back(TownBuildings::OperaHouse); + // building.push_back(TownBuildings::StockExchange); + // building.push_back(TownBuildings::Zoo); + + // best_units.push_back(Units::Citizen); + // best_units.push_back(Units::Worker); + // best_units.push_back(Units::Bowman); + // best_units.push_back(Units::Swordsman); +} + +size_t PlayerScience::count_open_buildings() const +{ + return get_open_buildings().size(); +} + +std::vector PlayerScience::get_open_buildings() const +{ + std::vector res; + auto science = Science(); + for(auto knowledge : open_knowledges) + for(auto buildings : science.get_knowledge(knowledge).buildings) + res.push_back(buildings); + return res; +} + +bool PlayerScience::is_open_building(Buildings building) const +{ + auto buildings = get_open_buildings(); + return std::find(buildings.begin(), buildings.end(), building) != buildings.end(); +} + +size_t PlayerScience::count_open_resources() const +{ + return get_open_resources().size(); +} +std::vector PlayerScience::get_open_resources() const +{ + if(mod == Mod::Play) + { + std::vector res; + auto science = Science(); + for(auto knowledge : open_knowledges) + for(auto resource : science.get_knowledge(knowledge).resources) + res.push_back(resource); + return res; + } + + + //для разработки + return {Resources::Fish, + Resources::Oil, + Resources::Aluminum, + Resources::Coal, + Resources::Horses, + Resources::Gold, + Resources::Iron, + Resources::Silver, + Resources::Stone, + Resources::Uranium,}; +} + +bool PlayerScience::is_open_resource(Resources resource) const +{ + auto resources = get_open_resources(); + return std::find(resources.begin(), resources.end(), resource) != resources.end(); +} + +size_t PlayerScience::count_open_town_buildings() const +{ + return get_open_town_buildings().size(); +} + +std::vector PlayerScience::get_open_town_buildings() const +{ + std::vector res; + auto science = Science(); + for(auto knowledge : open_knowledges) + for(auto building : science.get_knowledge(knowledge).town_buildings) + if(building.level == 1) + res.push_back(building.town_building); + return res; +} + +size_t PlayerScience::count_open_units() const +{ + return get_open_unit().size(); +} + +std::vector PlayerScience::get_open_unit() const +{ + std::vector res; + auto science = Science(); + for(auto knowledge : open_knowledges) + for(auto unit : science.get_knowledge(knowledge).units) + res.push_back(unit); + return res; +} + +size_t PlayerScience::count_best_open_units() const +{ + return get_best_open_units().size(); +} + +std::vector PlayerScience::get_best_open_units() const +{ + return get_open_unit(); +} + +int PlayerScience::max_level_building(TownBuildings town_building) const +{ + int level = 0; + auto science = Science(); + for(auto knowledge : open_knowledges) + for(auto building : science.get_knowledge(knowledge).town_buildings) + if(building.town_building == town_building) + if(building.level > level) + level = building.level; + return level; +} + +bool PlayerScience::is_knowledge_open(Knowledges knowledge) const +{ + return std::find(open_knowledges.begin(), open_knowledges.end(), knowledge) + != open_knowledges.end(); +} + +void PlayerScience::set_study_knowledge(Knowledges name_knowledge) +{ + queue_science.clear(); + auto science = Science(); + std::stack> stack; + stack.push({science.get_knowledge(name_knowledge), 0}); + while (!stack.empty()) + { + auto& [knowledge, i] = stack.top(); + auto& need_knowledges = knowledge.necessary_knowledges; + if(i == need_knowledges.size()) + { + if(std::find(queue_science.begin(), queue_science.end(), knowledge.name_knowledge) == queue_science.end()) + queue_science.push_back(knowledge.name_knowledge); + stack.pop(); + continue; + } + + bool need_push = false; + std::pair push_pair{{name_knowledge},0}; + for(;i < need_knowledges.size(); ++i) + if(!is_knowledge_open(need_knowledges[i])) + { + push_pair = {science.get_knowledge(need_knowledges[i]), 0}; + need_push = true; + ++i; + break; + } + stack.top().second = i; + if(need_push) + stack.push(push_pair); + } + std::sort(queue_science.begin(), queue_science.end(), + [&science](const Knowledges& k1, const Knowledges& k2) + { return science.get_knowledge(k1).position_knowledge < + science.get_knowledge(k2).position_knowledge; }); + + // std::cout << "=====" << std::endl; + // for(size_t i{0}; i < queue_science.size(); ++i) + // { + // auto pos = science.get_knowledge(queue_science[i]).position_knowledge; + // std::cout << pos.num_x << " " << pos.num_y << std::endl; + // } + // std::cout << std::endl; +} + +const std::vector& PlayerScience::get_queue_science() const +{ + return queue_science; +} + +void PlayerScience::study(double science_glasses) +{ + Knowledges name_knowledge = queue_science[0]; + double need_science_glasses = get_knowledge_science_glasses(name_knowledge); + if(need_science_glasses > science_glasses + remains_science_glasses) + knowledge_science_glasses[name_knowledge] = need_science_glasses - science_glasses - remains_science_glasses; + else + { + remains_science_glasses = science_glasses + remains_science_glasses - need_science_glasses; + knowledge_science_glasses[name_knowledge] = 0; + open_knowledge(name_knowledge); + queue_science.erase(queue_science.begin()); + } +} + +double PlayerScience::get_knowledge_science_glasses(Knowledges name_knowledge) +{ + if(knowledge_science_glasses.find(name_knowledge) == knowledge_science_glasses.end()) + { + int science_glasses = Science().get_knowledge(name_knowledge).need_science_glasses; + knowledge_science_glasses[name_knowledge] = science_glasses; + } + + return knowledge_science_glasses[name_knowledge]; +} + +void PlayerScience::open_knowledge(Knowledges name_knowledge) +{ + open_knowledges.push_back(name_knowledge); +} + + diff --git a/Controllers/Player/PlayerScience.h b/Controllers/Player/PlayerScience.h new file mode 100644 index 0000000..344364c --- /dev/null +++ b/Controllers/Player/PlayerScience.h @@ -0,0 +1,58 @@ +#ifndef PLAYERSCIENCE_H +#define PLAYERSCIENCE_H + +#include +#include +#include +#include + +#include "../Enums.h" +#include "../Science.h" +#include "../TownBuildings.h" +#include "../../IObject.h" + + +class PlayerScience : public IObject +{ +public: + PlayerScience(Mod mod); + size_t count_open_buildings() const; + std::vector get_open_buildings() const; + bool is_open_building(Buildings building) const; + + size_t count_open_resources() const; + std::vector get_open_resources() const; + bool is_open_resource(Resources resource) const; + + size_t count_open_town_buildings() const; + std::vector get_open_town_buildings() const; + + size_t count_open_units() const; + std::vector get_open_unit() const; + + size_t count_best_open_units() const; + std::vector get_best_open_units() const; + + int max_level_building(TownBuildings town_building) const; + + bool is_knowledge_open(Knowledges knowledge) const; + void set_study_knowledge(Knowledges knowledge); + const std::vector& get_queue_science() const; + + void study(double science_glasses); + double get_knowledge_science_glasses(Knowledges knowledge); +private: + void open_knowledge(Knowledges knowledge); +// IMenuTownPlayer* player; + + std::vector queue_science; + + std::vector open_knowledges{}; + + std::map knowledge_science_glasses; + double remains_science_glasses = 0; + + Mod mod; +}; + +#endif // PLAYERSCIENCE_H diff --git a/Controllers/Player/PlayerTown.cpp b/Controllers/Player/PlayerTown.cpp new file mode 100644 index 0000000..e8c0d4b --- /dev/null +++ b/Controllers/Player/PlayerTown.cpp @@ -0,0 +1,257 @@ +#include "PlayerTown.h" +#include + +PlayerTown::PlayerTown(class Town* town, ITownPlayer* _player, Position pos, Mod _mod) + :_town{town}, player{_player}, _pos{pos}, mod{_mod} +{ + town_resource.gold_per_turn = 1; + if(mod == Mod::Show) + { + town_resource.gold_per_turn = -1; + } + + town_resource.science_per_turn = 1; + town_resource.production_per_turn = 10; +} + +Position PlayerTown::position_town() const +{ + return _pos; +} + +class Town* PlayerTown::town() const +{ + return _town; +} + +void PlayerTown::move_build() +{ + if(build_queue.size() == 0) + return; + + if(build_in_this_move) + remains_production = build_queue[0]->build(remains_production); + else + remains_production = build_queue[0]->build(get_production() + remains_production); + + build_in_this_move = true; + + if(build_queue[0]->need_production == 0.) + { + if(build_queue[0]->type_build == BuildInTown::Unit) + { + player->add_unit(build_queue[0]->unit, _pos); + del_build(build_queue[0]); + } + else + { + build_queue[0]->level++; + build_queue[0]->build_next_level(); + } + + build_queue.erase(build_queue.begin()); + move_build(); + } +} + +void PlayerTown::new_move() +{ + build_in_this_move = false; +} + +double PlayerTown::get_gold_per_turn() const +{ + return town_resource.get_gold(); +} + +double PlayerTown::get_science_per_turn() const +{ + return town_resource.get_science(); +} + +size_t PlayerTown::count_town_buildings() const +{ + return build_in_town.size(); +} + +std::vector PlayerTown::get_building_already_build() const +{ + std::vector building_in_town; + for(size_t i{0}; i < build_in_town.size(); ++i) + if(build_in_town[i]->type_build == BuildInTown::Building) + if(build_in_town[i]->need_production == 0. || build_in_town[i]->level != 0) + building_in_town.push_back(build_in_town[i]->building); + return building_in_town; +} + +std::vector PlayerTown::get_queue_buildings() const +{ + std::vector building_queue; + for(auto build : build_queue) + if(build->type_build == BuildInTown::Building) + building_queue.push_back(build->building); + return building_queue; +} + +std::vector PlayerTown::get_open_build_buildings() const +{ + PlayerScience* player_science = player->player_science(); + auto open_buildings = player_science->get_open_town_buildings(); + auto already_build = get_building_already_build(); + auto queue_building = get_queue_buildings(); + + std::vector res; + + for(size_t i{0}; i < open_buildings.size(); ++i) + { + if(std::find(already_build.begin(), already_build.end(), open_buildings[i]) != already_build.end()) + continue; + + if(std::find(queue_building.begin(), queue_building.end(), open_buildings[i]) != queue_building.end()) + continue; + + res.push_back(open_buildings[i]); + } + return res; +} + +size_t PlayerTown::get_count_can_build() const +{ + size_t count{0}; + + auto science = player->player_science(); + auto town_building_needs = TownBuildNeeds(); + for(auto unit : science->get_best_open_units()) + { + auto resurces = town_building_needs.get_build_need_res(unit); + bool can = true; + for(auto res : resurces) + if(player->get_player_res()->get_resource(res.first) < res.second) + can = false; + if(can) + count++; + } + + for(auto building : get_open_build_buildings()) + { + auto resurces = town_building_needs.get_build_need_res(building, 1); + bool can = true; + for(auto res : resurces) + if(player->get_player_res()->get_resource(res.first) < res.second) + can = false; + if(can) + count++; + } + return count; +} + +void PlayerTown::add_queue_build(Units type_unit) +{ + build_in_town.push_back(std::unique_ptr{new BuildInTown(type_unit)}); + build_queue.push_back(build_in_town[build_in_town.size() - 1].get()); +} + +void PlayerTown::add_queue_build(TownBuildings type_building) +{ + + for(size_t i{0}; i < build_in_town.size(); ++i) + if(build_in_town[i]->type_build == BuildInTown::Building) + if(build_in_town[i]->building == type_building) + { + build_queue.push_back(build_in_town[i].get()); + return; + } + + build_in_town.push_back(std::unique_ptr{new BuildInTown(type_building)}); + build_queue.push_back(build_in_town[build_in_town.size() - 1].get()); +} + +void PlayerTown::set_build(Units type_unit) +{ + build_queue.clear(); + add_queue_build(type_unit); +} + +void PlayerTown::set_build(TownBuildings type_building) +{ + build_queue.clear(); + add_queue_build(type_building); +} + +void PlayerTown::del_build(size_t i) +{ + build_queue.erase(build_queue.begin() + i); +} + +void PlayerTown::move_up_build(size_t i) +{ + if(i == 0) + return; + std::swap(build_queue[i], build_queue[i-1]); +} + +void PlayerTown::move_down_build(size_t i) +{ + if(i+1 >= build_queue.size()) + return; + std::swap(build_queue[i], build_queue[i+1]); +} + +size_t PlayerTown::max_build_in_queue() +{ + return _max_build_in_queue; +} + +double PlayerTown::get_build_need_production(TownBuildings type_building) +{ + for(size_t i{0}; i < build_in_town.size(); ++i) + if(build_in_town[i]->type_build == BuildInTown::Building) + if(build_in_town[i]->building == type_building) + return build_in_town[i]->need_production; + return TownBuildNeeds().get_build_need_production(type_building, 1); +} + +double PlayerTown::get_build_need_production(Units type_unit) +{ + for(size_t i{0}; i < build_in_town.size(); ++i) + if(build_in_town[i]->type_build == BuildInTown::Unit) + if(build_in_town[i]->unit == type_unit) + return build_in_town[i]->need_production; + return TownBuildNeeds().get_build_need_production(type_unit); +} + +int PlayerTown::get_level_build(TownBuildings type_building) +{ + for(size_t i{0}; i < build_in_town.size(); ++i) + if(build_in_town[i]->type_build == BuildInTown::Building) + if(build_in_town[i]->building == type_building) + return build_in_town[i]->level; + return 0; +} + +const std::vector& PlayerTown::get_build_queue() const +{ + return build_queue; +} + +double PlayerTown::get_production() const +{ + return town_resource.get_production(); +} + +double PlayerTown::get_remains_production() const +{ + return remains_production; +} + +Countries PlayerTown::get_country() const +{ + return player->get_country(); +} + +void PlayerTown::del_build(BuildInTown* build) +{ + for(size_t i{0}; i < build_in_town.size(); ++i) + if(build_in_town[i].get() == build) + build_in_town.erase(build_in_town.begin() + i); +} diff --git a/Controllers/Player/PlayerTown.h b/Controllers/Player/PlayerTown.h new file mode 100644 index 0000000..ee96a5a --- /dev/null +++ b/Controllers/Player/PlayerTown.h @@ -0,0 +1,89 @@ +#ifndef PLAYERTOWN_H +#define PLAYERTOWN_H + +#include + +#include "BuildInTown.h" +#include "ITownPlayer.h" +#include "../../Graphics/Buildings/Town.h" +#include "../../IObject.h" +#include "../TownBuildings.h" +#include "../TownBuildNeeds.h" + +struct TownResource +{ + double production_per_turn = 0; + double coef_production = 1; + double get_production() const + { return coef_production * production_per_turn; } + + double gold_per_turn = 0; + double coef_gold = 1; + double get_gold() const + { return coef_gold * gold_per_turn; } + + double science_per_turn = 0; + double coef_science = 1; + double get_science() const + { return coef_science * science_per_turn; } +}; + + +class PlayerTown : public IObject +{ + const size_t _max_build_in_queue = 6; + +public: + PlayerTown(class Town* town, ITownPlayer* player, Position position_town, Mod mod); + + Position position_town() const; + class Town* town() const; + void move_build(); + void new_move(); + + size_t count_town_buildings() const; + std::vector get_building_already_build() const; + std::vector get_queue_buildings() const; + std::vector get_open_build_buildings() const; + size_t get_count_can_build() const; + void add_town_building(TownBuildings town_building); + + void add_queue_build(Units type_unit); + void add_queue_build(TownBuildings type_building); + void set_build(Units type_unit); + void set_build(TownBuildings type_building); + void del_build(size_t i); + void move_up_build(size_t i); + void move_down_build(size_t i); + size_t max_build_in_queue(); + + double get_build_need_production(TownBuildings type_building); + double get_build_need_production(Units type_unit); + + int get_level_build(TownBuildings type_building); + + const std::vector& get_build_queue() const; + double get_production() const; + double get_remains_production() const; + + double get_gold_per_turn() const; + double get_science_per_turn() const; + + Countries get_country() const; +private: + void del_build(BuildInTown* build); + + class Town* _town; + ITownPlayer* player; + Position _pos; + + TownResource town_resource{}; + double remains_production = 0; + bool build_in_this_move = false; + + std::vector> build_in_town; + std::vector build_queue; + Mod mod; +}; + +#endif // PLAYERTOWN_H diff --git a/Controllers/Player/PlayerUnit.h b/Controllers/Player/PlayerUnit.h new file mode 100644 index 0000000..eb6d7ec --- /dev/null +++ b/Controllers/Player/PlayerUnit.h @@ -0,0 +1,23 @@ +#ifndef PLAYERUNIT_H +#define PLAYERUNIT_H + +#include + +#include "../../Graphics/GraphicsController/EventsStructures.h" +#include "../../IObject.h" + + +struct PlayerUnit +{ + Position pos; + class Unit* unit; + std::unique_ptr event; + + PlayerUnit(class Unit* _unit, Position _pos) + :pos{_pos}, unit{_unit}, event{new struct NoEvent} {} + + PlayerUnit(const PlayerUnit& playerunit) + :pos{playerunit.pos}, unit{playerunit.unit}, event{playerunit.event->copy()} {} +}; + +#endif // PLAYERUNIT_H diff --git a/Controllers/Science.cpp b/Controllers/Science.cpp new file mode 100644 index 0000000..8f66db2 --- /dev/null +++ b/Controllers/Science.cpp @@ -0,0 +1,261 @@ +#include "Science.h" + +std::vector Science::get_all_name_knowledges() const +{ + return std::vector{ + Knowledges::Agriculture, + Knowledges::StoneProcessing, + Knowledges::Language, + Knowledges::WoodProcessing, + Knowledges::Writing, + Knowledges::AnimalHusbandry, + Knowledges::Wheel, + Knowledges::OreMining, + Knowledges::Archery, + Knowledges::Theology, + Knowledges::Navigation, + Knowledges::HorseRiding, + Knowledges::Winemaking, + Knowledges::BronzeProcessing, + Knowledges::Money, + Knowledges::Philosophy, + Knowledges::Optics, + Knowledges::IronProcessing, + Knowledges::PreciousOres, + Knowledges::DramaAndPoetry, + Knowledges::Mathematics, + Knowledges::MetalStructures, + Knowledges::Engineering, + Knowledges::Guilds, + Knowledges::Education, + Knowledges::Compass, + Knowledges::Knighthood, + Knowledges::Steelmaking, + Knowledges::Machinery, + Knowledges::Trading, + Knowledges::Medicine + }; +} + +Knowledge Science::get_knowledge(Knowledges name_knowledge) const +{ + Knowledge knowledge{name_knowledge}; + if(name_knowledge == Knowledges::Agriculture) + { + knowledge.position_knowledge = {0,1}; + knowledge.buildings.push_back(Buildings::Farm); + knowledge.units.push_back(Units::Worker); + knowledge.units.push_back(Units::Citizen); + } + else if(name_knowledge == Knowledges::StoneProcessing) + { + knowledge.position_knowledge = {0,2}; + // knowledge.units.push_back(Units::) Воины + knowledge.town_buildings.push_back({TownBuildings::Walls, 1}); + knowledge.resources.push_back(Resources::Stone); + knowledge.buildings.push_back(Buildings::Quarry); + } + else if(name_knowledge == Knowledges::Language) + { + knowledge.position_knowledge = {0,4}; + knowledge.town_buildings.push_back({TownBuildings::Monument, 1}); + } + else if(name_knowledge == Knowledges::WoodProcessing) + { + knowledge.position_knowledge = {1,2}; + knowledge.necessary_knowledges.push_back(Knowledges::StoneProcessing); + knowledge.buildings.push_back(Buildings::LumberMill); + } + else if(name_knowledge == Knowledges::Writing) + { + knowledge.position_knowledge = {1,4}; + knowledge.necessary_knowledges.push_back(Knowledges::Language); + knowledge.town_buildings.push_back({TownBuildings::PublicSchool, 1}); + } + else if(name_knowledge == Knowledges::AnimalHusbandry) + { + knowledge.position_knowledge = {2,0}; + knowledge.necessary_knowledges.push_back(Knowledges::Agriculture); + knowledge.resources.push_back(Resources::Horses); + knowledge.buildings.push_back(Buildings::Pasture); + } + else if(name_knowledge == Knowledges::Wheel) + { + knowledge.position_knowledge = {2,1}; + knowledge.necessary_knowledges.push_back(Knowledges::Agriculture); + // knowledge.units.push_back(Units::) Колесницы + } + else if(name_knowledge == Knowledges::OreMining) + { + knowledge.position_knowledge = {2,2}; + knowledge.necessary_knowledges.push_back(Knowledges::Agriculture); + knowledge.necessary_knowledges.push_back(Knowledges::WoodProcessing); + knowledge.resources.push_back(Resources::Iron); + knowledge.buildings.push_back(Buildings::Mine); + } + else if(name_knowledge == Knowledges::Archery) + { + knowledge.position_knowledge = {2,3}; + knowledge.necessary_knowledges.push_back(Knowledges::WoodProcessing); + knowledge.units.push_back(Units::Bowman); + } + else if(name_knowledge == Knowledges::Theology) + { + knowledge.position_knowledge = {2,4}; + knowledge.necessary_knowledges.push_back(Knowledges::Writing); + knowledge.town_buildings.push_back({TownBuildings::Shrine, 1}); + // knowledge.town_buildings.push_back({TownBuildings::, 1}); Арена + } + else if(name_knowledge == Knowledges::Navigation) + { + knowledge.position_knowledge = {2,6}; + knowledge.necessary_knowledges.push_back(Knowledges::Writing); + // knowledge.units.push_back(Units::); тримера + } + else if(name_knowledge == Knowledges::HorseRiding) + { + knowledge.position_knowledge = {3,0}; + knowledge.necessary_knowledges.push_back(Knowledges::AnimalHusbandry); + // knowledge.units.push_back(Units::) Кавалерия + } + else if(name_knowledge == Knowledges::Winemaking) + { + knowledge.position_knowledge = {3,1}; + knowledge.necessary_knowledges.push_back(Knowledges::Wheel); + // knowledge.town_buildings.push_back({TownBuildings::, 1}); Винодельня + // knowledge.town_buildings.push_back({TownBuildings::, 1}); Бани + } + else if(name_knowledge == Knowledges::BronzeProcessing) + { + knowledge.position_knowledge = {3,2}; + knowledge.necessary_knowledges.push_back(Knowledges::OreMining); + // knowledge.units.push_back(Units::); Копейщики + } + else if(name_knowledge == Knowledges::Money) + { + knowledge.position_knowledge = {3,5}; + knowledge.necessary_knowledges.push_back(Knowledges::Theology); + knowledge.town_buildings.push_back({TownBuildings::Market, 1}); + } + else if(name_knowledge == Knowledges::Philosophy) + { + knowledge.position_knowledge = {3,4}; + knowledge.necessary_knowledges.push_back(Knowledges::Theology); + knowledge.town_buildings.push_back({TownBuildings::Library, 1}); + // knowledge.town_buildings.push_back({TownBuildings::, 1}); Храм + } + else if(name_knowledge == Knowledges::Optics) + { + knowledge.position_knowledge = {3,6}; + knowledge.necessary_knowledges.push_back(Knowledges::Navigation); + // knowledge.town_buildings.push_back({TownBuildings::, 1}); Маяк + } + else if(name_knowledge == Knowledges::IronProcessing) + { + knowledge.position_knowledge = {4,2}; + knowledge.necessary_knowledges.push_back(Knowledges::Winemaking); + knowledge.necessary_knowledges.push_back(Knowledges::BronzeProcessing); + knowledge.necessary_knowledges.push_back(Knowledges::Archery); + knowledge.units.push_back(Units::Swordsman); + knowledge.town_buildings.push_back({TownBuildings::Workshop, 1}); + } + else if(name_knowledge == Knowledges::Mathematics) + { + knowledge.position_knowledge = {4,5}; + knowledge.necessary_knowledges.push_back(Knowledges::Money); + knowledge.town_buildings.push_back({TownBuildings::PublicSchool, 2}); + // knowledge.units.push_back(Units::); Катапульта + } + else if(name_knowledge == Knowledges::DramaAndPoetry) + { + knowledge.position_knowledge = {4,4}; + knowledge.necessary_knowledges.push_back(Knowledges::Money); + knowledge.necessary_knowledges.push_back(Knowledges::Philosophy); +// knowledge.town_buildings.push_back({TownBuildings::, 1}); Амфитеатор + } + else if(name_knowledge == Knowledges::Knighthood) + { + knowledge.position_knowledge = {5,0}; + knowledge.necessary_knowledges.push_back(Knowledges::HorseRiding); + knowledge.necessary_knowledges.push_back(Knowledges::IronProcessing); + // knowledge.units.push_back(Units::); Рыцари + knowledge.town_buildings.push_back({TownBuildings::Walls, 1}); + } + else if(name_knowledge == Knowledges::PreciousOres) + { + knowledge.position_knowledge = {5,3}; + knowledge.necessary_knowledges.push_back(Knowledges::IronProcessing); + knowledge.necessary_knowledges.push_back(Knowledges::DramaAndPoetry); + knowledge.resources.push_back(Resources::Gold); + knowledge.resources.push_back(Resources::Silver); + // knowledge.town_buildings.push_back({TownBuildings::, 1}); Казна + } + else if(name_knowledge == Knowledges::MetalStructures) + { + knowledge.position_knowledge = {5,2}; + knowledge.necessary_knowledges.push_back(Knowledges::IronProcessing); + // knowledge.units.push_back(Units::); Крутые лучники + } + else if(name_knowledge == Knowledges::Guilds) + { + knowledge.position_knowledge = {5,4}; + knowledge.necessary_knowledges.push_back(Knowledges::Mathematics); + knowledge.necessary_knowledges.push_back(Knowledges::DramaAndPoetry); + knowledge.buildings.push_back(Buildings::TradingPost); + } + else if(name_knowledge == Knowledges::Compass) + { + knowledge.position_knowledge = {5,6}; + knowledge.necessary_knowledges.push_back(Knowledges::Mathematics); + knowledge.necessary_knowledges.push_back(Knowledges::Optics); + // knowledge.units.push_back(Units::); Галеас + // knowledge.town_buildings.push_back({TownBuildings::, 1}); Гавань + } + else if(name_knowledge == Knowledges::Engineering) + { + knowledge.position_knowledge = {6,3}; + knowledge.necessary_knowledges.push_back(Knowledges::IronProcessing); + knowledge.necessary_knowledges.push_back(Knowledges::Guilds); + knowledge.town_buildings.push_back({TownBuildings::Aqueduct, 1}); + knowledge.buildings.push_back(Buildings::Fort); + } + else if(name_knowledge == Knowledges::Education) + { + knowledge.position_knowledge = {6,4}; + knowledge.necessary_knowledges.push_back(Knowledges::Mathematics); + knowledge.town_buildings.push_back({TownBuildings::University, 1}); + knowledge.town_buildings.push_back({TownBuildings::Library, 2}); + } + else if(name_knowledge == Knowledges::Steelmaking) + { + knowledge.position_knowledge = {7,2}; + knowledge.necessary_knowledges.push_back(Knowledges::MetalStructures); + // knowledge.units.push_back(Units::); Крутые мечники + } + else if(name_knowledge == Knowledges::Machinery) + { + knowledge.position_knowledge = {7,3}; + knowledge.necessary_knowledges.push_back(Knowledges::MetalStructures); + knowledge.necessary_knowledges.push_back(Knowledges::Engineering); + knowledge.town_buildings.push_back({TownBuildings::Workshop, 2}); + // knowledge.units.push_back(Units::); Требушет + } + else if(name_knowledge == Knowledges::Trading) + { + knowledge.position_knowledge = {7,4}; + knowledge.necessary_knowledges.push_back(Knowledges::Guilds); + knowledge.necessary_knowledges.push_back(Knowledges::Education); + knowledge.town_buildings.push_back({TownBuildings::Market, 2}); + knowledge.town_buildings.push_back({TownBuildings::Bank, 1}); + } + else if(name_knowledge == Knowledges::Medicine) + { + knowledge.position_knowledge = {7,5}; + knowledge.necessary_knowledges.push_back(Knowledges::Education); + knowledge.town_buildings.push_back({TownBuildings::Hospital, 1}); + } + else + throw std::runtime_error("There are no images for this resource"); + + return knowledge; +} diff --git a/Controllers/Science.h b/Controllers/Science.h new file mode 100644 index 0000000..037d52b --- /dev/null +++ b/Controllers/Science.h @@ -0,0 +1,117 @@ +#ifndef SCIENCE_H +#define SCIENCE_H + +#include +#include + +#include "Enums.h" +#include "TownBuildings.h" +#include "../IObject.h" + + +enum class Knowledges +{ + ///////////////// + Agriculture, + StoneProcessing, + Language, + WoodProcessing, + Writing, + + ///////////////// + AnimalHusbandry, + Wheel, + OreMining, + Archery, + Theology, + Navigation, + HorseRiding, + Winemaking, + BronzeProcessing, + Money, + Philosophy, + Optics, + IronProcessing, + PreciousOres, + DramaAndPoetry, + Mathematics, + + ///////////// + MetalStructures, + Engineering, + Guilds, + Education, + Compass, + Knighthood, + Steelmaking, + Machinery, + Trading, + Medicine, +}; + + +enum class Epochs +{ + AncientWorld, + Antiquity, + MiddleAges, + NewTime, + ModernTimes, + Modernity, + AgeOfAtom, + InformationAge +}; + +struct PositionKnowledge +{ + int num_x = 0; + int num_y = 0; + PositionKnowledge(int x, int y) + :num_x{x}, num_y{y} + {} + + PositionKnowledge() {} + + bool operator<(const PositionKnowledge& pos1) + { + return num_x < pos1.num_x || (num_x == pos1.num_x && num_y < pos1.num_y); + } +}; + +struct TownBuilding +{ + TownBuildings town_building; + int level; + + TownBuilding(TownBuildings _town_building, int _level) + :town_building{_town_building}, level{_level} + {} +}; + +struct Knowledge +{ + Knowledges name_knowledge; + Epochs epoch; + + PositionKnowledge position_knowledge; + std::vector necessary_knowledges; + double need_science_glasses = 2; + + std::vector town_buildings; + std::vector units; + std::vector resources; + std::vector buildings; + + Knowledge(Knowledges _name_knowledge) + :name_knowledge{_name_knowledge} + {} +}; + +class Science : public IObject +{ +public: + std::vector get_all_name_knowledges() const; + Knowledge get_knowledge(Knowledges name_knowledge) const; +}; + +#endif // SCIENCE_H diff --git a/Controllers/TownBuildNeeds.cpp b/Controllers/TownBuildNeeds.cpp new file mode 100644 index 0000000..8b5725b --- /dev/null +++ b/Controllers/TownBuildNeeds.cpp @@ -0,0 +1,35 @@ +#include "TownBuildNeeds.h" +#include + +double TownBuildNeeds::get_build_need_production(TownBuildings type_building, int level) const +{ + return 30; +} + +double TownBuildNeeds::get_build_need_production(Units unit) const +{ + return 30; +} + +std::vector> TownBuildNeeds::get_build_need_res(TownBuildings type_building, int level) const +{ + srand(int(type_building) + level); + std::vector> res; + res.push_back({Resources::Iron, rand()%4 + 1}); + res.push_back({Resources::Stone, rand()%5}); + res.push_back({Resources::Horses, rand()%5}); + res.push_back({Resources::Coal, rand()%5}); + res.push_back({Resources::Aluminum, rand()%5}); + res.push_back({Resources::Oil, rand()%5}); + res.push_back({Resources::Uranium, rand()%5}); + return res; +} + +std::vector> TownBuildNeeds::get_build_need_res(Units type_unit) const +{ + std::vector> res; + res.push_back({Resources::Iron, 3}); + res.push_back({Resources::Stone, 3}); + res.push_back({Resources::Horses, 3}); + return res; +} diff --git a/Controllers/TownBuildNeeds.h b/Controllers/TownBuildNeeds.h new file mode 100644 index 0000000..1426439 --- /dev/null +++ b/Controllers/TownBuildNeeds.h @@ -0,0 +1,21 @@ +#ifndef TOWNBUILDNEEDS_H +#define TOWNBUILDNEEDS_H + +#include + +#include "Enums.h" +#include "TownBuildings.h" +#include "../IObject.h" + + +class TownBuildNeeds : public IObject +{ +public: + double get_build_need_production(TownBuildings type_building, int level) const; + double get_build_need_production(Units type_unit) const; + + std::vector> get_build_need_res(TownBuildings type_building, int level) const; + std::vector> get_build_need_res(Units type_unit) const; +}; + +#endif // TOWNBUILDNEEDS_H diff --git a/Controllers/TownBuildings.h b/Controllers/TownBuildings.h new file mode 100644 index 0000000..aae3d23 --- /dev/null +++ b/Controllers/TownBuildings.h @@ -0,0 +1,28 @@ +#ifndef TOWNBUILDINGS_H +#define TOWNBUILDINGS_H + +enum class TownBuildings +{ + Aqueduct, + Market, + PublicSchool, + University, + Bank, + MedicalLab, + ResearchLab, + Walls, + Factory, + Monument, + Shrine, + Windmill, + Hospital, + Museum, + Stadium, + Workshop, + Library, + OperaHouse, + StockExchange, + Zoo +}; + +#endif // TOWNBUILDINGS_H diff --git a/Diagram.drawio b/Diagram.drawio new file mode 100644 index 0000000..b35c307 --- /dev/null +++ b/Diagram.drawio @@ -0,0 +1 @@ +7T3ZctvItV+jquRhVOgNy6MsWY5TccYZz8Rx3miJljhDkboUNbLz9RcA0VjOaaCxdDcAiq4pDQmyF3affT1jlw/f3+0Wj/cftrfL9Rn1br+fsaszSiknYfy/5MmPwxPCQv/w5G63us2eFQ8+rf63zB562dPn1e3yqfLF/Xa73q8eqw9vtpvN8mZfebbY7bYv1a99266rqz4u7pbowaebxRo//by63d9nT33Biw/+tlzd3WdLU8ayH/iwkN/OfsrT/eJ2+1J6xN6escvddrs/vHr4frlcJ8cnD+Yw7rrm03xnu+Vm32bAP8OX3erh55fV6sPn371//7r/n//wUzbLn4v1c/aL339YPGYb3v+Qx7DbPm9ul8lE3hl783K/2i8/PS5ukk9f4puPn93vH9bxOxK//Lbd7LObpF72/nrxsFonQPDr6iG+T+r9c/kS//1l+7DYxF/Bv0VubLnbL7+XHmW/7d1y+7Dc737EX8k+ZTTM7iSDNe5lB/9Sujh5GfelOxPZs0UGK3f53MVpxi+yA+1wuBQd7lzPlvnVsxWqs/UUZ+vbOluGzvYwaoaHS3iLwyUuD5djqnAZn0XyG2d4wNwDlIEGrB1lCG0dsFAc8LGAr5LuqsDXGt310em+eV6tb1ebuzkeMOdeT8ZmDXwDdMBn1F/vk9OKz96/26e//PDk6TE+iPKZ+//3nIg86en99JJt9yL+yma7e1isiy/ImS7Wzw+rzfODnDHe8mHS6kLx4/LqJi/axC0ScIvCp+gWQ8UlcluXGCouERzacnN7kQjR8bvb1eJhu7n99X6VgHX8wfVqLY8rfidPi1cPsnrq8FiXt7Gsna223e3vt3fbzWL9tngazxz/0v8kw8+FfPslXzV+c/U9m/vw7kf27mm/2O3B1uXjbOON9xp/726515OY5Bc03n4ZRSW73i3Xi/3qz6qGobrebLqP21XCeAt6AIUxwapzPG2fdzfLbFhZIwAzMT+qzhREtDrT4RzQTPHJLn6UvvaYfOGpw5Z55DXuTDcgfnHYQwH++aH3xwjJpBzRtesY5udN0wSp3pI/Nk0jWJ+1eoOrp5ge3r3ZLm7Hu0hHUghj4K7J2HeNVUCbd/1htVnOG1vRDY6OrVjPtHmDHxdP++ed40vUYKaNe+Z0aveM1V2b9/yv58Uu2fWRXzNivqMTZKx327zmX3eLRKVPsPro7xqS7tGVR+qW+SaC1tFfskemdslu+fO7xDl37JcMzUCjU23qljm/3203R3/JEJPHv2S3rPnn1fro75hEE5OyqVur/KfVOj6to79mhMqjX7PKbm/xmvdb13aPKXDl0W85UtwyOFgL3pmORz9jBw7PqOUoHhwU8QFd4a09OBGvkTQ0HhxTLhPmlulcrvYx+B29AIkcc6MLkMwx13nZ7m6fHhbHf9NhMDGln504j2XOE43HeVhIIefpGzsQRtBD347z1McOmOZNnB4JJH9f7UuAHL/7IiE3fl2AcfLmRxmme0D/t/g3X27X2116PMz3FhEJUvDfbf9Ylj6hV4HvmcCXA8C1kNT0iDUmXgEyzgKADe3xCs7Eh+JVSyFUhhXWxuTAASwLo7Uak8NVNug5IrFddtSHRvRHSdYSI8WIGMkkn63jT60xMmZ11Zkkhk6H06ls+HNEkh5QbJ3/0BGB2PMA6Mn0uc5AzIEdk/u0FRAbA1HsgXh/tVu8/Pz19yRvb46qGwOcmkpOrYvLD0Q9IAzL28HWmF+WT8MPdwI5O+MnPXCsGP+2Wc0yI4oFMLy67ekGoaXTFarI3TmyMDOK17dvS//mRqV43QbRVyOKl16fGjHJgXEQ8cQgv2rN+WgAOd9Q8a3tljMQtqofCZW57mAcTYD3rNYM+5SCdWKEJeHjd0U0TpLRv7p5ShI/d9v1uvD1ft0pzLCHxeZriKUhq4pahAb0PPIRWaTKNGcglplLZaxPSWl7vfHBKK43SfOvv+JjuFAWeJULDUPM43IzuhMJwse2jMvF+uY5oZTbjQE5bQQh2PMB2kRSRFBxBTfHjFWNDMKzJPZZnjSNgBlCeAp1gwl80MKWzOZj3nO9uNlvdz/SfOtZnnIAIkGYZAujgXOAWUB2yh+Wm+cnMzrIGPQZmpPHP2msg2QnnRzyPKmGoJM7ZWyszE754+r7g4kCORMAZj76MYeYbFzulov90kgNohEkDR5W5TkShS0lDWtGi5CiM363eFh+Xm2SSl8zPGTqA7MbCYOWUjOBarW5U67PNWqONNLqQDXRRfL+TKyBdazr53V9dPz8QIblKCdBhjPvXEpRZagJXJK/yG1ay6/bl6OPVUOJxaPHqkXO01o+LxuQ91juGWYWj3/PbqOMrxe7mRebgvnCAcFc3G1uuOe2Msub7ctriB6GceKjYyqRRilH9/x5u/vj+LPQWBBO7p7d5oZfbheO+a71fNGxUzqI51ZE/m232KxcV3GcQGLw+LjKMO+9SGzH19vdXK3HnAX8XFTOmYhIYQ9y6uAjDHO/9KTfb+ZrE+IecImoD9qpcZMwbBN6s93vtw/Jac/zlCNoeaOKU2Yuy4ATpnBYHzIwZ3vMDAJzIMY/ZsyIf3t8XO7mesgs4oA0TwGWsa3ooDzM9ZQxKE/hlLGl5sNqs5qpW48FArI+lc/JaRgy4fWp2G1dFeqIvzp3iJnZD5KmxQUOeGxxgcZwuU7L3RzCeZOldndfF3+JYSX+L4YHT/nqr2cZQHvpPr9leJAMf9hutk8p1lS+UvwUpVPqjIoU4EtNm0QMgsnTtB9R/k6CpEiBMn5ylbxONiYSqBMxJOu+S/LvSlzsNQ0tpjkAfv5J8cHhoPMP8nDx5Ek5YDx+n4eMJ58R+SQlH8mTxNEhMgJUfENSrOSJlz4pkaXkYUaYREaahCRO8qvF/IfhRTh58lAVUH7YWBpSnq6a6DwiDysvb/4QWl5sTYaXl56k2VXV91+yaQORP6rOcki1Kh6Uos5Lx1p8lB/q4evF5aRR5G2gIv8oB4iCMAtJeItv+wUUFUHnqnUWT8Xju9KMlaWymG6RsIBiEo+XFvlR+oAEnnqBSnS6CsiVCyUZ1ap1KK9ZphK6jpfJQtjBIBnI3uan1+2o8stLK6Zv5bLlZ5VbrH6Q4Xv5YZUKyQkguToaH3qSaF+VM3hEkJyhtBrBtAiDckZ9ZsGU5YyP68WP/pzZtCAwP1hE8RxhgEPZ3MZyEFkeq9KmMFYranIY5nfoKFkhChSZJ25tmaLe6T5l/K+aW09UwBRHEn7QkiPZyoUiPvZjvE/iLa+3u+wy5njUhEX+efyn+Fc5+EBaF8YztksZQ3Huktse3bGHfPxjxz6O5NRnediENsK4jw9bmWeZm9rMn7Yizeb9fKGbSflBkm/fxxG5Sni254ZWpNfM94BFBA5YCEXIs+qAibW+pyRQxcOCs51FEYWsDhA5K1UBymsCjVQHKKfHo5QMZjH9rPoiIsh52lZEICxs5HyQxlquDESCekNDluP+bXFTFdBVgFYS0PsmayQFiT4npisLWfAGaA7lUCgPFUFkOX1x4/FTZOdcx8pX4u5Jj3J+pJ0QyDyZinmqvH4Wj7k+WK91nQ+hgnlb8D7S3Xlhi7tzG34X1mepDLu6nzfLD9s/l1O5PlSqyIv/XV/bulg+/sViC9nH7dMqKebh8vCJGOHwyeiH361/+SZpY8Le3C6e7tNbINUTT55/XOz3y90mfUI9lh/q5+wnsoHCb3pPeuEX3eT1NYv/Nd1kF4lUJR0IM0IqIRwqRTKCsLOMqp/KUNkuwmjNSvXyMxxBI80ITwweAXZlp5oYCbEs/vbP5cZpjPgY9MwfnZ5F2P6UMPdjPH1K4OkHCvlaZf+zePzYOJUWMTrG8/eg7WoK50/R+X9arx6P8fgR+Ad0/ONX1diYkuWwpfCUl1/N662WbIdjdn3JOesY1kNCvTp3QFfBzPerM9G8QaJpuQzv2YkEpKwpYVWvoCPpFcm/ZqI2Eb2CC1iVKJD9yLqCb4upTPVXqV2pdm8UpoB1HxFGmhFi+AjtrnS/3BbmYnOM87p9avHh8jIRIExJb7zJe6OsiuZYk8GWmTEKrzq4CtYY1RAzsNGvAqvzqVaz2twd2100o8X4d5HHs1Sbc6R869juohkvWpMoFpzb6pRCFfWIPixWm38sNrdPN4vHo7uSWOLveiVKD6dF/MAWgJ/398vdK70SJcVyfSXdrALz0YVqr28iGg/xWCNsENJT/+k8sSltnpNW69buu3k8iYRmfPPvhuPtaCi0oWhW20gAdeDS283zw1PbOICYPu2rmLlYr+4SnLyJ0WEZk7o3CRVb3SzWF9kHD6vb2xRxdst4K4uv6VQJdmb3Hs8r3pyJq2Su5/32KUNGREIzClFudiQfARxugfZGaHBEGmmwoqKCKvWJ2SPBitogiVJ7eb/YLeLLWt3cxzc1y9r0zAcVvVVVKvNqWhUqG1k7bqNRBYZ5W7vg2cnztjy1Qgac9o1j1U1kzhKtWqZ2W+Dr2gEc/o7uI6rft8S9iCohsB43to/LJucQoc6dQxUnzzb+GV08PGP4bYqeVRIyOAGkr3UbPA8CGSfhuWxgYBhj6vdtGUIV1Du+1Sj9+yZI/3rp3zD9e5n+fSv/krPw8M2r0pPDN0XpeZg+vz7JVQ2R6mEEAIBFCt6uqk1lLcOLStSZu497qK96GpSMwVj5/pQMTWWKjEV1K9XtTTvCEuGTSAMJ35UkeTHBIunrNyVyxkvkj5aI41WJRIoTmWsgc5EnwHWrsrVVoTz2yBzFlu0mMqdRYU7GuJjgGKRd2qlMdSPO/U1taZdiBNWMwL+m+wg39JGq6SNLKaOnon3xcz97Tg8fXZe+/LZERi9KkqN3IpcNBh98+0xBLlU+Dovk8uTjmAxZ7WsJajGVKbKKVuI6kofIavcRzIl9R0Yh1xLJ+C+TlDCnhyf/QmMxNQKvUqEHq6pEWCR42KPw/uevvy9v3MfZGzhhEkFza57/PlqyNqUGMn65snBvgo8XJUUuV+3Sv9QrGa6ofHuB7FtvkSTDstfZEFrSGIV8qFUmc/og5Fr53q5PzsnuoB2CooCJKolAmzoWl+qrAhoA7dzMmoPSpWQyly3AOf1mBWbDErRel+D9Tfr8UtqFD8vFf9+qINcrWUve5OC8eEgI4Obr02O2+8xiwqsG43yXh63w0jcvSgjll56HJUSO/x72cVGjcUjzzQm/OuNXy5iQMrYxVZyiRWxznuQ+WDnhR6GcYNqLSs+1d1NrpzLlqMYrMY2vGrMYrrFwe9Cz030E0ShAMeY1j7ClAGkLUfUMzzqUuQMdMMaq1ZJiaH2G69168fR0pnEhDaiTx1W5xm7Fc0U/vISJXpAS8y+ruxel51WL4aBrK5/01MrtMIocWWFLtcpeOLKiu55OIZra/ZgKHlfcj8rz5Ph+sCn1QPl+3b4MrIg05bsQsFxcwMYncbZqjqWEMqwSyly5EY0O5SuVgqZVcQ7anzRLUA95bAL0hCANUc4MtbZjUZpaooUBYKc+tGhyDxMexyZNrmAMM2hVcCCLp5ZoyQenlmidp6HFNKeWaKeWaKeWaGenlmhH3ICGE4blDGUDGm5NzsAe8oTFpiUV5njInMP+tuO3EKYc+6evlg/b9erp/hirwaFifONXg6OK1n9ZBZdhh2/1JGkkS6xlJ8kVXWWUZSasnaNQFJn48eZ5vz+2AtFcUEBIfNYuc9YeEAtsjUrpx8BcWbs1ISgsezx6YVoqMNMbIWl9OnfEeF2cdJVihy4vSdEr7GB6/RCfzdFaXgMGmz1Eo1tefYwuh5swICVO2WMUwHKdE7CC+1iUPNzFL0OLCc0KKybgcvWxP+JwE59uVsvNzcCmhlO+DeQAnwKNwkF87xNjtIl2fFO+C9wV0YvwXTjtikh9HOKVcor3m2l6TU3xC+Q1Db3x8QLrve8TA8+rxA1VQ0vHuKHoyYouwE0qa8vGlTjCkp6pIixr72si4Y/Ch8gZAKNq2+hH/UyGgh9D2DBH2tHqdoYGyJ3ZDTJUdMGVWVbKzIx4T+nbKJSJGuALFzWxaFMPWqDughaQbhIqrCpKM7c922BAO9G2o+rVm3fpyN+URlns0qHv8Ss5jr6fR9CDYhvr50FgCxnet58HnkrIMGjDBFpAeuuHzQQaD6AuikgFU2+F8xoRM1dZp46YsDUg7ys44akEa4eY5jBBZfk/YcLYmBDNAxOQFTLsjQlwKsEdsSgRTJNFqZqB99aL26QFcjeYOt/et7DgIYkIUB3agrt+JlMac91CtYVJ+NABTDQPQFsCA2zhkyJbolnlnpuyLdwp2ww5ZVWGRBUqBvaUbaN51EMIIetCCMvUt8m0OEeCyfJuCBmcMJ/2I5j6mUwVf4Kt8ORCtTuDA3xPkysdiYEDwJZsEUxFpnSRiemVMmjnWhbPIcGsvcMKweQuCSZRGScPgVr3frcUopdsv0kc2Ga7e1iscSTYP54fvi53H9I8icb0ofhxeX0AU51DKI2HU4MoSJ/gi3QbvBfOrrphSwY5dfbGKWiCKvoWN9TPZKpjLVwoyKIKa3fmeQMHCI0+gH+7E31ALjok5JXWZk97pRpppFpUIn9yNKnJzB0f5QTCr6JcWuSW/Do31JzI7+FKfUhpQnIuG0R3psBtJjNFhOFaQRbEWrs5RgcOEKJZi8E/vzrAFhEeXsKigQgTVMKiXNIbNHqp1r+s1CHEuo44ke4ekjPRk27imHbPrvZecsJHQLuZD/i4L7NbOluGtDOZsgyhhTQd3FjkDxwgRLOsjbYEBtii2mrL0MVbRFfz2j4zI4spljkypYcQSiQN0ki09sLW5GrHEhNQxAF8OSuFAWhiAoowgC/5j6mPCSjD01lS2GARkUBlvKdXge85iSLIZCttDAHvzhlMRRBwAsyivK9HFc3EAjtsgHOAryzUGEQIbxxgiUhH3VpEnZB4mkgso2AmjcV5AJx5LLYlzIV0HlhMO2HxFKKA2ikoM3Zq+wBGhddbddHNZEx1qVmo9c5CzQA+eADlHbfUeQB3ohxFCm9c4TbPVaSSKan8pLMZamaKlcsYJQQwinI1yl4P9mKUZKjI7IUyKWDlElUulLUXr759W/o3NypecBtEX42IV3qpyR9PbFJQNNqTkXhAmqECzGSKkfBIvWXLNBW7Ca4XN/vt7sen/W61uUM4NIO6fBSW0+Iy9UOXiw1DAwySJ1wzIjvnA3LO8ZgDb3rH7NzrcArt1/WuZzC+FKaftKXF+plMda6HC1EWNe8sGjpAiGa3M9oSGGCLPSj8ERUvcjXAsK1nWaiLiCeeDl7tRFBukZCL63mHN9BUrtxc8a3sbpB/DXeorm+reHj8dTfgxxyJG9tlJG8d2pUpFVc5bKypFczDDpvPi91utd0dugPMj23jqsWBolOf26rFzMMm9X9uX0e9YlV1Oaf1imMVR0Pk9TSQJzQwJXr1fUlVRplKsGY7clu/1JFQXO6O4hIKy1coy4ipkieEPXCcXdA9PY7IIUJREdLe5Rf0U5nq2olWCjWVq4gXDh7h+5oRDJaf6D4icFFQKxe53GEbO7nBNHjooboIvfFQP5UpPEQrCU2BIsKGjwiFDnM1I2xh1ewyF/piVfKvWTqeCFaxSFbUzkGBhP2wqsVUprwCeKXMxFmf82VgBGkeUf/7LWNVTaGJS6RZvD2r9LwE1R6vZuridZhSwCKQUkCEwsdLnKbjMg87UZqoqnsfb2pAaENEW/le+8ba1V6/vuaV7BE9SqybF5oj0CCSlAR8KIE2XR+OeQrbehM1S18o0gBKPYNPBK3e7EmDFgSNurW8EWxdPhE0swRtxCJ+nHNIhVhPgsYJlLj8wI7EiTftRy5kO9ItqH4Knvtjt0OgQFISRH3hF08VWoJfFC4baJQZPxo4gERCo2GhXw9G2MIp2kHCmJno4DTcFV54GCp0Iac1+ZhUz0Az3Yv1brm4/ZH2wBneAWckD7UHpPfIV0hqKqeUtcAyRrBBL+YjMcFKDjk97ZkGS3JGRRW4WRieS027fOAyGMPRgWNbT3Hgv21WTgMDrEF27WE7hm5sWEmIyb+el8/L2VIRWKiFeIo4F9cHjeNT8xbosz1oBNRTOGhFL7LNt+3u4UBE5njOLIRiiCrtxm3Pt7x3r6rn2ywPOQig7IFL6TiGZYpV4/SIfzwuP293f8z1qBGBnoCYJ40OpaNOjneusZ4ImokXjH/GOL7rohDt5njMnCDKPD4HpFhBRGc7rRCETsXd5xiCwD1oByK0r0FNP5Upg1rtSq33prWPCch0uw4gRDcC/4ruI6gLox2dXejQK8RbLmK1HczTH3VVs1nDXqk0tMet7iN42BW3wAhbuKUqilqPW9MvEtDRkdrWTysLQ5217/hWi8PaOky5bVXrzc1Fx0kUVAuIOPf8qPjXkxzAeX3eOK/ltoWMTj3Ialo40qUr4hAcaVtycFwcYQw4Ezgr7NudMQNZcFnLKC5zyKDKfz4hQy3D6FBJcAAyyEtogQzeeMjAQpDOTLze4T/jYwLrlpW3fVw2oQCh5lCgT4zaNv4Z4xN1eYTjRNtC6CS9oRNryoPTIczDbzdz2DzhtxYWxxEGYAqBNLn0oH9wKgqB1ZS+jDetCQfTjrCky7JudqJ5AnQhWARlyYI0UuQ6YUdXRM+JRCId0+PQfChGDLA/Q6f/cPuzeZrfzdwzgdzmY+kf5UGHmOibytNiKmOm0rqVaiOBAxiV33lEpBnAfTJwgHZP2t9ti4EpDE3N2ZwRk9lOoO2ULPAFkXvqQcwuEzoRrHJFKIDbJlFMCnHzIdD0OEq94PTe3qkdLaYylgxft1L7vWnJJ0WpGp1HCI2/rD63uvsZWybR3cyfJ/w01/8YulT7p17ppzLWAblupfZ76y7e9BCIdP7s2lThDmfsxJ/NcfTtxPHzoOAUZofj0HewcOXD9MbW7FQ/lbFGPVDu9zVhG3iElnFhDYk5QQxFNnGhW4TVMgoNbUBOKkUnlUJZI0ZVAd6eSsFfg1nUCD00ZVUMpc6Y8z5z1epsVY2M6hayTJbqm3I/Pcbw0qL8LQlV1cbff1wvfsTEpyiBe5ivWhl32BrvdovH+9XN02X85d12vV7urp+T31yzJMC5GYTxsxwjcoe9rEpRDuMPnIbx827hWBMIBxZHKeJRXwDgyKt0d+5joZ/KWCOLupXq+0yAEaGvGRCRgQPgnmzR3m62xumGcvWItRqrPpPWcSrU3tCqI/X3n8Ti48vf//Yh+sV/9/N/veDh3defqDP5JubaDLCFgJ7LOv6dkT8IoupsNPLQbKbwP2JwMRHIxeoRVD/IFo4eSbilZXxzHG7J28YeE65GZzdoSqU/K0fTUPTDUZYXMMinEmCq8YMbxPwKpvXME5tNwbRc9inUStpXRtRPZUxGhEFBcqV6GRGMCHnzgJiCDBwA92SJ/8jentBsyEoRBwfzIC/VYA1kwELefOyiZFqMSWK51TBoUwwCGd6U/orsU4jUU7dAuuwYFnlANPNl9coyxrutzCZeQ6S8EVJsjPV7kFgSeL2tWX/e7Kh2KlPul9pNW6Zx/ASejsGTw5v2of+jNXgKOFVkCzxFULPp+r3BEZEbgD55fEant73lXDxVBIuVWaO3OkuldoQtgO4Wtj5PgC5sH2XLh3ceikBn/UjefVzGB7dMpd2BJeKZ1PUn4TvN2XN33ynsH4emmoDN4uTMmoShgrDQPycM1ZiQOQasJzXvOq+p3nPCb7Ns7a6bhwdEM7z5R4PhtniGyrvVo4evuoHvdWqKYCWjxeVZ25Y0x9GU16FRA0fBUBl2p6smaM+o4SssY0cnkxgh26ZEA9R0NoJBJm2pcuAjycASHUZ9conGlIy2RpzYef2Tic4xNFPYQ0P0rQXAYDMVW52Q0JZ9bWOYmp1ZBubXYNBLZi25BL34n7nSkcaAXIAOhmFfOx+aCaGLKSCHCwVuYPY12OxmAbOM1vhmuxNmOJOwlQcKF3IEsyrjRTcViypVrKSbzaE5RXyR201blWkWEdUw9y5v6arLELEXUe0PV5XV9/gpwf8P2z+X6/Qyj+keKeqANoF7dJ6cfAqA0jqGEJxA4by9Y0g7lTHHEFwp0An6HKX7dh6hS1vGu4qcVGWRJqQB1JHVGxLDUvQTR8VcLksBVn4phKpsYzyMlRFSWWgVLX35MK1fCqGi2ZAjMUVShxmeGDVCiug+U2VEQVO/ObofnAJfp0b3qaLBLe1H91tMZcy+A1cKNdnsNBo8gnqakhhoV3CELbpPB9N9UU/3WSmutUyyr0r0Pafmb0vhsvILR0K7HWbnKwCJK2i310AVLNDuk+HduX0HRuX1j9XCU0HtzpiFB62kCz7UjbBFNl+D8X1SAE0jDmL++yfZoKmQ8dNYIibadKhLk9aMsAXQr8EyPymAxslOvftEMOiyxFOZotA+rP3j6UpB6UbYAmgcTZu2215t7i7vF7tFLBWubu5jkfAJwfkMLLOcg1ONNY4zKORR2eqh0hMadOUxKORhR0nS2TU99X8ul7ezPGgGYsHzRIwyRZBOWjcG8AA7Mt5/WDxeb3fXq83t8EMewd7EQWYp9xSnrOpwblFlce5mMBKzXOd8PrpYZkZBBAOXsYrd9RvdTObUG/VCDdpNdQCLNAOEGDgAbMkScw6xtyGhXYlH/N+rp9QZPkNWwYAqSqUXvMKTVfG7oAyMOSoWqozmJpzeOWeP5aknKy5vZBa/vEyomZm7ErwFW3fr15YelvkU9e2XJDNfdwcDqVZ+38hs7UTmIqaq60SasGzqDfq+0Frr/Kbv22I2KuNzhQbe5MBYkLlUdEqItdKxEVT6j8BUmOuz3EGdvWjuYCJem5+jc4hkp5ilKgxLN2KZCatUCXu1iaV4OR/K3trmNldSzmVz4jw3hvSk5fqZjPWpqlmobmdClgrrPYAIDT0nQwfotqT70bZYhsIanpB9HHAUyggmHJ10gYo60UqVqFdE3E2J7Xk/9BzgfIWKxdxS99dQtsEIPTflOREhULR7V08QsE4yMigaIt5oy1Q4oWPOCy8MjZl7bTplkjvbVMOgr1jSdV6DqcBNy2q83zGFsDhcV8lKs3nfjbY6PE2lISAvlNoo0EPLxRtk5cqod+XKV6/MmpJ3tBCJdVuuslrac5NF3aKy5yn9zCOjs67a7vBUe2udPeGW3bS3zHxiDqUi35Jr1zMjLSUTXV7OQFriAUwsJb0bjOunMmW4gStRT5MLkDsJew8gmhqHeE/ESY3DSGuL10o3YWO6QV297lKzvyMRT9qWprIonhQRZjmg+jg/WJlrYM+PKkMhT9R9btSdBKg0NhRcW6u/+qlMaby1K7XeG9U15+IDv6/jBnhHnUfAX22Lf5zC1B2rFai4W+8i5ii6wFLSRcjUG67bl+b7tiC5W1+6CZhmjz+dmbPovGRrkcQmzxLq2+C288Sm0o847GoB+t0q0pBhEGP3EaEmagjvCoywg3HcU5iqYjS48EqROwTZREF0T9nBC8rjztKp2zbK36YWUQul1SQLl9UmuNfNRnQSNAwUk/AgGPRO8MRTWWqXUr/pDntzUfuWS03djuUF+5WOxs4yAQpJYPuf+C4YppBhg2hkgUKeVDHXqhhWuntTSGgxxlOZso9EUD7UFQfXjrBFIU+BXK5ZPoJCr29KBcYNNJUxgIaxXJ4uLEU3whZAO4/+Ghp3Htq1hM/GEgHjXKPetXt0E5ny5BNPuU79viBGaIzmYuiAyA0PwVnjn25Wy83NEmFep2TI9eLrcv1mcfPHXTpMwvTt8tviOZfhO5ry6vBM6UAqfVLOV69FpC4JOwBEpaqmy/2HDQPNibYSdOwUQ70q+afZMXqmJ6AxcarG/jJQRQqYsmdQIgrr40m6dJwm0JOLYubj2WGjaMuextUrYM8wMGAwm/v9J7H4+PL3v32IfvHf/fxfL3h49/UnlW20G3kkoYo8vn8XM7771c3TZfzt3Xa9jmlZNvHXXUEOp1RfH5EkBfjXW75DVg3oJUSE55GPSJWyaoRvoGqE8nqHx2ipa0YkVYrwDV8/Jzs65lv2QZZRGGJmRCUkmA6SUt7wcFuw+oaVF3zMVxnTWxzwpuzRaO0uu5lhb1eLh+3m9tf7VZN4Qbk58aJ12EBJvMh2qZAw8v7RRL75knxyLuTbuu7R31f7/5Rel0bF74pByRs5Rim6KMWbgyChJ6nartSZl9ORww3aWb3efcs4zm+0FNLg80a9Xj+AeJlNxKqI1M2WfMLKSWOlPyJSRtDM0d4JTiHgU//cK/2jljBUdMXQ5gF2EFRp43kFGFpCyi9lhNVhaI6VX8pIaRtDOcbQekx2hKDA0RTB0JLeCBpB65MpjAwCNU2xi2D1pQefHmNg728lKCkUh5mqKuOw2T8sN89WF2jWgLsumZUuS5bb3X1d/CW+2Pi/+MY85au/nmWqkJfu9VtGjZLhMeHYPqX6VuUrxc9RW7SpSHEu+VEftrfLdfLgbfp0t42/mb+TQCNSsImfXCWvk42JBDBEDIy675L8u5KW9JqGFtMcYDP/pPjgcND5BzkjSJ6UWUH8PmcGyWdEPkmJePIkqWwsMqZQfEMyhuSJlz4pMYfkYcYeRMYghGQR8qvF/IfhBaNIHqpYxWFjKRdIV40Jev7oS2XzB25QbE1yhNKTlCtU33/Jpg1E/qg6y4FFFA9KnKt0rMVH+aEevl5cTspZ2kBF/lEOEAVvEJI7FN/2CygquIRqncVT8fiuNGNlqYwIi4QMF5OkKpac50fpAxJ46gUq7EQF5MqF0ihDxTqU1yxT4TV4mYzngEGS87T56XU7qvzy0orpW7ls+VnlFqsfZPheflilQnICSK5qiO8cLVRQE+cEhwpSVaggrHptzEJF6v0Fs+PVJz594tMnPn3i0yc+feLTZvm0kB19xuPT3bo0TtYk1seqbNnQbdAkRlymZEETMvNYkwm5vekLOmV8SxE11IcNIjnXJbTCEb6LmBpZj+eEfNNHvjaOXB46RNMIwrjgZtAUhjv4luqGmkBTkWGMXTQ9knCLE5qmaEoPFTSPDU0FA1PZ8u22QFM8QjhA0yOJv+jjfrXsETaJphSj6fgyrzMs5UIYjceoKH8mkMh5/iAdiFX9qse3hehG+LNZl8gHPY2Iz0lfINROZYpVMCQ7ZivV7g2NkCV7akdEfjR0BNiVJXakatm73Dx/Smiyysng2KBVwdkzA9Yt2DaZEE7PQ0VtUFVin7VQaYKzM08EbZT05sA/j/yC84F6aDFY5Fkw3TOeu89tLAkaWrUoY5rNghGhrxkAa2V1HgD3ZClDTBVd2c0jW5NDVOMD+Lza3CYOKhNrdPD6OqbTBkgzI5A0C0HOZXWosu8hcEma8xTfAmBOV9r7ShnxJnCl9LULPdRn4ws9tJtX7yT0WNPieHQOK7+yGEJkT4QeTrR2E1rT6FgB3+2VulgA0Q4KcHWyHoPw9iwJO0fiujvuVBJ5KXpjo0PPXYAKPlCSs4zOBCEIovMqPYgChqYzRQ4EDA6gLchBi0GWkPTYHHcVLCI2PQKeBrFNImlbx13oLuOLxYz2PFOzS14slkvYnU0UFLkYSvL6ZMz/9Kh9aDPEmAZEaMHWqLsk5hhj6HkQ1vY7EMIfgDwocJJPEXlOvrNJaF2MJApRYQ4mVdjxeV8w7DivNRNzvJKE/tZWZhIzIO0gbDjuMwhvz5J4V982eVgK0Mf14kf/tB/TWUbHYJzMoXE8y2Q3P+BkJZsjV9hDLNmoe2lx36FoA3ojEwIrHbWXZNBUg4PgTYsxsiLFSYwZ2XgcokwMEvT2kStmo3g2U3YitBhh+WK1uOEhrtFnEOPaQYqzQIPsiCzs9VQEHohYxog3BhCPnTPRk34jsVo1mynBv2nrdsGUnsDULZjSCAFW38rVeCpuK9EOb9qn5xEvjEAOjPysm6/7BKsGBBNojiO9i4jiqWzBKl6JeF33Vh1hCZ67eZZP8GxB0EYt9Nq7Y2FAAprKGDzXrVQPz5oRluD59fQMnAg8K2y/kKi2lneRCIqmMtdNqmalhn5SzSMswfPraRk4WXhmsGpqf3hGUxmDZ9hARq5UD8+aEZbguZvX8gTPBnQ9KG8gBa29rocsWbbkDbySr5E3dCMswbPKK3iCZ6sRjYgRJyGIPV0kCmlcMZuxMtkwVJkGmuIGuhGWoLqb+/IE1Qa0QuSO6E2l8VTQYGJMK6xrF95hby5aMcjf787JyF3555sbEE/X38g8QNniU+zr5tZPZcxHAslxpBFLGB08guq6fyt+v+Hu32qk6uZdPCGVA6TiPoQE3jfLXT+VKaSCK5EooM17gx1Suo+gXqQZgX9/dYQlpKKukYoNRCp2lOEwLJAsRIJYGPRlT/qpTGFSGNWsVLs3NCKgmhHo14ARlvAC+13TLO9DgX6AIHPL62YBjNMLJIToWtTba+Cqcgya6OCadKK/IGlvelrqU++VnrxN/5Zfi3i69MVl9jb5e5UOKdfsnnVTe9aS9hoBOITEsnKRSrdV0dcOAHeW1V4vEYSi6jp7+/8= \ No newline at end of file diff --git a/Game.pro b/Game.pro new file mode 100644 index 0000000..a399238 --- /dev/null +++ b/Game.pro @@ -0,0 +1,189 @@ +QT += core gui widgets +TEMPLATE = app +CONFIG += console c++17 + + +RESOURCES += \ + Images.qrc + +HEADERS += \ + Graphics/Buildings/BuildingCharaterichtics.h \ + Controllers/Enums.h \ + Controllers/FindUnitWay.h \ + Controllers/FindVision.h \ + Controllers/Game.h \ + Controllers/IGame.h \ + Controllers/Player/BuildInTown.h \ + Controllers/Player/IMenuTownPlayer.h \ + Controllers/Player/IPlayer.h \ + Controllers/Player/ITownPlayer.h \ + Controllers/Player/Player.h \ + Controllers/Player/PlayerBuild.h \ + Controllers/Player/PlayerMap.h \ + Controllers/Player/PlayerRes.h \ + Controllers/Player/PlayerScience.h \ + Controllers/Player/PlayerTown.h \ + Controllers/Player/PlayerUnit.h \ + Controllers/Science.h \ + Controllers/TownBuildNeeds.h \ + Controllers/TownBuildings.h \ + Graphics/GraphicsController/CreateMap.h \ + Graphics/GraphicsController/GraphicsController.h \ + Graphics/GraphicsController/IMapGraphicsController.h \ + Graphics/GraphicsController/IMapGraphicsControllerFull.h \ + Graphics/GraphicsController/IMenuGraphicsController.h \ + Graphics/GraphicsController/IMenuGraphicsControllerFull.h \ + Graphics/GraphicsController/IMenuStartGraphicsController.h \ + Graphics/GraphicsController/IWindowGraphicsController.h \ + Graphics/GraphicsController/MapGraphicsController.h \ + Graphics/GraphicsController/MenuGraphicsController.h \ + Graphics/GraphicsController/MenuStartGraphicsController.h \ + Graphics/GraphicsController/WindowGraphicsController.h \ + Graphics/Menus/ManuStart/StartMenu.h \ + Graphics/Menus/MenuInWindow/MenuLists.h \ + Graphics/Menus/MenuInWindow/MenuTypeMap.h \ + Graphics/Menus/MenuInWindow/OpenMenuLists.h \ + Graphics/Menus/MenuScience/IMenuScience.h \ + Graphics/Menus/MenuScience/MenuScience.h \ + Graphics/Menus/MenuScience/WidgetKnowledge.h \ + Graphics/Menus/MenuTypeMap/IMenuTypeMap.h \ + Graphics/Menus/MenuTypeMap/MenuTypeMap.h \ + Graphics/Map/TypeMap.h \ + Graphics/Menus/MenuTypeMap/TypesList.h \ + Graphics/Units/UnitsCharaterichtics.h \ + Graphics/Buildings/Building.h \ + Graphics/Buildings/Farm.h \ + Graphics/Buildings/FishingBoat.h \ + Graphics/Buildings/Fort.h \ + Graphics/Buildings/LumberMill.h \ + Graphics/Buildings/Mine.h \ + Graphics/Buildings/OilWell.h \ + Graphics/Buildings/Pasture.h \ + Graphics/Buildings/Quarry.h \ + Graphics/Buildings/Town.h \ + Graphics/Buildings/TradingPost.h \ + Graphics/Map/Cell.h \ + Graphics/DrawWay.h \ + Graphics/Factories/FactoryBuild.h \ + Graphics/Factories/FactoryColor.h \ + Graphics/Factories/FactoryMenusUnit.h \ + Graphics/Factories/FactoryPixmap.h \ + Graphics/Factories/FactoryRes.h \ + Graphics/Factories/FactoryString.h \ + Graphics/Factories/FactoryUnits.h \ + Graphics/GameWindow.h \ + Graphics/GraphicsController/Calculations.h \ + Graphics/GraphicsController/CreateMap.h \ + Graphics/GraphicsController/EventsStructures.h \ + Graphics/GraphicsController/IGraphicsController.h \ + Graphics/GraphicsController/IPlayerGraphicsController.h \ + Graphics/GraphicsController/PlayerGraphicsController.h \ + Graphics/Map/ICell.h \ + Graphics/IContent.h \ + Graphics/IDrawObject.h \ + Graphics/Map/IMap.h \ + Graphics/InformationWidgets/StartMoveInform.h \ + Graphics/Map/Map.h \ + Graphics/Menus/MenuTown/AWidgetTown.h \ + Graphics/Menus/MenuTown/IMenuTown.h \ + Graphics/Menus/MenuTown/InformWidget.h \ + Graphics/Menus/MenuTown/MenuAlreadyBuildTown.h \ + Graphics/Menus/MenuTown/MenuBuildTown.h \ + Graphics/Menus/MenuTown/MenuQueueTown.h \ + Graphics/Menus/MenuTown/MenuTown.h \ + Graphics/Menus/MenuTown/MenuTypeWorkTown.h \ + Graphics/Menus/MenuTown/WidgetTownBuilding.h \ + Graphics/Menus/MenuTown/WidgetTownUnit.h \ + Graphics/Menus/MenuInWindow/AMenuInWindow.h \ + Graphics/Menus/MenuInWindow/BottomMenu.h \ + Graphics/Menus/MenuInWindow/UpperMenu.h \ + Graphics/Menus/MenuUnit/AMenuForUnit.h \ + Graphics/Menus/MenuUnit/CitizenMenu.h \ + Graphics/Menus/MenuUnit/WarriorMenu.h \ + Graphics/Menus/MenuUnit/WorkerMenu.h \ + Graphics/Minimap.h \ + Graphics/Resources/Aluminum.h \ + Graphics/Resources/Coal.h \ + Graphics/Resources/Fish.h \ + Graphics/Resources/Gold.h \ + Graphics/Resources/Horses.h \ + Graphics/Resources/Iron.h \ + Graphics/Resources/Oil.h \ + Graphics/Resources/Res.h \ + Graphics/Resources/Silver.h \ + Graphics/Resources/Stone.h \ + Graphics/Resources/Uranium.h \ + Graphics/InformationWidgets/UnitInformation.h \ + Graphics/Units/Bowman.h \ + Graphics/Units/Citizen.h \ + Graphics/Units/Swordsman.h \ + Graphics/Units/Unit.h \ + Graphics/Units/Worker.h \ + IObject.h + +SOURCES += \ + Controllers/FindUnitWay.cpp \ + Controllers/FindVision.cpp \ + Controllers/Game.cpp \ + Controllers/Player/BuildInTown.cpp \ + Controllers/Player/Player.cpp \ + Controllers/Player/PlayerMap.cpp \ + Controllers/Player/PlayerRes.cpp \ + Controllers/Player/PlayerScience.cpp \ + Controllers/Player/PlayerTown.cpp \ + Controllers/Science.cpp \ + Controllers/TownBuildNeeds.cpp \ + Graphics/Buildings/Building.cpp \ + Graphics/Buildings/Town.cpp \ + Graphics/GraphicsController/MenuStartGraphicsController.cpp \ + Graphics/Map/Cell.cpp \ + Graphics/Map/ControlContents.cpp \ + Graphics/DrawWay.cpp \ + Graphics/Factories/FactoryBuild.cpp \ + Graphics/Factories/FactoryColor.cpp \ + Graphics/Factories/FactoryMenusUnit.cpp \ + Graphics/Factories/FactoryPixmap.cpp \ + Graphics/Factories/FactoryRes.cpp \ + Graphics/Factories/FactoryString.cpp \ + Graphics/Factories/FactoryUnits.cpp \ + Graphics/GameWindow.cpp \ + Graphics/GraphicsController/Calculations.cpp \ + Graphics/GraphicsController/CreateMap.cpp \ + Graphics/GraphicsController/EventsStructures.cpp \ + Graphics/GraphicsController/GraphicsController.cpp \ + Graphics/GraphicsController/MapGraphicsController.cpp \ + Graphics/GraphicsController/MenuGraphicsController.cpp \ + Graphics/GraphicsController/PlayerGraphicsController.cpp \ + Graphics/GraphicsController/WindowGraphicsController.cpp \ + Graphics/InformationWidgets/StartMoveInform.cpp \ + Graphics/InformationWidgets/UnitInformation.cpp \ + Graphics/Map/Map.cpp \ + Graphics/Menus/ManuStart/StartMenu.cpp \ + Graphics/Menus/MenuInWindow/MenuLists.cpp \ + Graphics/Menus/MenuInWindow/OpenMenuLists.cpp \ + Graphics/Menus/MenuScience/MenuScience.cpp \ + Graphics/Menus/MenuScience/WidgetKnowledge.cpp \ + Graphics/Menus/MenuTown/AWidgetTown.cpp \ + Graphics/Menus/MenuTown/InformWidget.cpp \ + Graphics/Menus/MenuTown/MenuAlreadyBuildTown.cpp \ + Graphics/Menus/MenuTown/MenuBuildTown.cpp \ + Graphics/Menus/MenuTown/MenuQueueTown.cpp \ + Graphics/Menus/MenuTown/MenuTown.cpp \ + Graphics/Menus/MenuTown/MenuTypeWorkTown.cpp \ + Graphics/Menus/MenuTown/WidgetTownBuilding.cpp \ + Graphics/Menus/MenuTown/WidgetTownUnit.cpp \ + Graphics/Menus/MenuTypeMap/MenuTypeMap.cpp \ + Graphics/Menus/MenuTypeMap/TypesList.cpp \ + Graphics/Menus/MenuUnit/AMenuForUnit.cpp \ + Graphics/Menus/MenuInWindow/AMenuInWindow.cpp \ + Graphics/Menus/MenuInWindow/BottomMenu.cpp \ + Graphics/Menus/MenuUnit/CitizenMenu.cpp \ + Graphics/Menus/MenuInWindow/UpperMenu.cpp \ + Graphics/Menus/MenuUnit/WarriorMenu.cpp \ + Graphics/Menus/MenuUnit/WorkerMenu.cpp \ + Graphics/Minimap.cpp \ + Graphics/Resources/Res.cpp \ + Graphics/Units/Unit.cpp \ + Graphics/Units/Worker.cpp \ + main.cpp + diff --git a/Game.pro.user b/Game.pro.user new file mode 100644 index 0000000..d4b3362 --- /dev/null +++ b/Game.pro.user @@ -0,0 +1,358 @@ + + + + + + EnvironmentId + {f1927754-bf81-4d3e-9d99-76d564afc35b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + true + true + true + true + + + 0 + true + + -fno-delayed-template-parsing + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 2 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.1.3 MinGW 64-bit + Desktop Qt 6.1.3 MinGW 64-bit + qt.qt6.613.win64_mingw81_kit + 0 + 0 + 0 + + true + 0 + D:\Project_C++\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Отладка + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + D:\Project_C++\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Release + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Выпуск + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 2 + + + true + 0 + D:\Project_C++\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Profile + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Профилирование + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + Game2 + Qt4ProjectManager.Qt4RunConfiguration:D:/Project_C++/Landoria/Game.pro + D:/Project_C++/Landoria/Game.pro + + false + + false + true + true + false + false + true + + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Game.pro.user.18313f3 b/Game.pro.user.18313f3 new file mode 100644 index 0000000..b836a0a --- /dev/null +++ b/Game.pro.user.18313f3 @@ -0,0 +1,262 @@ + + + + + + EnvironmentId + {18313f3c-3335-491a-a9ef-f1ab8793b7ea} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + -fno-delayed-template-parsing + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.1.3 MinGW 64-bit + Desktop Qt 6.1.3 MinGW 64-bit + qt.qt6.613.win64_mingw81_kit + 0 + 0 + 0 + + 0 + C:\Users\aidia\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + C:/Users/aidia/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Отладка + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:\Users\aidia\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Release + C:/Users/aidia/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Выпуск + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + C:\Users\aidia\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Profile + C:/Users/aidia/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Профилирование + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Game.pro.user.f192775 b/Game.pro.user.f192775 new file mode 100644 index 0000000..08aa320 --- /dev/null +++ b/Game.pro.user.f192775 @@ -0,0 +1,358 @@ + + + + + + EnvironmentId + {f1927754-bf81-4d3e-9d99-76d564afc35b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + true + true + true + true + + + 0 + true + + -fno-delayed-template-parsing + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 2 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.1.3 MinGW 64-bit + Desktop Qt 6.1.3 MinGW 64-bit + qt.qt6.613.win64_mingw81_kit + 0 + 0 + 0 + + true + 0 + D:\Project_C++\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Отладка + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + D:\Project_C++\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Release + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Выпуск + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 2 + + + true + 0 + D:\Project_C++\build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Profile + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Профилирование + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + Game2 + Qt4ProjectManager.Qt4RunConfiguration:D:/Project_C++/Landoria/Game.pro + D:/Project_C++/Landoria/Game.pro + + false + + false + true + true + false + false + true + + D:/Project_C++/build-Game-Desktop_Qt_6_1_3_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Game.qrc b/Game.qrc new file mode 100644 index 0000000..a2e6d26 --- /dev/null +++ b/Game.qrc @@ -0,0 +1,12 @@ + + + Graphics/Resources/Image/Aluminum.png + Graphics/Resources/Image/Coal.png + Graphics/Resources/Image/Gold.png + Graphics/Resources/Image/Horses.png + Graphics/Resources/Image/Iron.png + Graphics/Resources/Image/Oil.png + Graphics/Resources/Image/Stone.png + Graphics/Resources/Image/Uranium.png + + diff --git a/Graphics/Buildings/Building.cpp b/Graphics/Buildings/Building.cpp new file mode 100644 index 0000000..297d2b9 --- /dev/null +++ b/Graphics/Buildings/Building.cpp @@ -0,0 +1,85 @@ +#include "Building.h" + +void Building::draw(QPoint point) +{ + if(!pixmap_for_building) + pixmap_for_building.reset(new QPixmap{FactoryPixmap().create_pixmap_for_building(what_building_I())}); + + int rad = calculations()->circle_radius(); + + if(phase < end_phase) + draw_build_phase(point); + + QPainter qp(window()); + QPen pen(Qt::black, 2, Qt::SolidLine); + + QRectF source = FactoryPixmap().size_picture_content(); + int adjustment = rad/10; + QRectF target{(point.x() - rad - adjustment)*1., (point.y() - rad - adjustment)*1., 2.*(rad+adjustment), 2.*(rad+adjustment)}; + qp.drawPixmap(target, *pixmap_for_building.get(), source); + + if(phase < end_phase) + qp.setBrush(QBrush(QColor(100, 100, 255, 200))); + qp.drawEllipse(point, rad, rad); +} + +QWidget* Building::window() const +{ + return cell->window(); +} + +Calculations* Building::calculations() const +{ + return cell->calculations(); +} + +void Building::set_standard_charaterichtics() +{ + end_phase = BuildingCharaterichtics().get_building_count_phase(what_building_I()); +} + +void Building::set_build_phase(int _phase) +{ + if(_phase < end_phase) + phase = _phase; + else + phase = end_phase; +} + +int Building::get_build_phase() const +{ + return phase; +} + +void Building::set_end_build_phase(int _end_phase) +{ + end_phase = _end_phase; +} + +int Building::get_end_build_phase() const +{ + return end_phase; +} + +bool Building::is_built() const +{ + return end_phase == phase; +} + +void Building::draw_build_phase(QPoint point) +{ + int rad = calculations()->circle_radius(); + + QPainter qp(window()); + QPen pen(Qt::black, 2, Qt::SolidLine); + + QRect rect1{QPoint{point.x() - rad, point.y() - rad - rad/5}, + QPoint{point.x() + rad, point.y() - rad}}; + + QRect rect2{QPoint{point.x() - rad, point.y() - rad - rad/5}, + QPoint{point.x() - rad + 2*rad*phase/end_phase, point.y() - rad}}; + + qp.drawRect(rect1); + qp.setBrush(QBrush(Qt::blue)); + qp.drawRect(rect2); +} diff --git a/Graphics/Buildings/Building.h b/Graphics/Buildings/Building.h new file mode 100644 index 0000000..a71c10e --- /dev/null +++ b/Graphics/Buildings/Building.h @@ -0,0 +1,43 @@ +#ifndef BUILDING_H +#define BUILDING_H + +#include + +#include "BuildingCharaterichtics.h" +#include "../Factories/FactoryPixmap.h" +#include "../IContent.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Building : public IContent +{ +public: + virtual void draw(QPoint point) override; + virtual QWidget* window() const override; + virtual Calculations* calculations() const override; + virtual Contents what_content_I() const override {return Contents::Building;} + virtual Buildings what_building_I() const = 0; + + void set_standard_charaterichtics(); + void set_build_phase(int phase); + void set_end_build_phase(int end_phase); + int get_build_phase() const; + int get_end_build_phase() const; + + bool is_built() const; + +protected: + Building(ICell* cell) : cell{cell}{} + +private: + void draw_build_phase(QPoint point); + + ICell* cell; + int phase = 0; + int end_phase = 0; + + std::unique_ptr pixmap_for_building; +}; + +#endif // BUILDING_H diff --git a/Graphics/Buildings/BuildingCharaterichtics.h b/Graphics/Buildings/BuildingCharaterichtics.h new file mode 100644 index 0000000..6021353 --- /dev/null +++ b/Graphics/Buildings/BuildingCharaterichtics.h @@ -0,0 +1,29 @@ +#ifndef BUILDINGCHARATERICHTICS_H +#define BUILDINGCHARATERICHTICS_H + +#include + +#include "../../Controllers/Enums.h" +#include "../../IObject.h" + + +class BuildingCharaterichtics : public IObject +{ + std::map count_phase{ + {Buildings::Farm, 30}, + {Buildings::FishingBoat, 30}, + {Buildings::Fort, 30}, + {Buildings::LumberMill, 30}, + {Buildings::Mine, 30}, + {Buildings::OilWell, 30}, + {Buildings::Pasture, 30}, + {Buildings::Quarry, 30}, + {Buildings::TradingPost, 30} + }; + +public: + int get_building_count_phase(Buildings type_building) + { return count_phase.at(type_building); } +}; + +#endif // BUILDINGCHARATERICHTICS_H diff --git a/Graphics/Buildings/Farm.h b/Graphics/Buildings/Farm.h new file mode 100644 index 0000000..67fefb2 --- /dev/null +++ b/Graphics/Buildings/Farm.h @@ -0,0 +1,16 @@ +#ifndef FARM_H +#define FARM_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Farm : public Building +{ +public: + Farm(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::Farm; } +}; + +#endif // FARM_H diff --git a/Graphics/Buildings/FishingBoat.h b/Graphics/Buildings/FishingBoat.h new file mode 100644 index 0000000..f1ad392 --- /dev/null +++ b/Graphics/Buildings/FishingBoat.h @@ -0,0 +1,16 @@ +#ifndef FISHING_BOATS_H +#define FISHING_BOATS_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class FishingBoat : public Building +{ +public: + FishingBoat(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::FishingBoat; } +}; + +#endif // FISHING_BOATS_H diff --git a/Graphics/Buildings/Fort.h b/Graphics/Buildings/Fort.h new file mode 100644 index 0000000..f9dece0 --- /dev/null +++ b/Graphics/Buildings/Fort.h @@ -0,0 +1,16 @@ +#ifndef FORT_H +#define FORT_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Fort : public Building +{ +public: + Fort(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::Fort; } +}; + +#endif // FORT_H diff --git a/Graphics/Buildings/LumberMill.h b/Graphics/Buildings/LumberMill.h new file mode 100644 index 0000000..fc44da5 --- /dev/null +++ b/Graphics/Buildings/LumberMill.h @@ -0,0 +1,16 @@ +#ifndef LUMBERMILL_H +#define LUMBERMILL_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class LumberMill : public Building +{ +public: + LumberMill(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::LumberMill; } +}; + +#endif // LUMBERMILL_H diff --git a/Graphics/Buildings/Mine.h b/Graphics/Buildings/Mine.h new file mode 100644 index 0000000..853f2cd --- /dev/null +++ b/Graphics/Buildings/Mine.h @@ -0,0 +1,16 @@ +#ifndef MINE_H +#define MINE_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Mine : public Building +{ +public: + Mine(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::Mine; } +}; + +#endif // MINE_H diff --git a/Graphics/Buildings/OilWell.h b/Graphics/Buildings/OilWell.h new file mode 100644 index 0000000..9904241 --- /dev/null +++ b/Graphics/Buildings/OilWell.h @@ -0,0 +1,16 @@ +#ifndef OILWELL_H +#define OILWELL_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class OilWell : public Building +{ +public: + OilWell(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::OilWell; } +}; + +#endif // OILWELL_H diff --git a/Graphics/Buildings/Pasture.h b/Graphics/Buildings/Pasture.h new file mode 100644 index 0000000..a26f927 --- /dev/null +++ b/Graphics/Buildings/Pasture.h @@ -0,0 +1,16 @@ +#ifndef PASTURE_H +#define PASTURE_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Pasture : public Building +{ +public: + Pasture(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::Pasture; } +}; + +#endif // PASTURE_H diff --git a/Graphics/Buildings/Quarry.h b/Graphics/Buildings/Quarry.h new file mode 100644 index 0000000..2c32e06 --- /dev/null +++ b/Graphics/Buildings/Quarry.h @@ -0,0 +1,16 @@ +#ifndef QUARRY_H +#define QUARRY_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Quarry : public Building +{ +public: + Quarry(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::Quarry; } +}; + +#endif // QUARRY_H diff --git a/Graphics/Buildings/Town.cpp b/Graphics/Buildings/Town.cpp new file mode 100644 index 0000000..2b3b0ff --- /dev/null +++ b/Graphics/Buildings/Town.cpp @@ -0,0 +1,21 @@ +#include "Town.h" + +void Town::set_health(int _health) +{ + health = _health; +} + +int Town::get_health() const +{ + return health; +} + +void Town::set_max_health(int _max_health) +{ + max_health = _max_health; +} + +int Town::get_max_health() const +{ + return max_health; +} diff --git a/Graphics/Buildings/Town.h b/Graphics/Buildings/Town.h new file mode 100644 index 0000000..627b7ef --- /dev/null +++ b/Graphics/Buildings/Town.h @@ -0,0 +1,24 @@ +#ifndef TOWN_H +#define TOWN_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Town : public Building +{ +public: + Town(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::Town; } + + void set_health(int health); + int get_health() const; + void set_max_health(int max_health); + int get_max_health() const; +private: + int max_health; + int health; +}; + +#endif // TOWN_H diff --git a/Graphics/Buildings/TradingPost.h b/Graphics/Buildings/TradingPost.h new file mode 100644 index 0000000..ab1f94a --- /dev/null +++ b/Graphics/Buildings/TradingPost.h @@ -0,0 +1,16 @@ +#ifndef TRADINGPOST_H +#define TRADINGPOST_H + +#include "Building.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class TradingPost : public Building +{ +public: + TradingPost(ICell* cell) : Building{cell}{} + virtual Buildings what_building_I() const override { return Buildings::TradingPost; } +}; + +#endif // TRADINGPOST_H diff --git a/Graphics/DrawWay.cpp b/Graphics/DrawWay.cpp new file mode 100644 index 0000000..d5cb324 --- /dev/null +++ b/Graphics/DrawWay.cpp @@ -0,0 +1,46 @@ +#include "DrawWay.h" +#include + +DrawWay::DrawWay(QWidget* _win, Map* _map, Position _start_way, class Unit* _unit) + :win{_win}, map{_map}, start_way{_start_way}, unit{_unit} +{} + +void DrawWay::set_end_way(Position _end_way) +{ + end_way = _end_way; +} + +void DrawWay::draw() +{ + Way way = FindUnitWay().get_way(unit, map, start_way, end_way); + for(size_t i{0}; i < way.get_count_moves_in_way(); ++i) + { + OneMove onemove = way.get_move_in_way(i); + std::vector minimove = onemove.minimove; + for(size_t j{1}; j < minimove.size()-1; ++j) + draw_circle(map->point_of_cell_in_win(minimove[j])); + draw_big_circle(map->point_of_cell_in_win(minimove[minimove.size()-1])); + } +} + +void DrawWay::draw_circle(QPoint pos) +{ + QPainter qp(win); + QPen pen(Qt::blue, 2, Qt::SolidLine); + qp.setPen(pen); + QBrush brush(Qt::blue); + qp.setBrush(brush); + int rad = map->calculations()->circle_radius(); + qp.drawEllipse(pos, rad, rad); +} + +void DrawWay::draw_big_circle(QPoint pos) +{ + QPainter qp(win); + QPen pen(Qt::blue, 2, Qt::SolidLine); + qp.setPen(pen); + QBrush brush(Qt::blue); + qp.setBrush(brush); + int rad = map->calculations()->circle_radius(); + qp.drawEllipse(pos, int(rad*1.5), int(rad*1.5)); +} diff --git a/Graphics/DrawWay.h b/Graphics/DrawWay.h new file mode 100644 index 0000000..44aefb3 --- /dev/null +++ b/Graphics/DrawWay.h @@ -0,0 +1,30 @@ +#ifndef DRAWWAY_H +#define DRAWWAY_H + +#include +#include + +#include "IObject.h" +#include "Map/Map.h" +#include "Units/Unit.h" +#include "../Controllers/FindUnitWay.h" + + +class DrawWay : public IObject +{ +public: + DrawWay(QWidget* win, Map* map, Position start_way, class Unit* unit); + void set_end_way(Position end_way); + void draw(); + +private: + void draw_circle(QPoint pos); + void draw_big_circle(QPoint pos); + QWidget* win; + Map* map; + Position start_way; + class Unit* unit; + Position end_way; +}; + +#endif // DRAWWAY_H diff --git a/Graphics/Factories/FactoryBuild.cpp b/Graphics/Factories/FactoryBuild.cpp new file mode 100644 index 0000000..6b6b955 --- /dev/null +++ b/Graphics/Factories/FactoryBuild.cpp @@ -0,0 +1,31 @@ +#include "FactoryBuild.h" + + +IContent* FactoryBuild::create_building(Buildings type_build, ICell *cell) const +{ + switch (type_build) + { + case Buildings::Town: + return new class Town(cell); + case Buildings::Farm: + return new class Farm(cell); + case Buildings::FishingBoat: + return new class FishingBoat(cell); + case Buildings::Fort: + return new class Fort(cell); + case Buildings::LumberMill: + return new class LumberMill(cell); + case Buildings::Mine: + return new class Mine(cell); + case Buildings::OilWell: + return new class OilWell(cell); + case Buildings::Pasture: + return new class Pasture(cell); + case Buildings::Quarry: + return new class Quarry(cell); + case Buildings::TradingPost: + return new class TradingPost(cell); + default: + throw std::runtime_error("This build doesn't exist"); + } +} diff --git a/Graphics/Factories/FactoryBuild.h b/Graphics/Factories/FactoryBuild.h new file mode 100644 index 0000000..39a8243 --- /dev/null +++ b/Graphics/Factories/FactoryBuild.h @@ -0,0 +1,26 @@ +#ifndef FUBRICBUILD_H +#define FUBRICBUILD_H + + +#include "../Buildings/Farm.h" +#include "../Buildings/FishingBoat.h" +#include "../Buildings/Fort.h" +#include "../Buildings/LumberMill.h" +#include "../Buildings/Mine.h" +#include "../Buildings/OilWell.h" +#include "../Buildings/Pasture.h" +#include "../Buildings/Quarry.h" +#include "../Buildings/Town.h" +#include "../Buildings/TradingPost.h" +#include "../IContent.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class FactoryBuild : public QObject +{ + public: + IContent* create_building(Buildings type_build, ICell* cell) const; +}; + +#endif // FUBRICBUILD_H diff --git a/Graphics/Factories/FactoryColor.cpp b/Graphics/Factories/FactoryColor.cpp new file mode 100644 index 0000000..71668a5 --- /dev/null +++ b/Graphics/Factories/FactoryColor.cpp @@ -0,0 +1,14 @@ +#include "FactoryColor.h" + +QColor FactoryColor::country_color(Countries country) const +{ + std::map _country_color{ + {Countries::Nothing, Qt::red}, + {Countries::Russia, Qt::yellow}, + {Countries::America, Qt::blue}, + {Countries::China, Qt::green}, + {Countries::England, Qt::magenta} + }; + + return _country_color.at(country); +} diff --git a/Graphics/Factories/FactoryColor.h b/Graphics/Factories/FactoryColor.h new file mode 100644 index 0000000..8dab1d0 --- /dev/null +++ b/Graphics/Factories/FactoryColor.h @@ -0,0 +1,18 @@ +#ifndef FACTORYCOLOR_H +#define FACTORYCOLOR_H + +#include + +#include + +#include "../../Controllers/Enums.h" +#include "../../IObject.h" + + +class FactoryColor : public IObject +{ +public: + QColor country_color(Countries country) const; +}; + +#endif // FACTORYCOLOR_H diff --git a/Graphics/Factories/FactoryMenusUnit.cpp b/Graphics/Factories/FactoryMenusUnit.cpp new file mode 100644 index 0000000..ff34b2a --- /dev/null +++ b/Graphics/Factories/FactoryMenusUnit.cpp @@ -0,0 +1,15 @@ +#include "FactoryMenusUnit.h" + +AMenuForUnit* FactoryMenusUnit::create_menu(QWidget* win, IUnitMenuGraphicsController* graphics_controller, + PlayerUnit* unit, Cell* cell) +{ + switch (unit->unit->what_unit_I()) + { + case Units::Worker: + return new WorkerMenu{win, graphics_controller, unit, cell}; + case Units::Citizen: + return new CitizenMenu{win, graphics_controller, unit, cell}; + default: + return new WarriorMenu{win, graphics_controller, unit, cell}; + } +} diff --git a/Graphics/Factories/FactoryMenusUnit.h b/Graphics/Factories/FactoryMenusUnit.h new file mode 100644 index 0000000..b84c797 --- /dev/null +++ b/Graphics/Factories/FactoryMenusUnit.h @@ -0,0 +1,21 @@ +#ifndef FACTORYMENUSUNIT_H +#define FACTORYMENUSUNIT_H + +#include + +#include "../Menus/MenuUnit/AMenuForUnit.h" +#include "../Menus/MenuUnit/CitizenMenu.h" +#include "../Menus/MenuUnit/WarriorMenu.h" +#include "../Menus/MenuUnit/WorkerMenu.h" +#include "../../Controllers/Player/IPlayer.h" +#include "../../IObject.h" + + +class FactoryMenusUnit : public IObject +{ +public: + AMenuForUnit* create_menu(QWidget* win, IUnitMenuGraphicsController* graphics_controller, + PlayerUnit* unit, Cell* cell); +}; + +#endif // FACTORYMENUSUNIT_H diff --git a/Graphics/Factories/FactoryPixmap.cpp b/Graphics/Factories/FactoryPixmap.cpp new file mode 100644 index 0000000..601cc64 --- /dev/null +++ b/Graphics/Factories/FactoryPixmap.cpp @@ -0,0 +1,376 @@ +#include "FactoryPixmap.h" +#include + + +QPixmap FactoryPixmap::create_pixmap_for_res(Resources type_resource) const +{ + switch (type_resource) + { + case Resources::Gold: + return QPixmap{image_path + resources_dir + "Gold.png/"}; + case Resources::Iron: + return QPixmap{image_path + resources_dir + "Iron.png/"}; + case Resources::Stone: + return QPixmap{image_path + resources_dir + "Stone.png/"}; + case Resources::Aluminum: + return QPixmap{image_path + resources_dir + "Aluminum.png/"}; + case Resources::Horses: + return QPixmap{image_path + resources_dir + "Horses.png/"}; + case Resources::Oil: + return QPixmap{image_path + resources_dir + "Oil.png/"}; + case Resources::Uranium: + return QPixmap{image_path + resources_dir + "Uranium.png/"}; + case Resources::Coal: + return QPixmap{image_path + resources_dir + "Coal.png/"}; + case Resources::Fish: + return QPixmap{image_path + resources_dir + "Fish.png/"}; + case Resources::Silver: + return QPixmap{image_path + resources_dir + "Silver.png/"}; + default: + throw std::runtime_error("There are no images for this resource"); + } +} + +QPixmap FactoryPixmap::create_pixmap_for_unit_on_map(Units type_unit) const +{ + switch (type_unit) + { + case Units::Worker: + return QPixmap{image_path + units_on_map_dir + "Worker.png/"}; + case Units::Citizen: + return QPixmap{image_path + units_on_map_dir + "Citizen.png/"}; + case Units::Bowman: + return QPixmap{image_path + units_on_map_dir + "Bowman.png/"}; + case Units::Swordsman: + return QPixmap{image_path + units_on_map_dir + "Swordsman.png/"}; + default: + throw std::runtime_error("There are no images for this unit"); + } +} + +QPixmap FactoryPixmap::create_pixmap_for_unit(Units type_unit) const +{ + switch (type_unit) + { + case Units::Worker: + return QPixmap{image_path + units_dir + "Worker.png/"}; + case Units::Citizen: + return QPixmap{image_path + units_dir + "Citizen.png/"}; + case Units::Bowman: + return QPixmap{image_path + units_dir + "Bowman.png/"}; + case Units::Swordsman: + return QPixmap{image_path + units_dir + "Swordsman.png/"}; + default: + throw std::runtime_error("There are no images for this unit"); + } +} + +QPixmap FactoryPixmap::create_pixmap_for_building(Buildings type_building) const +{ + switch (type_building) + { + case Buildings::Town: + return QPixmap{image_path + buildings_dir + "Town.png/"}; + case Buildings::Farm: + return QPixmap{image_path + buildings_dir + "Farm.png/"}; + case Buildings::FishingBoat: + return QPixmap{image_path + buildings_dir + "FishingBoats.png/"}; + case Buildings::Fort: + return QPixmap{image_path + buildings_dir + "Fort.png/"}; + case Buildings::Pasture: + return QPixmap{image_path + buildings_dir + "Pasture.png/"}; + case Buildings::Mine: + return QPixmap{image_path + buildings_dir + "Mine.png/"}; + case Buildings::OilWell: + return QPixmap{image_path + buildings_dir + "OilWell.png/"}; + case Buildings::Quarry: + return QPixmap{image_path + buildings_dir + "Quarry.png/"}; + case Buildings::TradingPost: + return QPixmap{image_path + buildings_dir + "TradingPost.png/"}; + case Buildings::LumberMill: + return QPixmap{image_path + buildings_dir + "LumberMill.png/"}; + default: + throw std::runtime_error("There are no images for this building"); + } +} + +QPixmap FactoryPixmap::create_pixmap_for_main_landscape(MainLandscapes type_landscape) const +{ + switch (type_landscape) + { + case MainLandscapes::Plain: + return QPixmap{image_path + landscapes_dir + "Plain.png/"}; + case MainLandscapes::Mountain: + return QPixmap{image_path + landscapes_dir + "Mountain.png/"}; + case MainLandscapes::Ocean: + return QPixmap{image_path + landscapes_dir + "Ocean.png/"}; + case MainLandscapes::Coast: + return QPixmap{image_path + landscapes_dir + "Coast.png/"}; + case MainLandscapes::Tundra: + return QPixmap{image_path + landscapes_dir + "Tundra.png/"}; + case MainLandscapes::Desert: + return QPixmap{image_path + landscapes_dir + "Desert.png/"}; + case MainLandscapes::Snow: + return QPixmap{image_path + landscapes_dir + "Snow.png/"}; + case MainLandscapes::Ice: + return QPixmap{image_path + landscapes_dir + "Ice.png/"}; + default: + throw std::runtime_error("There are no images for this landscape"); + } +} + + +QPixmap FactoryPixmap::create_pixmap_for_other_landscape(OtherLandscapes type_landscape) const +{ + switch (type_landscape) + { + case OtherLandscapes::Forest: + return QPixmap{image_path + landscapes_dir + "Forest.png/"}; + case OtherLandscapes::ForestAndHills: + return QPixmap{image_path + landscapes_dir + "Forest_hills.png/"}; + case OtherLandscapes::Jungles: + return QPixmap{image_path + landscapes_dir + "Jungles.png/"}; + case OtherLandscapes::JunglesAndHills: + return QPixmap{image_path + landscapes_dir + "Jungles_hills.png/"}; + case OtherLandscapes::Nothing: + return QPixmap{""}; + case OtherLandscapes::Hills: + return QPixmap{image_path + landscapes_dir + "Hills.png/"}; + default: + throw std::runtime_error("There are no images for this other landscape"); + } +} + +QPixmap FactoryPixmap::create_pixmap_for_knowledges(Knowledges name_knowledge) const +{ + switch (name_knowledge) + { + case Knowledges::Agriculture: + return QPixmap{image_path + knowledges_dir + "Agriculture.png/"}; + case Knowledges::StoneProcessing: + return QPixmap{image_path + knowledges_dir + "StoneProcessing.png/"}; + case Knowledges::Language: + return QPixmap{image_path + knowledges_dir + "Language.png/"}; + case Knowledges::WoodProcessing: + return QPixmap{image_path + knowledges_dir + "WoodProcessing.png/"}; + case Knowledges::Writing: + return QPixmap{image_path + knowledges_dir + "Writing.png/"}; + case Knowledges::AnimalHusbandry: + return QPixmap{image_path + knowledges_dir + "AnimalHusbandry.png/"}; + case Knowledges::Wheel: + return QPixmap{image_path + knowledges_dir + "Wheel.png/"}; + case Knowledges::OreMining: + return QPixmap{image_path + knowledges_dir + "OreMining.png/"}; + case Knowledges::Archery: + return QPixmap{image_path + knowledges_dir + "Archery.png/"}; + case Knowledges::Theology: + return QPixmap{image_path + knowledges_dir + "Theology.png/"}; + case Knowledges::Navigation: + return QPixmap{image_path + knowledges_dir + "Navigation.png/"}; + case Knowledges::HorseRiding: + return QPixmap{image_path + knowledges_dir + "HorseRiding.png/"}; + case Knowledges::Winemaking: + return QPixmap{image_path + knowledges_dir + "Winemaking.png/"}; + case Knowledges::BronzeProcessing: + return QPixmap{image_path + knowledges_dir + "BronzeProcessing.png/"}; + case Knowledges::Money: + return QPixmap{image_path + knowledges_dir + "Money.png/"}; + case Knowledges::Philosophy: + return QPixmap{image_path + knowledges_dir + "Philosophy.png/"}; + case Knowledges::Optics: + return QPixmap{image_path + knowledges_dir + "Optics.png/"}; + case Knowledges::IronProcessing: + return QPixmap{image_path + knowledges_dir + "IronProcessing.png/"}; + case Knowledges::PreciousOres: + return QPixmap{image_path + knowledges_dir + "PreciousOres.png/"}; + case Knowledges::DramaAndPoetry: + return QPixmap{image_path + knowledges_dir + "DramaAndPoetry.png/"}; + case Knowledges::Mathematics: + return QPixmap{image_path + knowledges_dir + "Mathematics.png/"}; + case Knowledges::MetalStructures: + return QPixmap{image_path + knowledges_dir + "MetalStructures.png/"}; + case Knowledges::Engineering: + return QPixmap{image_path + knowledges_dir + "Engineering.png/"}; + case Knowledges::Guilds: + return QPixmap{image_path + knowledges_dir + "Guilds.png/"}; + case Knowledges::Education: + return QPixmap{image_path + knowledges_dir + "Education.png/"}; + case Knowledges::Compass: + return QPixmap{image_path + knowledges_dir + "Compass.png/"}; + case Knowledges::Knighthood: + return QPixmap{image_path + knowledges_dir + "Knighthood.png/"}; + case Knowledges::Steelmaking: + return QPixmap{image_path + knowledges_dir + "Steelmaking.png/"}; + case Knowledges::Machinery: + return QPixmap{image_path + knowledges_dir + "Machinery.png/"}; + case Knowledges::Trading: + return QPixmap{image_path + knowledges_dir + "Trading.png/"}; + case Knowledges::Medicine: + return QPixmap{image_path + knowledges_dir + "Medicine.png/"}; + default: + return QPixmap{image_path + knowledges_dir + ""}; + } +} + +QPixmap FactoryPixmap::create_pixmap_for_butt_menu(Event* event) const +{ + if(!event) + throw std::runtime_error("create_pixmap_for_butt_menu(): event == nullptr"); + + switch (event->event) + { + case Events::Move: + { + delete event; + return QPixmap{image_path + menu_dir + "Move.png/"}; + } + case Events::Build: + { + BuildEvent* build_event = static_cast(event); + delete event; + return create_pixmap_for_building(build_event->building); + } + case Events::Slip: + { + delete event; + return QPixmap{image_path + menu_dir + "Slip.png/"}; + } + case Events::NoEvent: + { + delete event; + return QPixmap{image_path + menu_dir + "Cancel.png"}; + } + default: + throw std::runtime_error("create_pixmap_for_butt_menu(): There are no images for this event"); + } +} + +QPixmap FactoryPixmap::create_pixmap_for_exit() const +{ + return QPixmap{image_path + menu_dir + "Exit.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_del_in_queue() const +{ + return QPixmap{image_path + menu_dir + "DelInQueue.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_up_in_queue() const +{ + return QPixmap{image_path + menu_dir + "ArrowUp.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_down_in_queue() const +{ + return QPixmap{image_path + menu_dir + "ArrowDown.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_minimap() const +{ + return QPixmap{image_path + menu_dir + "Map.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_nextmotion() const +{ + return QPixmap{image_path + menu_dir + "NextMotion.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_type_map() const +{ + return QPixmap{image_path + menu_dir + "TypeMap.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_butt_build() const +{ + return QPixmap{image_path + menu_dir + "Build.png"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_town_building(TownBuildings type_building) const +{ + switch (type_building) + { + case TownBuildings::Aqueduct: + return QPixmap{image_path + town_building_dir + "Aqueduct.png/"}; + case TownBuildings::Market: + return QPixmap{image_path + town_building_dir + "Market.png/"}; + case TownBuildings::PublicSchool: + return QPixmap{image_path + town_building_dir + "PublicSchool.png/"}; + case TownBuildings::University: + return QPixmap{image_path + town_building_dir + "University.png/"}; + case TownBuildings::Bank: + return QPixmap{image_path + town_building_dir + "Bank.png/"}; + case TownBuildings::MedicalLab: + return QPixmap{image_path + town_building_dir + "Medical_Lab.png/"}; + case TownBuildings::ResearchLab: + return QPixmap{image_path + town_building_dir + "ResearchLab.png/"}; + case TownBuildings::Walls: + return QPixmap{image_path + town_building_dir + "Walls.png/"}; + case TownBuildings::Factory: + return QPixmap{image_path + town_building_dir + "Factory.png/"}; + case TownBuildings::Monument: + return QPixmap{image_path + town_building_dir + "Monument.png/"}; + case TownBuildings::Shrine: + return QPixmap{image_path + town_building_dir + "Shrine.png/"}; + case TownBuildings::Windmill: + return QPixmap{image_path + town_building_dir + "Windmill.png/"}; + case TownBuildings::Hospital: + return QPixmap{image_path + town_building_dir + "Hospital.png/"}; + case TownBuildings::Museum: + return QPixmap{image_path + town_building_dir + "Museum.png/"}; + case TownBuildings::Workshop: + return QPixmap{image_path + town_building_dir + "Workshop.png/"}; + case TownBuildings::Stadium: + return QPixmap{image_path + town_building_dir + "Stadium.png/"}; + case TownBuildings::Library: + return QPixmap{image_path + town_building_dir + "Library.png/"}; + case TownBuildings::OperaHouse: + return QPixmap{image_path + town_building_dir + "OperaHouse.png/"}; + case TownBuildings::StockExchange: + return QPixmap{image_path + town_building_dir + "StockExchange.png/"}; + case TownBuildings::Zoo: + return QPixmap{image_path + town_building_dir + "Zoo.png/"}; + default: + throw std::runtime_error("create_pixmap_for_town_building(): There are no images for this town building"); + } +} + +QPixmap FactoryPixmap::create_pixmap_for_fog_of_war() const +{ + return QPixmap{image_path + landscapes_dir + "FogOfWar.png/"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_gold() const +{ + return QPixmap{image_path + menu_dir + "Gold.png/"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_science() const +{ + return QPixmap{image_path + menu_dir + "Science.png/"}; +} + +QPixmap FactoryPixmap::create_pixmap_for_upgrade() const +{ + return QPixmap{image_path + menu_dir + "Upgrade.png/"}; +} + +QRectF FactoryPixmap::size_picture_content() const +{ + return {0., 0., 188., 188.}; +} + +QRectF FactoryPixmap::size_picture_unit() const +{ + return {0., 0., 256., 256.}; +} + +QRectF FactoryPixmap::size_picture_landscape() const +{ + return {0., 0., 500., 500.}; +} + +QRectF FactoryPixmap::size_picture_gold() const +{ + return {0., 0., 20., 20.}; +} + diff --git a/Graphics/Factories/FactoryPixmap.h b/Graphics/Factories/FactoryPixmap.h new file mode 100644 index 0000000..1179fbd --- /dev/null +++ b/Graphics/Factories/FactoryPixmap.h @@ -0,0 +1,58 @@ +#ifndef FACTORYPIXMAP_H +#define FACTORYPIXMAP_H + +#include + +#include + +#include "../GraphicsController/EventsStructures.h" +#include "../../Controllers/Enums.h" +#include "../../Controllers/Science.h" +#include "../../Controllers/TownBuildings.h" +#include "../../IObject.h" + + +class FactoryPixmap : public IObject +{ +public: + QPixmap create_pixmap_for_res(Resources type_resource) const; + QPixmap create_pixmap_for_unit_on_map(Units type_unit) const; + QPixmap create_pixmap_for_unit(Units type_unit) const; + QPixmap create_pixmap_for_building(Buildings type_building) const; + QPixmap create_pixmap_for_main_landscape(MainLandscapes type_landscape) const; + QPixmap create_pixmap_for_other_landscape(OtherLandscapes type_landscape) const; + QPixmap create_pixmap_for_knowledges(Knowledges name_knowledge) const; + QPixmap create_pixmap_for_butt_menu(Event* event) const; + QPixmap create_pixmap_for_exit() const; + QPixmap create_pixmap_for_del_in_queue() const; + QPixmap create_pixmap_for_up_in_queue() const; + QPixmap create_pixmap_for_down_in_queue() const; + QPixmap create_pixmap_for_minimap() const; + QPixmap create_pixmap_for_nextmotion() const; + QPixmap create_pixmap_for_type_map() const; + QPixmap create_pixmap_for_butt_build() const; + QPixmap create_pixmap_for_town_building(TownBuildings type_building) const; + QPixmap create_pixmap_for_fog_of_war() const; + QPixmap create_pixmap_for_gold() const; + QPixmap create_pixmap_for_science() const; + QPixmap create_pixmap_for_upgrade() const; + + QRectF size_picture_content() const; + QRectF size_picture_unit() const; + QRectF size_picture_landscape() const; + + /// для золота и науки + QRectF size_picture_gold() const; +private: + const QString image_path {":/Graphics/image/"}; + const QString resources_dir {"resources/"}; + const QString units_on_map_dir {"units_on_map/"}; + const QString units_dir {"units/"}; + const QString buildings_dir {"building/"}; + const QString landscapes_dir {"landscapes/"}; + const QString knowledges_dir {"knowledges/"}; + const QString menu_dir {"menu/"}; + const QString town_building_dir{"town_building/"}; +}; + +#endif // FACTORYPIXMAP_H diff --git a/Graphics/Factories/FactoryRes.cpp b/Graphics/Factories/FactoryRes.cpp new file mode 100644 index 0000000..908ac1c --- /dev/null +++ b/Graphics/Factories/FactoryRes.cpp @@ -0,0 +1,30 @@ +#include "FactoryRes.h" + +IContent* FactoryRes::create_res(Resources type_res, ICell* cell, int count_of_res) const +{ + switch (type_res) + { + case Resources::Gold: + return new class Gold(cell, count_of_res); + case Resources::Iron: + return new class Iron(cell, count_of_res); + case Resources::Stone: + return new class Stone(cell, count_of_res); + case Resources::Aluminum: + return new class Aluminum(cell, count_of_res); + case Resources::Horses: + return new class Horses(cell, count_of_res); + case Resources::Oil: + return new class Oil(cell, count_of_res); + case Resources::Uranium: + return new class Uranium(cell, count_of_res); + case Resources::Coal: + return new class Coal(cell, count_of_res); + case Resources::Fish: + return new class Fish(cell, count_of_res); + case Resources::Silver: + return new class Silver(cell, count_of_res); + default: + throw std::runtime_error("This resource doesn't exist"); + } +} diff --git a/Graphics/Factories/FactoryRes.h b/Graphics/Factories/FactoryRes.h new file mode 100644 index 0000000..9fdbf3f --- /dev/null +++ b/Graphics/Factories/FactoryRes.h @@ -0,0 +1,26 @@ +#ifndef FUBRICRES_H +#define FUBRICRES_H + +#include "../Map/ICell.h" +#include "../IContent.h" +#include "../Resources/Aluminum.h" +#include "../Resources/Coal.h" +#include "../Resources/Fish.h" +#include "../Resources/Horses.h" +#include "../Resources/Gold.h" +#include "../Resources/Iron.h" +#include "../Resources/Oil.h" +#include "../Resources/Silver.h" +#include "../Resources/Stone.h" +#include "../Resources/Uranium.h" +#include "../../Controllers/Enums.h" + + +class FactoryRes : public QObject +{ + public: + IContent* create_res(Resources type_res, ICell* cell, int count_of_res) const; +}; + + +#endif // FUBRICRES_H diff --git a/Graphics/Factories/FactoryString.cpp b/Graphics/Factories/FactoryString.cpp new file mode 100644 index 0000000..d0b2255 --- /dev/null +++ b/Graphics/Factories/FactoryString.cpp @@ -0,0 +1,239 @@ +#include "FactoryString.h" + +std::string FactoryString::unit_string(Units type_unit) const +{ + switch (type_unit) + { + case Units::Worker: + return "Рабочии"; + case Units::Citizen: + return "Поселенецы"; + case Units::Bowman: + return "Лучники"; + case Units::Swordsman: + return "Мечники"; + default: + throw std::runtime_error("unit_string(): Haven't strind for this unit"); + } +} + +std::string FactoryString::build_string(Buildings type_building) const +{ + switch (type_building) + { + case Buildings::Farm: + return "Ферма"; + case Buildings::Town: + return "Город"; + case Buildings::FishingBoat: + return "Рыбацкая лодка"; + case Buildings::Fort: + return "Форт"; + case Buildings::LumberMill: + return "Лесопилка"; + case Buildings::Mine: + return "Рудник"; + case Buildings::OilWell: + return "Нефтяная скважина"; + case Buildings::Pasture: + return "Пастбище"; + case Buildings::Quarry: + return "Карьер"; + case Buildings::TradingPost: + return "Торговый пост"; + default: + throw std::runtime_error("build_string(): Haven't strind for this building"); + } +} + +std::string FactoryString::building_in_town_string(TownBuildings type_building) const +{ + std::map building_in_town_str{ + {TownBuildings::Aqueduct, "Акведук"}, + {TownBuildings::Market, "Рынок"}, + {TownBuildings::PublicSchool, "Школа"}, + {TownBuildings::University, "Университет"}, + {TownBuildings::Bank, "Банк"}, + {TownBuildings::MedicalLab, "Медицинская лаборатория"}, + {TownBuildings::ResearchLab, "Лаборатория"}, + {TownBuildings::Walls, "Стены"}, + {TownBuildings::Monument, "Монумент"}, + {TownBuildings::Shrine, "Cвятилище"}, + {TownBuildings::Windmill, "Ветряная мельница"}, + {TownBuildings::Hospital, "Больница"}, + {TownBuildings::Stadium, "Стадион"}, + {TownBuildings::Workshop, "Мастерская"}, + {TownBuildings::Library, "Библиотека"}, + {TownBuildings::OperaHouse, "Опера"}, + {TownBuildings::StockExchange, "Биржа"}, + {TownBuildings::Zoo, "Зоопарк"}, + {TownBuildings::Factory, "Фабрика"}, + {TownBuildings::Museum, "Музей"} + }; + return building_in_town_str.at(type_building); +} + +std::string FactoryString::resource_string(Resources type_res) const +{ + std::map res_str{ + {Resources::Iron, "Железо"}, + {Resources::Gold, "Золото"}, + {Resources::Stone, "Камень"}, + {Resources::Aluminum, "Алюминий"}, + {Resources::Horses, "Лошади"}, + {Resources::Oil, "Нефть"}, + {Resources::Uranium, "Уран"}, + {Resources::Coal, "Уголь"}, + {Resources::Fish, "Рыба"}, + {Resources::Silver, "Серебро"}, + }; + + return res_str.at(type_res); +} + +std::string FactoryString::landscape_string(MainLandscapes landscape) const +{ + std::map main_landscape_str{ + {MainLandscapes::Ocean, "Океан"}, + {MainLandscapes::Coast, "Побережье"}, + {MainLandscapes::Plain, "Равнина"}, + {MainLandscapes::Mountain, "Горы"}, + {MainLandscapes::Tundra, "Тундра"}, + {MainLandscapes::Desert, "Пустыня"}, + {MainLandscapes::Snow, "Снег"}, + {MainLandscapes::Ice, "Лед"} + }; + + return main_landscape_str.at(landscape); +} + +std::string FactoryString::landscape_string(OtherLandscapes landscape) const +{ + std::map other_landscape_str{ + {OtherLandscapes::Nothing, ""}, + {OtherLandscapes::Forest, "Лес"}, + {OtherLandscapes::Jungles, "Джунгли"}, + {OtherLandscapes::Hills, "Холмы"}, + {OtherLandscapes::ForestAndHills, "Холмы, Лес"}, + {OtherLandscapes::JunglesAndHills, "Холмы, Джунгли"} + }; + + return other_landscape_str.at(landscape); +} + +std::string FactoryString::country_string(Countries country) const +{ + std::map country_str{ + {Countries::Nothing, ""}, + {Countries::Russia, "Россия"}, + {Countries::America, "Америка"}, + {Countries::China, "Китай"}, + {Countries::England, "Англия"} + }; + + return country_str.at(country); +} + +std::string FactoryString::knowledge_string(Knowledges name_knowledge) const +{ + switch (name_knowledge) + { + case Knowledges::Agriculture: + return "Земледелие"; + case Knowledges::StoneProcessing: + return "Обработка Камня"; + case Knowledges::Language: + return "Язык"; + case Knowledges::WoodProcessing: + return "Обработка дерева"; + case Knowledges::Writing: + return "Письменность"; + case Knowledges::AnimalHusbandry: + return "Животноводство"; + case Knowledges::Wheel: + return "Колесо"; + case Knowledges::OreMining: + return "Добыча руды"; + case Knowledges::Archery: + return "Стрельба из лука"; + case Knowledges::Theology: + return "Богословие"; + case Knowledges::Navigation: + return "Мореходство"; + case Knowledges::HorseRiding: + return "Верховая езда"; + case Knowledges::Winemaking: + return "Виноделие"; + case Knowledges::BronzeProcessing: + return "Обработка бронзы"; + case Knowledges::Money: + return "Деньги"; + case Knowledges::Philosophy: + return "Философия"; + case Knowledges::Optics: + return "Оптика"; + case Knowledges::IronProcessing: + return "Обработка Железа"; + case Knowledges::PreciousOres: + return "Драгоценные руды"; + case Knowledges::DramaAndPoetry: + return "Драма и поэзия"; + case Knowledges::Mathematics: + return "Математика"; + case Knowledges::MetalStructures: + return "Металлоконструкции"; + case Knowledges::Engineering: + return "Инженерное дело"; + case Knowledges::Guilds: + return "Гильдии"; + case Knowledges::Education: + return "Образование"; + case Knowledges::Compass: + return "Компас"; + case Knowledges::Knighthood: + return "Рыцарство"; + case Knowledges::Steelmaking: + return "Сталеварение"; + case Knowledges::Machinery: + return "Машиностроение"; + case Knowledges::Trading: + return "Торговля"; + case Knowledges::Medicine: + return "Медицина"; + default: + return ""; + } +} + +std::string FactoryString::typemap_overlay_string(TypeMap::Overlay overlay) const +{ + switch (overlay) { + case TypeMap::NoOverlay: + return "Без наложения"; + case TypeMap::Political: + return "Политическая"; + case TypeMap::HighlightResources: + return "Ресурсы"; + default: + return ""; + } +} + +std::string FactoryString::typemap_typecontent_string(TypeMap::TypeContent typecontent) const +{ + switch (typecontent) { + case TypeMap::All: + return "Все"; + case TypeMap::Nothing: + return "Ничего"; + case TypeMap::Units: + return "Юниты"; + case TypeMap::Resources: + return "Ресурсы"; + case TypeMap::Building: + return "Улучшения"; + default: + return ""; + } +} + diff --git a/Graphics/Factories/FactoryString.h b/Graphics/Factories/FactoryString.h new file mode 100644 index 0000000..1216502 --- /dev/null +++ b/Graphics/Factories/FactoryString.h @@ -0,0 +1,29 @@ +#ifndef FACTORYSTRING_H +#define FACTORYSTRING_H + +#include +#include + +#include "../Map/TypeMap.h" +#include "../../Controllers/Enums.h" +#include "../../Controllers/Science.h" +#include "../../Controllers/TownBuildings.h" +#include "../../IObject.h" + + +class FactoryString : IObject +{ +public: + std::string unit_string(Units type_unit) const; + std::string build_string(Buildings type_building) const; + std::string building_in_town_string(TownBuildings type_building) const; + std::string resource_string(Resources type_res) const; + std::string landscape_string(MainLandscapes landscape) const; + std::string landscape_string(OtherLandscapes landscape) const; + std::string country_string(Countries country) const; + std::string knowledge_string(Knowledges name_knowledge) const; + std::string typemap_overlay_string(TypeMap::Overlay overlay) const; + std::string typemap_typecontent_string(TypeMap::TypeContent typecontent) const; +}; + +#endif // FACTORYSTRING_H diff --git a/Graphics/Factories/FactoryUnits.cpp b/Graphics/Factories/FactoryUnits.cpp new file mode 100644 index 0000000..62d3fcb --- /dev/null +++ b/Graphics/Factories/FactoryUnits.cpp @@ -0,0 +1,19 @@ +#include "FactoryUnits.h" + + +IContent* FactoryUnits::create_unit(Units type_unit, ICell *cell) const +{ + switch (type_unit) + { + case Units::Worker: + return new class Worker(cell); + case Units::Citizen: + return new class Citizen(cell); + case Units::Bowman: + return new class Bowman(cell); + case Units::Swordsman: + return new class Swordsman(cell); + default: + throw std::runtime_error("This unit doesn't exist"); + } +} diff --git a/Graphics/Factories/FactoryUnits.h b/Graphics/Factories/FactoryUnits.h new file mode 100644 index 0000000..3dc2928 --- /dev/null +++ b/Graphics/Factories/FactoryUnits.h @@ -0,0 +1,20 @@ +#ifndef FABRICUNITS_H +#define FABRICUNITS_H + +#include "../Map/ICell.h" +#include "../IContent.h" +#include "../Units/Bowman.h" +#include "../Units/Citizen.h" +#include "../Units/Swordsman.h" +#include "../Units/Worker.h" +#include "../../Controllers/Enums.h" + + +class FactoryUnits : public QObject +{ +public: + IContent* create_unit(Units type_unit, ICell* cell) const; +}; + + +#endif // FUBRICUNITS_H diff --git a/Graphics/GameWindow.cpp b/Graphics/GameWindow.cpp new file mode 100644 index 0000000..f323bc0 --- /dev/null +++ b/Graphics/GameWindow.cpp @@ -0,0 +1,120 @@ +#include "GameWindow.h" +#include + +GameWindow::GameWindow(IWindowGraphicsController* game) + : QWidget(), graphics_controller{game}, inform_widget{new InformWidget{this}} +{ + // setWindowState(windowState() ^ Qt::WindowFullScreen); + setStyleSheet("background-color:black;"); + QWidget::setMouseTracking(true); + setFocusPolicy(Qt::TabFocus); + inform_widget->resize(width()/20, width()/20); +} + +void GameWindow::show() +{ + QWidget::showFullScreen(); + // QWidget::setFixedSize(graphics_controller->width_win(), graphics_controller->height_win()); + // QWidget::resize(game_controller->width_win(), game_controller->height_win()); + // QWidget::move(_p_win); + // QWidget::show(); +} + +void GameWindow::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + graphics_controller->draw_elements(); +} + +void GameWindow::mouseMoveEvent(QMouseEvent* event) +{ + inform_widget->hide(); + control_mouse_at_edge(event->pos()); + graphics_controller->move_mouse(event->pos()); + if(mouse_is_clicked and mouse_button_cliked == Qt::LeftButton){ + graphics_controller->move_map(event->pos() - pos_mouse); + } + pos_mouse = event->pos(); + +} + +void GameWindow::mousePressEvent(QMouseEvent* event) +{ + if(event->button() == Qt::RightButton) + { + mouse_button_cliked = Qt::RightButton; + graphics_controller->start_check_move_unit(); + } + if(event->button() == Qt::LeftButton) + { + mouse_button_cliked = Qt::LeftButton; + } + pos_mouse = event->pos(); + mouse_is_clicked = true; + pos_mouse_clicked = event->pos(); +} + +void GameWindow::mouseReleaseEvent(QMouseEvent* event) +{ + if(mouse_button_cliked == Qt::RightButton) + { + graphics_controller->stop_check_move_unit(event->pos()); + } + else + { + QPoint move_mouse = event->pos() - pos_mouse_clicked; + if(abs(move_mouse.x()) < 5 and abs(move_mouse.y()) < 5) + graphics_controller->click(event->pos()); + } + mouse_is_clicked = false; +} + +void GameWindow::wheelEvent(QWheelEvent* event) +{ + int angle_delta = event->angleDelta().y(); + double coefficient = 1. + angle_delta*1./1000; + graphics_controller->resize_map(coefficient, event->position().toPoint()); +} + +void GameWindow::do_inform_widget(std::vector> text) +{ +// std::cout << "111" << std::endl; + // std::string str = pair.first.toStdString(); + QPoint globalCursorPos = QCursor::pos(); + // inform_widget->move(globalCursorPos - QPoint{width()/20, 0} - inform_widget->pos()); +// inform_widget->set_set_geometry(globalCursorPos - QPoint{width()/20, 0}, {width()/20, int(text.size())*height()/70}); + int a = inform_widget->height(); + if(!inform_widget->height()) + a = width()/20; + inform_widget->set_set_geometry(globalCursorPos - QPoint{width()/20, 0}, {width()/20, a}); + inform_widget->set_text(text); + inform_widget->show(); +// inform_widget->update(); + inform_widget->raise(); +} + +void GameWindow::keyPressEvent(QKeyEvent *event) +{ + if(event->key() == Qt::Key_Enter-1 || event->key() == Qt::Key_Enter) + graphics_controller->press_enter(); + if(event->key() == Qt::Key_Escape) + graphics_controller->press_escape(); + +} + +void GameWindow::del_inform_widget() +{ + inform_widget->hide(); +} + +void GameWindow::control_mouse_at_edge(QPoint event_pos) +{ + if(event_pos.x() < 5 && pos_mouse.x() < 5) + graphics_controller->move_map({50, 0}); + if(event_pos.x() > width()-5 && pos_mouse.x() > width()-5) + graphics_controller->move_map({-50, 0}); + if(event_pos.y() < 5) + graphics_controller->move_map({0, 50}); + if(event_pos.y() > height() - 5) + graphics_controller->move_map({0, -50}); +} diff --git a/Graphics/GameWindow.h b/Graphics/GameWindow.h new file mode 100644 index 0000000..0315de1 --- /dev/null +++ b/Graphics/GameWindow.h @@ -0,0 +1,44 @@ +#ifndef GAME_WINDOW_H +#define GAME_WINDOW_H + +#include + +#include +#include +#include +#include + +#include "GraphicsController/IWindowGraphicsController.h" +#include "Menus/MenuTown/InformWidget.h" + + +class GameWindow : public QWidget +{ + const QPoint _p_win = QPoint{0,0}; +public: + GameWindow(IWindowGraphicsController* game); + + void show(); + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + virtual void keyPressEvent(QKeyEvent *event) override; + + void do_inform_widget(std::vector> text); + void del_inform_widget(); +private: + void control_mouse_at_edge(QPoint event_pos); + + IWindowGraphicsController* graphics_controller; + + QPoint pos_mouse{-1, -1}; + QPoint pos_mouse_clicked{-1, -1}; + bool mouse_is_clicked = false; + Qt::MouseButton mouse_button_cliked = Qt::NoButton; + + std::unique_ptr inform_widget; +}; + +#endif // GAME_WINDOW_H diff --git a/Graphics/GraphicsController/Calculations.cpp b/Graphics/GraphicsController/Calculations.cpp new file mode 100644 index 0000000..376ede1 --- /dev/null +++ b/Graphics/GraphicsController/Calculations.cpp @@ -0,0 +1,252 @@ +#include "Calculations.h" +#include + +Calculations::Calculations(int hexagon_side) + :side{hexagon_side} +{} + +void Calculations::set_side(int hexagon_side) +{ + side = hexagon_side; +} + +void Calculations::set_height(int hexagon_height) +{ + side = my_round(hexagon_height*2/sqrt(3)); +} + +int Calculations::my_round(double a) +{ + return static_cast(round(a)); +} + +int Calculations::hexagon_height() +{ + return my_round(side*sqrt(3)/2); +} + +int Calculations::hexagon_side() +{ + return side; +} + +bool Calculations::point_in_hexagon(QPoint p) +{ + if (abs(p.x()) >= hexagon_height() || abs(p.y()) >= hexagon_side()) + return false; + + pair_of_QPoint vector{QPoint(0,0), p}; + + if (check_intersect_of_vectors({point_0(), point_60()}, vector)) + return false; + if (check_intersect_of_vectors({point_60(), point_120()}, vector)) + return false; + if (check_intersect_of_vectors({point_120(), point_180()}, vector)) + return false; + if (check_intersect_of_vectors({point_180(), point_240()}, vector)) + return false; + if (check_intersect_of_vectors({point_240(), point_300()}, vector)) + return false; + if (check_intersect_of_vectors({point_300(), point_0()}, vector)) + return false; + + return true; +} + +int Calculations::point_in_circle(QPoint point, int count_units) +{ + QPoint p; + if(type_content == TypeMap::All || type_content == TypeMap::Units) + { + for(int i{0}; i < count_units; ++i) + { + p = point - point_circle_for_unit(i, count_units); + if (my_round(std::sqrt(p.x()*p.x() + p.y()*p.y())) < circle_radius(count_units)) + return i; + } + } + + if(type_content == TypeMap::All || type_content == TypeMap::Resources) + { + p = point - point_circle_for_res(); + if (my_round(std::sqrt(p.x()*p.x() + p.y()*p.y())) < circle_radius(count_units)) + { + if(type_content == TypeMap::All) + return 4; + else if(type_content == TypeMap::Resources) + return 0; + else + return -1; + } + } + + if(type_content == TypeMap::All || type_content == TypeMap::Building) + { + p = point - point_circle_for_build(); + if (my_round(std::sqrt(p.x()*p.x() + p.y()*p.y())) < circle_radius(count_units)) + { + if(type_content == TypeMap::All) + return 5; + else if(type_content == TypeMap::Building) + return 0; + else + return -1; + } + } + + return -1; +} + +QPoint Calculations::point_0() +{ + return {0,-side}; +} + +QPoint Calculations::point_60() +{ + return {-hexagon_height(), -side/2}; +} + +QPoint Calculations::point_120() +{ + return {-hexagon_height(), side/2}; +} + +QPoint Calculations::point_180() +{ + return {0,side}; +} + +QPoint Calculations::point_240() +{ + return {hexagon_height(), side/2}; +} + +QPoint Calculations::point_300() +{ + return {hexagon_height(), -side/2}; +} + +QPoint Calculations::point_circle_for_unit(int num_unit, int count_units) +{ + if(type_content == TypeMap::Units) + { + if(count_units == 4) + { + switch (num_unit) + { + case 0: + return {-hexagon_height()/3, -side/2}; + case 1: + return {hexagon_height()/3, -side/2}; + case 2: + return point_circle_for_res(); + case 3: + return point_circle_for_build(); + } + } + else if(count_units == 3) + { + switch (num_unit) + { + case 0: + return {-hexagon_height()/2, -hexagon_side()/4}; + case 1: + return {hexagon_height()/2, -hexagon_side()/4}; + case 2: + return {0, hexagon_side()/2}; + } + } + else if(count_units == 2) + { + switch (num_unit) + { + case 0: + return {0, -hexagon_side()/2}; + case 1: + return {0, hexagon_side()/2}; + } + } + else if(count_units == 1) + return {0,0}; + else + throw std::runtime_error("The max number of units in a cell is 4"); + } + else { + switch (num_unit) + { + case 0: + return {-hexagon_height()/3, -side/2}; + case 1: + return {hexagon_height()/3, -side/2}; + case 2: + return {-hexagon_height()*2/3, 0}; + case 3: + return {hexagon_height()*2/3, 0}; + default: + throw std::runtime_error("The max number of units in a cell is 4"); + } + } + throw std::runtime_error("point_circle_for_unit(): I don't know"); +} + +QPoint Calculations::point_circle_for_res() +{ + if(type_content == TypeMap::Resources) + return {0,0}; + return {-hexagon_height()/3, side/2}; +} + +QPoint Calculations::point_circle_for_build() +{ + if(type_content == TypeMap::Building) + return {0,0}; + return {hexagon_height()/3, side/2}; +} + +int Calculations::circle_radius(int count_units) +{ + int rad = 0; + if(type_content == TypeMap::All) + rad = hexagon_side()/4; + else if(type_content == TypeMap::Resources || type_content == TypeMap::Building) + rad = hexagon_height()*9/10; + else if(type_content == TypeMap::Units) + { + if(count_units == 4) + rad = hexagon_side()/4; + else if(count_units == 3) + rad = hexagon_side()*7/20; + else if(count_units == 2) + rad = hexagon_side()*7/20; + else if(count_units == 1) + rad = hexagon_height()*9/10; + } + + return rad; +} + +void Calculations::set_type_content(TypeMap::TypeContent _type_content) +{ + type_content = _type_content; +} + +int Calculations::vector_product(pair_of_QPoint v1, pair_of_QPoint v2) +{ + int x1 = v1.second.x() - v1.first.x(); + int y1 = v1.second.y() - v1.first.y(); + int x2 = v2.second.x() - v2.first.x(); + int y2 = v2.second.y() - v2.first.y(); + + return x1*y2 - x2*y1; +} + +bool Calculations::check_intersect_of_vectors(pair_of_QPoint v1, pair_of_QPoint v2) +{ + bool check1_1 = vector_product(v1, {v1.first, v2.first}) < 0; + bool check1_2 = vector_product(v1, {v1.first, v2.second}) < 0; + + bool check2_1 = vector_product(v2, {v2.first, v1.first}) < 0; + bool check2_2 = vector_product(v2, {v2.first, v1.second}) < 0; + return (check1_1^check1_2) && (check2_1^check2_2); +} diff --git a/Graphics/GraphicsController/Calculations.h b/Graphics/GraphicsController/Calculations.h new file mode 100644 index 0000000..02e66b2 --- /dev/null +++ b/Graphics/GraphicsController/Calculations.h @@ -0,0 +1,65 @@ +#ifndef CALCULATIONS_H +#define CALCULATIONS_H + +#include + +#include + +#include "../../IObject.h" +#include "../../Graphics/Map/TypeMap.h" + + +class Calculations : public IObject +{ +public: + Calculations(int hexagon_side = 0); + + void set_side(int hexagon_side); + void set_height(int hexagon_height); + + int my_round(double a); + int hexagon_height(); + int hexagon_side(); + + // точка указывается относительно центра + bool point_in_hexagon(QPoint point); + + /* + * точка указывается относительно центра, + * выдает номер окружности: + * 0-3: номера окружностей юнитов + * 4: номер окружности ресурса + * 5: номер окружности строения + * если точка не в окружностях, то выдает -1 + */ + int point_in_circle(QPoint point, int count_units = 4); + + + // функции возвращающие вершины относительно центра, число - градусы от вертикали вверх + QPoint point_0(); + QPoint point_60(); + QPoint point_120(); + QPoint point_180(); + QPoint point_240(); + QPoint point_300(); + + // функции возвращающие центры окружности относительно центра, + // число - градусы от вертикали вверх + QPoint point_circle_for_unit(int num_unit, int count_units = 4); + QPoint point_circle_for_res(); + QPoint point_circle_for_build(); + + int circle_radius(int count_units = 4); + + void set_type_content(TypeMap::TypeContent type_content); + +private: + typedef std::pair pair_of_QPoint; + int vector_product(pair_of_QPoint v1, pair_of_QPoint v2); + bool check_intersect_of_vectors(pair_of_QPoint v1, pair_of_QPoint v2); + + int side = 0; + TypeMap::TypeContent type_content = TypeMap::All; +}; + +#endif // CALCULATIONS_H diff --git a/Graphics/GraphicsController/CreateMap.cpp b/Graphics/GraphicsController/CreateMap.cpp new file mode 100644 index 0000000..ca1bb81 --- /dev/null +++ b/Graphics/GraphicsController/CreateMap.cpp @@ -0,0 +1,374 @@ +#include "CreateMap.h" +#include +#include +#include +#include + + +void CreateMap::create_map(Map* map) +{ + set_landscapes(map); + set_otherlandscapes(map); +} + +void CreateMap::set_landscapes(Map* map) +{ + for(size_t i{1}; i < 4; ++i) + for(size_t j{0}; j < graphics_controller->count_cell_y(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({graphics_controller->count_cell_x()/2 + i, j})}; + controlcontents.set_main_landscape(MainLandscapes(7)); + } + for(size_t j{2}; j < graphics_controller->count_cell_y() - 2; ++j) + { + ControlContents controlcontents{map->cell_by_indexes({graphics_controller->count_cell_x()/2, j})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + + for(size_t i{1}; i < graphics_controller->count_cell_x()/2; ++i) + { + ControlContents controlcontents{map->cell_by_indexes({i, 1})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + for(size_t j{1}; j < graphics_controller->count_cell_y() - 2; ++j) + { + ControlContents controlcontents{map->cell_by_indexes({1, j})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + for(size_t i{1}; i < graphics_controller->count_cell_x()/2 + 1; ++i) + { + ControlContents controlcontents{map->cell_by_indexes({i, graphics_controller->count_cell_y() - 2})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + for(size_t j{2}; j < graphics_controller->count_cell_y() - 2; ++j) + { + ControlContents controlcontents{map->cell_by_indexes({graphics_controller->count_cell_x()/2 + 3, j})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + for(size_t i{graphics_controller->count_cell_x()/2 + 4}; i < graphics_controller->count_cell_x() - 2; ++i) + { + ControlContents controlcontents{map->cell_by_indexes({i, graphics_controller->count_cell_y() - 2})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + for(size_t i{graphics_controller->count_cell_x()/2 + 3}; i < graphics_controller->count_cell_x() - 2; ++i) + { + ControlContents controlcontents{map->cell_by_indexes({i, 1})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + for(size_t j{2}; j < graphics_controller->count_cell_y() - 1; ++j) + { + ControlContents controlcontents{map->cell_by_indexes({graphics_controller->count_cell_x() - 2, j})}; + controlcontents.set_main_landscape(MainLandscapes(5)); + } + for(size_t j{0}; j < graphics_controller->count_cell_x(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({j, 0})}; + controlcontents.set_main_landscape(MainLandscapes(4)); + } + for(size_t j{0}; j < graphics_controller->count_cell_x(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({j, graphics_controller->count_cell_y() - 1})}; + controlcontents.set_main_landscape(MainLandscapes(4)); + } + + for(size_t i{0}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{0}; j < 2; ++j) + { + ControlContents controlcontents{map->cell_by_indexes({i, j})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(7)); + } + for(size_t i{0}; i < 2; ++i) + for(size_t j{0}; j < graphics_controller->count_cell_y(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({i, j})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(7)); + } + for(size_t i{graphics_controller->count_cell_x() - 2}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{0}; j < graphics_controller->count_cell_y(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({i, j})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(7)); + } + for(size_t i{0}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{graphics_controller->count_cell_y() - 2}; j < graphics_controller->count_cell_y(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({i, j})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(7)); + } + + for(size_t i{0}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{2}; j < 4; ++j) + { + + ControlContents controlcontents{map->cell_by_indexes({size_t(i), size_t(j)})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(6)); + } + size_t map_size_y = graphics_controller->count_cell_y(); + for(size_t i{0}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{map_size_y - 4}; j < graphics_controller->count_cell_y(); ++j) + { + + ControlContents controlcontents{map->cell_by_indexes({size_t(i), size_t(j)})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(6)); + } + for(size_t i{2}; i < 3; ++i) + for(size_t j{0}; j < graphics_controller->count_cell_y(); ++j) + { + + ControlContents controlcontents{map->cell_by_indexes({size_t(i), size_t(j)})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(6)); + } + for(size_t i{0}; i < graphics_controller->count_cell_y(); ++i) + { + + ControlContents controlcontents{map->cell_by_indexes({graphics_controller->count_cell_x() / 2 - 1, size_t(i)})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(6)); + } + for(size_t i{0}; i < graphics_controller->count_cell_y(); ++i) + { + + ControlContents controlcontents{map->cell_by_indexes({graphics_controller->count_cell_x() - 3, size_t(i)})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(6)); + } + for(size_t i{0}; i < graphics_controller->count_cell_y(); ++i) + { + ControlContents controlcontents{map->cell_by_indexes({graphics_controller->count_cell_x() / 2 + 4, size_t(i)})}; + if(!controlcontents.has_main_landscape()) + controlcontents.set_main_landscape(MainLandscapes(6)); + } + srand(rand() % 8); + for(size_t i{0}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{0}; j < graphics_controller->count_cell_y(); ++j) + { + int type_landscape = 0; + ControlContents controlcontents{map->cell_by_indexes({size_t(i), size_t(j)})}; + if(!controlcontents.has_main_landscape()) + { + type_landscape = rand() % 7; + switch (type_landscape) + { + case 0: + controlcontents.set_main_landscape(MainLandscapes(1)); + break; + case 1: + controlcontents.set_main_landscape(MainLandscapes(2)); + break; + default: + controlcontents.set_main_landscape(MainLandscapes(0)); + break; + } + + // controlcontents.set_main_landscape(MainLandscapes(rand() % 5)); + } + } +} + +void CreateMap::set_otherlandscapes(Map *map) +{ + for(size_t i{0}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{0}; j < graphics_controller->count_cell_y(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({size_t(i), size_t(j)})}; + MainLandscapes scape = controlcontents.get_main_landscape(); + if(scape == MainLandscapes(0)) + { + int other_land = rand() % 4; + switch (other_land) + { + case 0: + controlcontents.set_other_landscape(OtherLandscapes(0)); + break; + case 1: + controlcontents.set_other_landscape(OtherLandscapes(1)); + break; + case 2: + controlcontents.set_other_landscape(OtherLandscapes(3)); + break; + case 3: + controlcontents.set_other_landscape(OtherLandscapes(4)); + + + } + + } + if(scape == MainLandscapes(6)) + { + int other_land = rand() % 4; + switch (other_land) + { + case 0: + controlcontents.set_other_landscape(OtherLandscapes(0)); + break; + case 1: + controlcontents.set_other_landscape(OtherLandscapes(2)); + break; + case 2: + controlcontents.set_other_landscape(OtherLandscapes(3)); + break; + case 3: + controlcontents.set_other_landscape(OtherLandscapes(5)); + + + } + + } + if(scape == MainLandscapes(2)) + { + int other_land = rand() % 2; + switch (other_land) + { + case 0: + controlcontents.set_other_landscape(OtherLandscapes(0)); + break; + case 1: + controlcontents.set_other_landscape(OtherLandscapes(1)); + break; + + } + + } + } + +} + + + +Resources CreateMap::give_resourse(int number) +{ + Resources result = Resources(0); + if(number <= 9) + result = Resources(8); + else if(number >= 10 and number <= 12) + { + int some_res = rand() % 2; + switch (some_res) + { + case 0: + result = Resources(6); + break; + case 1: + result = Resources(4); + break; + } + } + else if(number >= 13 and number <= 16) + { + int some_res = rand() % 3; + switch (some_res) + { + case 0: + result = Resources(1); + break; + case 1: + result = Resources(2); + break; + case 2: + result = Resources(3); + break; + } + + } + else if(number >= 17 && number <= 19) + { + int some_res = rand() % 3; + switch (some_res) + { + case 0: + result = Resources(5); + break; + case 1: + result = Resources(7); + break; + case 2: + result = Resources(9); + break; + } + + } + else + throw std::runtime_error("give_resourse(): number must be less 20"); + + return result; +} + +void CreateMap::add_resource(Map* map) +{ + for(size_t i{0}; i < graphics_controller->count_cell_x(); ++i) + for(size_t j{0}; j < graphics_controller->count_cell_y(); ++j) + { + ControlContents controlcontents{map->cell_by_indexes({size_t(i), size_t(j)})}; + int give_res = rand() % 2; + if(give_res == 0) + { + MainLandscapes scape = controlcontents.get_main_landscape(); + if(scape != MainLandscapes(1) and scape != MainLandscapes(4)) + { + switch(scape) + { + case MainLandscapes(7): + controlcontents.add_resource(Resources(rand() % 2), rand() % 10); + break; + case MainLandscapes(5): + controlcontents.add_resource(Resources(1), rand() % 10); + break; + default: + Resources res = give_resourse(rand() % 20); + controlcontents.add_resource(res, rand() % 10); + break; + + } + } + + // controlcontents.add_resource(Resources(rand() % 10), rand() % 10); + + } + } +} + +std::vector CreateMap::initial_pos_player(int num_player, Map* map) +{ + std :: vector start_positions; + int x_position, y_position = 0; + for(int i = 0; i < num_player; ++i) + { + Position pos; + while(true) + { + + srand(time(0)); + pos.x = rand() % graphics_controller->count_cell_x(); + pos.y = rand() % graphics_controller->count_cell_y(); + ControlContents controlcontents{map->cell_by_indexes({size_t(pos.x), size_t(pos.y)})}; + MainLandscapes scape = controlcontents.get_main_landscape(); + if(scape != MainLandscapes(1) and scape != MainLandscapes(4) and scape != MainLandscapes(7) + and scape != MainLandscapes(5)) + { + int control = 0; + if(start_positions.size() == 0) + { + start_positions.push_back(pos); + break; + } + for(int j = 0; j < start_positions.size(); ++j) + if(pos.x == start_positions[j].x and pos.y == start_positions[j].y) + control = 1; + if(control == 0) + { + start_positions.push_back(pos); + break; + } + } + } + } + + return start_positions; +} diff --git a/Graphics/GraphicsController/CreateMap.h b/Graphics/GraphicsController/CreateMap.h new file mode 100644 index 0000000..8b6681b --- /dev/null +++ b/Graphics/GraphicsController/CreateMap.h @@ -0,0 +1,28 @@ +#ifndef CREATEMAP_H +#define CREATEMAP_H + +#include "../Map/Cell.h" +#include "../Map/Map.h" +#include "../../IObject.h" + + +class CreateMap : public IObject +{ +public: + CreateMap(IMapGraphicsController* _graphics_controller) + :graphics_controller{_graphics_controller} {} + + void create_map(Map* map); + void add_resource(Map* map); + + std::vector initial_pos_player(int num_player, Map* map); +private: + Resources give_resourse(int number); + + void set_landscapes(Map* map); + void set_otherlandscapes(Map* map); + + IMapGraphicsController* graphics_controller; +}; + +#endif // CREATEMAP_H diff --git a/Graphics/GraphicsController/EventsStructures.cpp b/Graphics/GraphicsController/EventsStructures.cpp new file mode 100644 index 0000000..15587e1 --- /dev/null +++ b/Graphics/GraphicsController/EventsStructures.cpp @@ -0,0 +1,27 @@ +#include "EventsStructures.h" + +Event* NoEvent::copy() const +{ + return new NoEvent{}; +} + +Event* MoveEvent::copy() const +{ + return new MoveEvent{cell_move}; +} + +Event* BuildEvent::copy() const +{ + return new BuildEvent{building}; +} + +Event* SlipEvent::copy() const +{ + return new SlipEvent{}; +} + +Event* DemolishEvent::copy() const +{ + return new DemolishEvent{}; +} + diff --git a/Graphics/GraphicsController/EventsStructures.h b/Graphics/GraphicsController/EventsStructures.h new file mode 100644 index 0000000..b3fa280 --- /dev/null +++ b/Graphics/GraphicsController/EventsStructures.h @@ -0,0 +1,73 @@ +#ifndef EVENTSSTRUCTURES_H +#define EVENTSSTRUCTURES_H + +#include + +#include "../../Controllers/Enums.h" +#include "../../IObject.h" + + +enum Events +{ + NoEvent, + Move, + Build, + Slip, + Demolish +}; + + +struct Event +{ + Events event; + virtual Event* copy() const = 0; + virtual ~Event() {} +protected: + Event(Events _event) :event{_event} {} +}; + + +struct NoEvent : Event +{ + virtual Event* copy() const override; + NoEvent() + : Event{Events::NoEvent} {} +}; + + +struct MoveEvent : Event +{ + Position cell_move; + virtual Event* copy() const override; + MoveEvent(Position _cell_move) + : Event{Events::Move}, cell_move{_cell_move} {} +}; + + +struct BuildEvent : Event +{ + Buildings building; + Position pos_cell; + virtual Event* copy() const override; + BuildEvent(Buildings _building) + : Event{Events::Build}, building{_building} {} +}; + + +struct SlipEvent : Event +{ + virtual Event* copy() const override; + SlipEvent() + : Event{Events::Slip} {} +}; + + +struct DemolishEvent : Event +{ + virtual Event* copy() const override; + DemolishEvent() + : Event{Events::Demolish} {} +}; + + +#endif // EVENTSSTRUCTURES_H diff --git a/Graphics/GraphicsController/GraphicsController.cpp b/Graphics/GraphicsController/GraphicsController.cpp new file mode 100644 index 0000000..0ac743c --- /dev/null +++ b/Graphics/GraphicsController/GraphicsController.cpp @@ -0,0 +1,207 @@ +#include "GraphicsController.h" +#include +#include + +GraphicsController::GraphicsController(class IGameForGraphic* _game_controller) + :game_controller{_game_controller}, window_gc{new WindowGraphicsController(this)}, + map_gc{new MapGraphicsController(this)}, + player_gc{new PlayerGraphicsController(this)}, + menu_gc{new MenuGraphicsController(this)}, + menu_start_gc{new MenuStartGraphicsController(this)} +{} + +void GraphicsController::start_game() +{ + game_controller->start_game(); +} + +void GraphicsController::do_start_menu() +{ + window_gc->do_window(); + window_gc->get_window()->show(); + window_gc->set_win_settings(); + menu_start_gc->do_start_menu(); +} + +QWidget* GraphicsController::window() const +{ + return window_gc->get_window(); +} + +void GraphicsController::do_start_inform(QString string) +{ + start_move_inform.reset(new StartMoveInform(game_controller->igame_for_widget(), string, + QPoint{_size_win.width/2, _size_win.height/2})); + Size size{_size_win.width/3, _size_win.height/3}; + start_move_inform->set_geometry(QPoint{_size_win.width/2 - size.width/2, _size_win.height/2 - size.height/2}, size); + start_move_inform->hide(); + start_move_inform->show(); + start_move_inform->raise(); + enabled_map = false; +} + +void GraphicsController::del_start_inform() +{ + start_move_inform.reset(); + enabled_map = true; +} + +void GraphicsController::create_elements() +{ + menu_gc->create_elements(); + map_gc->create_map(); + + + side_square_unit_menu = _size_win.width/20; + map_gc->create_minimap(); + window_gc->get_window()->update(); +} + +Size& GraphicsController::get_size_win() +{ + return _size_win; +} + +Size& GraphicsController::get_size_uppermenu() +{ + return _size_uppermenu; +} + +Size& GraphicsController::get_size_bottommenu() +{ + return _size_bottommenu; +} + +Size& GraphicsController::get_size_win_map() +{ + return _size_win_map; +} + +Size& GraphicsController::get_size_map() +{ + return _size_map; +} + +Position& GraphicsController::get_num_cell() +{ + return num_cell; +} + +QPoint& GraphicsController::get_map_center() +{ + return _map_center; +} + +QPoint& GraphicsController::get_win_map_center() +{ + return _win_map_center; +} + +bool& GraphicsController::get_enabled_map() +{ + return enabled_map; +} + +IGameForGraphic* GraphicsController::get_game_controller() +{ + return game_controller; +} + +GameWindow* GraphicsController::get_game_window() +{ + return window_gc->get_window(); +} + +bool& GraphicsController::get_is_moving_unit() +{ + return is_moving_unit; +} + +class Unit*& GraphicsController::get_tracking_unit() +{ + return tracking_unit; +} + +Position& GraphicsController::get_pos_tracking_unit() +{ + return pos_tracking_unit; +} + +int& GraphicsController::get_side_square_unit_menu() +{ + return side_square_unit_menu; +} + +int& GraphicsController::get_hexagon_side_minimap() +{ + return hexagon_side_minimap; +} + +DrawWay* GraphicsController::get_drawway() +{ + return drawway.get(); +} + +void GraphicsController::set_drawway(DrawWay* _drawway) +{ + drawway.reset(_drawway); +} + +AMenuForUnit* GraphicsController::get_unit_menu() +{ + return unit_menu.get(); +} + +void GraphicsController::set_unit_menu(AMenuForUnit* _unit_menu) +{ + unit_menu.reset(_unit_menu); +} + +UnitInformation* GraphicsController::get_unit_information() +{ + return unit_information.get(); +} + +void GraphicsController::set_unit_information(UnitInformation* _unit_information) +{ + unit_information.reset(_unit_information); +} + +MenuTown* GraphicsController::get_town_menu() +{ + return town_menu.get(); +} + +void GraphicsController::set_town_menu(MenuTown* _town_menu) +{ + town_menu.reset(_town_menu); +} +StartMoveInform* GraphicsController::get_start_move_inform() +{ + return start_move_inform.get(); +} + +IWindowGraphicsControllerFull* GraphicsController::get_iwindow_gc_full() +{ + return window_gc.get(); +} + +IMenuGraphicsControllerFull* GraphicsController::get_imenu_gc_full() +{ + return menu_gc.get(); +} + +IPlayerGraphicsControllerFull* GraphicsController::get_iplayer_gc() +{ + return player_gc.get(); +} + +IMapGraphicsControllerFull* GraphicsController::get_imap_gc_full() +{ + return map_gc.get(); +} + +IMenuStartGraphicsController* GraphicsController::get_imenu_start_full() +{ + return menu_start_gc.get(); +} diff --git a/Graphics/GraphicsController/GraphicsController.h b/Graphics/GraphicsController/GraphicsController.h new file mode 100644 index 0000000..40c6167 --- /dev/null +++ b/Graphics/GraphicsController/GraphicsController.h @@ -0,0 +1,106 @@ +#ifndef GRAPHICSCONTROLLER_H +#define GRAPHICSCONTROLLER_H + +#include +#include +#include + +#include "IGraphicsController.h" +#include "MapGraphicsController.h" +#include "MenuGraphicsController.h" +#include "MenuStartGraphicsController.h" +#include "PlayerGraphicsController.h" +#include "WindowGraphicsController.h" + + +class GraphicsController : public IGraphicsController +{ +public: + GraphicsController(IGameForGraphic* game_controller); + QWidget* window() const; + virtual void start_game() override; + void do_start_menu(); + void do_start_inform(QString string); + void del_start_inform(); + virtual void create_elements(); + + virtual Size& get_size_win() override; + virtual Size& get_size_uppermenu() override; + virtual Size& get_size_bottommenu() override; + virtual Size& get_size_win_map() override; + virtual Size& get_size_map() override; + virtual Position& get_num_cell() override; + virtual QPoint& get_map_center() override; + virtual QPoint& get_win_map_center() override; + virtual bool& get_enabled_map() override; + + virtual IGameForGraphic* get_game_controller() override; + + virtual GameWindow* get_game_window() override; + + virtual bool& get_is_moving_unit() override; + virtual class Unit*& get_tracking_unit() override; + virtual Position& get_pos_tracking_unit() override; + + virtual int& get_side_square_unit_menu() override; + virtual int& get_hexagon_side_minimap() override; + + virtual DrawWay* get_drawway() override; + virtual void set_drawway(DrawWay* drawway) override; + + virtual AMenuForUnit* get_unit_menu() override; + virtual void set_unit_menu(AMenuForUnit* unit_menu) override; + + virtual UnitInformation* get_unit_information() override; + virtual void set_unit_information(UnitInformation* unit_information) override; + + virtual MenuTown* get_town_menu() override; + virtual void set_town_menu(MenuTown*) override; + + virtual StartMoveInform* get_start_move_inform() override; + + virtual IWindowGraphicsControllerFull* get_iwindow_gc_full() override; + virtual IMenuGraphicsControllerFull* get_imenu_gc_full() override; + virtual IPlayerGraphicsControllerFull* get_iplayer_gc() override; + virtual IMapGraphicsControllerFull* get_imap_gc_full() override; + virtual IMenuStartGraphicsController* get_imenu_start_full() override; + +protected: + Size _size_win; + Size _size_uppermenu; + Size _size_bottommenu; + Size _size_win_map; + Size _size_map; + Position num_cell; + QPoint _map_center; + QPoint _win_map_center; + bool enabled_map = true; + + IGameForGraphic* game_controller; + + std::unique_ptr window_gc; + std::unique_ptr map_gc; + std::unique_ptr player_gc; + std::unique_ptr menu_gc; + std::unique_ptr menu_start_gc; + + + bool is_moving_unit = false; + class Unit* tracking_unit = nullptr; + Position pos_tracking_unit; + + int side_square_unit_menu; + int hexagon_side_minimap; + + Cell* click_cell = nullptr; + std::unique_ptr drawway{nullptr}; + std::unique_ptr unit_menu{nullptr}; + std::unique_ptr unit_information{nullptr}; + std::unique_ptr town_menu{nullptr}; + std::unique_ptr minimap; + std::unique_ptr start_move_inform; + + +}; + +#endif // GRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/IGraphicsController.h b/Graphics/GraphicsController/IGraphicsController.h new file mode 100644 index 0000000..086b8a9 --- /dev/null +++ b/Graphics/GraphicsController/IGraphicsController.h @@ -0,0 +1,68 @@ +#ifndef IGRAPHICSCONTROLLER_H +#define IGRAPHICSCONTROLLER_H + +#include "IMenuStartGraphicsController.h" +#include "IMapGraphicsControllerFull.h" +#include "IMenuGraphicsControllerFull.h" +#include "../DrawWay.h" +#include "../GameWindow.h" +#include "../InformationWidgets/StartMoveInform.h" +#include "../InformationWidgets/UnitInformation.h" +#include "../Map/Map.h" +#include "../Menus/MenuInWindow/BottomMenu.h" +#include "../Menus/MenuInWindow/UpperMenu.h" +#include "../Menus/MenuTown/MenuTown.h" +#include "../Menus/MenuUnit/AMenuForUnit.h" +#include "../Minimap.h" +#include "../../Controllers/IGame.h" +#include "../../Controllers/Player/IMenuTownPlayer.h" + + +class IGraphicsController : public IObject +{ +public: + virtual void start_game() = 0; + + virtual Size& get_size_win() = 0; + virtual Size& get_size_uppermenu() = 0; + virtual Size& get_size_bottommenu() = 0; + virtual Size& get_size_win_map() = 0; + virtual Size& get_size_map() = 0; + virtual Position& get_num_cell() = 0; + virtual QPoint& get_map_center() = 0; + virtual QPoint& get_win_map_center() = 0; + virtual bool& get_enabled_map() = 0; + + virtual IGameForGraphic* get_game_controller() = 0; + + virtual GameWindow* get_game_window() = 0; + + virtual bool& get_is_moving_unit() = 0; + virtual class Unit*& get_tracking_unit() = 0; + virtual Position& get_pos_tracking_unit() = 0; + + virtual int& get_side_square_unit_menu() = 0; + virtual int& get_hexagon_side_minimap() = 0; + + virtual DrawWay* get_drawway() = 0; + virtual void set_drawway(DrawWay*) = 0; + + virtual AMenuForUnit* get_unit_menu() = 0; + virtual void set_unit_menu(AMenuForUnit*) = 0; + + virtual UnitInformation* get_unit_information() = 0; + virtual void set_unit_information(UnitInformation*) = 0; + + virtual MenuTown* get_town_menu() = 0; + virtual void set_town_menu(MenuTown*) = 0; + + virtual StartMoveInform* get_start_move_inform() = 0; + + virtual IWindowGraphicsControllerFull* get_iwindow_gc_full() = 0; + virtual IMenuGraphicsControllerFull* get_imenu_gc_full() = 0; + virtual IPlayerGraphicsControllerFull* get_iplayer_gc() = 0; + virtual IMapGraphicsControllerFull* get_imap_gc_full() = 0; + virtual IMenuStartGraphicsController* get_imenu_start_full() = 0; +}; + +#endif // IGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/IMapGraphicsController.h b/Graphics/GraphicsController/IMapGraphicsController.h new file mode 100644 index 0000000..afe2990 --- /dev/null +++ b/Graphics/GraphicsController/IMapGraphicsController.h @@ -0,0 +1,41 @@ +#ifndef IMAPGRAPHICSCONTROLLER_H +#define IMAPGRAPHICSCONTROLLER_H + +#include +#include + +#include "Calculations.h" +#include "../../IObject.h" + + +class IMapGraphicsController : public IObject +{ +public: + virtual QWidget* window() const = 0; + virtual Calculations* calculations() const = 0; + + virtual size_t count_cell_x() const = 0; + virtual size_t count_cell_y() const = 0; + + virtual Size size_map() const = 0; + virtual Size size_win_map() const = 0; + virtual QPoint win_map_center() const = 0; + virtual QPoint map_center() const = 0; +}; + + +class IMiniMapGraphicsController : public IObject +{ +public: + virtual size_t count_cell_x() const = 0; + virtual size_t count_cell_y() const = 0; + + /* + * coeffx = new_map_center.x / width_map + * coeffy = new_map_center.y / height_map + */ + virtual void move_map(double coeffx, double coeffy) = 0; +}; + + +#endif // IMAPGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/IMapGraphicsControllerFull.h b/Graphics/GraphicsController/IMapGraphicsControllerFull.h new file mode 100644 index 0000000..be4b6fc --- /dev/null +++ b/Graphics/GraphicsController/IMapGraphicsControllerFull.h @@ -0,0 +1,20 @@ +#ifndef IMAPGRAPHICSCONTROLLERFULL_H +#define IMAPGRAPHICSCONTROLLERFULL_H + +#include "IMapGraphicsController.h" +#include "../Map/Map.h" +#include "../Minimap.h" + +class IMapGraphicsControllerFull : public IMapGraphicsController, public IMiniMapGraphicsController +{ +public: + virtual void move_map(double coeffx, double coeffy) = 0; + virtual void move_map(QPoint move_point) = 0; + virtual void resize_map(double coefficient, QPoint pos_mouse) = 0; + virtual void no_highlight_unit(class Unit* unit, Position pos) = 0; + + virtual Map* get_map() = 0; + virtual Minimap* get_minimap() = 0; +}; + +#endif // IMAPGRAPHICSCONTROLLERFULL_H diff --git a/Graphics/GraphicsController/IMenuGraphicsController.h b/Graphics/GraphicsController/IMenuGraphicsController.h new file mode 100644 index 0000000..da1a683 --- /dev/null +++ b/Graphics/GraphicsController/IMenuGraphicsController.h @@ -0,0 +1,57 @@ +#ifndef IMENUGRAPHICSCONTROLLER_H +#define IMENUGRAPHICSCONTROLLER_H + +#include +#include + +#include "../Map/TypeMap.h" +#include "../Units/Unit.h" +#include "../../Controllers/Player/PlayerScience.h" +#include "../../IObject.h" + + +class IMenuInWindowGraphicsController : public IObject +{ +public: + virtual QWidget* window() const = 0; + virtual void move_map(QPoint move_point) = 0; + virtual void exit() = 0; + virtual void show_minimap() = 0; + virtual void next_move() = 0; + + virtual void do_inform_widget(std::vector> text) = 0; + virtual void del_inform_widget() = 0; + + virtual void open_menu_lists() = 0; + virtual void close_menu_lists() = 0; + + virtual void open_menu_science() = 0; + virtual void close_menu_science() = 0; + + virtual void click_open_menu_type_map() = 0; + virtual void open_menu_type_map() = 0; + virtual void close_menu_type_map() = 0; + virtual void set_type_map(TypeMap type_map) = 0; +}; + + +class IUnitMenuGraphicsController : public IObject +{ +public: + virtual void menu_unit_event(class Unit* unit, Event* event) = 0; + virtual PlayerScience* player_science() = 0; +}; + + +class ITownMenuGraphicsController : public IObject +{ +public: + virtual QWidget* window() const = 0; + virtual void delete_townmenu() = 0; + virtual void do_inform_widget(std::vector> text) = 0; + virtual void del_inform_widget() = 0; +}; + + + +#endif // IMENUGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/IMenuGraphicsControllerFull.h b/Graphics/GraphicsController/IMenuGraphicsControllerFull.h new file mode 100644 index 0000000..25172d0 --- /dev/null +++ b/Graphics/GraphicsController/IMenuGraphicsControllerFull.h @@ -0,0 +1,19 @@ +#ifndef IMENUGRAPHICSCONTROLLERFULL_H +#define IMENUGRAPHICSCONTROLLERFULL_H + +#include "IMenuGraphicsController.h" +#include "../Menus/MenuInWindow/BottomMenu.h" +#include "../Menus/MenuInWindow/UpperMenu.h" + +class IMenuGraphicsControllerFull : public IMenuInWindowGraphicsController, + public IUnitMenuGraphicsController, public ITownMenuGraphicsController +{ +public: + virtual void del_menu_unit() = 0; + virtual void press_escape() = 0; + virtual void event_open_menu_type_map() = 0; + virtual BottomMenu* get_bottom_menu() = 0; + virtual UpperMenu* get_upper_menu() = 0; +}; + +#endif // IMENUGRAPHICSCONTROLLERFULL_H diff --git a/Graphics/GraphicsController/IMenuStartGraphicsController.h b/Graphics/GraphicsController/IMenuStartGraphicsController.h new file mode 100644 index 0000000..40ceed0 --- /dev/null +++ b/Graphics/GraphicsController/IMenuStartGraphicsController.h @@ -0,0 +1,16 @@ +#ifndef IMENUSTARTGRAPHICSCONTROLLER_H +#define IMENUSTARTGRAPHICSCONTROLLER_H + +#include + +#include "../../IObject.h" + + +class IMenuStartGraphicsController : public IObject +{ +public: + virtual QWidget* window() const = 0; + virtual void start_game() = 0; +}; + +#endif // IMENUSTARTGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/IPlayerGraphicsController.h b/Graphics/GraphicsController/IPlayerGraphicsController.h new file mode 100644 index 0000000..5d7b200 --- /dev/null +++ b/Graphics/GraphicsController/IPlayerGraphicsController.h @@ -0,0 +1,42 @@ +#ifndef IPLAYERGRAPHICSCONTROLLER_H +#define IPLAYERGRAPHICSCONTROLLER_H + +#include "../Map/IMap.h" +#include "../../Controllers/Player/IMenuTownPlayer.h" +#include "../../Controllers/Player/PlayerMap.h" +#include "../../Controllers/Player/PlayerTown.h" +#include "../../Controllers/Player/PlayerUnit.h" + + +class IPlayerGraphicsController : public IObject +{ +public: + virtual class Unit* add_unit(Units unit, Position pos_cell) = 0; + + virtual void move_unit(class Unit* unit, Position old_position, Position new_position) = 0; + virtual class Building* build(Buildings building, Position pos_cell) = 0; + virtual void del_build(Position pos_cell) = 0; + virtual void del_unit(class Unit* unit, Position pos_cell) = 0; + + virtual void do_menu_unit(PlayerUnit* unit) = 0; + virtual void do_menu_town(IMenuTownPlayer* player, PlayerTown* town) = 0; + virtual void do_menu_science() = 0; + virtual void centering_by_cell(Position pos_cell) = 0; + virtual void highlight_unit(class Unit* unit, Position pos) = 0; + virtual void draw_playermap(PlayerMap* playermap, PlayerScience* player_science) = 0; + virtual IMapForFind* mapforfind() = 0; + virtual void update_res_inform(IMenuTownPlayer* player) = 0; + + virtual int count_cell_resource(Position pos) = 0; + virtual Resources cell_resource(Position pos) = 0; + virtual bool has_cell_building(Position pos) = 0; + virtual Buildings cell_building(Position pos) = 0; +}; + +class IPlayerGraphicsControllerFull : public IPlayerGraphicsController +{ +public: + virtual bool& get_is_tracking_unit() = 0; +}; + +#endif // IPLAYERGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/IWindowGraphicsController.h b/Graphics/GraphicsController/IWindowGraphicsController.h new file mode 100644 index 0000000..56b6d58 --- /dev/null +++ b/Graphics/GraphicsController/IWindowGraphicsController.h @@ -0,0 +1,39 @@ +#ifndef IWINDOWGRAPHICSCONTROLLER_H +#define IWINDOWGRAPHICSCONTROLLER_H + +#include +#include + +#include "../../IObject.h" + + +class IWindowGraphicsController : public IObject +{ +public: + virtual Size size_win() const = 0; + + virtual void draw_elements() = 0; + virtual void move_map(QPoint move_point) = 0; + virtual void resize_map(double coefficient, QPoint pos_mouse) = 0; + virtual void click(QPoint pos) = 0; + virtual void start_check_move_unit() = 0; + virtual void stop_check_move_unit(QPoint mouse_pos) = 0; + virtual void move_mouse(QPoint new_pos) = 0; + virtual void press_enter() = 0; + virtual void press_escape() = 0; + + virtual int map_upper_edge() const = 0; + virtual int map_bottom_edge() const = 0; +}; + +class IWindowGraphicsControllerFull : public IWindowGraphicsController +{ +public: + virtual void start_check_move_unit() = 0; + virtual void stop_check_move_unit(QPoint mouse_pos) = 0; + + virtual void start_check_move_unit(class Unit* unit) = 0; + virtual void stop_check_move_unit() = 0; +}; + +#endif // IWINDOWGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/MapGraphicsController.cpp b/Graphics/GraphicsController/MapGraphicsController.cpp new file mode 100644 index 0000000..e9a9584 --- /dev/null +++ b/Graphics/GraphicsController/MapGraphicsController.cpp @@ -0,0 +1,228 @@ +#include "MapGraphicsController.h" + +MapGraphicsController::MapGraphicsController(IGraphicsController* _graphics_controller) + :graphics_controller{_graphics_controller} +{} + +QWidget* MapGraphicsController::window() const +{ + return graphics_controller->get_game_window(); +} + +Calculations* MapGraphicsController::calculations() const +{ + return calc.get(); +} + +size_t MapGraphicsController::count_cell_x() const +{ + return graphics_controller->get_num_cell().x; +} + +size_t MapGraphicsController::count_cell_y() const +{ + return graphics_controller->get_num_cell().y; +} + +Size MapGraphicsController::size_map() const +{ + return graphics_controller->get_size_map(); +} + +Size MapGraphicsController::size_win_map() const +{ + return graphics_controller->get_size_win_map(); +} + +QPoint MapGraphicsController::win_map_center() const +{ + return graphics_controller->get_win_map_center(); +} + +QPoint MapGraphicsController::map_center() const +{ + return graphics_controller->get_map_center(); +} + +void MapGraphicsController::move_map(double coeffx, double coeffy) +{ + if(!graphics_controller->get_enabled_map()) + return; + + Size size_map = _size_map(); + _map_center().setX(int(size_map.width * coeffx)); + _map_center().setY(int(size_map.height * coeffy)); + control_pos_map(); + set_win_rect_minimap(); + graphics_controller->get_game_window()->update(); +} + +QPoint MapGraphicsController::map_center_in_win_map() +{ + Size size_uppermenu = graphics_controller->get_size_uppermenu(); + return {_map_center().x(), _map_center().y() - size_uppermenu.height}; +} + +void MapGraphicsController::control_pos_map() +{ + if (_map_center().y() - _win_map_center().y() + size_win_map().height/2 > size_map().height/2) + _map_center().setY(_win_map_center().y() - size_win_map().height/2 + size_map().height/2); + else if (_win_map_center().y() - _map_center().y() + size_win_map().height/2 > size_map().height/2) + _map_center().setY(_win_map_center().y() + size_win_map().height/2 - size_map().height/2); + + if (_map_center().x() - _win_map_center().x() + size_win_map().width/2 > size_map().width/2) + _map_center().setX(_win_map_center().x() - size_win_map().width/2 + size_map().width/2); + else if (_win_map_center().x() - _map_center().x() + size_win_map().width/2 > size_map().width/2) + _map_center().setX(_win_map_center().x() + size_win_map().width/2 - size_map().width/2); +} + +void MapGraphicsController::set_win_rect_minimap() +{ + double coeffx = map_center_in_win_map().x()*1. / size_map().width; + double coeffy = map_center_in_win_map().y()*1. / size_map().height; + double coeff_width = size_win_map().width*1. / size_map().width; + double coeff_height = size_win_map().height*1. / size_map().height; + minimap->set_win_rect(coeffx, coeffy, coeff_width, coeff_height); +} + +void MapGraphicsController::move_map(QPoint move_point) +{ + // QPoint new_map_center = map_center + move_point; + if(!graphics_controller->get_enabled_map()) + return; + _map_center() += move_point; + control_pos_map(); + graphics_controller->get_game_window()->update(); + + set_win_rect_minimap(); +} + +void MapGraphicsController::resize_map(double coeff, QPoint pos_mouse) +{ + if(!graphics_controller->get_enabled_map()) + return; + + if(6*calculations()->hexagon_side() * coeff > graphics_controller->get_size_win().height) + return; + + int old_side = calculations()->hexagon_side(); + QPoint old_map_center = _map_center(); + int old_hexagon_height = calculations()->hexagon_height(); + + calculations()->set_side(calculations()->my_round(coeff * calculations()->hexagon_side())); + do_size_map(); + + QPoint point1 = pos_mouse - _map_center(); + QPoint point2 = {(pos_mouse.x() - _map_center().x()) * old_hexagon_height / calculations()->hexagon_height(), + int((pos_mouse.y() - _map_center().y())/coeff)}; + _map_center() += (point2 - point1); + + if((size_map().height < size_win_map().height) || (size_map().width < size_win_map().width)) + { + calculations()->set_side(old_side); + do_size_map(); + _map_center() = old_map_center; + } + else + control_pos_map(); + + set_win_rect_minimap(); + graphics_controller->get_game_window()->update(); +} + +void MapGraphicsController::do_size_map() +{ + _size_map().height = calculations()->hexagon_side()*int(count_cell_y()) + calculations()->hexagon_side()*(int(count_cell_y())+1)/2; + _size_map().width = calculations()->hexagon_height()*(int(count_cell_x())*2+1); +} + +void MapGraphicsController::create_map() +{ + calc.reset(new Calculations()); + map.reset(new Map(this)); + + auto game_controller = graphics_controller->get_game_controller(); + graphics_controller->get_num_cell() = {game_controller->count_cell_x(), game_controller->count_cell_y()}; + calculations()->set_side(130); + + int height_uppermenu = graphics_controller->get_size_uppermenu().height; + int height_bottommenu = graphics_controller->get_size_bottommenu().height; + _size_win_map() = {size_win().width, size_win().height - height_uppermenu - height_bottommenu}; + + do_size_map(); + _win_map_center() = {_size_win_map().width/2, _size_win_map().height/2 + height_uppermenu}; + _map_center() = _win_map_center(); + map->do_cells(); + + + CreateMap creator_map{this}; + creator_map.create_map(map.get()); + creator_map.add_resource(map.get()); + + // game_window->update(); +} + +void MapGraphicsController::create_minimap() +{ + minimap.reset(new Minimap(window(), map.get(), this)); + + Size size_win = graphics_controller->get_size_win(); + + int width_minimap = size_win.width/3; + int height_minimap = size_win.height/3; + + int hexagon_height1 = width_minimap/(int(count_cell_x())*2+1); + int side1 = calculations()->my_round(hexagon_height1*2/sqrt(3)); + + int side2 = height_minimap*2 / (3*int(count_cell_y())+1); + + int& hexagon_side_minimap = graphics_controller->get_hexagon_side_minimap(); + + hexagon_side_minimap = std::min(side1, side2); + + int height_bottommenu = graphics_controller->get_size_bottommenu().height; + minimap->set_geometry(QPoint{size_win.width, size_win.height - height_bottommenu}, hexagon_side_minimap); + set_win_rect_minimap(); + minimap->hide(); +} + +void MapGraphicsController::no_highlight_unit(class Unit* unit, Position pos_cell) +{ + ControlContents controlcontents{map->cell_by_indexes(pos_cell)}; + controlcontents.set_highlight_unit(unit, false); +} + +Size MapGraphicsController::size_win() const +{ + return graphics_controller->get_size_win(); +} + +Size& MapGraphicsController::_size_map() +{ + return graphics_controller->get_size_map(); +} + +Size& MapGraphicsController::_size_win_map() +{ + return graphics_controller->get_size_win_map(); +} + +QPoint& MapGraphicsController::_win_map_center() +{ + return graphics_controller->get_win_map_center(); +} + +QPoint& MapGraphicsController::_map_center() +{ + return graphics_controller->get_map_center(); +} + +Map* MapGraphicsController::get_map() +{ + return map.get(); +} + +Minimap* MapGraphicsController::get_minimap() +{ + return minimap.get(); +} diff --git a/Graphics/GraphicsController/MapGraphicsController.h b/Graphics/GraphicsController/MapGraphicsController.h new file mode 100644 index 0000000..1e4534c --- /dev/null +++ b/Graphics/GraphicsController/MapGraphicsController.h @@ -0,0 +1,58 @@ +#ifndef MAPGRAPHICSCONTROLLER_H +#define MAPGRAPHICSCONTROLLER_H + +#include "CreateMap.h" +#include "IGraphicsController.h" +#include "IMapGraphicsControllerFull.h" + + +class MapGraphicsController : public IMapGraphicsControllerFull +{ +public: + MapGraphicsController(IGraphicsController* graphics_controller); + + virtual QWidget* window() const override; + virtual Calculations* calculations() const override; + + virtual size_t count_cell_x() const override; + virtual size_t count_cell_y() const override; + + virtual Size size_map() const override; + virtual Size size_win_map() const override; + virtual QPoint win_map_center() const override; + virtual QPoint map_center() const override; + + virtual void move_map(double coeffx, double coeffy) override; + + // Возвращает центр кары относительно центра окна карты + QPoint map_center_in_win_map(); + + void control_pos_map(); + void set_win_rect_minimap(); + + virtual void move_map(QPoint move_point) override; + virtual void resize_map(double coefficient, QPoint pos_mouse) override; + void do_size_map(); + + void create_map(); + void create_minimap(); + virtual void no_highlight_unit(class Unit* unit, Position pos) override; + virtual Map* get_map() override; + virtual Minimap* get_minimap() override; +private: + Size size_win() const; + + Size& _size_map(); + Size& _size_win_map(); + QPoint& _win_map_center(); + QPoint& _map_center(); + + std::unique_ptr calc; + std::unique_ptr map; + std::unique_ptr minimap; + + IGraphicsController* graphics_controller; +}; + + +#endif // MAPGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/MenuGraphicsController.cpp b/Graphics/GraphicsController/MenuGraphicsController.cpp new file mode 100644 index 0000000..a1cb7d0 --- /dev/null +++ b/Graphics/GraphicsController/MenuGraphicsController.cpp @@ -0,0 +1,256 @@ +#include "MenuGraphicsController.h" +#include + +MenuGraphicsController::MenuGraphicsController(IGraphicsController* _graphics_controller) + :graphics_controller{_graphics_controller} +{} + +QWidget* MenuGraphicsController::window() const +{ + return graphics_controller->get_game_window(); +} + +void MenuGraphicsController::move_map(QPoint move_point) +{ + auto map_gc = graphics_controller->get_imap_gc_full(); + map_gc->move_map(move_point); +} + +void MenuGraphicsController::exit() +{ + graphics_controller->get_game_window()->hide(); + graphics_controller->get_game_controller()->exit(); +} + +void MenuGraphicsController::show_minimap() +{ + auto minimap = graphics_controller->get_imap_gc_full()->get_minimap(); + if(minimap->isVisible()) + minimap->hide(); + else + minimap->show(); + event_open_menu_type_map(); +} + +void MenuGraphicsController::next_move() +{ + graphics_controller->get_game_controller()->next_move(); +} + +void MenuGraphicsController::menu_unit_event(class Unit* unit, Event* event) +{ + auto iwindow_gc = graphics_controller->get_iwindow_gc_full(); + if(event->event == Events::Move) + { + if(graphics_controller->get_is_moving_unit()) + iwindow_gc->stop_check_move_unit(); + else + iwindow_gc->start_check_move_unit(unit); + return; + } + + if(event->event == Events::Build) + { + BuildEvent* build_event = static_cast(event); + build_event->pos_cell = graphics_controller->get_pos_tracking_unit(); + } + + graphics_controller->get_game_controller()->current_player()->menu_event(unit, event); + + auto imenu_gc = graphics_controller->get_imenu_gc_full(); + imenu_gc->del_menu_unit(); + // no_highlight_unit(unit) +} + +void MenuGraphicsController::delete_townmenu() +{ + graphics_controller->set_town_menu(nullptr); + upper_menu->set_enable_move_map(true); + bottom_menu->show(); + + graphics_controller->get_game_controller()->current_player()->del_menu_town(); + + graphics_controller->get_enabled_map() = true; +} + +void MenuGraphicsController::do_inform_widget(std::vector> text) +{ + graphics_controller->get_game_window()->do_inform_widget(text); +} + +void MenuGraphicsController::del_inform_widget() +{ + graphics_controller->get_game_window()->del_inform_widget(); +} + +void MenuGraphicsController::open_menu_lists() +{ + menu_lists->show(); +} + +void MenuGraphicsController::close_menu_lists() +{ + menu_lists->hide(); +} + +void MenuGraphicsController::open_menu_science() +{ + menu_lists->hide(); + wid_open_menu_lists->switch_arrow(); + + menu_science.reset(new MenuScience(this, player_science())); + Size size = graphics_controller->get_size_win(); + QPoint pos = {0,0}; + menu_science->set_geometry(pos, size); + menu_science->hide(); + menu_science->show(); +} + +void MenuGraphicsController::close_menu_science() +{ + menu_science.reset(); +} + +void MenuGraphicsController::event_open_menu_type_map() +{ + if(menu_type_map) + { + close_menu_type_map(); + open_menu_type_map(); + } +} + +void MenuGraphicsController::click_open_menu_type_map() +{ + if(menu_type_map) + close_menu_type_map(); + else + open_menu_type_map(); +} + +void MenuGraphicsController::open_menu_type_map() +{ + menu_type_map.reset(new MenuTypeMap(this, map())); + QPoint pos; + Size size_win = graphics_controller->get_size_win(); + Size size{size_win.width/10, size_win.height/5}; + if(graphics_controller->get_imap_gc_full()->get_minimap()->is_enable()) + { + Calculations calc{graphics_controller->get_hexagon_side_minimap()}; + int num_cell_x = int(graphics_controller->get_num_cell().x); + int width_minimap = calc.hexagon_height()*(num_cell_x*2+1); + + pos = {size_win.width - size.width - width_minimap, + size_win.height - graphics_controller->get_size_bottommenu().height - size.height}; + } + else{ + pos = bottom_menu->open_type_map_butt().topRight() - + QPoint{size.width, -size_win.height + size.height + graphics_controller->get_size_bottommenu().height}; + } + + menu_type_map->set_geometry(pos, size); + menu_type_map->hide(); + menu_type_map->show(); +} + +void MenuGraphicsController::close_menu_type_map() +{ + menu_type_map.reset(); +} + +void MenuGraphicsController::set_type_map(TypeMap type_map) +{ + map()->set_type_map(type_map); +} + +PlayerScience* MenuGraphicsController::player_science() +{ + return graphics_controller->get_game_controller()->current_player()->player_science(); +} + +void MenuGraphicsController::create_elements() +{ + create_bottommenu(); + create_uppermenu(); + create_menu_lists(); +} + +void MenuGraphicsController::create_uppermenu() +{ + upper_menu.reset(new class UpperMenu(this)); + Size size_win = graphics_controller->get_size_win(); + Size& size_uppermenu = graphics_controller->get_size_uppermenu(); + + size_uppermenu = {size_win.width, size_win.height/30}; + upper_menu->set_geometry({0,0}, size_uppermenu); + upper_menu->hide(); + upper_menu->show(); +} + +void MenuGraphicsController::create_bottommenu() +{ + bottom_menu.reset(new class BottomMenu(this)); + Size size_win = graphics_controller->get_size_win(); + Size& size_bottommenu = graphics_controller->get_size_bottommenu(); + size_bottommenu = {size_win.width, size_win.height/30}; + QPoint pos{size_win.width - size_bottommenu.width, size_win.height - size_bottommenu.height}; + bottom_menu->set_geometry(pos, size_bottommenu); + bottom_menu->hide(); + bottom_menu->show(); +} + +void MenuGraphicsController::create_menu_lists() +{ + wid_open_menu_lists.reset(new OpenMenuLists(this)); + menu_lists.reset(new MenuLists(this)); + + Size size_win = graphics_controller->get_size_win(); + size_open_menu_lists = {size_win.height/30, size_win.height/30}; + QPoint pos{0, graphics_controller->get_size_uppermenu().height}; + wid_open_menu_lists->set_geometry(pos, size_open_menu_lists); + wid_open_menu_lists->hide(); + wid_open_menu_lists->show(); + + size_menu_lists = {size_win.height/10, size_win.height/10}; + pos += {0, size_open_menu_lists.height}; + menu_lists->set_geometry(pos, size_menu_lists); + menu_lists->hide(); +} + +void MenuGraphicsController::del_menu_unit() +{ + graphics_controller->set_unit_menu(nullptr); + graphics_controller->set_unit_information(nullptr); + + bool& is_tracking_unit = graphics_controller->get_iplayer_gc()->get_is_tracking_unit(); + Position pos_tracking_unit = graphics_controller->get_pos_tracking_unit(); + class Unit* tracking_unit = graphics_controller->get_tracking_unit(); + + auto map_gc = graphics_controller->get_imap_gc_full(); + map_gc->no_highlight_unit(tracking_unit, pos_tracking_unit); + is_tracking_unit = false; + tracking_unit = nullptr; +} + +void MenuGraphicsController::press_escape() +{ + if(menu_science) + close_menu_science(); + if(graphics_controller->get_town_menu()) + delete_townmenu(); +} + +UpperMenu* MenuGraphicsController::get_upper_menu() +{ + return upper_menu.get(); +} + +BottomMenu* MenuGraphicsController::get_bottom_menu() +{ + return bottom_menu.get(); +} + +Map* MenuGraphicsController::map() +{ + return graphics_controller->get_imap_gc_full()->get_map(); +} diff --git a/Graphics/GraphicsController/MenuGraphicsController.h b/Graphics/GraphicsController/MenuGraphicsController.h new file mode 100644 index 0000000..f3a030c --- /dev/null +++ b/Graphics/GraphicsController/MenuGraphicsController.h @@ -0,0 +1,65 @@ +#ifndef MENUGRAPHICSCONTROLLER_H +#define MENUGRAPHICSCONTROLLER_H + +#include "IGraphicsController.h" +#include "IMenuGraphicsControllerFull.h" +#include "../Menus/MenuInWindow/MenuLists.h" +#include "../Menus/MenuInWindow/OpenMenuLists.h" +#include "../Menus/MenuScience/MenuScience.h" +#include "../Menus/MenuTypeMap/MenuTypeMap.h" + +class MenuGraphicsController : public IMenuGraphicsControllerFull +{ +public: + MenuGraphicsController(IGraphicsController* graphics_controller); + + virtual QWidget* window() const override; + virtual void move_map(QPoint move_point) override; + virtual void exit() override; + virtual void show_minimap() override; + virtual void next_move() override; + + virtual void menu_unit_event(class Unit* unit, Event* event) override; + + virtual void delete_townmenu() override; + virtual void do_inform_widget(std::vector> text) override; + virtual void del_inform_widget() override; + + virtual void open_menu_lists() override; + virtual void close_menu_lists() override; + + virtual void open_menu_science() override; + virtual void close_menu_science() override; + + virtual void event_open_menu_type_map() override; + virtual void click_open_menu_type_map() override; + virtual void open_menu_type_map() override; + virtual void close_menu_type_map() override; + virtual void set_type_map(TypeMap type_map) override; + + virtual PlayerScience* player_science() override; + + void create_elements(); + void create_uppermenu(); + void create_bottommenu(); + void create_menu_lists(); + virtual void del_menu_unit() override; + virtual void press_escape() override; + virtual BottomMenu* get_bottom_menu() override; + virtual UpperMenu* get_upper_menu() override; +private: + Map* map(); + IGraphicsController* graphics_controller; + + Size size_open_menu_lists; + Size size_menu_lists; + + std::unique_ptr upper_menu; + std::unique_ptr bottom_menu; + std::unique_ptr wid_open_menu_lists; + std::unique_ptr menu_lists; + std::unique_ptr menu_science; + std::unique_ptr menu_type_map; +}; + +#endif // MENUGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/MenuStartGraphicsController.cpp b/Graphics/GraphicsController/MenuStartGraphicsController.cpp new file mode 100644 index 0000000..444602c --- /dev/null +++ b/Graphics/GraphicsController/MenuStartGraphicsController.cpp @@ -0,0 +1,25 @@ +#include "MenuStartGraphicsController.h" +#include + +MenuStartGraphicsController::MenuStartGraphicsController(IGraphicsController* _graphics_controller) + :graphics_controller{_graphics_controller} +{} + +void MenuStartGraphicsController::do_start_menu() +{ + menu_start.reset(new StartMenu(this)); + menu_start->set_geometry({0,0}, graphics_controller->get_size_win()); + menu_start->hide(); + menu_start->show(); +} + +QWidget* MenuStartGraphicsController::window() const +{ + return graphics_controller->get_game_window(); +} + +void MenuStartGraphicsController::start_game() +{ + menu_start.reset(); + graphics_controller->start_game(); +} diff --git a/Graphics/GraphicsController/MenuStartGraphicsController.h b/Graphics/GraphicsController/MenuStartGraphicsController.h new file mode 100644 index 0000000..9369b24 --- /dev/null +++ b/Graphics/GraphicsController/MenuStartGraphicsController.h @@ -0,0 +1,24 @@ +#ifndef MENUSTARTGRAPHICSCONTROLLER_H +#define MENUSTARTGRAPHICSCONTROLLER_H + +#include "IGraphicsController.h" +#include "IMenuStartGraphicsController.h" + +#include "../Menus/ManuStart/StartMenu.h" + +class MenuStartGraphicsController : public IMenuStartGraphicsController +{ +public: + MenuStartGraphicsController(IGraphicsController* graphics_controller); + void do_start_menu(); + + virtual QWidget* window() const override; + virtual void start_game() override; + +private: + IGraphicsController* graphics_controller; + + std::unique_ptr menu_start; +}; + +#endif // MENUSTARTGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/PlayerGraphicsController.cpp b/Graphics/GraphicsController/PlayerGraphicsController.cpp new file mode 100644 index 0000000..3218086 --- /dev/null +++ b/Graphics/GraphicsController/PlayerGraphicsController.cpp @@ -0,0 +1,180 @@ +#include "PlayerGraphicsController.h" +#include + +PlayerGraphicsController::PlayerGraphicsController(IGraphicsController* _graphics_controller) + :graphics_controller{_graphics_controller} +{} + +class Unit* PlayerGraphicsController::add_unit(Units type_unit, Position pos_cell) +{ + ControlContents controlcontents{map()->cell_by_indexes(pos_cell)}; + class Unit* unit = static_cast(controlcontents.add_unit(type_unit)); + return unit; +} + +void PlayerGraphicsController::move_unit(class Unit* unit, Position old_position, Position new_position) +{ + ControlContents controlcontents_old{map()->cell_by_indexes({old_position})}; + ControlContents controlcontents_new{map()->cell_by_indexes({new_position})}; + + controlcontents_old.pop_content(unit); + controlcontents_new.add_unit(unit); + game_window()->update(); +} + + +class Building* PlayerGraphicsController::build(Buildings type_building, Position pos_cell) +{ + ControlContents controlcontents{map()->cell_by_indexes(pos_cell)}; + if(controlcontents.has_building()) + { + if(type_building == Buildings::Town && controlcontents.get_building()->what_building_I() != Buildings::Town) + controlcontents.del_building(); + else + throw std::runtime_error("build: There is already a building in this cell"); + } + IContent* content = controlcontents.add_building(type_building); + class Building* building = static_cast(content); + game_window()->update(); + return building; +} + +void PlayerGraphicsController::del_unit(class Unit* unit, Position pos_cell) +{ + ControlContents controlcontents{map()->cell_by_indexes(pos_cell)}; + controlcontents.del_content(unit); +} + +void PlayerGraphicsController::del_build(Position pos_cell) +{ + ControlContents controlcontents{map()->cell_by_indexes(pos_cell)}; + controlcontents.del_building(); +} + +void PlayerGraphicsController::do_menu_unit(PlayerUnit* unit) +{ + is_tracking_unit = true; + graphics_controller->get_tracking_unit() = unit->unit; + graphics_controller->get_pos_tracking_unit() = unit->pos; + + Cell* cell = map()->cell_by_indexes(unit->pos); + Size size_win = graphics_controller->get_size_win(); + Size size_bottommenu = graphics_controller->get_size_bottommenu(); + + auto imenu_gc = graphics_controller->get_imenu_gc_full(); + graphics_controller->set_unit_menu(FactoryMenusUnit().create_menu(game_window(), imenu_gc, unit, cell)); + + AMenuForUnit* unit_menu = graphics_controller->get_unit_menu(); + int side_square_unit_menu = graphics_controller->get_side_square_unit_menu(); + unit_menu->set_geometry( + {0, size_win.height - side_square_unit_menu * (unit_menu->count_button()+1) - size_bottommenu.height}, + side_square_unit_menu); + + unit_menu->hide(); + unit_menu->show(); + + graphics_controller->set_unit_information(new UnitInformation(game_window(), unit->unit)); + graphics_controller->get_unit_information()->set_geometry( + {0, size_win.height - size_bottommenu.height - side_square_unit_menu}, side_square_unit_menu); +} + +void PlayerGraphicsController::do_menu_town(IMenuTownPlayer* player, PlayerTown* town) +{ + auto imenu_gc = graphics_controller->get_imenu_gc_full(); + graphics_controller->set_town_menu(new MenuTown{player, imenu_gc, town}); + + Size size_win = graphics_controller->get_size_win(); + Size size_uppermenu = graphics_controller->get_size_uppermenu(); + graphics_controller->get_town_menu()->set_geometry({0, size_uppermenu.height}, + {size_win.width, size_win.height-size_uppermenu.height}); + graphics_controller->get_town_menu()->start(); + graphics_controller->get_imenu_gc_full()->get_upper_menu()->set_enable_move_map(false); + + graphics_controller->get_imenu_gc_full()->get_bottom_menu()->hide(); + graphics_controller->get_imap_gc_full()->get_minimap()->hide(); + graphics_controller->get_enabled_map() = false; +} + +void PlayerGraphicsController::do_menu_science() +{ + graphics_controller->get_imenu_gc_full()->open_menu_science(); +} + +void PlayerGraphicsController::centering_by_cell(Position pos_cell) +{ + QPoint point = map()->point_of_cell_in_win(pos_cell); + + auto map_gc = graphics_controller->get_imap_gc_full(); + map_gc->move_map(graphics_controller->get_win_map_center() - point); +} + +void PlayerGraphicsController::highlight_unit(class Unit* unit, Position pos_cell) +{ + + ControlContents controlcontents{map()->cell_by_indexes(pos_cell)}; + controlcontents.set_highlight_unit(unit, true); +} + +void PlayerGraphicsController::draw_playermap(PlayerMap* playermap, PlayerScience* player_science) +{ + Position num_cell = graphics_controller->get_num_cell(); + for(size_t i{0}; i < num_cell.x; ++i) + for(size_t j{0}; j < num_cell.y; ++j) + { + ControlContents cc{map()->cell_by_indexes({i,j})}; + cc.set_show_cell(playermap->get_show_cell({i,j})); + + if(cc.has_resource()) + cc.set_show_res(player_science->is_open_resource(cc.get_resource())); + } + graphics_controller->get_game_window()->update(); +} + +IMapForFind* PlayerGraphicsController::mapforfind() +{ + return map(); +} + +void PlayerGraphicsController::update_res_inform(IMenuTownPlayer* player) +{ + graphics_controller->get_imenu_gc_full()->get_upper_menu()->update_infofm(player); +} + +int PlayerGraphicsController::count_cell_resource(Position pos) +{ + ControlContents cc{map()->cell_by_indexes(pos)}; + return cc.get_count_of_res(); +} + +Resources PlayerGraphicsController::cell_resource(Position pos) +{ + ControlContents cc{map()->cell_by_indexes(pos)}; + return cc.get_resource(); +} + +bool PlayerGraphicsController::has_cell_building(Position pos) +{ + ControlContents cc{map()->cell_by_indexes(pos)}; + return cc.has_building(); +} + +Buildings PlayerGraphicsController::cell_building(Position pos) +{ + ControlContents cc{map()->cell_by_indexes(pos)}; + return cc.get_building()->what_building_I(); +} + +Map* PlayerGraphicsController::map() +{ + return graphics_controller->get_imap_gc_full()->get_map(); +} + +GameWindow* PlayerGraphicsController::game_window() +{ + return graphics_controller->get_game_window(); +} + +bool& PlayerGraphicsController::get_is_tracking_unit() +{ + return is_tracking_unit; +} diff --git a/Graphics/GraphicsController/PlayerGraphicsController.h b/Graphics/GraphicsController/PlayerGraphicsController.h new file mode 100644 index 0000000..1cfacf8 --- /dev/null +++ b/Graphics/GraphicsController/PlayerGraphicsController.h @@ -0,0 +1,46 @@ +#ifndef PLAYERGRAPHICSCONTROLLER_H +#define PLAYERGRAPHICSCONTROLLER_H + +#include "IGraphicsController.h" +#include "IPlayerGraphicsController.h" +#include "IWindowGraphicsController.h" +#include "../Factories/FactoryMenusUnit.h" + + +class PlayerGraphicsController : public IPlayerGraphicsControllerFull +{ +public: + PlayerGraphicsController(IGraphicsController* graphics_controller); + virtual class Unit* add_unit(Units unit, Position pos_cell) override; + + virtual void move_unit(class Unit* unit, Position old_position, Position new_position) override; + virtual class Building* build(Buildings building, Position pos_cell) override; + virtual void del_build(Position pos_cell) override; + virtual void del_unit(class Unit* unit, Position pos_cell) override; + + virtual void do_menu_unit(PlayerUnit* unit) override; + virtual void do_menu_town(IMenuTownPlayer* player, PlayerTown* town) override; + virtual void do_menu_science() override; + virtual void centering_by_cell(Position pos_cell) override; + virtual void highlight_unit(class Unit* unit, Position pos) override; + virtual void draw_playermap(PlayerMap* playermap, PlayerScience* player_science) override; + virtual IMapForFind* mapforfind() override; + + virtual void update_res_inform(IMenuTownPlayer* player) override; + + virtual int count_cell_resource(Position pos) override; + virtual Resources cell_resource(Position pos) override; + virtual bool has_cell_building(Position pos) override; + virtual Buildings cell_building(Position pos) override; + + virtual bool& get_is_tracking_unit() override; +private: + Map* map(); + GameWindow* game_window(); + + bool is_tracking_unit = false; + + IGraphicsController* graphics_controller; +}; + +#endif // PLAYERGRAPHICSCONTROLLER_H diff --git a/Graphics/GraphicsController/WindowGraphicsController.cpp b/Graphics/GraphicsController/WindowGraphicsController.cpp new file mode 100644 index 0000000..de745f2 --- /dev/null +++ b/Graphics/GraphicsController/WindowGraphicsController.cpp @@ -0,0 +1,193 @@ +#include "WindowGraphicsController.h" + +WindowGraphicsController::WindowGraphicsController(IGraphicsController* _graphics_controller) + :graphics_controller{_graphics_controller} +{} + +Size WindowGraphicsController::size_win() const +{ + return graphics_controller->get_size_win(); +} + +void WindowGraphicsController::draw_elements() +{ + if(!map()) + return; + + map()->draw(graphics_controller->get_map_center()); + if(drawway()) + drawway()->draw(); +} + +void WindowGraphicsController::move_map(QPoint move_point) +{ + auto map_gc = graphics_controller->get_imap_gc_full(); + map_gc->move_map(move_point); +} + +void WindowGraphicsController::resize_map(double coeff, QPoint pos_mouse) +{ + auto map_gc = graphics_controller->get_imap_gc_full(); + map_gc->resize_map(coeff, pos_mouse); +} + +void WindowGraphicsController::click(QPoint pos) +{ + if(!graphics_controller->get_enabled_map()) + return; + + auto pair = map()->click(pos - graphics_controller->get_map_center()); + Cell* cell = pair.first; + IContent* content = pair.second; + + + if(graphics_controller->get_is_moving_unit()) + { + unit_moved_to_cell(cell); + return; + } + + auto imenu_gc = graphics_controller->get_imenu_gc_full(); + imenu_gc->del_menu_unit(); + if(content) + { + if (content->what_content_I() == Contents::Unit) + game_controller()->current_player()->click_unit(static_cast(content)); + else if (content->what_content_I() == Contents::Building) + { + class Building* building = static_cast(content); + if(building->what_building_I() == Buildings::Town) + game_controller()->current_player()->click_town(static_cast(building)); + } + } + game_window->update(); +} + +void WindowGraphicsController::start_check_move_unit() +{ + if(graphics_controller->get_tracking_unit()) + start_check_move_unit(graphics_controller->get_tracking_unit()); +} + +void WindowGraphicsController::stop_check_move_unit(QPoint mouse_pos) +{ + if(!graphics_controller->get_tracking_unit()) + return; + + auto pair = map()->click(mouse_pos - graphics_controller->get_map_center()); + Cell* cell = pair.first; + if(cell) + unit_moved_to_cell(cell); + else + stop_check_move_unit(); +} + +void WindowGraphicsController::move_mouse(QPoint new_pos) +{ + if(!graphics_controller->get_enabled_map()) + return; + + auto pair = map()->click(new_pos - graphics_controller->get_map_center()); + Cell* cell = pair.first; + if(!cell) + return; + graphics_controller->get_imenu_gc_full()->get_bottom_menu()->update_infofm(cell); + + if(graphics_controller->get_is_moving_unit()) + { + Position end_way = map()->indexes_by_cell(pair.first); + if(drawway()) + drawway()->set_end_way(end_way); + game_window->update(); + } +} + +void WindowGraphicsController::press_enter() +{ + if(graphics_controller->get_start_move_inform()) + game_controller()->start_move(); +} + +void WindowGraphicsController::press_escape() +{ + if(graphics_controller->get_start_move_inform()) + game_controller()->start_move(); + graphics_controller->get_imenu_gc_full()->press_escape(); +} + +int WindowGraphicsController::map_upper_edge() const +{ + return graphics_controller->get_size_uppermenu().height; +} + +int WindowGraphicsController::map_bottom_edge() const +{ + return size_win().height - graphics_controller->get_size_bottommenu().height; +} + +void WindowGraphicsController::start_check_move_unit(class Unit* unit) +{ + graphics_controller->get_is_moving_unit() = true; + + Position pos_tracking_unit = graphics_controller->get_pos_tracking_unit(); + DrawWay* new_drawWay = new DrawWay{game_window.get(), map(), pos_tracking_unit, unit}; + graphics_controller->set_drawway(new_drawWay); +} + +void WindowGraphicsController::stop_check_move_unit() +{ + graphics_controller->set_drawway(nullptr); + graphics_controller->get_is_moving_unit() = false; + game_window->update(); +} + +void WindowGraphicsController::set_win_settings() +{ + _size_win() = {game_controller()->width_win(), game_controller()->height_win()}; +} + +void WindowGraphicsController::unit_moved_to_cell(Cell* cell) +{ + Position pos_cell = map()->indexes_by_cell(cell); + if(!graphics_controller->get_tracking_unit()) + throw std::runtime_error("click: unit_what_moving not set"); + FindUnitWay().get_way(graphics_controller->get_tracking_unit(), map(), + graphics_controller->get_pos_tracking_unit(), pos_cell); + + MoveEvent* move_event = new MoveEvent{pos_cell}; + game_controller()->current_player()->menu_event(graphics_controller->get_tracking_unit(), move_event); + stop_check_move_unit(); + + auto imenu_gc = graphics_controller->get_imenu_gc_full(); + imenu_gc->del_menu_unit(); +} + +Size& WindowGraphicsController::_size_win() +{ + return graphics_controller->get_size_win(); +} + +IGameForGraphic* WindowGraphicsController::game_controller() const +{ + return graphics_controller->get_game_controller(); +} + +DrawWay* WindowGraphicsController::drawway() const +{ + return graphics_controller->get_drawway(); +} + +Map* WindowGraphicsController::map() +{ + return graphics_controller->get_imap_gc_full()->get_map(); +} + +GameWindow* WindowGraphicsController::get_window() +{ + return game_window.get(); +} + +void WindowGraphicsController::do_window() +{ + game_window.reset(new GameWindow(this)); +} diff --git a/Graphics/GraphicsController/WindowGraphicsController.h b/Graphics/GraphicsController/WindowGraphicsController.h new file mode 100644 index 0000000..ac93006 --- /dev/null +++ b/Graphics/GraphicsController/WindowGraphicsController.h @@ -0,0 +1,47 @@ +#ifndef WINDOWGRAPHICSCONTROLLER_H +#define WINDOWGRAPHICSCONTROLLER_H + +#include "IGraphicsController.h" +#include "IWindowGraphicsController.h" + + +class WindowGraphicsController : public IWindowGraphicsControllerFull +{ +public: + WindowGraphicsController(IGraphicsController* graphics_controller); + + virtual Size size_win() const override; + + virtual void draw_elements() override; + virtual void move_map(QPoint move_point) override; + virtual void resize_map(double coefficient, QPoint pos_mouse) override; + virtual void click(QPoint pos) override; + virtual void start_check_move_unit() override; + virtual void stop_check_move_unit(QPoint mouse_pos) override; + virtual void move_mouse(QPoint new_pos) override; + virtual void press_enter() override; + virtual void press_escape() override; + + virtual int map_upper_edge() const override; + virtual int map_bottom_edge() const override; + + virtual void start_check_move_unit(class Unit* unit) override; + virtual void stop_check_move_unit() override; + + void set_win_settings(); + GameWindow* get_window(); + void do_window(); + +private: + Map* map(); + + void unit_moved_to_cell(Cell* cell); + Size& _size_win(); + IGameForGraphic* game_controller() const; + DrawWay* drawway() const; + std::unique_ptr game_window; + + IGraphicsController* graphics_controller; +}; + +#endif // WINDOWGRAPHICSCONTROLLER_H diff --git a/Graphics/IContent.h b/Graphics/IContent.h new file mode 100644 index 0000000..a318d7d --- /dev/null +++ b/Graphics/IContent.h @@ -0,0 +1,17 @@ +#ifndef ICONTENT_H +#define ICONTENT_H + +#include "../Controllers/Enums.h" +#include "IDrawObject.h" + + +class IContent : public IDrawObject +{ +public: + virtual void draw(QPoint point) override = 0; + virtual QWidget* window() const override = 0; + virtual Calculations* calculations() const override = 0; + virtual Contents what_content_I() const = 0; +}; + +#endif // ICONTENT_H diff --git a/Graphics/IDrawObject.h b/Graphics/IDrawObject.h new file mode 100644 index 0000000..c1c78c8 --- /dev/null +++ b/Graphics/IDrawObject.h @@ -0,0 +1,25 @@ +#ifndef IDRAW_OBJECT_H +#define IDRAW_OBJECT_H + +#include + +#include +#include + +#include "GraphicsController/Calculations.h" +#include "../IObject.h" + + +class IDrawObject : public IObject +{ +public: + IDrawObject(){} + + virtual void draw(QPoint point) = 0; + virtual QWidget* window() const = 0; + virtual Calculations* calculations() const = 0; + + virtual ~IDrawObject() {} +}; + +#endif // IDRAW_OBJECT_H diff --git a/Graphics/InformationWidgets/StartMoveInform.cpp b/Graphics/InformationWidgets/StartMoveInform.cpp new file mode 100644 index 0000000..4ccb6d8 --- /dev/null +++ b/Graphics/InformationWidgets/StartMoveInform.cpp @@ -0,0 +1,70 @@ +#include "StartMoveInform.h" +#include + +StartMoveInform::StartMoveInform(IGameForWidget* game, QString _string, QPoint _point) + :QWidget{game->window()}, game_controller{game}, string{_string}, point{_point} +{} + +void StartMoveInform::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); +} + +void StartMoveInform::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void StartMoveInform::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void StartMoveInform::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + if(point_in_rect(rect_butt(), event->pos())) + game_controller->start_move(); +} + +void StartMoveInform::draw() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 2}); + + QFont font(""); + font.setPixelSize(height()/5); + qp.setFont(font); + qp.drawText(QRect{0, 0, width(), height() - rect_butt().height() - indentation_butt()}, + Qt::AlignCenter, string); + + QFont font2(""); + font2.setPixelSize(height()/20); + qp.setFont(font2); + qp.drawRect(rect_butt()); + qp.drawText(rect_butt(), Qt::AlignCenter, "Ок"); +} + + +QRect StartMoveInform::rect_butt() const +{ + Size size_butt{width()/8, height()/10}; + return QRect{width()/2 - size_butt.width/2, height() - size_butt.height - indentation_butt(), + size_butt.width, size_butt.height}; +} + +int StartMoveInform::indentation_butt() const +{ + return height()/20; +} + +bool StartMoveInform::point_in_rect(QRectF rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} diff --git a/Graphics/InformationWidgets/StartMoveInform.h b/Graphics/InformationWidgets/StartMoveInform.h new file mode 100644 index 0000000..2ba3cd0 --- /dev/null +++ b/Graphics/InformationWidgets/StartMoveInform.h @@ -0,0 +1,35 @@ +#ifndef STARTMOVEINFORM_H +#define STARTMOVEINFORM_H + +#include +#include +#include + +#include "../../Controllers/IGame.h" + + +class StartMoveInform : public QWidget +{ +public: + StartMoveInform(IGameForWidget* game, QString string, QPoint point); + void set_geometry(QPoint pos, Size size); + +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + + void draw(); + QRect rect_butt() const; + int indentation_butt() const; + bool point_in_rect(QRectF rect, QPoint point); + + IGameForWidget* game_controller; + QString string; + QPoint point; + bool resized = false; + QPoint mouse_pos_clicked{-1,-1}; +}; + +#endif // STARTMOVEINFORM_H diff --git a/Graphics/InformationWidgets/UnitInformation.cpp b/Graphics/InformationWidgets/UnitInformation.cpp new file mode 100644 index 0000000..b59a282 --- /dev/null +++ b/Graphics/InformationWidgets/UnitInformation.cpp @@ -0,0 +1,42 @@ +#include "UnitInformation.h" + +UnitInformation::UnitInformation(QWidget* win, class Unit* _unit) + :QWidget{win}, unit{_unit} +{} + +void UnitInformation::set_geometry(QPoint pos, int height) +{ + QWidget::setGeometry(pos.x(), pos.y(), height*3, height); + this->hide(); + this->show(); +} + + +void UnitInformation::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void UnitInformation::draw() +{ + QPainter qp(this); + QPen pen{Qt::white, 2, Qt::SolidLine}; + qp.setPen(pen); + qp.drawRect(0, 0, width(), height()); + + QPixmap pixmap_unit = FactoryPixmap().create_pixmap_for_unit(unit->what_unit_I()); + QRectF source = FactoryPixmap().size_picture_unit(); + qp.drawPixmap(QRect{0, 0, height(), height()}, pixmap_unit, source); + + + QRect rect_movement{QPoint{width()/3 + width()/10, 0}, QPoint{width() - width()/10, height()/2}}; + std::stringstream ss1; + ss1 << "Movement: " << unit->get_movement() << "/" << unit->get_max_movement(); + qp.drawText(rect_movement, Qt::AlignVCenter, QString::fromStdString(ss1.str())); + + QRect rect_health{QPoint{width()/3 + width()/10, height()/2}, QPoint{width() - width()/10, height()}}; + std::stringstream ss2; + ss2 << "Health: " << unit->get_health() << "/" << unit->get_max_health(); + qp.drawText(rect_health, Qt::AlignVCenter, QString::fromStdString(ss2.str())); +} diff --git a/Graphics/InformationWidgets/UnitInformation.h b/Graphics/InformationWidgets/UnitInformation.h new file mode 100644 index 0000000..155674f --- /dev/null +++ b/Graphics/InformationWidgets/UnitInformation.h @@ -0,0 +1,29 @@ +#ifndef UNITINFORMATION_H +#define UNITINFORMATION_H + +#include + +#include + +#include "../Factories/FactoryPixmap.h" +#include "../Units/Unit.h" + + +class UnitInformation : public QWidget +{ +public: + UnitInformation(QWidget* win, class Unit* unit); + + //width = height*2 + virtual void set_geometry(QPoint pos, int height); +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mouseReleaseEvent(QMouseEvent *event) override {Q_UNUSED(event)} + + void draw(); + class Unit* unit; +}; + +#endif // UNITINFORMATION_H diff --git a/Graphics/Map/Cell.cpp b/Graphics/Map/Cell.cpp new file mode 100644 index 0000000..0f9c2cd --- /dev/null +++ b/Graphics/Map/Cell.cpp @@ -0,0 +1,370 @@ +#include "Cell.h" +#include + +Cell::Cell(IMap* map) + :map{map} +{} + +void Cell::draw(QPoint point) +{ + // std::cout << int(country) << std::endl; + if(show_cell == ShowCell::FogOfWar) + { + draw_fog_of_war(point); + draw_cell(point); + } + else{ + auto overplay = map->get_type_map().overplay; + ControlContents cc{this}; + + if(overplay == TypeMap::NoOverlay || + (overplay == TypeMap::Political && country == Countries::Nothing) || + (overplay == TypeMap::HighlightResources && !cc.has_resource())) + draw_landscape(point); + + draw_cell(point); + draw_contents(point); + } +} + +QWidget* Cell::window() const +{ + return map->window(); +} + +Calculations* Cell::calculations() const +{ + return map->calculations(); +} + +IContent* Cell::click(QPoint pos) +{ + auto map_type_content = map->get_type_map().type_content; + int num_circle = calculations()->point_in_circle(pos, count_units()); + + if (num_circle == -1) + return nullptr; + + ControlContents control_contents{this}; + + if ((map_type_content == TypeMap::All || map_type_content == TypeMap::Units) && + num_circle < 4) + { + if (control_contents.count_units() < num_circle+1) + return nullptr; + + int counter = 0; + for(size_t j{0}; j < contents.size(); ++j) + if(contents[j].content->what_content_I() == Contents::Unit) + if(++counter == num_circle+1) + return contents[j].content.get(); + } + else if((map_type_content == TypeMap::All && num_circle == 4) || + (map_type_content == TypeMap::Resources && num_circle == 0)) + { + if (!control_contents.has_resource()) + return nullptr; + + for(size_t j{0}; j < contents.size(); ++j) + if(contents[j].content->what_content_I() == Contents::Resource) + return contents[j].content.get(); + } + else if((map_type_content == TypeMap::All && num_circle == 5) || + (map_type_content == TypeMap::Building && num_circle == 0)) + { + if (!control_contents.has_building()) + return nullptr; + + for(size_t j{0}; j < contents.size(); ++j) + if(contents[j].content->what_content_I() == Contents::Building) + return contents[j].content.get(); + } + + throw std::runtime_error("Can't find content"); +} + +int Cell::count_units() +{ + ControlContents cc{this}; + return cc.count_units(); +} + +void Cell::update_pixmap_for_main_landscape() +{ + pixmap_for_main_landscape = FactoryPixmap().create_pixmap_for_main_landscape(mainlandscape); +} + +void Cell::update_pixmap_for_other_landscape() +{ + pixmap_for_other_landscape = FactoryPixmap().create_pixmap_for_other_landscape(otherlandscape); +} + +void Cell::draw_cell(QPoint point) +{ + Calculations* calc = calculations(); + + QPoint p1 = point - calc->point_0(); + QPoint p2 = point - calc->point_60(); + QPoint p3 = point - calc->point_120(); + QPoint p4 = point - calc->point_180(); + QPoint p5 = point - calc->point_240(); + QPoint p6 = point - calc->point_300(); + + QWidget* win = window(); + QPainter qp(win); + + if(show_cell == ShowCell::NotVisible && map->get_type_map().show_notvisible) + { + qp.setBrush(QBrush(QColor(0, 0, 0, 200))); + } + + auto overplay = map->get_type_map().overplay; + ControlContents cc{this}; + if(overplay == TypeMap::Political && country != Countries::Nothing) + qp.setBrush(FactoryColor().country_color(country)); + else if (show_cell != ShowCell::FogOfWar && overplay == TypeMap::HighlightResources && cc.has_resource()) + qp.setBrush(Qt::green); + + qp.setPen(QPen(Qt::black, calc->hexagon_height()/10)); + + QPointF points[6] {p1, p2, p3, p4, p5, p6}; + qp.drawPolygon(points, 6); +} + +void Cell::draw_landscape(QPoint point) +{ + Calculations* calc = calculations(); + QWidget* win = window(); + QPainter qp(win); + + if (!is_there_main_landscape) + throw std::runtime_error("The main landscape is not set in the cell"); + + QRectF source = FactoryPixmap().size_picture_landscape(); + QRectF target{1.* (point.x() - calc->hexagon_side()), 1.* (point.y() - calc->hexagon_side()), + calc->hexagon_side()*2., calc->hexagon_side()*2.}; + qp.drawPixmap(target, pixmap_for_main_landscape, source); + + if(map->get_type_map().show_other_landscapes) + { + qp.drawPixmap(target, pixmap_for_other_landscape, source); + } +} + +void Cell::draw_contents(QPoint point) +{ + auto map_type_content = map->get_type_map().type_content; + if(map_type_content == TypeMap::Nothing) + return; + + int count_drawn_unit = 0; + for(size_t i{0}; i < contents.size(); ++i) + { + Contents type_content = contents[i].content->what_content_I(); + if(type_content != Contents::Resource && show_cell == ShowCell::NotVisible) + continue; + + if(!contents[i].show_content) + continue; + + if(type_content == Contents::Unit) + draw_unit(&contents[i], point, count_drawn_unit++); + else if (type_content == Contents::Resource) + draw_resource(&contents[i], point); + else if (type_content == Contents::Building) + draw_building(&contents[i], point); + } +} + +void Cell::draw_fog_of_war(QPoint point) +{ + Calculations* calc = calculations(); + QWidget* win = window(); + QPainter qp(win); + + QPixmap pixmap = FactoryPixmap().create_pixmap_for_fog_of_war(); + QRectF source = FactoryPixmap().size_picture_landscape(); + QRectF target{1.* (point.x() - calc->hexagon_side()), 1.* (point.y() - calc->hexagon_side()), + calc->hexagon_side()*2., calc->hexagon_side()*2.}; + qp.drawPixmap(target, pixmap, source); +} + +void Cell::draw_highlight(QPoint point) +{ + int rad = calculations()->circle_radius(); + + QPainter qp(window()); + QPen pen(Qt::blue, int(rad/5), Qt::SolidLine); + qp.setBrush(QBrush (Qt::blue)); + qp.drawEllipse(point, rad*6/5, rad*6/5); +} + +void Cell::draw_borders(QPoint point) +{ + if(country == Countries::Nothing) + return; + if(show_cell == ShowCell::FogOfWar) + return; + + Calculations* calc = calculations(); + int width_border = calc->hexagon_height()/20; + QPainter qp(window()); + QPen pen(FactoryColor().country_color(country), width_border, Qt::SolidLine); + qp.setPen(pen); + + QPoint p1 = point + calc->point_0() + QPoint{0, width_border/2}; + QPoint p2 = point + calc->point_60() + QPoint{width_border/2, width_border/2}; + QPoint p3 = point + calc->point_120() + QPoint{width_border/2, -width_border/2}; + QPoint p4 = point + calc->point_180() + QPoint{0, -width_border/2}; + QPoint p5 = point + calc->point_240() + QPoint{-width_border/2, -width_border/2}; + QPoint p6 = point + calc->point_300() + QPoint{-width_border/2, width_border/2}; + + std::vector lines; + std::vector ends; + Position my_pos = map->indexes_by_cell(this); + auto neighbors = map->adjacent_cells(my_pos); + // std::cout << "---" << my_pos.x << " " << my_pos.y << std::endl; + for(auto pos_cell : neighbors) + { + // std::cout << pos_cell.x << " " << pos_cell.y << " " << int(cell_country(pos_cell)) << std::endl; + if(cell_country(pos_cell) == country) + continue; + + if(pos_cell.y == my_pos.y) + { + if(pos_cell.x < my_pos.x) + { + lines.push_back({p2, p3}); + ends.push_back(p2); + ends.push_back(p3); + } + else if (pos_cell.x > my_pos.x) + { + lines.push_back({p5, p6}); + ends.push_back(p5); + ends.push_back(p6); + } + } + else if(my_pos.y % 2 == 0) + { + if(pos_cell.y < my_pos.y) + { + if(pos_cell.x < my_pos.x) + { + lines.push_back({p1, p2}); + ends.push_back(p1); + ends.push_back(p2); + } + else if (pos_cell.x == my_pos.x) + { + lines.push_back({p6, p1}); + ends.push_back(p6); + ends.push_back(p1); + } + } + else + { + if(pos_cell.x < my_pos.x) + { + lines.push_back({p3, p4}); + ends.push_back(p3); + ends.push_back(p4); + } + else if (pos_cell.x == my_pos.x) + { + lines.push_back({p4, p5}); + ends.push_back(p4); + ends.push_back(p5); + } + } + } + else if(my_pos.y % 2 == 1) + { + if(pos_cell.y < my_pos.y) + { + if(pos_cell.x == my_pos.x) + { + lines.push_back({p1, p2}); + ends.push_back(p1); + ends.push_back(p2); + } + else if (pos_cell.x > my_pos.x) + { + lines.push_back({p6, p1}); + ends.push_back(p6); + ends.push_back(p1); + } + } + else + { + if(pos_cell.x == my_pos.x) + { + lines.push_back({p3, p4}); + ends.push_back(p3); + ends.push_back(p4); + } + else if (pos_cell.x > my_pos.x) + { + lines.push_back({p4, p5}); + ends.push_back(p4); + ends.push_back(p5); + } + } + } + } + + for(auto line : lines) + qp.drawLine(line); +} + +Countries Cell::cell_country(Position pos_cell) +{ + ControlContents cc{map->icell_by_indexes(pos_cell)}; + return cc.get_country(); +} + +void Cell::draw_unit(Content* content, QPoint point_cell, int count_drawn_unit) +{ + auto map_type_content = map->get_type_map().type_content; + Calculations* calc = calculations(); + QPoint p; + if(map_type_content == TypeMap::All || map_type_content == TypeMap::Units) + { + ControlContents cc{this}; + p = calc->point_circle_for_unit(count_drawn_unit, cc.count_units()); + } + else + return; + + if(content->highlight) + draw_highlight(p + point_cell); + content->content->draw(p + point_cell); +} + +void Cell::draw_resource(Content* content, QPoint point_cell) +{ + auto map_type_content = map->get_type_map().type_content; + Calculations* calc = calculations(); + + QPoint p; + if(map_type_content == TypeMap::All || map_type_content == TypeMap::Resources) + p = calc->point_circle_for_res(); + else + return; + content->content->draw(point_cell + p); +} + +void Cell::draw_building(Content* content, QPoint point_cell) +{ + auto map_type_content = map->get_type_map().type_content; + Calculations* calc = calculations(); + + QPoint p; + if(map_type_content == TypeMap::All || map_type_content == TypeMap::Building) + p = calc->point_circle_for_build(); + else + return; + + content->content->draw(point_cell + p); +} + diff --git a/Graphics/Map/Cell.h b/Graphics/Map/Cell.h new file mode 100644 index 0000000..d20ddac --- /dev/null +++ b/Graphics/Map/Cell.h @@ -0,0 +1,133 @@ +#ifndef CELL_H +#define CELL_H + +#include +#include + +#include +#include + +#include "ICell.h" +#include "IMap.h" +#include "../Buildings/Building.h" +#include "../Factories/FactoryBuild.h" +#include "../Factories/FactoryColor.h" +#include "../Factories/FactoryPixmap.h" +#include "../Factories/FactoryRes.h" +#include "../Factories/FactoryUnits.h" +#include "../GraphicsController/Calculations.h" +#include "../IContent.h" +#include "../Resources/Res.h" +#include "../Units/Unit.h" +#include "../../Controllers/Enums.h" + + +struct Content +{ + std::unique_ptr content; + bool show_content = true; + bool highlight = false; + Content(IContent* _content) : content{_content} {} +}; + + +class Cell : public ICell +{ +public: + Cell(IMap* map); + + // point - центр клетки + virtual void draw(QPoint point) override; + void draw_borders(QPoint point); + virtual QWidget* window() const override; + virtual Calculations* calculations() const override; + + // точка относительно центра клетки + IContent* click(QPoint pos); + + virtual int count_units() override; +private: + void update_pixmap_for_main_landscape(); + void update_pixmap_for_other_landscape(); + + void draw_cell(QPoint point); + void draw_landscape(QPoint point); + void draw_contents(QPoint point); + void draw_fog_of_war(QPoint point); + void draw_highlight(QPoint point); + Countries cell_country(Position pos_cell); + + void draw_unit(Content* content, QPoint point_cell, int count_drawn_unit); + void draw_resource(Content* content, QPoint point_cell); + void draw_building(Content* content, QPoint point_cell); + + IMap* map; + std::vector contents; + + bool is_there_main_landscape = false; + bool is_there_other_landscape = false; + MainLandscapes mainlandscape = MainLandscapes::Plain; + OtherLandscapes otherlandscape= OtherLandscapes::Nothing; + Countries country = Countries::Nothing; + + ShowCell show_cell = Show; + + friend class ControlContents; + + QPixmap pixmap_for_main_landscape; + QPixmap pixmap_for_other_landscape; +}; + + +class ControlContents : public IObject +{ +public: + ControlContents(Cell* _cell) : cell{_cell}{} + ControlContents(ICell* _cell) : cell{static_cast(_cell)}{} + + void set_main_landscape(MainLandscapes type_landscape); + void set_other_landscape(OtherLandscapes type_landscape); + IContent* add_resource(Resources type_resource, int count_of_res = 0); + IContent* add_building(Buildings type_building); + IContent* add_unit(Units type_unit); + void add_unit(IContent* unit); + + void del_content(IContent* content); + void del_building(); + IContent* pop_content(IContent* content); + + MainLandscapes get_main_landscape() const; + OtherLandscapes get_other_landscape() const; + Resources get_resource() const; + Building* get_building() const; + std::vector get_units() const; + Countries get_country_units() const; + + bool has_main_landscape() const; + bool has_other_landscape() const; + bool has_resource() const; + bool has_building() const; + int count_units() const; + + void set_show_cell(ICell::ShowCell show_cell); + ICell::ShowCell get_show_cell() const; + void set_show_res(bool show_res); + void set_show_unit(bool show_unit, class Unit* unit); + void set_highlight_unit(IContent* unit, bool highlight); + + void set_count_of_res(int count); + int get_count_of_res() const; + + void set_country(Countries country); + Countries get_country() const; + + virtual ~ControlContents() {} +private: + Res* _get_resource() const; + class Building* _get_building() const; + std::vector _get_units() const; + + Cell* cell; +}; + +#endif // CELL_H diff --git a/Graphics/Map/ControlContents.cpp b/Graphics/Map/ControlContents.cpp new file mode 100644 index 0000000..9dbaa72 --- /dev/null +++ b/Graphics/Map/ControlContents.cpp @@ -0,0 +1,241 @@ +#include "Cell.h" + +void ControlContents::set_main_landscape(MainLandscapes type_landscape) +{ + // if (cell->is_there_main_landscape) + // throw std::runtime_error("set_main_landscape: There is already a landscape in the cell"); + + cell->is_there_main_landscape = true; + cell->mainlandscape = type_landscape; + cell->update_pixmap_for_main_landscape(); +} + +void ControlContents::set_other_landscape(OtherLandscapes type_landscape) +{ + // if (cell->is_there_other_landscape) + // throw std::runtime_error("set_other_landscape: There is already other landscape in the cell"); + + cell->is_there_other_landscape = true; + cell->otherlandscape = type_landscape; + cell->update_pixmap_for_other_landscape(); +} + +IContent* ControlContents::add_resource(Resources type_resource, int count_of_res) +{ + if (has_resource()) + throw std::runtime_error("add_resource: There is already a resource in the cell"); + cell->contents.push_back({FactoryRes().create_res(type_resource, cell, count_of_res)}); + return cell->contents[cell->contents.size()-1].content.get(); +} + +IContent* ControlContents::add_building(Buildings type_building) +{ + if (has_building()) + throw std::runtime_error("add_building: There is already a building in the cell"); + cell->contents.push_back({FactoryBuild().create_building(type_building, cell)}); + return cell->contents[cell->contents.size()-1].content.get(); +} + +IContent* ControlContents::add_unit(Units type_unit) +{ + if(count_units() == 4) + throw std::runtime_error("add_unit: there are already 4 units in the cell"); + cell->contents.push_back({FactoryUnits().create_unit(type_unit, cell)}); + return cell->contents[cell->contents.size()-1].content.get(); +} + +void ControlContents::add_unit(IContent* unit) +{ + if (unit->what_content_I() != Contents::Unit) + throw std::runtime_error("add_unit: It isn't unit"); + if(count_units() == 4) + throw std::runtime_error("add_unit: there are already 4 units in the cell"); + cell->contents.push_back({unit}); +} + + +void ControlContents::del_content(IContent* content) +{ + for(size_t i{0}; i < cell->contents.size(); ++i) + if(cell->contents[i].content.get() == content){ + cell->contents.erase(cell->contents.begin() + i); + } +} + +void ControlContents::del_building() +{ + del_content(_get_building()); +} + +IContent* ControlContents::pop_content(IContent* content) +{ + for(size_t i{0}; i < cell->contents.size(); ++i) + { + if(cell->contents[i].content.get() == content){ + IContent* temp{nullptr}; + temp = cell->contents[i].content.release(); + cell->contents.erase(cell->contents.begin() + i); + return temp; + } + } + throw std::runtime_error("pop_content: hasn't this constent"); +} + +MainLandscapes ControlContents::get_main_landscape() const +{ + if(!cell->is_there_main_landscape) + throw std::runtime_error("landscape is not set"); + return cell->mainlandscape; +} + +OtherLandscapes ControlContents::get_other_landscape() const +{ + return cell->otherlandscape; +} + +Resources ControlContents::get_resource() const +{ + Res* resource = _get_resource(); + if(resource) + return resource->what_resource_I(); + throw std::runtime_error("Hasn't got resource"); +} + +Building* ControlContents::get_building() const +{ + class Building* building = _get_building(); + if(building) + return building; + throw std::runtime_error("Hasn't got building"); +} + +std::vector ControlContents::get_units() const +{ + std::vector units = _get_units(); + std::vector types_units; + for(auto unit : units) + types_units.push_back(unit->what_unit_I()); + return types_units; +} + +Countries ControlContents::get_country_units() const +{ + std::vector units = _get_units(); + if(!units.size()) + throw std::runtime_error("Hasn't got units"); + return units[0]->get_country(); +} + +bool ControlContents::has_main_landscape() const +{ + return cell->is_there_main_landscape; +} + +bool ControlContents::has_resource() const +{ + return _get_resource(); +} + +bool ControlContents::has_building() const +{ + return _get_building(); +} + +int ControlContents::count_units() const +{ + return int(_get_units().size()); +} + +void ControlContents::set_show_cell(Cell::ShowCell _show_cell) +{ + cell->show_cell = _show_cell; +} + +ICell::ShowCell ControlContents::get_show_cell() const +{ + return cell->show_cell; +} + +void ControlContents::set_show_res(bool show_res) +{ + for(size_t i{0}; i < cell->contents.size(); ++i) + if(cell->contents[i].content->what_content_I() == Contents::Resource) + cell->contents[i].show_content = show_res; +} + +void ControlContents::set_show_unit(bool show_unit, class Unit* unit) +{ + for(size_t i{0}; i < cell->contents.size(); ++i) + if(cell->contents[i].content->what_content_I() == Contents::Unit) + if(cell->contents[i].content.get() == unit) + cell->contents[i].show_content = show_unit; +} + +void ControlContents::set_highlight_unit(IContent* unit, bool highlight) +{ + for(size_t i{0}; i < cell->contents.size(); ++i) + if(cell->contents[i].content->what_content_I() == Contents::Unit) + if(cell->contents[i].content.get() == unit) + cell->contents[i].highlight = highlight; +} + +void ControlContents::set_count_of_res(int count) +{ + Res* res = _get_resource(); + if(res) + res->set_count_of_res(count); + else + throw std::runtime_error("set_count_of_res(): hasn't resource in this cell"); +} + +int ControlContents::get_count_of_res() const +{ + Res* res = _get_resource(); + if(res) + return res->get_count_of_res(); + return 0; +} + +void ControlContents::set_country(Countries country) +{ + cell->country = country; +} + +Countries ControlContents::get_country() const +{ + return cell->country; +} + +Res* ControlContents::_get_resource() const +{ + for(size_t i{0}; i < cell->contents.size(); ++i) + if(cell->contents[i].content->what_content_I() == Contents::Resource) + { + Res* res = static_cast(cell->contents[i].content.get()); + return res; + } + return nullptr; +} + +class Building* ControlContents::_get_building() const +{ + for(size_t i{0}; i < cell->contents.size(); ++i) + if(cell->contents[i].content->what_content_I() == Contents::Building) + { + class Building* building = static_cast(cell->contents[i].content.get()); + return building; + } + return nullptr; +} + +std::vector ControlContents::_get_units() const +{ + std::vector units; + for(size_t i{0}; i < cell->contents.size(); ++i) + if(cell->contents[i].content->what_content_I() == Contents::Unit) + { + class Unit* unit = static_cast(cell->contents[i].content.get()); + units.push_back(unit); + } + return units; +} diff --git a/Graphics/Map/ICell.h b/Graphics/Map/ICell.h new file mode 100644 index 0000000..b0032ec --- /dev/null +++ b/Graphics/Map/ICell.h @@ -0,0 +1,26 @@ +#ifndef ICELL_H +#define ICELL_H + +#include +#include + +#include "../GraphicsController/Calculations.h" +#include "../IDrawObject.h" + + +class ICell : public IDrawObject +{ +public: + enum ShowCell{ + FogOfWar, + Show, + NotVisible + }; + + virtual void draw(QPoint point) = 0; + virtual QWidget* window() const = 0; + virtual Calculations* calculations() const = 0; + virtual int count_units() = 0; +}; + +#endif // ICELL_H diff --git a/Graphics/Map/IMap.h b/Graphics/Map/IMap.h new file mode 100644 index 0000000..4a3754a --- /dev/null +++ b/Graphics/Map/IMap.h @@ -0,0 +1,40 @@ +#ifndef IMAP_H +#define IMAP_H + +#include +#include + +#include "ICell.h" +#include "TypeMap.h" +#include "../GraphicsController/Calculations.h" +#include "../IDrawObject.h" +#include "../../Controllers/Enums.h" + + +class IMapForFind : public IObject +{ +public: + virtual ICell* icell_by_indexes(Position pos) const = 0; + virtual std::vector adjacent_cells(Position pos) const = 0; + virtual void set_cell_country(Position pos_cell, Countries coutry) = 0; + virtual Countries get_cell_country(Position pos_cell) = 0; +}; + + +class IMap : public IDrawObject +{ +public: + // point - центр карты + virtual void draw(QPoint point) override = 0; + virtual QWidget* window() const override = 0; + virtual Calculations* calculations() const override = 0; + virtual std::vector adjacent_cells(Position pos) const = 0; + + virtual Position indexes_by_cell(ICell* cell) const = 0; + virtual ICell* icell_by_indexes(Position pos) const = 0; + + virtual const TypeMap& get_type_map() const = 0; + virtual void set_type_map(TypeMap type_map) = 0; +}; + +#endif // IMAP_H diff --git a/Graphics/Map/Map.cpp b/Graphics/Map/Map.cpp new file mode 100644 index 0000000..d45e9a1 --- /dev/null +++ b/Graphics/Map/Map.cpp @@ -0,0 +1,236 @@ +#include "Map.h" +#include + +Map::Map(IMapGraphicsController* game) + :IMap{}, graphics_controller{game} +{ + +} + +void Map::do_cells() +{ + size_t c_cell_x = graphics_controller->count_cell_x(); + size_t c_cell_y = graphics_controller->count_cell_y(); + for(size_t i{0}; i < c_cell_y; ++i) + { + cells.push_back(std::vector>()); + for(size_t j{0}; j < c_cell_x; ++j) + cells[i].push_back(std::unique_ptr{new Cell{this}}); + } +} + +void Map::draw(QPoint point) +{ +// std::cout << "start" << std::endl; + + Calculations* calc = calculations(); + Size size_win_map = graphics_controller->size_win_map(); + int height_win_map = size_win_map.height; + int width_win_map = size_win_map.width; + Size size_map = graphics_controller->size_map(); + int width_map = size_map.width; + int height_map = size_map.height; + + QPoint corner_of_map_win = graphics_controller->win_map_center() - + QPoint{width_win_map/2, height_win_map/2}; + + QPoint corner_of_map = point - + QPoint{width_map/2, height_map/2}; + + for(size_t i{0}; i < cells.size(); ++i) + for(size_t j{0}; j < cells[i].size(); ++j) + { + QPoint cell_point = point_of_cell({j, i}) + corner_of_map; + if (cell_point.x() + calc->hexagon_height() < corner_of_map_win.x()) + continue; + if (cell_point.x() - calc->hexagon_height() > corner_of_map_win.x() + width_win_map) + continue; + if (cell_point.y() + calc->hexagon_side() < corner_of_map_win.y()) + continue; + if (cell_point.y() - calc->hexagon_side() > corner_of_map_win.y() + height_win_map) + continue; + cells[i][j]->draw(cell_point); + } + + for(size_t i{0}; i < cells.size(); ++i) + for(size_t j{0}; j < cells[i].size(); ++j) + { + QPoint cell_point = point_of_cell({j, i}) + corner_of_map; + if (cell_point.x() + calc->hexagon_height() < corner_of_map_win.x()) + continue; + if (cell_point.x() - calc->hexagon_height() > corner_of_map_win.x() + width_win_map) + continue; + if (cell_point.y() + calc->hexagon_side() < corner_of_map_win.y()) + continue; + if (cell_point.y() - calc->hexagon_side() > corner_of_map_win.y() + height_win_map) + continue; + + if(type_map.overplay != TypeMap::Political) + cells[i][j]->draw_borders(cell_point); + } +} + +QWidget* Map::window() const +{ + return graphics_controller->window(); +} + +Calculations* Map::calculations() const +{ + return graphics_controller->calculations(); +} + +ICell* Map::icell_by_indexes(Position pos) const +{ + return cell_by_indexes(pos); +} + +Cell* Map::cell_by_indexes(Position pos) const +{ + return cells[pos.y][pos.x].get(); +} + +Position Map::indexes_by_cell(Cell* cell) const +{ + for(size_t j{0}; j < size_t(graphics_controller->count_cell_y()); ++j) + for(size_t i{0}; i < size_t(graphics_controller->count_cell_x()); ++i) + if(cells[j][i].get() == cell) + return {i,j}; + throw std::runtime_error("indexes_by_cell: Hasn't this got this cell"); +} + +Position Map::indexes_by_cell(ICell* cell) const +{ + return indexes_by_cell(static_cast(cell)); +} + +std::vector Map::adjacent_cells(Position pos) const +{ + size_t x = pos.x; + size_t y = pos.y; + std::vector res; + size_t max_ind_x = size_t(graphics_controller->count_cell_x() - 1); + size_t max_ind_y = size_t(graphics_controller->count_cell_y() - 1); + + + if(y < max_ind_y) + res.push_back({x, y+1}); + if(y > 0) + res.push_back({x, y-1}); + + if(x > 0) + res.push_back({x-1, y}); + if(x < max_ind_x) + res.push_back({x+1, y}); + + if (y % 2 == 0 && x > 0) + { + if(y > 0) + res.push_back({x-1, y-1}); + + if(y < max_ind_y) + res.push_back({x-1, y+1}); + } + else if(y % 2 == 1 && x < max_ind_x) + { + if(y > 0) + res.push_back({x+1, y-1}); + + if(y < max_ind_y) + res.push_back({x+1, y+1}); + } + + return res; +} + +void Map::set_cell_country(Position pos_cell, Countries coutry) +{ + ControlContents cc{cell_by_indexes(pos_cell)}; + cc.set_country(coutry); +} + +Countries Map::get_cell_country(Position pos_cell) +{ + ControlContents cc{cell_by_indexes(pos_cell)}; + return cc.get_country(); +} + +std::pair Map::click(QPoint pos) +{ + Position cell_pos = point_to_indexes_cell(pos); + size_t i = cell_pos.x; + size_t j = cell_pos.y; + if (i == size_t(graphics_controller->count_cell_y())) + return {nullptr, nullptr}; + + Size size_map = graphics_controller->size_map(); + int width_map = size_map.width; + int height_map = size_map.height; + + pos += QPoint{width_map/2, height_map/2}; + pos -= point_of_cell({j, i}); + return {cells[i][j].get(), cells[i][j]->click(pos)}; +} + +QPoint Map::point_of_cell_in_win(Position pos) +{ + Size size_map = graphics_controller->size_map(); + int width_map = size_map.width; + int height_map = size_map.height; + + QPoint corner_of_map = graphics_controller->map_center() - + QPoint{width_map/2, height_map/2}; + return point_of_cell(pos) + corner_of_map; +} + +void Map::set_type_map(TypeMap _type_map) +{ + type_map = _type_map; + calculations()->set_type_content(type_map.type_content); + window()->update(); +} + +const TypeMap& Map::get_type_map() const +{ + return type_map; +} + +int Map::sign(int a) +{ + if (!a) + return 0; + return (a>0) ? 1:-1; +} + +int Map::coord_to_cub_index(int a) +{ + return (a/calculations()->hexagon_height()+sign(a)) / 2; +} + +Position Map::point_to_indexes_cell(QPoint pos) +{ + Size size_map = graphics_controller->size_map(); + int width_map = size_map.width; + int height_map = size_map.height; + + pos += QPoint{width_map/2, height_map/2}; + for(size_t i{0}; i < size_t(graphics_controller->count_cell_x()); ++i) + for(size_t j{0}; j < size_t(graphics_controller->count_cell_y()); ++j){ + if(calculations()->point_in_hexagon(pos - point_of_cell({i, j}))) + return {j, i}; + } + return {graphics_controller->count_cell_y(), graphics_controller->count_cell_x()}; +} + +QPoint Map::point_of_cell(Position pos) +{ + Calculations* calc = calculations(); + + int y = int(pos.y+1)*calc->hexagon_side() + int(pos.y)*calc->hexagon_side()/2; + QPoint cell_point{calc->hexagon_height(), y}; + if (pos.y % 2 == 1) + cell_point += QPoint{calc->hexagon_height(), 0}; + + cell_point += QPoint{calc->hexagon_height()*2*int(pos.x), 0}; + return cell_point; +} diff --git a/Graphics/Map/Map.h b/Graphics/Map/Map.h new file mode 100644 index 0000000..3e7036d --- /dev/null +++ b/Graphics/Map/Map.h @@ -0,0 +1,59 @@ +#ifndef MAP_H +#define MAP_H + +#include +#include + +#include "Cell.h" +#include "IMap.h" +#include "../GameWindow.h" +#include "../GraphicsController/Calculations.h" +#include "../GraphicsController/IMapGraphicsController.h" + + + +class Map : public IMap, public IMapForFind +{ +public: + Map(IMapGraphicsController* graphics_controller); + + // point - центр карты + void do_cells(); + + virtual void draw(QPoint point) override; + virtual QWidget* window() const override; + virtual Calculations* calculations() const override; + + virtual ~Map() override {} + + virtual ICell* icell_by_indexes(Position pos) const override; + Cell* cell_by_indexes(Position pos) const; + Position indexes_by_cell(Cell* cell) const; + Position indexes_by_cell(ICell* cell) const override; + virtual std::vector adjacent_cells(Position pos) const override; + virtual void set_cell_country(Position pos_cell, Countries coutry) override; + virtual Countries get_cell_country(Position pos_cell) override; + std::pair click(QPoint pos); + QPoint point_of_cell_in_win(Position pos); + + virtual void set_type_map(TypeMap type_map) override; + virtual const TypeMap& get_type_map() const override; + +private: + int sign(int a); + int coord_to_cub_index(int a); + + // точка центра клетки относительно левого верхнего угла + QPoint point_of_cell(Position pos); + + // выдает индекс в массиве клетки, + // если точка не в клетки, то выдает {count_cell_y(), count_cell_x()} + Position point_to_indexes_cell(QPoint pos); + + IMapGraphicsController* graphics_controller; + std::vector>> cells; + + TypeMap type_map; +}; + +#endif // MAP_H diff --git a/Graphics/Map/TypeMap.h b/Graphics/Map/TypeMap.h new file mode 100644 index 0000000..8fea5f3 --- /dev/null +++ b/Graphics/Map/TypeMap.h @@ -0,0 +1,26 @@ +#ifndef TYPEMAP_H +#define TYPEMAP_H + +struct TypeMap +{ + enum Overlay { + NoOverlay, + Political, + HighlightResources + }; + + enum TypeContent{ + All, + Nothing, + Units, + Resources, + Building, + }; + + Overlay overplay = NoOverlay; + TypeContent type_content = All; + bool show_notvisible = true; + bool show_other_landscapes = true; +}; + +#endif // TYPEMAP_H diff --git a/Graphics/Menus/ManuStart/StartMenu.cpp b/Graphics/Menus/ManuStart/StartMenu.cpp new file mode 100644 index 0000000..9470eca --- /dev/null +++ b/Graphics/Menus/ManuStart/StartMenu.cpp @@ -0,0 +1,39 @@ +#include "StartMenu.h" + +StartMenu::StartMenu(IMenuStartGraphicsController* _graphics_controller) + :QWidget(_graphics_controller->window()), graphics_controller{_graphics_controller} +{} + +void StartMenu::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); +} + +void StartMenu::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void StartMenu::mousePressEvent(QMouseEvent* event) +{ + mouse_pos_clicked = event->pos(); +} + +void StartMenu::mouseReleaseEvent(QMouseEvent* event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + click(event->pos()); +} + +void StartMenu::draw() +{ + +} + +void StartMenu::click(QPoint pos) +{ + graphics_controller->start_game(); +} diff --git a/Graphics/Menus/ManuStart/StartMenu.h b/Graphics/Menus/ManuStart/StartMenu.h new file mode 100644 index 0000000..a26f48e --- /dev/null +++ b/Graphics/Menus/ManuStart/StartMenu.h @@ -0,0 +1,31 @@ +#ifndef STARTMENU_H +#define STARTMENU_H + +#include +#include + +#include "../../../IObject.h" +#include "../../GraphicsController/IMenuStartGraphicsController.h" + +class StartMenu : public QWidget +{ +public: + StartMenu(IMenuStartGraphicsController* graphics_controller); + + void set_geometry(QPoint pos, Size size); + +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + + void draw(); + void click(QPoint pos); + + IMenuStartGraphicsController* graphics_controller; + + QPoint mouse_pos_clicked; +}; + +#endif // STARTMENU_H diff --git a/Graphics/Menus/MenuInWindow/AMenuInWindow.cpp b/Graphics/Menus/MenuInWindow/AMenuInWindow.cpp new file mode 100644 index 0000000..4862fd2 --- /dev/null +++ b/Graphics/Menus/MenuInWindow/AMenuInWindow.cpp @@ -0,0 +1,42 @@ +#include "AMenuInWindow.h" + +AMenuInWindow::AMenuInWindow(IMenuInWindowGraphicsController* _graphics_controller) + : QWidget{_graphics_controller->window()}, graphics_controller{_graphics_controller} +{ + QWidget::setMouseTracking(true); +} + +void AMenuInWindow::set_geometry(QPoint pos, Size size) +{ + width_menu = size.width; + height_menu = size.height; + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); +} + +void AMenuInWindow::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void AMenuInWindow::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void AMenuInWindow::mouseReleaseEvent(QMouseEvent* event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + click(event->pos()); + +} + +bool AMenuInWindow::point_in_rect(QRectF rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} diff --git a/Graphics/Menus/MenuInWindow/AMenuInWindow.h b/Graphics/Menus/MenuInWindow/AMenuInWindow.h new file mode 100644 index 0000000..ddd7554 --- /dev/null +++ b/Graphics/Menus/MenuInWindow/AMenuInWindow.h @@ -0,0 +1,35 @@ +#ifndef AMENUINWINDOW_H +#define AMENUINWINDOW_H + +#include +#include + +#include "../../GraphicsController/IMenuGraphicsController.h" + + +class AMenuInWindow : public QWidget +{ +public: + AMenuInWindow(IMenuInWindowGraphicsController* graphics_controller); + + virtual void set_geometry(QPoint pos, Size size); + +protected: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + + virtual void draw() = 0; + virtual void click(QPoint pos) = 0; + + bool point_in_rect(QRectF rect, QPoint point); + + int width_menu; + int height_menu; + IMenuInWindowGraphicsController* graphics_controller; + + QPoint mouse_pos_clicked; +}; + +#endif // AMENUINWINDOW_H diff --git a/Graphics/Menus/MenuInWindow/BottomMenu.cpp b/Graphics/Menus/MenuInWindow/BottomMenu.cpp new file mode 100644 index 0000000..3060d25 --- /dev/null +++ b/Graphics/Menus/MenuInWindow/BottomMenu.cpp @@ -0,0 +1,114 @@ +#include "BottomMenu.h" + +BottomMenu::BottomMenu(IMenuInWindowGraphicsController* _graphic_controller) + : AMenuInWindow(_graphic_controller) +{} + +void BottomMenu::update_infofm(Cell* _cell) +{ + cell = _cell; + update(); +} + +void BottomMenu::del_inform() +{ + cell = nullptr; + update(); +} + +QRect BottomMenu::open_type_map_butt() const +{ + QPoint topleft = QPoint{width_menu - 3*height_menu, 0}; + QPoint bottomright = QPoint{width_menu - 2*height_menu, height_menu}; + return QRect{topleft, bottomright}; +} + +void BottomMenu::mouseMoveEvent(QMouseEvent *event) +{ + if(event->pos().y() > height_menu - 5) + graphics_controller->move_map({0, -50}); +} + +void BottomMenu::draw() +{ + draw_text(); + QPainter qp(this); + + QPixmap pixmap = FactoryPixmap().create_pixmap_for_minimap(); + QRectF source = FactoryPixmap().size_picture_content(); + qp.drawPixmap(show_minimap_butt(), pixmap, source); + + QPixmap pixmap2 = FactoryPixmap().create_pixmap_for_nextmotion(); + qp.drawPixmap(next_move_butt(), pixmap2, source); + + QPixmap pixmap3 = FactoryPixmap().create_pixmap_for_type_map(); + qp.drawPixmap(open_type_map_butt(), pixmap3, source); + + QPen pen{Qt::white, 2, Qt::SolidLine}; + qp.setPen(pen); + QPoint p1 = QPoint{0, 0}; + QPoint p2 = QPoint{width_menu, 0}; + qp.drawLine(p1, p2); +} + +void BottomMenu::click(QPoint pos) +{ + if (point_in_rect(show_minimap_butt(), pos)) + graphics_controller->show_minimap(); + else if (point_in_rect(next_move_butt(), pos)) + graphics_controller->next_move(); + else if (point_in_rect(open_type_map_butt(), pos)) + graphics_controller->click_open_menu_type_map(); +} + +void BottomMenu::draw_text() +{ + if(!cell) + return; + ControlContents cc{cell}; + std::stringstream ss; + FactoryString Fstr = FactoryString(); + + ss << "Ландшавт: " << Fstr.landscape_string(cc.get_main_landscape()); + OtherLandscapes otherland = cc.get_other_landscape(); + if(otherland != OtherLandscapes::Nothing) + ss << ", " << Fstr.landscape_string(otherland); + + if(cc.get_country() != Countries::Nothing) + ss << " | Страна: " << Fstr.country_string(cc.get_country()); + + if(cc.has_resource()) + ss << " | Ресурс: " << Fstr.resource_string(cc.get_resource()) << " " << cc.get_count_of_res(); + + if(cc.has_building()) + ss << " | Строение: " << Fstr.build_string(cc.get_building()->what_building_I()); + + auto units = cc.get_units(); + if(units.size()) + { + ss << " | Юниты: " << Fstr.unit_string(units[0]); + for(size_t i{1}; i < units.size(); ++i) + ss << ", " << Fstr.unit_string(units[i]); + ss << " - Страна " << Fstr.country_string(cc.get_country_units()); + } + + QPainter qp(this); + QPen pen{Qt::white, 2, Qt::SolidLine}; + qp.setPen(pen); + QRect rect{0, 0, show_minimap_butt().topLeft().x(), height()}; + qp.drawText(rect, Qt::AlignVCenter, QString::fromStdString(ss.str())); +} + +QRect BottomMenu::show_minimap_butt() const +{ + QPoint topleft = QPoint{width_menu - 2*height_menu, 0}; + QPoint bottomright = QPoint{width_menu - height_menu, height_menu}; + return QRect{topleft, bottomright}; +} + +QRect BottomMenu::next_move_butt() const +{ + QPoint topleft = QPoint{width_menu - height_menu, 0}; + QPoint bottomright = QPoint{width_menu, height_menu}; + return QRect{topleft, bottomright}; +} diff --git a/Graphics/Menus/MenuInWindow/BottomMenu.h b/Graphics/Menus/MenuInWindow/BottomMenu.h new file mode 100644 index 0000000..dd84fca --- /dev/null +++ b/Graphics/Menus/MenuInWindow/BottomMenu.h @@ -0,0 +1,34 @@ +#ifndef BOTTOMMENU_H +#define BOTTOMMENU_H + +#include + +#include "AMenuInWindow.h" +#include "../../Factories/FactoryString.h" +#include "../../GraphicsController/IMenuGraphicsController.h" +#include "../../Map/Cell.h" + + +class BottomMenu : public AMenuInWindow +{ +public: + BottomMenu(IMenuInWindowGraphicsController* graphic_controller); + + void update_infofm(Cell* cell); + void del_inform(); + + QRect open_type_map_butt() const; +protected: + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void draw() override; + virtual void click(QPoint pos) override; + + void draw_text(); + + QRect show_minimap_butt() const; + QRect next_move_butt() const; + + Cell* cell = nullptr; +}; + +#endif // BOTTOMMENU_H diff --git a/Graphics/Menus/MenuInWindow/MenuLists.cpp b/Graphics/Menus/MenuInWindow/MenuLists.cpp new file mode 100644 index 0000000..489d9e7 --- /dev/null +++ b/Graphics/Menus/MenuInWindow/MenuLists.cpp @@ -0,0 +1,17 @@ +#include "MenuLists.h" + +MenuLists::MenuLists(IMenuInWindowGraphicsController* graphics_controller) + :AMenuInWindow(graphics_controller) +{} + +void MenuLists::draw() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 2}); + qp.drawText(QRect{0, 0, width(), height()}, Qt::AlignCenter, QString("Меню науки")); +} + +void MenuLists::click(QPoint pos) +{ + graphics_controller->open_menu_science(); +} diff --git a/Graphics/Menus/MenuInWindow/MenuLists.h b/Graphics/Menus/MenuInWindow/MenuLists.h new file mode 100644 index 0000000..6efe17a --- /dev/null +++ b/Graphics/Menus/MenuInWindow/MenuLists.h @@ -0,0 +1,14 @@ +#ifndef MENULISTS_H +#define MENULISTS_H + +#include "AMenuInWindow.h" + +class MenuLists : public AMenuInWindow +{ +public: + MenuLists(IMenuInWindowGraphicsController* graphics_controller); + virtual void draw() override; + virtual void click(QPoint pos) override; +}; + +#endif // MENULISTS_H diff --git a/Graphics/Menus/MenuInWindow/OpenMenuLists.cpp b/Graphics/Menus/MenuInWindow/OpenMenuLists.cpp new file mode 100644 index 0000000..bcd78b8 --- /dev/null +++ b/Graphics/Menus/MenuInWindow/OpenMenuLists.cpp @@ -0,0 +1,38 @@ +#include "OpenMenuLists.h" + +OpenMenuLists::OpenMenuLists(IMenuInWindowGraphicsController* graphics_controller) + :AMenuInWindow(graphics_controller) +{} + +void OpenMenuLists::draw() +{ + QPainter qp(this); + QPixmap pixmap; + if(is_menu_open) + pixmap = FactoryPixmap().create_pixmap_for_up_in_queue(); + else + pixmap = FactoryPixmap().create_pixmap_for_down_in_queue(); + + QRectF source = FactoryPixmap().size_picture_content(); + QRect rect = QRect{0, 0, width(), height()}; + qp.drawPixmap(rect, pixmap, source); + qp.setPen(QPen{Qt::white}); + qp.drawRect(rect); +} + +void OpenMenuLists::click(QPoint pos) +{ + Q_UNUSED(pos) + if(is_menu_open) + graphics_controller->close_menu_lists(); + else + graphics_controller->open_menu_lists(); + is_menu_open = !is_menu_open; + update(); +} + +void OpenMenuLists::switch_arrow() +{ + is_menu_open = !is_menu_open; + update(); +} diff --git a/Graphics/Menus/MenuInWindow/OpenMenuLists.h b/Graphics/Menus/MenuInWindow/OpenMenuLists.h new file mode 100644 index 0000000..a0d23e8 --- /dev/null +++ b/Graphics/Menus/MenuInWindow/OpenMenuLists.h @@ -0,0 +1,22 @@ +#ifndef OPENMENULISTS_H +#define OPENMENULISTS_H + +#include + +#include "AMenuInWindow.h" +#include "../../GraphicsController/IMenuGraphicsController.h" + +class OpenMenuLists : public AMenuInWindow +{ +public: + OpenMenuLists(IMenuInWindowGraphicsController* graphics_controller); + virtual void draw() override; + virtual void click(QPoint pos) override; + void switch_arrow(); + +private: + bool is_menu_open = false; + +}; + +#endif // OPENMENULISTS_H diff --git a/Graphics/Menus/MenuInWindow/UpperMenu.cpp b/Graphics/Menus/MenuInWindow/UpperMenu.cpp new file mode 100644 index 0000000..e25712a --- /dev/null +++ b/Graphics/Menus/MenuInWindow/UpperMenu.cpp @@ -0,0 +1,199 @@ +#include "UpperMenu.h" +#include + +UpperMenu::UpperMenu(IMenuInWindowGraphicsController* _graphic_controller) + : AMenuInWindow(_graphic_controller) +{ + QWidget::setMouseTracking(true); +} + +void UpperMenu::update_infofm(IMenuTownPlayer* player) +{ + count_gold = int(player->get_gold()); + count_gold_per_turn = int(player->get_gold_per_turn()); + count_science_per_turn = int(player->get_science_per_turn()); + + draw_res.clear(); + PlayerRes* player_res = player->get_player_res(); + for(int i{0}; i < CountInEnums().resources(); ++i) + { + if(Resources(i) == Resources::Fish || Resources(i) == Resources::Gold || + Resources(i) == Resources::Silver) + continue; + + int count = player_res->get_resource(Resources(i)); + draw_res.push_back({Resources(i), count}); + } + update(); +} + +void UpperMenu::mouseMoveEvent(QMouseEvent *event) +{ + graphics_controller->del_inform_widget(); + if(enable_move_map) + if(event->pos().y() < 5) + graphics_controller->move_map({0, 50}); +} + +void UpperMenu::set_enable_move_map(bool _enable_move_map) +{ + enable_move_map = _enable_move_map; +} + +void UpperMenu::draw() +{ + draw_gold(); + draw_science(); + draw_resource(); + + QPainter qp(this); + + QPixmap pixmap = FactoryPixmap().create_pixmap_for_exit(); + QRectF source = FactoryPixmap().size_picture_content(); + qp.drawPixmap(exit_butt(), pixmap, source); + + QPen pen{Qt::white, 2, Qt::SolidLine}; + qp.setPen(pen); + QPoint p1 = QPoint{0, height_menu}; + QPoint p2 = QPoint{width_menu, height_menu}; + qp.drawLine(p1, p2); + + qp.drawLine(QPoint{rect_science_pic().bottomRight().x() + 2, 0}, + QPoint{rect_science_pic().topRight().x() + 2, height()}); +} + +QRect UpperMenu::exit_butt() const +{ + QPoint topleft = QPoint{width_menu - height_menu, 0}; + QPoint bottomright = QPoint{width_menu, height_menu}; + return QRect{topleft, bottomright}; +} + +void UpperMenu::click(QPoint pos) +{ + if (point_in_rect(exit_butt(), pos)) + graphics_controller->exit(); +} + +void UpperMenu::draw_gold() +{ + QPainter qp(this); + QColor color = Qt::white; + if(count_gold_per_turn < 0) + color = Qt::red; + + qp.setPen(QPen{color, 2, Qt::SolidLine}); + QRect rect = rect_gold_pic(); + QPixmap pixmap = FactoryPixmap().create_pixmap_for_gold(); + QRectF source = FactoryPixmap().size_picture_gold(); + qp.drawPixmap(rect, pixmap, source); + + std::stringstream ss; + + ss << count_gold << " ("; + if(count_gold_per_turn > 0) + ss << "+"; + + ss << count_gold_per_turn << ")"; + QRect rect2 = rect_gold(); + qp.drawText(rect2, Qt::AlignVCenter | Qt::AlignRight, QString::fromStdString(ss.str())); +} + +void UpperMenu::draw_science() +{ + QPainter qp(this); + QColor color = Qt::white; + if(count_science_per_turn < 0) + color = Qt::red; + + qp.setPen(QPen{color, 2, Qt::SolidLine}); + QRect rect = rect_science_pic(); + QPixmap pixmap = FactoryPixmap().create_pixmap_for_science(); + QRectF source = FactoryPixmap().size_picture_gold(); + qp.drawPixmap(rect, pixmap, source); + + std::stringstream ss; + + if(count_science_per_turn > 0) + ss << "+"; + + ss << count_science_per_turn; + QRect rect2 = rect_science(); + qp.drawText(rect2, Qt::AlignVCenter | Qt::AlignRight, QString::fromStdString(ss.str())); +} + +void UpperMenu::draw_resource() +{ + QPainter qp(this); + + for(size_t i{0}; i < draw_res.size(); ++i) + { + QColor color = Qt::white; + if(draw_res[i].count_res < 0) + color = Qt::red; + + qp.setPen(QPen{color, 2, Qt::SolidLine}); + QRect rect = rect_res_pic(i); + QPixmap pixmap = FactoryPixmap().create_pixmap_for_res(draw_res[i].res); + QRectF source = FactoryPixmap().size_picture_content(); + qp.drawPixmap(rect, pixmap, source); + + std::stringstream ss; + + if(draw_res[i].count_res > 0) + ss << "+"; + + ss << draw_res[i].count_res; + QRect rect2 = rect_res(i); + qp.drawText(rect2, Qt::AlignVCenter | Qt::AlignRight, QString::fromStdString(ss.str())); + } +} + +QRect UpperMenu::rect_gold() const +{ + return QRect{0, 0, + height() * (count_simbols(count_gold) + count_simbols(count_gold_per_turn)+3)/4, height()}; +} + +QRect UpperMenu::rect_gold_pic() const +{ + return QRect{rect_gold().bottomRight().x(), height()/4, height()/2, height()/2}; +} + +QRect UpperMenu::rect_science() const +{ + return QRect{rect_gold_pic().bottomRight().x(), 0, + height() * (count_simbols(count_science_per_turn)+1)/4, height()}; +} + +QRect UpperMenu::rect_science_pic() const +{ + return QRect{rect_science().bottomRight().x(), height()/4, height()/2, height()/2}; +} + +QRect UpperMenu::rect_res(size_t num) const +{ + if(num == 0) + return QRect{rect_science_pic().bottomRight().x(), 0, + height() * (count_simbols(draw_res[num].count_res)+1)/4, height()}; + return QRect{rect_res_pic(num-1).bottomRight().x(), 0, + height() * (count_simbols(draw_res[num].count_res)+1)/4, height()}; +} + +QRect UpperMenu::rect_res_pic(size_t num) const +{ + return QRect{rect_res(num).bottomRight().x(), height()/4, height()/2, height()/2}; +} + +int UpperMenu::count_simbols(int a) const +{ + a = std::abs(a); + int count = 0; + while(a != 0){ + a /= 10; + ++count; + } + if(count) + return count; + return 1; +} diff --git a/Graphics/Menus/MenuInWindow/UpperMenu.h b/Graphics/Menus/MenuInWindow/UpperMenu.h new file mode 100644 index 0000000..3cb4404 --- /dev/null +++ b/Graphics/Menus/MenuInWindow/UpperMenu.h @@ -0,0 +1,61 @@ +#ifndef UPPERMENU_H +#define UPPERMENU_H + +#include + +#include +#include + +#include "AMenuInWindow.h" +#include "../../Factories/FactoryPixmap.h" +#include "../../GraphicsController/IMenuGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" + + +class UpperMenu : public AMenuInWindow +{ + struct DrawRes + { + Resources res; + int count_res; + + DrawRes(Resources _res, int _count_res) + :res{_res}, count_res{_count_res} + {} + }; + +public: + UpperMenu(IMenuInWindowGraphicsController* graphic_controller); + + void set_enable_move_map(bool enable_move_map); + void update_infofm(IMenuTownPlayer* player); + +protected: + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void draw() override; + virtual void click(QPoint pos) override; + QRect exit_butt() const; + + void draw_gold(); + void draw_science(); + void draw_resource(); + + QRect rect_gold() const; + QRect rect_gold_pic() const; + QRect rect_science() const; + QRect rect_science_pic() const; + QRect rect_res(size_t num) const; + QRect rect_res_pic(size_t num) const; + + int count_simbols(int a) const; + + + bool enable_move_map = true; + + std::vector draw_res; + int count_gold = 0; + int count_gold_per_turn = 0; + int count_science_per_turn = 0; +}; + +#endif // UPPERMENU_H diff --git a/Graphics/Menus/MenuScience/IMenuScience.h b/Graphics/Menus/MenuScience/IMenuScience.h new file mode 100644 index 0000000..32ebce0 --- /dev/null +++ b/Graphics/Menus/MenuScience/IMenuScience.h @@ -0,0 +1,16 @@ +#ifndef IMENUSCIENCE_H +#define IMENUSCIENCE_H + +#include + +class IMenuScience : public QWidget +{ +public: + virtual void wheel_scroll(int angle) = 0; +protected: + IMenuScience(QWidget* win) + :QWidget{win} + {} +}; + +#endif // IMENUSCIENCE_H diff --git a/Graphics/Menus/MenuScience/MenuScience.cpp b/Graphics/Menus/MenuScience/MenuScience.cpp new file mode 100644 index 0000000..bc5f408 --- /dev/null +++ b/Graphics/Menus/MenuScience/MenuScience.cpp @@ -0,0 +1,227 @@ +#include "MenuScience.h" +#include + +MenuScience::MenuScience(IMenuInWindowGraphicsController* _graphics_controller, PlayerScience* _player_science) + :IMenuScience{_graphics_controller->window()}, graphics_controller{_graphics_controller}, + player_science{_player_science} +{ + QWidget::setAttribute( Qt::WA_TranslucentBackground, true ); +} + +void MenuScience::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); + update_information(); +} + +void MenuScience::wheel_scroll(int angle) +{ + indent_x -= angle; + if(indent_x > 0) + indent_x = 0; + else if(indent_x + end_widgets() < width()) + indent_x = width() - end_widgets(); + + set_geometry_widgets(); + update(); +} + +void MenuScience::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); + draw_queue(); + draw_connections(); + draw_scroll(); +} + +void MenuScience::mousePressEvent(QMouseEvent* event) +{ + mouse_pos_clicked = event->pos(); +} + +void MenuScience::mouseReleaseEvent(QMouseEvent* event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + click(event->pos()); +} + +void MenuScience::wheelEvent(QWheelEvent* event) +{ + wheel_scroll(event->angleDelta().y()); +} + +void MenuScience::update_information() +{ + knowledges.clear(); + Science science; + + init_space_x = width()/20; + init_space_y = height()/20; + space_x = width()/8; + space_y = height()/20; + size_block = {width()/7, height()/15}; + scroll_height = height()/50; + count_columns = 0; + for(auto name_knowledge : Science().get_all_name_knowledges()) + { + Knowledge knowledge = Science().get_knowledge(name_knowledge); + if (knowledge.position_knowledge.num_x > count_columns) + count_columns = knowledge.position_knowledge.num_x; + + knowledges.push_back(std::unique_ptr{ + new WidgetKnowledge(graphics_controller, this, knowledge, player_science)}); + knowledges.back()->hide(); + knowledges.back()->show(); + for(auto& need_knowledges : knowledge.necessary_knowledges) + { + PositionKnowledge need_know_pos = Science().get_knowledge(need_knowledges).position_knowledge; + connections.push_back({need_know_pos, knowledge.position_knowledge}); + } + } + count_columns++; + set_geometry_widgets(); +} + +void MenuScience::draw() +{ + QPainter qp(this); + + QRect rect{0, 0, width(), height()}; + qp.fillRect(rect, QBrush(QColor(0, 0, 0, 200))); + qp.setPen(QPen{Qt::white}); + qp.drawRect(rect_but_close()); + qp.drawText(rect_but_close(), Qt::AlignCenter, QString("Закрыть")); +} + +void MenuScience::draw_connections() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 3, Qt::SolidLine}); + for(Connection& connection : connections) + { + QPoint pos_begin_wid = pos_knowledge_widget(connection.begin); + QPoint begin = pos_begin_wid + QPoint{size_block.width, size_block.height/2}; + + QPoint pos_end_wid = pos_knowledge_widget(connection.end); + QPoint end = pos_end_wid + QPoint{0, size_block.height/2}; + + if(end.y() == begin.y()) + { + qp.drawLine(begin, end); + continue; + } + + QPoint p1{end.x() - space_x/2, begin.y()}; + QPoint p2{end.x() - space_x/2, end.y()}; + + int rad_rounding = std::min(space_x,space_y)/3; + + if(begin.y() > end.y()) + { + qp.drawLine(begin, p1 - QPoint(rad_rounding, 0)); + qp.drawArc(QRectF{p1 - QPoint(2*rad_rounding, 2*rad_rounding), p1}, 0, -90 * 16); + qp.drawLine(p1 - QPoint(0, rad_rounding), p2 + QPoint(0, rad_rounding)); + qp.drawArc(QRectF{p2, p2 + QPoint(2*rad_rounding, 2*rad_rounding)}, 90 * 16, 90 * 16); + qp.drawLine(p2 + QPoint(rad_rounding, 0), end); + } + else + { + qp.drawLine(begin, p1 - QPoint(rad_rounding, 0)); + qp.drawArc(QRectF{p1 - QPoint(2*rad_rounding, 0), + p1 + QPoint(0, 2*rad_rounding)}, 0, 90 * 16); + qp.drawLine(p1 + QPoint(0, rad_rounding), p2 - QPoint(0, rad_rounding)); + qp.drawArc(QRectF{p2 - QPoint(0, 2*rad_rounding), + p2 + QPoint(2*rad_rounding, 0)}, 180 * 16, 90 * 16); + qp.drawLine(p2 +QPoint(rad_rounding, 0), end); + } + } +} + +void MenuScience::draw_scroll() +{ + if(end_widgets() < width()) + return; + + QPainter qp(this); + + int scroll_begin = -indent_x*width()/end_widgets(); + int scroll_end = (-indent_x+width())*width()/end_widgets(); + + QRect rect{QPoint{scroll_begin, height()-scroll_height}, QPoint{scroll_end, height()}}; + + qp.fillRect(rect, QBrush{Qt::blue}); + + qp.setPen(QPen{Qt::white}); + qp.drawRect(QRect{0, height()-scroll_height, width(), scroll_height}); +} + +void MenuScience::draw_queue() +{ + auto& queue = player_science->get_queue_science(); + if(queue.size() < 2) + return; + + QPainter qp(this); + qp.setPen(QPen{Qt::white}); + + auto science = Science(); + for(size_t i{1}; i < queue.size(); ++i) + { + auto pos_knowledge = science.get_knowledge(queue[i]).position_knowledge; + QPoint pos_rect = pos_knowledge_widget(pos_knowledge) + QPoint{size_block.width, 0}; + QPoint size_rect{size_block.height/4, size_block.height/4}; + QRect rect{pos_rect, pos_rect+size_rect}; + + qp.drawEllipse(rect); + std::stringstream ss; + ss << i; + qp.drawText(rect, Qt::AlignCenter, QString::fromStdString(ss.str())); + } +} + +void MenuScience::click(QPoint pos) +{ + if(point_in_rect(rect_but_close(), pos)) + graphics_controller->close_menu_science(); +} + +void MenuScience::set_geometry_widgets() +{ + for(auto& knowledge : knowledges) + { + auto pos_knowledge = knowledge->get_knowledge().position_knowledge; + + QPoint pos = pos_knowledge_widget(pos_knowledge); + knowledge->set_geometry(pos, size_block); + } +} + +int MenuScience::end_widgets() +{ + return count_columns*(space_x + size_block.width) + init_space_x*2 - space_x; +} + +QPoint MenuScience::pos_knowledge_widget(PositionKnowledge pos) const +{ + return QPoint{pos.num_x*(space_x + size_block.width) + init_space_x + indent_x, + pos.num_y*(space_y + size_block.height) + init_space_y}; +} + +QRect MenuScience::rect_but_close() const +{ + Size size{width()/20, height()/20}; + int a = height()/50; + QPoint pos{width() - size.width - a, height() - size.height - a - scroll_height}; + return QRect{pos.x(), pos.y(), size.width, size.height}; +} + +bool MenuScience::point_in_rect(QRectF rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} diff --git a/Graphics/Menus/MenuScience/MenuScience.h b/Graphics/Menus/MenuScience/MenuScience.h new file mode 100644 index 0000000..f3b7f62 --- /dev/null +++ b/Graphics/Menus/MenuScience/MenuScience.h @@ -0,0 +1,69 @@ +#ifndef MENUSCIENCE_H +#define MENUSCIENCE_H + +#include + +#include +#include + +#include "IMenuScience.h" +#include "WidgetKnowledge.h" +#include "../../GraphicsController/IMenuGraphicsController.h" +#include "../../../Controllers/Player/PlayerScience.h" +#include "../../../Controllers/Science.h" + +struct Connection +{ + PositionKnowledge begin; + PositionKnowledge end; +}; + +class MenuScience : public IMenuScience +{ +public: + MenuScience(IMenuInWindowGraphicsController* graphics_controller, + PlayerScience* player_science); + + void set_geometry(QPoint pos, Size size); + + virtual void wheel_scroll(int angle) override; +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + + void update_information(); + void draw(); + void draw_connections(); + void draw_scroll(); + void draw_queue(); + void click(QPoint pos); + void set_geometry_widgets(); + + int end_widgets(); + QPoint pos_knowledge_widget(PositionKnowledge pos) const; + QRect rect_but_close() const; + bool point_in_rect(QRectF rect, QPoint point); + + IMenuInWindowGraphicsController* graphics_controller; + PlayerScience* player_science; + + std::vector> knowledges; + std::vector connections; + + QPoint mouse_pos_clicked; + + int init_space_x; + int init_space_y; + int space_x; + int space_y; + Size size_block; + int indent_x = 0; + int scroll_height; + int count_columns = 0; +}; + + +#endif // MENUSCIENCE_H diff --git a/Graphics/Menus/MenuScience/WidgetKnowledge.cpp b/Graphics/Menus/MenuScience/WidgetKnowledge.cpp new file mode 100644 index 0000000..258f891 --- /dev/null +++ b/Graphics/Menus/MenuScience/WidgetKnowledge.cpp @@ -0,0 +1,149 @@ +#include "WidgetKnowledge.h" +#include + +WidgetKnowledge::WidgetKnowledge(IMenuInWindowGraphicsController* _graphics_controller, + IMenuScience* _menu_science, + Knowledge _knowledge, PlayerScience* _player_sience) + :QWidget{_graphics_controller->window()}, graphics_controller{_graphics_controller}, + menu_science{_menu_science}, knowledge{_knowledge}, player_sience{_player_sience} +{} + + +void WidgetKnowledge::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); +} + +const Knowledge& WidgetKnowledge::get_knowledge() const +{ + return knowledge; +} + +void WidgetKnowledge::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void WidgetKnowledge::mousePressEvent(QMouseEvent* event) +{ + mouse_pos_clicked = event->pos(); +} + +void WidgetKnowledge::mouseReleaseEvent(QMouseEvent* event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + click(event->pos()); +} + +void WidgetKnowledge::wheelEvent(QWheelEvent *event) +{ + menu_science->wheel_scroll(event->angleDelta().y()); +} + +void WidgetKnowledge::draw() +{ + draw_wid(); + draw_knowledge_pixmap(); + draw_text(); + draw_open(); +} + +void WidgetKnowledge::draw_wid() +{ + QPainter qp(this); + + qp.setPen(QPen(Qt::white, 3)); + qp.drawRect(QRect{0, 0, width(), height()}); + if(player_sience->get_queue_science().size() > 0 && + player_sience->get_queue_science()[0] == knowledge.name_knowledge) + qp.fillRect(QRect{0, 0, width(), height()}, QBrush(QColor(Qt::yellow))); + else if(player_sience->is_knowledge_open(knowledge.name_knowledge)) + qp.fillRect(QRect{0, 0, width(), height()}, QBrush(QColor(Qt::green))); +} + +void WidgetKnowledge::draw_knowledge_pixmap() +{ + QPainter qp(this); + + QRect rect_knowledge = rect_knowledge_pixmap(); + QPixmap knowledge_pixmap = FactoryPixmap().create_pixmap_for_knowledges(knowledge.name_knowledge); + qp.drawPixmap(rect_knowledge, knowledge_pixmap); +} + +void WidgetKnowledge::draw_text() +{ + QPainter qp(this); + if(player_sience->get_queue_science().size() > 0 && + player_sience->get_queue_science()[0] == knowledge.name_knowledge) + qp.setPen(Qt::black); + else if(player_sience->is_knowledge_open(knowledge.name_knowledge)) + qp.setPen(Qt::black); + else + qp.setPen(Qt::white); + + QString text = QString::fromStdString(FactoryString().knowledge_string(knowledge.name_knowledge)); + qp.drawText(rect_text(), Qt::AlignVCenter, text); +} + +void WidgetKnowledge::draw_open() +{ + QPainter qp(this); + + auto factory_pixmap = FactoryPixmap(); + + int num = 0; + for(auto& res : knowledge.resources) + { + QRect rect = rect_open_pixmap(num++); + QPixmap pixmap = factory_pixmap.create_pixmap_for_res(res); + qp.drawPixmap(rect, pixmap); + } + for(auto& building : knowledge.buildings) + { + QRect rect = rect_open_pixmap(num++); + QPixmap pixmap = factory_pixmap.create_pixmap_for_building(building); + qp.drawPixmap(rect, pixmap); + } + for(auto& town_building : knowledge.town_buildings) + { + QRect rect = rect_open_pixmap(num++); + QPixmap pixmap = factory_pixmap.create_pixmap_for_town_building(town_building.town_building); + qp.drawPixmap(rect, pixmap); + } + for(auto& unit : knowledge.units) + { + QRect rect = rect_open_pixmap(num++); + QPixmap pixmap = factory_pixmap.create_pixmap_for_unit(unit); + qp.drawPixmap(rect, pixmap); + } +} + +void WidgetKnowledge::click(QPoint pos) +{ + Q_UNUSED(pos) + if(!player_sience->is_knowledge_open(knowledge.name_knowledge)) + player_sience->set_study_knowledge(knowledge.name_knowledge); + menu_science->update(); +} + +QRect WidgetKnowledge::rect_knowledge_pixmap() const +{ + return QRect{0, 0, height(), height()}; +} + +QRect WidgetKnowledge::rect_text() const +{ + return QRect{rect_knowledge_pixmap().topRight(), QPoint{width(), height()/3}}; +} + +QRect WidgetKnowledge::rect_open_pixmap(int num) const +{ + QPoint pos{rect_text().bottomLeft()}; + int rect_side = height() - pos.y(); + int space = rect_side/5; + pos += QPoint(num*(rect_side+space) + space, 0); + return QRect{pos.x(), pos.y(), rect_side, rect_side}; +} diff --git a/Graphics/Menus/MenuScience/WidgetKnowledge.h b/Graphics/Menus/MenuScience/WidgetKnowledge.h new file mode 100644 index 0000000..3726d2d --- /dev/null +++ b/Graphics/Menus/MenuScience/WidgetKnowledge.h @@ -0,0 +1,51 @@ +#ifndef WIDGETKNOWLEDGE_H +#define WIDGETKNOWLEDGE_H + +#include +#include + +#include "IMenuScience.h" +#include "../../Factories/FactoryPixmap.h" +#include "../../Factories/FactoryString.h" +#include "../../GraphicsController/IMenuGraphicsController.h" +#include "../../../Controllers/Player/PlayerScience.h" +#include "../../../Controllers/Science.h" + + +class WidgetKnowledge : public QWidget +{ +public: + WidgetKnowledge(IMenuInWindowGraphicsController* graphics_controller, + IMenuScience* menu_science, + Knowledge knowledge, PlayerScience* player_sience); + + void set_geometry(QPoint pos, Size size); + const Knowledge& get_knowledge() const; +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + + void draw(); + void draw_wid(); + void draw_knowledge_pixmap(); + void draw_text(); + void draw_open(); + + void click(QPoint pos); + + QRect rect_knowledge_pixmap() const; + QRect rect_text() const; + QRect rect_open_pixmap(int num) const; + + IMenuInWindowGraphicsController* graphics_controller; + IMenuScience* menu_science; + Knowledge knowledge; + PlayerScience* player_sience; + + QPoint mouse_pos_clicked; +}; + +#endif // WIDGETKNOWLEDGE_H diff --git a/Graphics/Menus/MenuTown/AWidgetTown.cpp b/Graphics/Menus/MenuTown/AWidgetTown.cpp new file mode 100644 index 0000000..d9d9be8 --- /dev/null +++ b/Graphics/Menus/MenuTown/AWidgetTown.cpp @@ -0,0 +1,78 @@ +#include "AWidgetTown.h" +#include + +AWidgetTown::AWidgetTown(QWidget* win, TypeWork _type_widget) + :QWidget{win}, type_widget{_type_widget} +{} + +void AWidgetTown::draw_butt() +{ + if(type_widget == InQueue) + { + QPainter qp(this); + + QPixmap pixmap = FactoryPixmap().create_pixmap_for_del_in_queue(); + QRectF source = FactoryPixmap().size_picture_content(); + qp.drawPixmap(rect_butt_del(), pixmap, source); + + if(num_from_queue() != 0) + { + pixmap = FactoryPixmap().create_pixmap_for_up_in_queue(); + source = FactoryPixmap().size_picture_content(); + qp.drawPixmap(rect_butt_up(), pixmap, source); + } + + if(num_from_queue() + 1 != count_from_queue()) + { + pixmap = FactoryPixmap().create_pixmap_for_down_in_queue(); + source = FactoryPixmap().size_picture_content(); + qp.drawPixmap(rect_butt_down(), pixmap, source); + } + } +} + +void AWidgetTown::draw_enable() +{ + if(!enable && type_widget == Build) + { + QPainter qp(this); + qp.fillRect(QRect(0,0, width(), height()), QBrush(QColor(0, 0, 0, 100))); + } +} + +QRect AWidgetTown::rect_butt_del() +{ + int side_butt = height()/2; + return QRect{QPoint{width() - side_butt - height()/10, height()/4}, + QPoint{width() - height()/10, height()/4 + side_butt}}; +} + +bool AWidgetTown::point_in_rect(QRectF rect, QPoint point) const +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} + +QRect AWidgetTown::rect_butt_up() +{ + int side_butt = height()/2; + int a = side_butt; + if(num_from_queue() + 1 != count_from_queue()) + a += side_butt; + return QRect{QPoint{width() - a - side_butt - height()/10, height()/4}, + QPoint{width() - a - height()/10, height()/4 + side_butt}}; +} + +QRect AWidgetTown::rect_butt_down() +{ + int side_butt = height()/2; + return QRect{QPoint{width() - 2*side_butt - height()/10, height()/4}, + QPoint{width() - side_butt - height()/10, height()/4 + side_butt}}; +} + +QRect AWidgetTown::rect_pic() +{ + return QRect{QPoint{0,0}, QPoint{height(), height()}}; +} diff --git a/Graphics/Menus/MenuTown/AWidgetTown.h b/Graphics/Menus/MenuTown/AWidgetTown.h new file mode 100644 index 0000000..6586779 --- /dev/null +++ b/Graphics/Menus/MenuTown/AWidgetTown.h @@ -0,0 +1,44 @@ +#ifndef AWIDGETTOWN_H +#define AWIDGETTOWN_H + +#include +#include +#include + +#include "../../Factories/FactoryPixmap.h" + + +class AWidgetTown : public QWidget +{ +public: + enum TypeWidget{ + ForUnit, + ForBuilding + }; + + enum TypeWork{ + Build, + InQueue, + AlreadyBuild + }; + + AWidgetTown(QWidget* win, TypeWork type_widget); + virtual TypeWidget who_i() const = 0; + +protected: + virtual void draw_butt(); + void draw_enable(); + QRect rect_butt_del(); + QRect rect_butt_up(); + QRect rect_butt_down(); + QRect rect_pic(); + bool point_in_rect(QRectF rect, QPoint point) const; + + virtual size_t num_from_queue() = 0; + virtual size_t count_from_queue() = 0; + + TypeWork type_widget; + bool enable = true; +}; + +#endif // AWIDGETTOWN_H diff --git a/Graphics/Menus/MenuTown/IMenuTown.h b/Graphics/Menus/MenuTown/IMenuTown.h new file mode 100644 index 0000000..fbae047 --- /dev/null +++ b/Graphics/Menus/MenuTown/IMenuTown.h @@ -0,0 +1,47 @@ +#ifndef IMENUTOWN_H +#define IMENUTOWN_H + +#include + +#include "AWidgetTown.h" +#include "../../GraphicsController/IMenuGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" +#include "../../../IObject.h" + + +class IMenuTown : public IObject +{ +public: + enum TypeWork + { + EditProject, + AddQueue + }; + + virtual ITownMenuGraphicsController* graphics_controller() const = 0; + virtual QWidget* window() const = 0; + virtual PlayerTown* town() const = 0; + virtual IMenuTownPlayer* player() const = 0; + + virtual void delete_townmenu() = 0; + virtual void open_menu_build() = 0; + virtual void open_menu_alreadybuild() = 0; + + virtual void set_build(Units type_unit) = 0; + virtual void set_build(TownBuildings type_building) = 0; + virtual void del_build_from_queue(AWidgetTown* wid) = 0; + virtual size_t num_from_queue(AWidgetTown* wid) const = 0; + virtual size_t count_from_queue() const = 0; + virtual void move_up_build(AWidgetTown* wid) = 0; + virtual void move_down_build(AWidgetTown* wid) = 0; + virtual void wheel_scroll(int angle_delta) = 0; + + virtual void do_inform_widget(std::vector> text) = 0; + virtual void del_inform_widget() = 0; + + virtual void set_type_work(TypeWork _type_work) = 0; + virtual TypeWork get_type_work() const = 0; +}; + +#endif // IMENUTOWN_H diff --git a/Graphics/Menus/MenuTown/InformWidget.cpp b/Graphics/Menus/MenuTown/InformWidget.cpp new file mode 100644 index 0000000..5576761 --- /dev/null +++ b/Graphics/Menus/MenuTown/InformWidget.cpp @@ -0,0 +1,38 @@ +#include "InformWidget.h" +#include + +InformWidget::InformWidget(QWidget* parent) + :QWidget{parent} +{ + setAttribute(Qt::WA_TransparentForMouseEvents); +} + +void InformWidget::set_set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(QRect{pos.x(), pos.y(), size.width, size.height}); +} + +void InformWidget::set_text(std::vector> _text) +{ + text = _text; +} + +void InformWidget::paintEvent(QPaintEvent* event) +{ + draw(); +} + +void InformWidget::draw() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 2}); +// std::cout << text.toStdString() << std::endl; + QFontMetrics fm = qp.fontMetrics(); + resize(width(), fm.height()*int(text.size())); + for(size_t i{}; i < text.size(); ++i) + { + QRect rect_str{0, fm.height()*int(i), width(), height()/int(text.size())}; + qp.setPen(text[i].second); + qp.drawText(rect_str, Qt::AlignVCenter, text[i].first); + } +} diff --git a/Graphics/Menus/MenuTown/InformWidget.h b/Graphics/Menus/MenuTown/InformWidget.h new file mode 100644 index 0000000..4bf1ec1 --- /dev/null +++ b/Graphics/Menus/MenuTown/InformWidget.h @@ -0,0 +1,26 @@ +#ifndef INFORMWIDGET_H +#define INFORMWIDGET_H + +#include +#include + +#include "../../../IObject.h" + + +class InformWidget : public QWidget +{ +public: + InformWidget(QWidget* parent); + + void set_set_geometry(QPoint pos, Size size); + void set_text(std::vector> text); + +private: + virtual void paintEvent(QPaintEvent* event) override; + + void draw(); + + std::vector> text; +}; + +#endif // INFORMWIDGET_H diff --git a/Graphics/Menus/MenuTown/MenuAlreadyBuildTown.cpp b/Graphics/Menus/MenuTown/MenuAlreadyBuildTown.cpp new file mode 100644 index 0000000..3243e24 --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuAlreadyBuildTown.cpp @@ -0,0 +1,137 @@ +#include "MenuAlreadyBuildTown.h" + +MenuAlreadyBuildTown::MenuAlreadyBuildTown(IMenuTown* _menu_town) + :QWidget{_menu_town->window()}, menu_town{_menu_town} +{ + QWidget::setAttribute( Qt::WA_TranslucentBackground, true ); + QWidget::setMouseTracking(true); +} + +void MenuAlreadyBuildTown::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); + height_rect_build = size.height/20; + pos_menu = pos; + width_scroll = width()/50; + do_buildings(); + set_geometry_buildings(); +} + +void MenuAlreadyBuildTown::update_inform() +{ + do_buildings(); + set_geometry_buildings(); + update(); +} + +void MenuAlreadyBuildTown::wheel_scroll(int angle_delta) +{ + scroll_indent += angle_delta; + + int count_wid = int(widget_town_buildings.size()); + if(scroll_indent + height_rect_build * count_wid < height()) + scroll_indent = height() - height_rect_build * count_wid; + if(scroll_indent > 0) + scroll_indent = 0; + + set_geometry_buildings(); + update(); +} + +void MenuAlreadyBuildTown::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); + draw_scroll(); +} + +void MenuAlreadyBuildTown::mouseMoveEvent(QMouseEvent *event) +{ + Q_UNUSED(event) + menu_town->del_inform_widget(); +} + +void MenuAlreadyBuildTown::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void MenuAlreadyBuildTown::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; +} + +void MenuAlreadyBuildTown::wheelEvent(QWheelEvent* event) +{ + int angle_delta = event->angleDelta().y(); + wheel_scroll(angle_delta); +} + +void MenuAlreadyBuildTown::draw() +{ + QPainter qp(this); + QRect rect{0, 0, width(), height()}; + qp.fillRect(rect, QBrush(QColor(0, 0, 0, 200))); +} + +void MenuAlreadyBuildTown::draw_scroll() +{ + QPainter qp(this); + int height_begin = 0; + int height_end = height(); + int count_wid = int(widget_town_buildings.size()); + if(height_rect_build * count_wid > height()) + { + height_begin = -scroll_indent*height()/(height_rect_build * count_wid); + height_end = height_begin + height()*height()/(height_rect_build * count_wid); + } + + QRect rect{width() - width_scroll, height_begin, width_scroll, height_end - height_begin}; + qp.fillRect(rect, QBrush(Qt::blue)); +} + +void MenuAlreadyBuildTown::do_buildings() +{ + widget_town_buildings.clear(); + auto already_build = menu_town->town()->get_building_already_build(); + + for(size_t i{0}; i < already_build.size(); ++i) + { + widget_town_buildings.push_back( + std::unique_ptr{new WidgetTownBuilding(menu_town, already_build[i], WidgetTownBuilding::AlreadyBuild)}); + } +} + +void MenuAlreadyBuildTown::set_geometry_buildings() +{ + + QPoint pos = pos_menu; + + for(size_t i{0}; i < widget_town_buildings.size(); ++i) + { + if(pos.y()+scroll_indent >= height() || pos.y()+scroll_indent <= 0) + widget_town_buildings[i]->hide(); + else + { + widget_town_buildings[i]->set_geometry(pos + QPoint{0, scroll_indent}, {width() - width_scroll, height_rect_build}); + widget_town_buildings[i]->show(); + } + pos += QPoint{0, height_rect_build}; + } +} + +bool MenuAlreadyBuildTown::point_in_rect(QRectF rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} + +QRect MenuAlreadyBuildTown::rect_build(size_t i) +{ + QPoint pos{0, int(i)*height_rect_build}; + return QRect{pos, pos + QPoint{height_rect_build, height_rect_build}}; +} diff --git a/Graphics/Menus/MenuTown/MenuAlreadyBuildTown.h b/Graphics/Menus/MenuTown/MenuAlreadyBuildTown.h new file mode 100644 index 0000000..1e7bbfe --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuAlreadyBuildTown.h @@ -0,0 +1,53 @@ +#ifndef MENUALREADYBUILDTOWN_H +#define MENUALREADYBUILDTOWN_H + +#include +#include + +#include "IMenuTown.h" +#include "InformWidget.h" +#include "WidgetTownBuilding.h" +#include "WidgetTownUnit.h" +#include "../../Factories/FactoryPixmap.h" +#include "../../GraphicsController/IWindowGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" + + +class MenuAlreadyBuildTown : public QWidget +{ +public: + MenuAlreadyBuildTown(IMenuTown* menu_town); + void set_geometry(QPoint pos, Size size); + + void update_inform(); + + void wheel_scroll(int angle_delta); + +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + + void draw(); + void draw_scroll(); + + void do_buildings(); + void set_geometry_buildings(); + + bool point_in_rect(QRectF rect, QPoint point); + QRect rect_build(size_t i); + + IMenuTown* menu_town; + QPoint mouse_pos_clicked; + int height_rect_build; + QPoint pos_menu; + int scroll_indent = 0; + int width_scroll; + + std::vector> widget_town_buildings; +}; + +#endif // MENUALREADYBUILDTOWN_H diff --git a/Graphics/Menus/MenuTown/MenuBuildTown.cpp b/Graphics/Menus/MenuTown/MenuBuildTown.cpp new file mode 100644 index 0000000..60a7d9e --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuBuildTown.cpp @@ -0,0 +1,182 @@ +#include "MenuBuildTown.h" +#include + +MenuBuildTown::MenuBuildTown(IMenuTown* _menu_town) + :QWidget{_menu_town->window()}, menu_town{_menu_town} +{ + QWidget::setAttribute( Qt::WA_TranslucentBackground, true ); + QWidget::setMouseTracking(true); +} + +void MenuBuildTown::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); + height_rect_build = size.height/20; + pos_menu = pos; + width_scroll = width()/50; + do_units(); + do_buildings(); + set_geometry_units(); + set_geometry_buildings(); +} + +void MenuBuildTown::update_inform() +{ + do_units(); + do_buildings(); + set_geometry_units(); + set_geometry_buildings(); + update(); +} + +void MenuBuildTown::wheel_scroll(int angle_delta) +{ + scroll_indent += angle_delta; + + int count_wid = int(widget_town_buildings.size() + widget_town_units.size()); + if(scroll_indent + height_rect_build * count_wid < height()) + scroll_indent = height() - height_rect_build * count_wid; + if(scroll_indent > 0) + scroll_indent = 0; + + + set_geometry_units(); + set_geometry_buildings(); + update(); +} + +void MenuBuildTown::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); + draw_scroll(); +} + +void MenuBuildTown::mouseMoveEvent(QMouseEvent *event) +{ + Q_UNUSED(event) + menu_town->del_inform_widget(); +} + +void MenuBuildTown::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void MenuBuildTown::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + click(event->pos()); +} + +void MenuBuildTown::wheelEvent(QWheelEvent* event) +{ + int angle_delta = event->angleDelta().y(); + wheel_scroll(angle_delta); +} + +void MenuBuildTown::draw() +{ + QPainter qp(this); + QRect rect{0, 0, width(), height()}; + qp.fillRect(rect, QBrush(QColor(0, 0, 0, 200))); +} + +void MenuBuildTown::draw_scroll() +{ + QPainter qp(this); + int height_begin = 0; + int height_end = height(); + int count_wid = int(widget_town_buildings.size() + widget_town_units.size()); + if(height_rect_build * count_wid > height()) + { + height_begin = -scroll_indent*height()/(height_rect_build * count_wid); + height_end = height_begin + height()*height()/(height_rect_build * count_wid); + } + + QRect rect{width() - width_scroll, height_begin, width_scroll, height_end - height_begin}; + qp.fillRect(rect, QBrush(Qt::blue)); +} + +void MenuBuildTown::do_units() +{ + widget_town_units.clear(); + PlayerScience* player_science = menu_town->player()->player_science(); + auto open_units = player_science->get_best_open_units(); + + for(size_t i{0}; i < open_units.size(); ++i) + widget_town_units.push_back( + std::unique_ptr{new WidgetTownUnit(menu_town, open_units[i], WidgetTownUnit::Build)}); + +} + +void MenuBuildTown::do_buildings() +{ + widget_town_buildings.clear(); + + auto open_build_buildings = menu_town->town()->get_open_build_buildings(); + + for(auto building : open_build_buildings) + { + widget_town_buildings.push_back( + std::unique_ptr{ + new WidgetTownBuilding(menu_town, building, WidgetTownBuilding::Build) + }); + } +} + +void MenuBuildTown::set_geometry_units() +{ + QPoint pos = pos_menu; + + for(size_t i{0}; i < widget_town_units.size(); ++i) + { + if(pos.y() >= height() || pos.y()+scroll_indent <= 0) + widget_town_units[i]->hide(); + else + { + widget_town_units[i]->set_geometry(pos + QPoint{0, scroll_indent}, {width() - width_scroll, height_rect_build}); + widget_town_units[i]->show(); + } + pos += QPoint{0, height_rect_build}; + } +} + +void MenuBuildTown::set_geometry_buildings() +{ + + QPoint pos = pos_menu + QPoint{0, int(widget_town_units.size())*height_rect_build}; + + for(size_t i{0}; i < widget_town_buildings.size(); ++i) + { + if(pos.y()+scroll_indent >= height() || pos.y()+scroll_indent <= 0) + widget_town_buildings[i]->hide(); + else + { + widget_town_buildings[i]->set_geometry(pos + QPoint{0, scroll_indent}, {width() - width_scroll, height_rect_build}); + widget_town_buildings[i]->show(); + } + pos += QPoint{0, height_rect_build}; + } +} + +void MenuBuildTown::click(QPoint) +{ + +} + +bool MenuBuildTown::point_in_rect(QRectF rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} + +QRect MenuBuildTown::rect_build(size_t i) +{ + QPoint pos{0, int(i)*height_rect_build}; + return QRect{pos, pos + QPoint{height_rect_build, height_rect_build}}; +} diff --git a/Graphics/Menus/MenuTown/MenuBuildTown.h b/Graphics/Menus/MenuTown/MenuBuildTown.h new file mode 100644 index 0000000..6f423aa --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuBuildTown.h @@ -0,0 +1,56 @@ +#ifndef MENUBUILDTOWN_H +#define MENUBUILDTOWN_H + +#include +#include + +#include "IMenuTown.h" +#include "InformWidget.h" +#include "WidgetTownBuilding.h" +#include "WidgetTownUnit.h" +#include "../../Factories/FactoryPixmap.h" +#include "../../GraphicsController/IWindowGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" + + +class MenuBuildTown : public QWidget +{ +public: + MenuBuildTown(IMenuTown* menu_town); + void set_geometry(QPoint pos, Size size); + + void update_inform(); + + void wheel_scroll(int angle_delta); +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + + void draw(); + void draw_scroll(); + + void do_units(); + void do_buildings(); + void set_geometry_units(); + void set_geometry_buildings(); + + void click(QPoint pos); + bool point_in_rect(QRectF rect, QPoint point); + QRect rect_build(size_t i); + + IMenuTown* menu_town; + QPoint mouse_pos_clicked; + int height_rect_build; + QPoint pos_menu; + int scroll_indent = 0; + int width_scroll; + + std::vector> widget_town_buildings; + std::vector> widget_town_units; +}; + +#endif // MENUBUILDTOWN_H diff --git a/Graphics/Menus/MenuTown/MenuQueueTown.cpp b/Graphics/Menus/MenuTown/MenuQueueTown.cpp new file mode 100644 index 0000000..42ccb5c --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuQueueTown.cpp @@ -0,0 +1,172 @@ +#include "MenuQueueTown.h" +#include + +MenuQueueTown::MenuQueueTown(IMenuTown* _menu_town) + :QWidget{_menu_town->window()}, menu_town{_menu_town} +{ + QWidget::setAttribute( Qt::WA_TranslucentBackground, true ); + QWidget::setMouseTracking(true); +} + +void MenuQueueTown::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); + height_butt_queue = size.width/20; + height_text_queue = size.width/20; + + height_rect_build = size.height - height_butt_queue - height_text_queue; + if(menu_town->get_type_work() == IMenuTown::AddQueue) + height_rect_build /= menu_town->town()->max_build_in_queue(); + + pos_menu = pos; + + numder_rect = {0,0}; + if(menu_town->get_type_work() == IMenuTown::AddQueue) + numder_rect = {size.width/10, height_rect_build}; + + update_queue(); +} + +void MenuQueueTown::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); + draw_number(); + draw_butt_queue(); +} + +void MenuQueueTown::mouseMoveEvent(QMouseEvent *event) +{ + Q_UNUSED(event) + menu_town->del_inform_widget(); +} + +void MenuQueueTown::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void MenuQueueTown::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + + if(point_in_rect(rect_butt_queue(), event->pos())) + { + if(menu_town->get_type_work() == IMenuTown::AddQueue) + menu_town->set_type_work(IMenuTown::EditProject); + else + menu_town->set_type_work(IMenuTown::AddQueue); + } +} + +void MenuQueueTown::draw() +{ + QPainter qp(this); + QRect rect{0, 0, width(), height()}; + qp.fillRect(rect, QBrush(QColor(0, 0, 0, 200))); +} + +void MenuQueueTown::draw_number() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 3}); + for(size_t i{0}; i < widgets_town_build.size(); ++i) + { + QRect rect{0, int(i)*numder_rect.height, + numder_rect.width, numder_rect.height}; + + qp.drawRect(rect); + QString str = QString::fromStdString(std::to_string(i+1)); + qp.drawText(rect, Qt::AlignCenter, str); + } +} + +void MenuQueueTown::draw_butt_queue() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 2}); + + qp.drawRect(rect_butt_queue()); + if(menu_town->get_type_work() == IMenuTown::AddQueue) + qp.fillRect(rect_butt_queue(), Qt::white); + + qp.drawText(rect_text_butt_queue(), Qt::AlignVCenter | Qt::AlignRight, "Показать очередь"); +} + +void MenuQueueTown::update_queue() +{ + widgets_town_build.clear(); + auto queue = menu_town->town()->get_build_queue(); + + if(queue.size() == 0) + { + update(); + return; + } + size_t a = 1; + if(menu_town->get_type_work() == IMenuTown::AddQueue) + a = queue.size(); + for(size_t i{0}; i < a; ++i) + { + if(queue[i]->type_build == BuildInTown::Unit) + widgets_town_build.push_back({new WidgetTownUnit(menu_town, queue[i]->unit, WidgetTownUnit::InQueue)}); + else if(queue[i]->type_build == BuildInTown::Building) + widgets_town_build.push_back({new WidgetTownBuilding(menu_town, queue[i]->building, WidgetTownBuilding::InQueue)}); + set_geometry_wid(i); + } + update(); +} + +size_t MenuQueueTown::num_widget(AWidgetTown* wid_build) const +{ + for(size_t i{0}; i < widgets_town_build.size(); ++i) + { + if(wid_build->who_i() == AWidgetTown::ForBuilding) + { + if(widgets_town_build[i].wid_town_building.get() == wid_build) + return i; + } + else if(wid_build->who_i() == AWidgetTown::ForUnit) + { + if(widgets_town_build[i].wid_town_unit.get() == wid_build) + return i; + } + } + throw std::runtime_error("num_widget(): I haven't got this widget"); +} + +size_t MenuQueueTown::count_widgets() const +{ + return widgets_town_build.size(); +} + +bool MenuQueueTown::point_in_rect(QRect rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} + +void MenuQueueTown::set_geometry_wid(size_t i) +{ + QPoint pos = pos_menu + QPoint{numder_rect.width, height_rect_build*int(i)}; + if(widgets_town_build[i].type_build == WidgetTownBuild::Unit) + widgets_town_build[i].wid_town_unit->set_geometry(pos, {width() - numder_rect.width, height_rect_build}); + else if(widgets_town_build[i].type_build == WidgetTownBuild::Building) + widgets_town_build[i].wid_town_building->set_geometry(pos, {width() - numder_rect.width, height_rect_build}); +} + +QRect MenuQueueTown::rect_butt_queue() const +{ + return QRect{width() - height_butt_queue*9/10 , height() - height_butt_queue*9/10, + height_butt_queue*8/10, height_butt_queue*8/10}; +} + +QRect MenuQueueTown::rect_text_butt_queue() const +{ + return QRect{QPoint{0, rect_butt_queue().topLeft().y()}, + rect_butt_queue().bottomLeft() - QPoint{height_butt_queue/5,0}}; +} diff --git a/Graphics/Menus/MenuTown/MenuQueueTown.h b/Graphics/Menus/MenuTown/MenuQueueTown.h new file mode 100644 index 0000000..f21bf63 --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuQueueTown.h @@ -0,0 +1,69 @@ +#ifndef MENUQUEUETOWN_H +#define MENUQUEUETOWN_H + +#include + +#include +#include + +#include "IMenuTown.h" +#include "WidgetTownBuilding.h" +#include "WidgetTownUnit.h" +#include "../../Factories/FactoryPixmap.h" +#include "../../GraphicsController/IWindowGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" + + +class MenuQueueTown : public QWidget +{ + struct WidgetTownBuild{ + enum TypeBuild{ + Building, + Unit + }; + std::unique_ptr wid_town_building; + std::unique_ptr wid_town_unit; + TypeBuild type_build; + + WidgetTownBuild(WidgetTownBuilding* _wid_town_building) + :wid_town_building{_wid_town_building}, type_build{Building} + {} + + WidgetTownBuild(WidgetTownUnit* _wid_town_unit) + :wid_town_unit{_wid_town_unit}, type_build{Unit} + {} + }; + +public: + MenuQueueTown(IMenuTown* menu_town); + void set_geometry(QPoint pos, Size size); + void update_queue(); + + size_t num_widget(AWidgetTown* wid_building) const; + size_t count_widgets() const; +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + + void draw(); + void draw_number(); + void draw_butt_queue(); + void click(QPoint pos); + bool point_in_rect(QRect rect, QPoint point); + void set_geometry_wid(size_t ind); + QRect rect_butt_queue() const; + QRect rect_text_butt_queue() const; + + IMenuTown* menu_town; + QPoint mouse_pos_clicked; + int height_rect_build; + int height_butt_queue; + int height_text_queue; + QPoint pos_menu; + std::vector widgets_town_build; + Size numder_rect; +}; +#endif // MENUQUEUETOWN_H diff --git a/Graphics/Menus/MenuTown/MenuTown.cpp b/Graphics/Menus/MenuTown/MenuTown.cpp new file mode 100644 index 0000000..30b58d5 --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuTown.cpp @@ -0,0 +1,249 @@ +#include "MenuTown.h" +#include "iostream" + +MenuTown::MenuTown(IMenuTownPlayer* player, ITownMenuGraphicsController* graphics_controller, + PlayerTown* town) + : _player{player}, _graphics_controller{graphics_controller}, _town{town}, + menu_build_town{new MenuBuildTown(this)}, menu_type_work_town{new MenuTypeWorkTown{this}}, + menu_queue_town{new MenuQueueTown(this)} +{ + if(town->get_build_queue().size() > 1) + type_work = AddQueue; +} + +void MenuTown::set_geometry(QPoint _pos, Size _size) +{ + pos = _pos; + size = _size; + if(menu_build_town) + set_geometry_menu_build(); + + set_geometry_menu_selectwork(); + set_geometry_menu_queue(); +} + +void MenuTown::start() +{ + menu_build_town->hide(); + menu_build_town->show(); + menu_type_work_town->hide(); + menu_type_work_town->show(); + menu_queue_town->hide(); + menu_queue_town->show(); +} + +ITownMenuGraphicsController* MenuTown::graphics_controller() const +{ + return _graphics_controller; +} + +QWidget* MenuTown::window() const +{ + return _graphics_controller->window(); +} + +PlayerTown* MenuTown::town() const +{ + return _town; +} + +IMenuTownPlayer* MenuTown::player() const +{ + return _player; +} + +void MenuTown::delete_townmenu() +{ + _graphics_controller->delete_townmenu(); +} + +void MenuTown::open_menu_build() +{ + close_menu_alreadybuild(); + + if(menu_build_town.get()) + return; + menu_build_town.reset(new MenuBuildTown{this}); + set_geometry_menu_build(); + menu_build_town->hide(); + menu_build_town->show(); +} + +void MenuTown::open_menu_alreadybuild() +{ + close_menu_build(); + + if(menu_already_build_town.get()) + return; + + menu_already_build_town.reset(new MenuAlreadyBuildTown{this}); + set_geometry_menu_alreadybuild(); + menu_already_build_town->hide(); + menu_already_build_town->show(); +} + +void MenuTown::set_build(Units type_unit) +{ + if(type_work == AddQueue) + _town->add_queue_build(type_unit); + else if(type_work == EditProject) + _town->set_build(type_unit); + menu_queue_town->update_queue(); + if(menu_build_town) + menu_build_town->update_inform(); + del_inform_widget(); +} + +void MenuTown::set_build(TownBuildings type_building) +{ + if(type_work == AddQueue) + _town->add_queue_build(type_building); + else if(type_work == EditProject) + _town->set_build(type_building); + + if(menu_queue_town) + menu_queue_town->update_queue(); + + if(menu_build_town) + menu_build_town->update_inform(); + if(menu_already_build_town) + menu_already_build_town->update_inform(); + + del_inform_widget(); +} + +void MenuTown::del_build_from_queue(AWidgetTown* wid) +{ + _town->del_build(num_from_queue(wid)); + + if(menu_queue_town) + menu_queue_town->update_queue(); + + if(menu_build_town) + menu_build_town->update_inform(); + + del_inform_widget(); +} + +size_t MenuTown::num_from_queue(AWidgetTown* wid) const +{ + return menu_queue_town->num_widget(wid); +} + +size_t MenuTown::count_from_queue() const +{ + return menu_queue_town->count_widgets(); +} + +void MenuTown::move_up_build(AWidgetTown* wid) +{ + _town->move_up_build(num_from_queue(wid)); + menu_queue_town->update_queue(); + + if(menu_build_town) + menu_build_town->update_inform(); + + del_inform_widget(); +} + +void MenuTown::move_down_build(AWidgetTown* wid) +{ + _town->move_down_build(num_from_queue(wid)); + menu_queue_town->update_queue(); + + if(menu_build_town) + menu_build_town->update_inform(); + + del_inform_widget(); +} + +void MenuTown::wheel_scroll(int angle_delta) +{ + if(menu_build_town) + menu_build_town->wheel_scroll(angle_delta); +} + +void MenuTown::do_inform_widget(std::vector> text) +{ + graphics_controller()->do_inform_widget(text); +} + +void MenuTown::del_inform_widget() +{ + graphics_controller()->del_inform_widget(); +} + +void MenuTown::set_type_work(TypeWork _type_work) +{ + if(_type_work == type_work) + return; + type_work = _type_work; + set_geometry_menu_queue(); + + if(menu_build_town) + menu_build_town->update_inform(); +} + +IMenuTown::TypeWork MenuTown::get_type_work() const +{ + return type_work; +} + +void MenuTown::close_menu_build() +{ + menu_build_town.reset(); +} + +void MenuTown::close_menu_alreadybuild() +{ + menu_already_build_town.reset(); +} + +void MenuTown::close_menu_queue() +{ + menu_queue_town.reset(); +} + +void MenuTown::set_geometry_menu_build() +{ + if(!menu_build_town) + return; + menu_build_town->set_geometry(pos + QPoint{size.width*4/5, 0}, {size.width/5, size.height*3/4}); +} + +void MenuTown::set_geometry_menu_alreadybuild() +{ + if(!menu_already_build_town) + return; + menu_already_build_town->set_geometry(pos + QPoint{size.width*4/5, 0}, {size.width/5, size.height*3/4}); +} + +void MenuTown::set_geometry_menu_selectwork() +{ + if(!menu_type_work_town) + return; + + Size size_menu_type_work{size.width/5, + size.height/20*int(menu_type_work_town->count_button())}; + + QPoint pos_menu_type_work{pos.x(), + pos.y() + size.height - size_menu_type_work.height}; + + menu_type_work_town->set_geometry(pos_menu_type_work, size_menu_type_work); +} + +void MenuTown::set_geometry_menu_queue() +{ + if(!menu_queue_town) + return; + + Size size_menu_queue{size.width/5, size.height/10+1}; + QPoint pos_menu_queue{pos + QPoint{size.width*4/5, size.height*9/10}}; + + if(type_work == AddQueue) + { + size_menu_queue = {size.width/5, size.height/4-1}; + pos_menu_queue = {pos + QPoint{size.width*4/5, size.height*3/4+1}}; + } + menu_queue_town->set_geometry(pos_menu_queue, size_menu_queue); +} diff --git a/Graphics/Menus/MenuTown/MenuTown.h b/Graphics/Menus/MenuTown/MenuTown.h new file mode 100644 index 0000000..edba842 --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuTown.h @@ -0,0 +1,71 @@ +#ifndef MENUTOWN_H +#define MENUTOWN_H + +#include + +#include "MenuBuildTown.h" +#include "MenuTypeWorkTown.h" +#include "MenuQueueTown.h" +#include "MenuAlreadyBuildTown.h" +#include "IMenuTown.h" +#include "InformWidget.h" +#include "../../GraphicsController/IWindowGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" + + +class MenuTown : public IMenuTown +{ +public: + MenuTown(IMenuTownPlayer* player, ITownMenuGraphicsController* graphics_controller, PlayerTown* town); + void set_geometry(QPoint pos, Size size); + void start(); + + virtual ITownMenuGraphicsController* graphics_controller() const override; + virtual QWidget* window() const override; + virtual PlayerTown* town() const override; + virtual IMenuTownPlayer* player() const override; + virtual void delete_townmenu() override; + virtual void open_menu_build() override; + virtual void open_menu_alreadybuild() override; + + virtual void set_build(Units type_unit) override; + virtual void set_build(TownBuildings type_building) override; + virtual void del_build_from_queue(AWidgetTown* wid_build) override; + virtual size_t num_from_queue(AWidgetTown* wid) const override; + virtual size_t count_from_queue() const override; + virtual void move_up_build(AWidgetTown* wid) override; + virtual void move_down_build(AWidgetTown* wid) override; + virtual void wheel_scroll(int angle_delta) override; + virtual void do_inform_widget(std::vector> text) override; + virtual void del_inform_widget() override; + + virtual void set_type_work(TypeWork _type_work) override; + virtual TypeWork get_type_work() const override; +private: + void close_menu_build(); + void close_menu_alreadybuild(); + void close_menu_queue(); + + void set_geometry_menu_build(); + void set_geometry_menu_alreadybuild(); + void set_geometry_menu_selectwork(); + void set_geometry_menu_queue(); + + IMenuTownPlayer* _player; + ITownMenuGraphicsController* _graphics_controller; + PlayerTown* _town; + + std::unique_ptr menu_build_town; + std::unique_ptr menu_type_work_town; + std::unique_ptr menu_queue_town; + std::unique_ptr menu_already_build_town; + std::unique_ptr inform_widget; + + QPoint pos; + Size size; + + TypeWork type_work = TypeWork::EditProject; +}; + +#endif // MENUTOWN_H diff --git a/Graphics/Menus/MenuTown/MenuTypeWorkTown.cpp b/Graphics/Menus/MenuTown/MenuTypeWorkTown.cpp new file mode 100644 index 0000000..c41fa8c --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuTypeWorkTown.cpp @@ -0,0 +1,111 @@ +#include "MenuTypeWorkTown.h" + +MenuTypeWorkTown::MenuTypeWorkTown(IMenuTown* _menu_town) + :QWidget{_menu_town->window()}, menu_town{_menu_town} +{ + QWidget::setAttribute( Qt::WA_TranslucentBackground, true ); + buttuns.push_back(TypesWork::Build); + buttuns.push_back(TypesWork::AlreadyBuilt); + buttuns.push_back(TypesWork::Close); +} + +void MenuTypeWorkTown::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); +} + +size_t MenuTypeWorkTown::count_button() const +{ + return buttuns.size(); +} + +void MenuTypeWorkTown::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void MenuTypeWorkTown::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void MenuTypeWorkTown::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + + for(size_t i{0}; i < buttuns.size(); ++i) + { + if(point_in_rect(rect_butt(int(i)), event->pos())) + click_on_butt(i); + } +} + +void MenuTypeWorkTown::draw() +{ + QPainter qp(this); + QRect rect{0, 0, width(), height()}; + qp.setPen(QPen{Qt::white, 2}); + qp.fillRect(rect, QBrush(QColor(0, 0, 0, 200))); + for(size_t i{0}; i < buttuns.size(); ++i) + { + qp.drawRect(rect_butt(int(i))); + qp.drawText(rect_butt(int(i)), Qt::AlignCenter, str_text_butt(i)); + } +} + +QRectF MenuTypeWorkTown::rect_butt(int i) +{ + return QRectF{0., i*height_butt()*1., + width()*1., height_butt()*1.}; +} + +bool MenuTypeWorkTown::point_in_rect(QRectF rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} + +int MenuTypeWorkTown::height_butt() +{ + return height()/int(buttuns.size()); +} + +void MenuTypeWorkTown::click_on_butt(size_t i) +{ + TypesWork type_work = buttuns[i]; + switch (type_work) + { + case TypesWork::Close: + menu_town->delete_townmenu(); + break; + case TypesWork::AlreadyBuilt: + menu_town->open_menu_alreadybuild(); + break; + case TypesWork::Build: + menu_town->open_menu_build(); + break; + } +} + +QString MenuTypeWorkTown::str_text_butt(size_t i) +{ + QString str = ""; + TypesWork type_work = buttuns[i]; + switch (type_work) { + case TypesWork::Close: + str = "Закрыть"; + break; + case TypesWork::Build: + str = "Построить"; + break; + case TypesWork::AlreadyBuilt: + str = "Построенно в городе"; + break; + } + return str; +} diff --git a/Graphics/Menus/MenuTown/MenuTypeWorkTown.h b/Graphics/Menus/MenuTown/MenuTypeWorkTown.h new file mode 100644 index 0000000..dbc1dac --- /dev/null +++ b/Graphics/Menus/MenuTown/MenuTypeWorkTown.h @@ -0,0 +1,47 @@ +#ifndef MENUTYPEWORKTOWN_H +#define MENUTYPEWORKTOWN_H + +#include + +#include +#include + +#include "IMenuTown.h" +#include "../../GraphicsController/IWindowGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" + + +class MenuTypeWorkTown : public QWidget +{ + enum TypesWork{ + Build, + AlreadyBuilt, + Close + }; + +public: + MenuTypeWorkTown(IMenuTown* menu_town); + void set_geometry(QPoint pos, Size size); + + size_t count_button() const; +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + + void draw(); + void click(QPoint pos); + QRectF rect_butt(int ind); + bool point_in_rect(QRectF rect, QPoint point); + int height_butt(); + void click_on_butt(size_t ind); + QString str_text_butt(size_t ind); + + IMenuTown* menu_town; + QPoint mouse_pos_clicked; + std::vector buttuns; +}; + +#endif // MENUTYPEWORKTOWN_H diff --git a/Graphics/Menus/MenuTown/WidgetTownBuilding.cpp b/Graphics/Menus/MenuTown/WidgetTownBuilding.cpp new file mode 100644 index 0000000..a5c1444 --- /dev/null +++ b/Graphics/Menus/MenuTown/WidgetTownBuilding.cpp @@ -0,0 +1,192 @@ +#include "WidgetTownBuilding.h" +#include + +WidgetTownBuilding::WidgetTownBuilding(IMenuTown* _menu_town, TownBuildings _type_building, TypeWork _type_widget) + :AWidgetTown{_menu_town->window(), _type_widget}, menu_town{_menu_town}, type_building{_type_building} +{ + QWidget::setAttribute( Qt::WA_TranslucentBackground, true ); + QWidget::setMouseTracking(true); + + auto player = menu_town->player(); + auto player_res = player->get_player_res(); + int level = menu_town->town()->get_level_build(type_building); + + for(auto res : TownBuildNeeds().get_build_need_res(type_building,level)) + if(player_res->get_resource(res.first) < res.second) + enable = false; +} + +void WidgetTownBuilding::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); + this->hide(); + this->show(); +} + +size_t WidgetTownBuilding::num_from_queue() +{ + return menu_town->num_from_queue(this); +} + +size_t WidgetTownBuilding::count_from_queue() +{ + return menu_town->count_from_queue(); +} + +void WidgetTownBuilding::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); + draw_butt(); + AWidgetTown::draw_enable(); +} + +void WidgetTownBuilding::mouseMoveEvent(QMouseEvent *event) +{ + if(event->pos().x() > 0 && event->pos().y() > 0 && + event->pos().x() < width() && event->pos().y() < height()) + menu_town->do_inform_widget(text()); + else + menu_town->del_inform_widget(); +} + +void WidgetTownBuilding::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void WidgetTownBuilding::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + if(type_widget == Build && enable && + menu_town->count_from_queue() < menu_town->town()->max_build_in_queue()) + menu_town->set_build(type_building); + + else if(type_widget == InQueue) + { + if(point_in_rect(rect_butt_del(), event->pos())) + menu_town->del_build_from_queue(this); + else if(point_in_rect(rect_butt_up(), event->pos())) + menu_town->move_up_build(this); + else if(point_in_rect(rect_butt_down(), event->pos())) + menu_town->move_down_build(this); + } + else if(type_widget == AlreadyBuild) + if(point_in_rect(rect_butt_del(), event->pos()) && enable) + menu_town->set_build(type_building); +} + +void WidgetTownBuilding::wheelEvent(QWheelEvent *event) +{ + if(type_widget == TypeWork::Build) + menu_town->wheel_scroll(event->angleDelta().y()); +} + +void WidgetTownBuilding::draw() +{ + draw_widget(); + draw_level(); +} + +void WidgetTownBuilding::draw_butt() +{ + AWidgetTown::draw_butt(); + + if(type_widget == AlreadyBuild) + { + int level = menu_town->town()->get_level_build(type_building); + int max_level = menu_town->player()->player_science()->max_level_building(type_building); + if(level == max_level) + return; + + QPainter qp(this); + + QPixmap pixmap = FactoryPixmap().create_pixmap_for_upgrade(); + QRectF source = FactoryPixmap().size_picture_content(); + qp.drawPixmap(rect_butt_del(), pixmap, source); + + if(!enable) + qp.fillRect(rect_butt_del(), QBrush(QColor(0, 0, 0, 100))); + } +} + +void WidgetTownBuilding::draw_widget() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 3}); + qp.drawRect(QRect{QPoint{0,0}, QPoint{width(), height()}}); + + QPixmap pixmap = FactoryPixmap().create_pixmap_for_town_building(type_building); + QRectF source = FactoryPixmap().size_picture_content(); + QRectF rect = rect_pic(); + qp.drawPixmap(rect, pixmap, source); + + QString name_build = QString::fromStdString(FactoryString().building_in_town_string(type_building)); + QRectF rect2{QPoint{height(), 0}, QPoint{width(), height()/2}}; + qp.drawText(rect2, Qt::AlignLeft | Qt::AlignVCenter, name_build); + + int level = menu_town->town()->get_level_build(type_building); + int max_level = menu_town->player()->player_science()->max_level_building(type_building); + if(type_widget != AlreadyBuild || level != max_level) + { + QRectF rect3{QPoint{height(), height()/2}, QPoint{width(), height()}}; + std::stringstream ss; + int build_moves = int(round(menu_town->town()->get_build_need_production(type_building) / + menu_town->town()->get_production())); + ss << build_moves << " Ход"; + qp.drawText(rect3, Qt::AlignLeft | Qt::AlignVCenter, QString::fromStdString(ss.str())); + } + + if(type_widget == Build && enable && + menu_town->count_from_queue() == menu_town->town()->max_build_in_queue()) + { + QRect rect{0, 0, width(), height()}; + qp.fillRect(rect, QBrush(QColor(0, 0, 0, 100))); + } +} + +void WidgetTownBuilding::draw_level() +{ + int level = menu_town->town()->get_level_build(type_building); + if(!level) + return; + + QPainter qp(this); + qp.setPen(QPen{Qt::white, 1}); + qp.setBrush(QBrush(Qt::black)); + int rad = rect_pic().width()/8; + QPoint point = rect_pic().topRight()-QPoint(rad, -rad); + qp.drawEllipse(point, rad, rad); + + std::stringstream ss; + ss << level; + qp.drawText(QRect{point.x() - rad, point.y() - rad, rad*2, rad*2}, Qt::AlignCenter, + QString::fromStdString(ss.str())); +} + +std::vector> WidgetTownBuilding::text() +{ + int level = menu_town->town()->get_level_build(type_building); + auto res = TownBuildNeeds().get_build_need_res(type_building, level); + + std::vector> text; + text.push_back({QString::fromStdString( + FactoryString().building_in_town_string(type_building)), Qt::white}); + + auto player = menu_town->player(); + auto player_res = player->get_player_res(); + for(size_t i{0}; i < res.size(); ++i) + { + std::stringstream ss; + ss << FactoryString().resource_string(res[i].first) + << ": " << res[i].second; + + QColor color = Qt::white; + if (player_res->get_resource(res[i].first) < res[i].second) + color = Qt::red; + text.push_back({QString::fromStdString(ss.str()), color}); + } + return text; +} diff --git a/Graphics/Menus/MenuTown/WidgetTownBuilding.h b/Graphics/Menus/MenuTown/WidgetTownBuilding.h new file mode 100644 index 0000000..8083ec6 --- /dev/null +++ b/Graphics/Menus/MenuTown/WidgetTownBuilding.h @@ -0,0 +1,49 @@ +#ifndef WIDGETTOWNBUILDING_H +#define WIDGETTOWNBUILDING_H + +#include + +#include +#include + +#include "AWidgetTown.h" +#include "IMenuTown.h" +#include "../../Factories/FactoryString.h" +#include "../../Factories/FactoryPixmap.h" +#include "../../GraphicsController/IWindowGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" + + +class WidgetTownBuilding : public AWidgetTown +{ +public: + WidgetTownBuilding(IMenuTown* menu_town, TownBuildings type_building, TypeWork type_widget); + void set_geometry(QPoint pos, Size size); + + virtual TypeWidget who_i() const override{ return ForBuilding; } + +protected: + virtual size_t num_from_queue() override; + virtual size_t count_from_queue() override; + +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + + void draw(); + virtual void draw_butt() override; + void draw_widget(); + void draw_level(); + std::vector> text(); + + IMenuTown* menu_town; + QPoint mouse_pos_clicked; + TownBuildings type_building; + +}; + +#endif // WIDGETTOWNBUILDING_H diff --git a/Graphics/Menus/MenuTown/WidgetTownUnit.cpp b/Graphics/Menus/MenuTown/WidgetTownUnit.cpp new file mode 100644 index 0000000..0ab0619 --- /dev/null +++ b/Graphics/Menus/MenuTown/WidgetTownUnit.cpp @@ -0,0 +1,136 @@ +#include "WidgetTownUnit.h" +#include + +WidgetTownUnit::WidgetTownUnit(IMenuTown* _menu_town, Units _type_unit, TypeWork _type_widget) + :AWidgetTown{_menu_town->window(), _type_widget}, menu_town{_menu_town}, + type_unit{_type_unit} +{ + QWidget::setAttribute( Qt::WA_TranslucentBackground, true ); + QWidget::setMouseTracking(true); + + auto player = menu_town->player(); + auto player_res = player->get_player_res(); + + for(auto res : TownBuildNeeds().get_build_need_res(type_unit)) + if(player_res->get_resource(res.first) < res.second) + enable = false; +} + +void WidgetTownUnit::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); + this->hide(); + this->show(); +} + +size_t WidgetTownUnit::num_from_queue() +{ + return menu_town->num_from_queue(this); +} + +size_t WidgetTownUnit::count_from_queue() +{ + return menu_town->count_from_queue(); +} + +void WidgetTownUnit::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw_widget(); + draw_butt(); + AWidgetTown::draw_enable(); +} + +void WidgetTownUnit::mouseMoveEvent(QMouseEvent *event) +{ + if(event->pos().x() > 0 && event->pos().y() > 0 && + event->pos().x() < width() && event->pos().y() < height()) + menu_town->do_inform_widget(text()); + else + menu_town->del_inform_widget(); +} + +void WidgetTownUnit::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void WidgetTownUnit::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + + if(type_widget == Build && enable && + menu_town->count_from_queue() < menu_town->town()->max_build_in_queue()) + menu_town->set_build(type_unit); + if(type_widget == InQueue) + { + if(point_in_rect(rect_butt_del(), event->pos())) + menu_town->del_build_from_queue(this); + else if(point_in_rect(rect_butt_up(), event->pos())) + menu_town->move_up_build(this); + else if(point_in_rect(rect_butt_down(), event->pos())) + menu_town->move_down_build(this); + } +} + +void WidgetTownUnit::wheelEvent(QWheelEvent *event) +{ + if(type_widget == TypeWork::Build) + menu_town->wheel_scroll(event->angleDelta().y()); +} + +void WidgetTownUnit::draw_widget() +{ + QPainter qp(this); + qp.setPen(QPen{Qt::white, 3}); + qp.drawRect(QRect{QPoint{0,0}, QPoint{width(), height()}}); + + QPixmap pixmap = FactoryPixmap().create_pixmap_for_unit(type_unit); + QRectF source = FactoryPixmap().size_picture_unit(); + QRectF rect = QRect{QPoint{0,0}, QPoint{height(), height()}}; + qp.drawPixmap(rect, pixmap, source); + + QString name_build = QString::fromStdString(FactoryString().unit_string(type_unit)); + QRectF rect2{QPoint{height(), 0}, QPoint{width(), height()/2}}; + qp.drawText(rect2, Qt::AlignVCenter, name_build); + + QRectF rect3{QPoint{height(), height()/2}, QPoint{width(), height()}}; + std::stringstream ss; + int build_moves = int(round(menu_town->town()->get_build_need_production(type_unit) / + menu_town->town()->get_production())); + ss << build_moves << " Ход"; + qp.drawText(rect3, Qt::AlignVCenter, QString::fromStdString(ss.str())); + + if(type_widget == Build && enable && + menu_town->count_from_queue() == menu_town->town()->max_build_in_queue()) + { + QRect rect{0, 0, width(), height()}; + qp.fillRect(rect, QBrush(QColor(0, 0, 0, 100))); + } +} + +std::vector> WidgetTownUnit::text() +{ + auto res = TownBuildNeeds().get_build_need_res(type_unit); + + std::vector> text; + text.push_back({QString::fromStdString( + FactoryString().unit_string(type_unit)), Qt::white}); + + auto player = menu_town->player(); + auto player_res = player->get_player_res(); + for(size_t i{0}; i < res.size(); ++i) + { + std::stringstream ss; + ss << FactoryString().resource_string(res[i].first) + << ": " << res[i].second; + + QColor color = Qt::white; + if (player_res->get_resource(res[i].first) < res[i].second) + color = Qt::red; + text.push_back({QString::fromStdString(ss.str()), color}); + } + return text; +} diff --git a/Graphics/Menus/MenuTown/WidgetTownUnit.h b/Graphics/Menus/MenuTown/WidgetTownUnit.h new file mode 100644 index 0000000..412427a --- /dev/null +++ b/Graphics/Menus/MenuTown/WidgetTownUnit.h @@ -0,0 +1,43 @@ +#ifndef WIDGETTOWNUNIT_H +#define WIDGETTOWNUNIT_H + +#include +#include + +#include "AWidgetTown.h" +#include "IMenuTown.h" +#include "../../Factories/FactoryString.h" +#include "../../Factories/FactoryPixmap.h" +#include "../../GraphicsController/IWindowGraphicsController.h" +#include "../../../Controllers/Player/IMenuTownPlayer.h" +#include "../../../Controllers/Player/PlayerTown.h" + + +class WidgetTownUnit : public AWidgetTown +{ +public: + WidgetTownUnit(IMenuTown* menu_town, Units type_unit, TypeWork type_widget); + void set_geometry(QPoint pos, Size size); + + virtual TypeWidget who_i() const override{ return ForUnit; } + +protected: + virtual size_t num_from_queue() override; + virtual size_t count_from_queue() override; + +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + + void draw_widget(); + std::vector> text(); + + IMenuTown* menu_town; + QPoint mouse_pos_clicked; + Units type_unit; +}; + +#endif // WIDGETTOWNUNIT_H diff --git a/Graphics/Menus/MenuTypeMap/IMenuTypeMap.h b/Graphics/Menus/MenuTypeMap/IMenuTypeMap.h new file mode 100644 index 0000000..478ae64 --- /dev/null +++ b/Graphics/Menus/MenuTypeMap/IMenuTypeMap.h @@ -0,0 +1,18 @@ +#ifndef IMENUTYPEMAP_H +#define IMENUTYPEMAP_H + +#include + + +class IMenuTypeMap : public QWidget +{ +public: + virtual void set_type(size_t i) = 0; + +protected: + IMenuTypeMap(QWidget* win) + :QWidget(win) + {} +}; + +#endif // IMENUTYPEMAP_H diff --git a/Graphics/Menus/MenuTypeMap/MenuTypeMap.cpp b/Graphics/Menus/MenuTypeMap/MenuTypeMap.cpp new file mode 100644 index 0000000..0c07d91 --- /dev/null +++ b/Graphics/Menus/MenuTypeMap/MenuTypeMap.cpp @@ -0,0 +1,234 @@ +#include "MenuTypeMap.h" + +MenuTypeMap::MenuTypeMap(IMenuInWindowGraphicsController* _graphics_controller, IMap* _map) + : IMenuTypeMap{_graphics_controller->window()}, graphics_controller{_graphics_controller}, + map{_map}, type_map{_map->get_type_map()} +{ + QWidget::setMouseTracking(true); +} + +void MenuTypeMap::set_geometry(QPoint pos, Size size) +{ + QWidget::setGeometry(pos.x(), pos.y(), size.width, size.height); +} + +void MenuTypeMap::set_type(size_t i) +{ + types_list.reset(); + if(type_work == Overlay) + type_map.overplay = v_overlay()[i]; + else if(type_work == TypeContent) + type_map.type_content = v_type_content()[i]; + map->set_type_map(type_map); + type_work = Nothing; +} + +void MenuTypeMap::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); + draw_notvisible(); + draw_other_landscapes(); +} + +void MenuTypeMap::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void MenuTypeMap::mouseReleaseEvent(QMouseEvent* event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + click(event->pos()); +} + + +void MenuTypeMap::draw() +{ + QPainter qp(this); + qp.setPen(QPen(Qt::white, 2)); + QPoint p1; + QPoint p2; + + auto fact_str = FactoryString(); + + qp.drawText(text_overlay(), Qt::AlignBottom, "Активное наложение:"); + qp.fillRect(wid_overlay(), QBrush(Qt::gray)); + qp.drawRect(wid_overlay()); + qp.drawText(wid_overlay(), Qt::AlignCenter, + QString::fromStdString(fact_str.typemap_overlay_string(type_map.overplay))); + p1 = (wid_overlay().topRight() + wid_overlay().bottomRight())/2; + p2 = wid_overlay().bottomRight() - QPoint{wid_overlay().height()/2, 0}; + qp.drawLine(p1, p2); + + qp.drawText(text_icons(), Qt::AlignBottom, "Отображение значков:"); + qp.fillRect(wid_icons(), QBrush(Qt::gray)); + qp.drawRect(wid_icons()); + qp.drawText(wid_icons(), Qt::AlignCenter, + QString::fromStdString(fact_str.typemap_typecontent_string(type_map.type_content))); + p1 = (wid_icons().topRight() + wid_icons().bottomRight())/2; + p2 = wid_icons().bottomRight() - QPoint{wid_icons().height()/2, 0}; + qp.drawLine(p1, p2); +} + +void MenuTypeMap::draw_notvisible() +{ + QPainter qp(this); + qp.setPen(QPen(Qt::white, 2)); + + if(type_map.show_notvisible) + qp.setBrush(Qt::white); + + qp.drawText(text_notvisible(), Qt::AlignVCenter, "Туман войны"); + QRect rect_notv = wid_notvisible(); + qp.drawEllipse(rect_notv.center(), rad_wid_notvisible(), rad_wid_notvisible()); +} + +void MenuTypeMap::draw_other_landscapes() +{ + QPainter qp(this); + qp.setPen(QPen(Qt::white, 2)); + + if(type_map.show_other_landscapes) + qp.setBrush(Qt::white); + + qp.drawText(text_other_landscapes(), Qt::AlignVCenter, "Особенности"); + QRect rect_ol = wid_other_landscapes(); + qp.drawEllipse(rect_ol.center(), rad_wid_other_landscapes(), rad_wid_other_landscapes()); +} + +void MenuTypeMap::click(QPoint pos) +{ + types_list.reset(); + type_work = Nothing; + if(wid_overlay().contains(pos)) + { + type_work = Overlay; + do_tipes_list(); + return; + } + else if(wid_icons().contains(pos)) + { + type_work = TypeContent; + do_tipes_list(); + return; + } + else if(point_in_circle(wid_notvisible().center(), rad_wid_notvisible(), pos)) + type_map.show_notvisible = !type_map.show_notvisible; + else if(point_in_circle(wid_other_landscapes().center(), rad_wid_other_landscapes(), pos)) + type_map.show_other_landscapes = !type_map.show_other_landscapes; + else + return; + + map->set_type_map(type_map); + update(); +} + +void MenuTypeMap::do_tipes_list() +{ + types_list.reset(new TypesList{this}); + if(type_work == Overlay) + { + std::vector text; + for(auto overlay : v_overlay()) + text.push_back(QString::fromStdString(FactoryString().typemap_overlay_string(overlay))); + types_list->set_text(text); + types_list->set_geometry(wid_overlay().topLeft(), {wid_overlay().width(), wid_overlay().height()}); + } + else if(type_work == TypeContent) + { + std::vector text; + for(auto type_c : v_type_content()) + text.push_back(QString::fromStdString(FactoryString().typemap_typecontent_string(type_c))); + types_list->set_text(text); + types_list->set_geometry(wid_icons().topLeft(), {wid_icons().width(), wid_icons().height()}); + } + else + { + types_list.reset(); + return; + } + + types_list->hide(); + types_list->show(); +} + +std::vector MenuTypeMap::v_overlay() const +{ + std::vector overlay; + overlay.push_back(TypeMap::NoOverlay); + overlay.push_back(TypeMap::Political); + overlay.push_back(TypeMap::HighlightResources); + return overlay; +} + +std::vector MenuTypeMap::v_type_content() const +{ + std::vector type_c; + type_c.push_back(TypeMap::All); + type_c.push_back(TypeMap::Nothing); + type_c.push_back(TypeMap::Units); + type_c.push_back(TypeMap::Resources); + type_c.push_back(TypeMap::Building); + return type_c; +} + +QRect MenuTypeMap::text_icons() const +{ + return QRect{width()/10, 0, width()*8/10, height()/7}; +} + +QRect MenuTypeMap::wid_icons() const +{ + return QRect{width()/10, height()/6, width()*8/10, height()/7}; +} + +QRect MenuTypeMap::text_overlay() const +{ + return QRect{width()/10, 2*height()/6, width()*8/10, height()/7}; +} + +QRect MenuTypeMap::wid_overlay() const +{ + return QRect{width()/10, 3*height()/6, width()*8/10, height()/7}; +} + +QRect MenuTypeMap::text_notvisible() const +{ + return QRect{width()/10, 4*height()/6, width()*3/4, height()/6}; +} + +QRect MenuTypeMap::wid_notvisible() const +{ + return QRect{width()*3/4, 4*height()/6, width()/4, height()/6}; +} + +int MenuTypeMap::rad_wid_notvisible() const +{ + return wid_notvisible().width()/6; +} + +QRect MenuTypeMap::text_other_landscapes() const +{ + return QRect{width()/10, 5*height()/6, width()*3/4, height()/6}; +} + +QRect MenuTypeMap::wid_other_landscapes() const +{ + return QRect{width()*3/4, 5*height()/6, width()/4, height()/6}; +} + +int MenuTypeMap::rad_wid_other_landscapes() const +{ + return wid_other_landscapes().width()/6; +} + +bool MenuTypeMap::point_in_circle(QPoint center_circle, int rad_circle, QPoint point) +{ + QPointF distance = point-center_circle; + int a = int(std::sqrt(distance.x()*distance.x() + distance.y()*distance.y())); + return a <= rad_circle; +} + diff --git a/Graphics/Menus/MenuTypeMap/MenuTypeMap.h b/Graphics/Menus/MenuTypeMap/MenuTypeMap.h new file mode 100644 index 0000000..9b15fb3 --- /dev/null +++ b/Graphics/Menus/MenuTypeMap/MenuTypeMap.h @@ -0,0 +1,67 @@ +#ifndef MENUTYPEMAP_H +#define MENUTYPEMAP_H + +#include +#include + +#include "IMenuTypeMap.h" +#include "TypesList.h" +#include "../../Factories/FactoryString.h" +#include "../../GraphicsController/IMenuGraphicsController.h" +#include "../../Map/IMap.h" + + +class MenuTypeMap : public IMenuTypeMap +{ + enum TypeWork + { + Nothing, + Overlay, + TypeContent + }; + +public: + MenuTypeMap(IMenuInWindowGraphicsController* graphics_controller, IMap* map); + + void set_geometry(QPoint pos, Size size); + + virtual void set_type(size_t i) override; + +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + + void draw(); + void draw_notvisible(); + void draw_other_landscapes(); + void click(QPoint pos); + + QRect text_overlay() const; + QRect wid_overlay() const; + QRect text_icons() const; + QRect wid_icons() const; + QRect text_notvisible() const; + QRect wid_notvisible() const; + int rad_wid_notvisible() const; + QRect text_other_landscapes() const; + QRect wid_other_landscapes() const; + int rad_wid_other_landscapes() const; + + bool point_in_circle(QPoint center_circle, int rad_circle, QPoint point); + + void do_tipes_list(); + std::vector v_overlay() const; + std::vector v_type_content() const; + + IMenuInWindowGraphicsController* graphics_controller; + IMap* map; + TypeMap type_map; + + QPoint mouse_pos_clicked; + TypeWork type_work = Nothing; + std::unique_ptr types_list; +}; + +#endif // MENUTYPEMAP_H diff --git a/Graphics/Menus/MenuTypeMap/TypesList.cpp b/Graphics/Menus/MenuTypeMap/TypesList.cpp new file mode 100644 index 0000000..b4a18f7 --- /dev/null +++ b/Graphics/Menus/MenuTypeMap/TypesList.cpp @@ -0,0 +1,63 @@ +#include "TypesList.h" + +TypesList::TypesList(IMenuTypeMap* _menu_type_map) + :QWidget{_menu_type_map}, menu_type_map{_menu_type_map} +{} + +void TypesList::set_text(std::vector text) +{ + strings = text; +} + +void TypesList::set_geometry(QPoint pos, Size _size_block) +{ + size_block = _size_block; + QWidget::setGeometry(pos.x(), pos.y(), + _size_block.width, _size_block.height*int(strings.size())); +} + +void TypesList::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void TypesList::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void TypesList::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + click(event->pos()); +} + +void TypesList::draw() +{ + QPainter qp(this); + qp.setPen(QPen(Qt::black, 2)); + qp.setBrush(Qt::green); + for(size_t i{0}; i < strings.size(); ++i) + { + qp.drawRect(rect_str(int(i))); + qp.drawText(rect_str(int(i)), Qt::AlignCenter, strings[i]); + } +} + +void TypesList::click(QPoint pos) +{ + for(int i{0}; i < int(strings.size()); ++i) + if(rect_str(i).contains(pos)) + { + menu_type_map->set_type(i); + return; + } +} + +QRect TypesList::rect_str(int i) +{ + return QRect{0, i*size_block.height, size_block.width, size_block.height}; +} diff --git a/Graphics/Menus/MenuTypeMap/TypesList.h b/Graphics/Menus/MenuTypeMap/TypesList.h new file mode 100644 index 0000000..7338750 --- /dev/null +++ b/Graphics/Menus/MenuTypeMap/TypesList.h @@ -0,0 +1,37 @@ +#ifndef TYPESLIST_H +#define TYPESLIST_H + +#include +#include +#include + +#include "IMenuTypeMap.h" +#include "../../../IObject.h" + + +class TypesList : public QWidget +{ +public: + TypesList(IMenuTypeMap* menu_type_map); + + void set_text(std::vector text); + void set_geometry(QPoint pos, Size size_block); + +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + + void draw(); + void click(QPoint pos); + + QRect rect_str(int i); + + std::vector strings; + Size size_block; + IMenuTypeMap* menu_type_map; + QPoint mouse_pos_clicked; +}; + +#endif // TYPESLIST_H diff --git a/Graphics/Menus/MenuUnit/AMenuForUnit.cpp b/Graphics/Menus/MenuUnit/AMenuForUnit.cpp new file mode 100644 index 0000000..ddc0651 --- /dev/null +++ b/Graphics/Menus/MenuUnit/AMenuForUnit.cpp @@ -0,0 +1,108 @@ +#include "AMenuForUnit.h" +#include + +AMenuForUnit::AMenuForUnit(QWidget* _win, IUnitMenuGraphicsController* _graphics_controller, + PlayerUnit* _unit, Cell* _cell) + :QWidget(_win), graphics_controller{_graphics_controller}, unit{_unit}, cell{_cell}, win{_win} +{} + +void AMenuForUnit::set_geometry(QPoint pos, int _side_square) +{ + pos_menu = pos; + side_square = _side_square; + QWidget::setGeometry(pos.x(), pos.y(), side_square, side_square * int(buttons.size())); +} + +void AMenuForUnit::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + draw(); +} + +void AMenuForUnit::mousePressEvent(QMouseEvent *event) +{ + mouse_pos_clicked = event->pos(); +} + +void AMenuForUnit::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mouse_move = event->pos() - mouse_pos_clicked; + if(abs(mouse_move.x()) > 5 or abs(mouse_move.y()) > 5) + return; + + for(size_t i{0}; i < buttons.size(); ++i) + if(point_in_rect(rect_butt(i), event->pos())) + { + click_butt(i); + break; + } +} + +int AMenuForUnit::count_button() const +{ + return int(buttons.size()); +} + +void AMenuForUnit::draw() +{ + QList list; + for(size_t i{0}; i < buttons.size(); ++i) + { + list.append(rect_butt(i)); + draw_butt(i); + } + QPainter qp(this); + QPen pen{Qt::white, 2, Qt::SolidLine}; + qp.setPen(pen); + qp.drawRects(list); +} + +void AMenuForUnit::click_butt(size_t num_butt) +{ + if(buttons[num_butt].event->event == Events::Move) + { + graphics_controller->menu_unit_event(unit->unit, buttons[num_butt].event->copy()); + has_move_event = !has_move_event; + return; + } + + if(has_move_event) + { + has_move_event = false; + graphics_controller->menu_unit_event(unit->unit, new MoveEvent{{0,0}}); + } + + if (buttons[num_butt].is_enable) + graphics_controller->menu_unit_event(unit->unit, buttons[num_butt].event->copy()); +} + +void AMenuForUnit::draw_butt(size_t num_butt) +{ + QPainter qp(this); + QRectF source = FactoryPixmap().size_picture_content(); + QPixmap pixmap = FactoryPixmap().create_pixmap_for_butt_menu(buttons[num_butt].event->copy()); + + qp.drawPixmap(rect_butt(num_butt), pixmap, source); + if(!buttons[num_butt].is_enable) + qp.fillRect(rect_butt(num_butt), QBrush(QColor(0, 0, 0, 100))); +} + + +bool AMenuForUnit::point_in_rect(QRectF rect, QPoint point) +{ + if (point.x() >= rect.topLeft().x() && point.x() < rect.bottomRight().x()) + if (point.y() >= rect.topLeft().y() && point.y() <= rect.bottomRight().y()) + return true; + return false; +} + +QRectF AMenuForUnit::rect_butt(size_t i) +{ + return QRectF{0., int(i)*side_square*1., side_square*1., side_square*1.}; +} + +void AMenuForUnit::set_buttons() +{ + if(unit->event->event != Events::NoEvent) + buttons.push_back(new struct NoEvent()); +} diff --git a/Graphics/Menus/MenuUnit/AMenuForUnit.h b/Graphics/Menus/MenuUnit/AMenuForUnit.h new file mode 100644 index 0000000..3fbfc9e --- /dev/null +++ b/Graphics/Menus/MenuUnit/AMenuForUnit.h @@ -0,0 +1,63 @@ +#ifndef AMENUFORUNIT_H +#define AMENUFORUNIT_H + +#include + +#include +#include +#include +#include + +#include "../../Factories/FactoryPixmap.h" +#include "../../GraphicsController/EventsStructures.h" +#include "../../GraphicsController/IMenuGraphicsController.h" +#include "../../GraphicsController/IPlayerGraphicsController.h" +#include "../../Map/Cell.h" +#include "../../Units/Unit.h" +#include "../../../Controllers/Player/IPlayer.h" + + +struct MyButton +{ + std::unique_ptr event; + bool is_enable = true; + MyButton(Event* _event) + :event{_event} {} +}; + +class AMenuForUnit : public QWidget +{ +public: + AMenuForUnit(QWidget* win, IUnitMenuGraphicsController* graphics_controller, + PlayerUnit* unit, Cell* cell); + virtual void set_geometry(QPoint pos, int side_square); + virtual void draw(); + + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual int count_button() const; +protected: + virtual void click_butt(size_t num_butt); + virtual void draw_butt(size_t num_butt); + virtual QRectF rect_butt(size_t i); + virtual void set_buttons(); + + int side_square; + QPoint pos_menu; + QPoint mouse_pos_clicked; + IUnitMenuGraphicsController* graphics_controller; + PlayerUnit* unit; + Cell* cell; + std::vector buttons; + QWidget* win; + + bool has_move_event = false; +private: + bool point_in_rect(QRectF rect, QPoint point); + // начиная сверху, относительно левого верхнего угла + +}; + +#endif // AMENUFORUNIT_H diff --git a/Graphics/Menus/MenuUnit/CitizenMenu.cpp b/Graphics/Menus/MenuUnit/CitizenMenu.cpp new file mode 100644 index 0000000..64000ab --- /dev/null +++ b/Graphics/Menus/MenuUnit/CitizenMenu.cpp @@ -0,0 +1,38 @@ +#include "CitizenMenu.h" +#include + +CitizenMenu::CitizenMenu(QWidget* _win, IUnitMenuGraphicsController* _graphics_controller, + PlayerUnit* _unit, Cell* _cell) + :AMenuForUnit(_win, _graphics_controller, _unit, _cell) +{ set_buttons(); } + +void CitizenMenu::set_buttons() +{ + AMenuForUnit::set_buttons(); + buttons.push_back(new BuildEvent{Buildings::Town}); + set_is_enable(buttons[0]); + buttons.push_back(new MoveEvent{{0,0}}); + buttons.push_back(new SlipEvent{}); +} + +void CitizenMenu::set_is_enable(MyButton& my_butt) +{ + if(my_butt.event->event == Events::Build) + { + ControlContents controlcontents(cell); + if(controlcontents.has_building()) + if(controlcontents.get_building()->what_building_I() == Buildings::Town) + my_butt.is_enable = false; + } + + if(my_butt.event->event == Events::Slip) + { + ControlContents controlcontents(cell); + int count = 0; + for(auto type_unit : controlcontents.get_units()) + if(type_unit == Units::Worker || type_unit == Units::Citizen) + count++; + if(count > 1) + my_butt.is_enable = false; + } +} diff --git a/Graphics/Menus/MenuUnit/CitizenMenu.h b/Graphics/Menus/MenuUnit/CitizenMenu.h new file mode 100644 index 0000000..ffe22ed --- /dev/null +++ b/Graphics/Menus/MenuUnit/CitizenMenu.h @@ -0,0 +1,19 @@ +#ifndef CITIZENMENU_H +#define CITIZENMENU_H + +#include "AMenuForUnit.h" +#include "../../GraphicsController/EventsStructures.h" +#include "../../Map/Cell.h" + + +class CitizenMenu : public AMenuForUnit +{ +public: + CitizenMenu(QWidget* win, IUnitMenuGraphicsController* graphics_controller, + PlayerUnit* unit, Cell* cell); +private: + void set_buttons(); + void set_is_enable(MyButton& my_butt); +}; + +#endif // CITIZENMENU_H diff --git a/Graphics/Menus/MenuUnit/WarriorMenu.cpp b/Graphics/Menus/MenuUnit/WarriorMenu.cpp new file mode 100644 index 0000000..b725ebd --- /dev/null +++ b/Graphics/Menus/MenuUnit/WarriorMenu.cpp @@ -0,0 +1,18 @@ +#include "WarriorMenu.h" + +WarriorMenu::WarriorMenu(QWidget* _win, IUnitMenuGraphicsController* _graphics_controller, + PlayerUnit* _unit, Cell* _cell) + :AMenuForUnit(_win, _graphics_controller, _unit, _cell) +{ set_buttons(); } + +void WarriorMenu::set_buttons() +{ + AMenuForUnit::set_buttons(); + buttons.push_back(new MoveEvent{{0,0}}); + buttons.push_back(new SlipEvent{}); +} + +void WarriorMenu::set_is_enable(MyButton& ) +{ + +} diff --git a/Graphics/Menus/MenuUnit/WarriorMenu.h b/Graphics/Menus/MenuUnit/WarriorMenu.h new file mode 100644 index 0000000..5c2d634 --- /dev/null +++ b/Graphics/Menus/MenuUnit/WarriorMenu.h @@ -0,0 +1,19 @@ +#ifndef WARRIORMENU_H +#define WARRIORMENU_H + +#include "AMenuForUnit.h" +#include "../../GraphicsController/EventsStructures.h" +#include "../../Map/Cell.h" + + +class WarriorMenu : public AMenuForUnit +{ +public: + WarriorMenu(QWidget* win, IUnitMenuGraphicsController* graphics_controller, + PlayerUnit* unit, Cell* cell); +private: + void set_buttons() override; + void set_is_enable(MyButton& my_butt); +}; + +#endif // WARRIORMENU_H diff --git a/Graphics/Menus/MenuUnit/WorkerMenu.cpp b/Graphics/Menus/MenuUnit/WorkerMenu.cpp new file mode 100644 index 0000000..73f78a1 --- /dev/null +++ b/Graphics/Menus/MenuUnit/WorkerMenu.cpp @@ -0,0 +1,225 @@ +#include "WorkerMenu.h" +#include + +WorkerMenu::WorkerMenu(QWidget* _win, IUnitMenuGraphicsController* _graphics_controller, + PlayerUnit* _unit, Cell* _cell) + :AMenuForUnit(_win, _graphics_controller, _unit, _cell) +{ + set_buttons(); +} + +void WorkerMenu::set_buttons() +{ + AMenuForUnit::set_buttons(); + num_butt_build = buttons.size(); + buttons.push_back(new BuildEvent{Buildings::Farm}); + set_is_enable(buttons[num_butt_build]); + buttons.push_back(new MoveEvent{{0,0}}); + buttons.push_back(new SlipEvent{}); + set_is_enable(buttons[num_butt_build+2]); +} + +void WorkerMenu::draw_butt(size_t num_butt) +{ + if(num_butt != num_butt_build) + { + AMenuForUnit::draw_butt(num_butt); + return; + } + + QPainter qp(this); + QRectF source = FactoryPixmap().size_picture_content(); + QPixmap pixmap = FactoryPixmap().create_pixmap_for_butt_build(); + + qp.drawPixmap(rect_butt(num_butt), pixmap, source); + if(!buttons[num_butt].is_enable) + qp.fillRect(rect_butt(num_butt), QBrush(QColor(0, 0, 0, 100))); +} + +void WorkerMenu::click_butt(size_t num_butt) +{ + if(num_butt != num_butt_build) + { + AMenuForUnit::click_butt(num_butt); + has_menu = false; + // menu.reset(); + return; + } + if(!buttons[num_butt].is_enable) + return; + + if(has_move_event) + { + has_move_event = false; + graphics_controller->menu_unit_event(unit->unit, new MoveEvent{{0,0}}); + } + + if(has_menu) + { + has_menu = false; + menu.reset(); + return; + } + + menu.reset(new MenuBuild{win, graphics_controller, unit, cell}); + menu->set_geometry(pos_menu + rect_butt(num_butt_build).topRight().toPoint(), side_square); + menu->hide(); + menu->show(); + win->update(); + has_menu = true; +} + +void WorkerMenu::set_is_enable(MyButton& my_butt) +{ + if(my_butt.event->event == Events::Build) + { + ControlContents controlcontents(cell); + if(controlcontents.has_building()) + { + Building* building = controlcontents.get_building(); + if(building->is_built()) + my_butt.is_enable = false; + } + if(controlcontents.get_country() != unit->unit->get_country()) + my_butt.is_enable = false; + } + + if(my_butt.event->event == Events::Slip) + { + ControlContents controlcontents(cell); + int count = 0; + for(auto type_unit : controlcontents.get_units()) + if(type_unit == Units::Worker || type_unit == Units::Citizen) + count++; + if(count > 1) + my_butt.is_enable = false; + } +} + +MenuBuild::MenuBuild(QWidget* _win, IUnitMenuGraphicsController* _graphics_controller, + PlayerUnit* _unit, Cell* _cell) + :AMenuForUnit(_win, _graphics_controller, _unit, _cell) +{ + set_buttons(); +} + +void MenuBuild::set_buttons() +{ + add_farm(); + add_lumbermill(); + add_mine(); + add_pasture(); + add_oilwell(); + add_quarry(); + add_tradingpost(); + add_fort(); + + set_is_enable(); +} + +QRectF MenuBuild::rect_butt(size_t i) +{ + return QRectF{int(i)*side_square*1., 0, side_square*1., side_square*1.}; +} + +void MenuBuild::set_geometry(QPoint pos, int _side_square) +{ + side_square = _side_square; + QWidget::setGeometry(pos.x(), pos.y(), side_square * int(buttons.size()), side_square); +} + +void MenuBuild::set_is_enable() +{ + ControlContents controlcontents(cell); + if(controlcontents.has_building()) + { + Building* building = controlcontents.get_building(); + for(size_t i{0}; i < buttons.size(); ++i) + { + BuildEvent* build_event = static_cast(buttons[i].event.get()); + if(building->is_built() || building->what_building_I() != build_event->building) + buttons[i].is_enable = false; + } + } +} + +void MenuBuild::add_farm() +{ + ControlContents cc(cell); + if(graphics_controller->player_science()->is_open_building(Buildings::Farm)) + if(cc.get_main_landscape() == MainLandscapes::Plain) + buttons.push_back(new BuildEvent{Buildings::Farm}); +} + +void MenuBuild::add_lumbermill() +{ + ControlContents cc(cell); + if(graphics_controller->player_science()->is_open_building(Buildings::LumberMill)) + if(cc.get_other_landscape() == OtherLandscapes::Forest || + cc.get_other_landscape() == OtherLandscapes::ForestAndHills) + buttons.push_back(new BuildEvent{Buildings::LumberMill}); +} + +void MenuBuild::add_mine() +{ + ControlContents cc(cell); + + if(!graphics_controller->player_science()->is_open_building(Buildings::Mine)) + return; + + if(cc.get_other_landscape() == OtherLandscapes::Hills || + cc.get_other_landscape() == OtherLandscapes::ForestAndHills || + cc.get_other_landscape() == OtherLandscapes::JunglesAndHills) + buttons.push_back(new BuildEvent{Buildings::Mine}); + else if(cc.has_resource()) + if(cc.get_resource() == Resources::Aluminum || + cc.get_resource() == Resources::Coal || + cc.get_resource() == Resources::Gold || + cc.get_resource() == Resources::Iron || + cc.get_resource() == Resources::Silver || + cc.get_resource() == Resources::Uranium + ) + buttons.push_back(new BuildEvent{Buildings::Mine}); +} + +void MenuBuild::add_pasture() +{ + ControlContents cc(cell); + if(graphics_controller->player_science()->is_open_building(Buildings::Pasture)) + if(cc.has_resource()) + if(cc.get_resource() == Resources::Horses) + buttons.push_back(new BuildEvent{Buildings::Pasture}); +} + +void MenuBuild::add_oilwell() +{ + ControlContents cc(cell); + if(graphics_controller->player_science()->is_open_building(Buildings::OilWell)) + if(cc.has_resource()) + if(cc.get_resource() == Resources::Oil) + buttons.push_back(new BuildEvent{Buildings::OilWell}); +} + +void MenuBuild::add_quarry() +{ + ControlContents cc(cell); + if(graphics_controller->player_science()->is_open_building(Buildings::Quarry)) + if(cc.has_resource()) + if(cc.get_resource() == Resources::Stone) + buttons.push_back(new BuildEvent{Buildings::Quarry}); +} + +void MenuBuild::add_tradingpost() +{ + ControlContents cc(cell); + if(graphics_controller->player_science()->is_open_building(Buildings::TradingPost)) + buttons.push_back(new BuildEvent{Buildings::TradingPost}); +} + +void MenuBuild::add_fort() +{ + ControlContents cc(cell); + if(graphics_controller->player_science()->is_open_building(Buildings::Fort)) + buttons.push_back(new BuildEvent{Buildings::Fort}); +} + diff --git a/Graphics/Menus/MenuUnit/WorkerMenu.h b/Graphics/Menus/MenuUnit/WorkerMenu.h new file mode 100644 index 0000000..a219851 --- /dev/null +++ b/Graphics/Menus/MenuUnit/WorkerMenu.h @@ -0,0 +1,52 @@ +#ifndef WORKERMENU_H +#define WORKERMENU_H + +#include + +#include "AMenuForUnit.h" +#include "../../GraphicsController/EventsStructures.h" +#include "../../Map/Cell.h" + + +class MenuBuild; + +class WorkerMenu : public AMenuForUnit +{ +public: + WorkerMenu(QWidget* win, IUnitMenuGraphicsController* graphics_controller, + PlayerUnit* unit, Cell* cell); + +protected: + void set_buttons() override; + virtual void draw_butt(size_t num_butt) override; + virtual void click_butt(size_t num_butt) override; + void set_is_enable(MyButton& my_butt); + + bool has_menu = false; + std::unique_ptr menu{nullptr}; + size_t num_butt_build; +}; + +class MenuBuild : public AMenuForUnit +{ +public: + MenuBuild(QWidget* win, IUnitMenuGraphicsController* graphics_controller, + PlayerUnit* unit, Cell* cell); + virtual void set_geometry(QPoint pos, int side_square) override; +protected: + void set_buttons() override; + QRectF rect_butt(size_t i) override; + void set_is_enable(); + + + void add_farm(); + void add_lumbermill(); + void add_mine(); + void add_pasture(); + void add_oilwell(); + void add_quarry(); + void add_tradingpost(); + void add_fort(); +}; + +#endif // WORKERMENU_H diff --git a/Graphics/Minimap.cpp b/Graphics/Minimap.cpp new file mode 100644 index 0000000..09a7093 --- /dev/null +++ b/Graphics/Minimap.cpp @@ -0,0 +1,135 @@ +#include "Minimap.h" +#include + +Minimap::Minimap(QWidget* win, Map* _map, IMiniMapGraphicsController* _graphics_controller) + :QWidget(win), graphics_controller{_graphics_controller}, map{_map}, calc() +{} + +void Minimap::set_geometry(QPoint bottomright, int hexagon_side) +{ + calc.set_side(hexagon_side); + do_size(); + + QWidget::setGeometry(bottomright.x() - width_minimap, bottomright.y() - height_minimap, + width_minimap, height_minimap); +} + +void Minimap::draw() +{ + for(size_t i{0}; i < size_t(graphics_controller->count_cell_y()); ++i) + for(size_t j{0}; j < size_t(graphics_controller->count_cell_x()); ++j) + draw_cell(pos_corner_map + point_of_cell({j,i}), map->cell_by_indexes({j, i})); + + QPainter qp(this); + qp.setPen(QPen{Qt::black, 4, Qt::SolidLine}); + qp.drawRect(win_on_map); + + qp.setPen(QPen{Qt::white, 4, Qt::SolidLine}); + QRect win{QPoint{0,0}, QPoint{width(), height()}}; + qp.drawRect(win); +} + +void Minimap::set_win_rect(double coeffx, double coeffy, double coeff_width, double coeff_height) +{ + double win_center_x = width_minimap/2 - coeffx*width_minimap; + double win_center_y = height_minimap/2 - coeffy*height_minimap; + double win_width = coeff_width * width_minimap; + double win_height = coeff_height * height_minimap; + win_on_map = QRectF(win_center_x, win_center_y, win_width, win_height); +} + +bool Minimap::is_enable() const +{ + return enable; +} + +void Minimap::show() +{ + enable = true; + QWidget::show(); +} + +void Minimap::hide() +{ + enable = false; + QWidget::hide(); +} + +void Minimap::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event) + draw(); +} + +void Minimap::mousePressEvent(QMouseEvent *event) +{ + double coeffx = (width_minimap/2 - event->pos().x() + win_on_map.width()/2)*1. / width_minimap; + double coeffy = (height_minimap/2 - event->pos().y() + win_on_map.height()/2)*1. / height_minimap; + graphics_controller->move_map(coeffx, coeffy); +} + +QPoint Minimap::point_of_cell(Position pos) +{ + int y = int(pos.y+1)*calc.hexagon_side() + int(pos.y)*calc.hexagon_side()/2; + QPoint cell_point{calc.hexagon_height(), y}; + if (pos.y % 2 == 1) + cell_point += QPoint{calc.hexagon_height(), 0}; + + cell_point += QPoint{calc.hexagon_height()*2*int(pos.x), 0}; + return cell_point; +} + +void Minimap::draw_cell(QPoint pos, Cell* cell) +{ + QPoint p1 = pos - calc.point_0(); + QPoint p2 = pos - calc.point_60(); + QPoint p3 = pos - calc.point_120(); + QPoint p4 = pos - calc.point_180(); + QPoint p5 = pos - calc.point_240(); + QPoint p6 = pos - calc.point_300(); + + QPainter qp(this); + + QBrush brush(color(cell)); + qp.setBrush(brush); + + QPointF points[6] {p1, p2, p3, p4, p5, p6}; + qp.drawPolygon(points, 6); +} + +QColor Minimap::color(Cell* cell) +{ + ControlContents controlcontents{cell}; + if(controlcontents.get_show_cell() == ICell::FogOfWar) + return QColor(Qt::white); + + switch (controlcontents.get_main_landscape()) + { + case MainLandscapes::Ocean: + return QColor(Qt::darkBlue); + case MainLandscapes::Coast: + return QColor(Qt::blue); + case MainLandscapes::Plain: + return QColor(Qt::darkGreen); + case MainLandscapes::Mountain: + return QColor(Qt::darkGray); + case MainLandscapes::Tundra: + return QColor(Qt::gray); + case MainLandscapes::Desert: + return QColor(Qt::yellow); + case MainLandscapes::Snow: + return QColor(Qt::white); + case MainLandscapes::Ice: + return QColor(10, 10, 10); + default: + throw std::runtime_error("Minimap::color(): here are no color for this landscape"); + } +} + +void Minimap::do_size() +{ + int num_cell_x = int(graphics_controller->count_cell_x()); + int num_cell_y = int(graphics_controller->count_cell_y()); + height_minimap = calc.hexagon_side()*num_cell_y + calc.hexagon_side()*(num_cell_y+1)/2; + width_minimap = calc.hexagon_height()*(num_cell_x*2+1); +} diff --git a/Graphics/Minimap.h b/Graphics/Minimap.h new file mode 100644 index 0000000..c0f877e --- /dev/null +++ b/Graphics/Minimap.h @@ -0,0 +1,58 @@ +#ifndef MINIMAP_H +#define MINIMAP_H + +#include +#include + +#include "GraphicsController/Calculations.h" +#include "GraphicsController/IWindowGraphicsController.h" +#include "Map/Cell.h" +#include "Map/Map.h" +#include "../Controllers/Enums.h" + + +class Minimap : public QWidget +{ + const QPoint pos_corner_map{0,0}; + +public: + Minimap(QWidget* win, Map* map, IMiniMapGraphicsController* graphics_controller); + + void set_geometry(QPoint pos, int hexagon_side); + void draw(); + + // ставит прямоугольник изображающий где находиться карта относительно окна + // прямоугольник - окно + // coeffx = map_center.x / width_map + // coeffy = map_center.y / height_map + // coeff_width = width_win_map / width_map + // coeff_height = height_win_map / height_map + void set_win_rect(double coeffx, double coeffy, double coeff_width, double coeff_height); + + bool is_enable() const; + + virtual void show(); + virtual void hide(); +private: + virtual void paintEvent(QPaintEvent* event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override {Q_UNUSED(event)} + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override {Q_UNUSED(event)} + + + QPoint point_of_cell(Position pos); + void draw_cell(QPoint bottomright, Cell* cell); + QColor color(Cell* cell); + void do_size(); + + QRectF win_on_map{}; + IMiniMapGraphicsController* graphics_controller; + Map* map; + Calculations calc; + int width_minimap; + int height_minimap; + + bool enable = false; +}; + +#endif // MINIMAP_H diff --git a/Graphics/Resources/Aluminum.h b/Graphics/Resources/Aluminum.h new file mode 100644 index 0000000..4355de8 --- /dev/null +++ b/Graphics/Resources/Aluminum.h @@ -0,0 +1,16 @@ +#ifndef ALUMINUM_H +#define ALUMINUM_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Aluminum : public Res +{ +public: + Aluminum(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Aluminum; } + virtual ~Aluminum() override {} +}; + +#endif // ALUMINUM_H diff --git a/Graphics/Resources/Coal.h b/Graphics/Resources/Coal.h new file mode 100644 index 0000000..38d42c6 --- /dev/null +++ b/Graphics/Resources/Coal.h @@ -0,0 +1,16 @@ +#ifndef COAL_H +#define COAL_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Coal : public Res +{ +public: + Coal(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Coal; } + virtual ~Coal() override {} +}; + +#endif // COAL_H diff --git a/Graphics/Resources/Fish.h b/Graphics/Resources/Fish.h new file mode 100644 index 0000000..6056481 --- /dev/null +++ b/Graphics/Resources/Fish.h @@ -0,0 +1,16 @@ +#ifndef FISH_H +#define FISH_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Fish : public Res +{ +public: + Fish(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Fish; } + virtual ~Fish() override {} +}; + +#endif // FISH_H diff --git a/Graphics/Resources/Gold.h b/Graphics/Resources/Gold.h new file mode 100644 index 0000000..302becf --- /dev/null +++ b/Graphics/Resources/Gold.h @@ -0,0 +1,16 @@ +#ifndef GOLD_H +#define GOLD_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Gold : public Res +{ +public: + Gold(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Gold; } + virtual ~Gold() override {} +}; + +#endif // GOLD_H diff --git a/Graphics/Resources/Horses.h b/Graphics/Resources/Horses.h new file mode 100644 index 0000000..3c4c76e --- /dev/null +++ b/Graphics/Resources/Horses.h @@ -0,0 +1,16 @@ +#ifndef HORSES_H +#define HORSES_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Horses : public Res +{ +public: + Horses(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Horses; } + virtual ~Horses() override {} +}; + +#endif // HORSES_H diff --git a/Graphics/Resources/Iron.h b/Graphics/Resources/Iron.h new file mode 100644 index 0000000..e4d0545 --- /dev/null +++ b/Graphics/Resources/Iron.h @@ -0,0 +1,15 @@ +#ifndef IRON_H +#define IRON_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Iron : public Res +{ +public: + Iron(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Iron; } +}; + +#endif // IRON_H diff --git a/Graphics/Resources/Oil.h b/Graphics/Resources/Oil.h new file mode 100644 index 0000000..6179ee3 --- /dev/null +++ b/Graphics/Resources/Oil.h @@ -0,0 +1,16 @@ +#ifndef OIL_H +#define OIL_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Oil : public Res +{ +public: + Oil(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Oil; } + virtual ~Oil() override {} +}; + +#endif // OIL_H diff --git a/Graphics/Resources/Res.cpp b/Graphics/Resources/Res.cpp new file mode 100644 index 0000000..fda9b7e --- /dev/null +++ b/Graphics/Resources/Res.cpp @@ -0,0 +1,33 @@ +#include "Res.h" + +void Res::draw(QPoint point) +{ + if(!pixmap_for_res) + pixmap_for_res.reset(new QPixmap{FactoryPixmap().create_pixmap_for_res(what_resource_I())}); + + int rad = calculations()->circle_radius(); + + QPainter qp(window()); + QPen pen(Qt::black, 2, Qt::SolidLine); + + qp.drawEllipse(point, rad, rad); + + QRectF source = FactoryPixmap().size_picture_content(); + int adjustment = rad/10; + QRectF target{(point.x() - rad - adjustment)*1., (point.y() - rad - adjustment)*1., 2.*(rad+adjustment), 2.*(rad+adjustment)}; + qp.drawPixmap(target, *pixmap_for_res.get(), source); +} + +QWidget* Res::window() const +{ + return cell->window(); +} + +Calculations* Res::calculations() const +{ + return cell->calculations(); +} + +Res::Res(ICell* cell, int count_of_res) + :cell{cell}, count_of_res{count_of_res} +{} diff --git a/Graphics/Resources/Res.h b/Graphics/Resources/Res.h new file mode 100644 index 0000000..59c05f1 --- /dev/null +++ b/Graphics/Resources/Res.h @@ -0,0 +1,35 @@ +#ifndef RES_H +#define RES_H + +#include +#include + +#include "../Factories/FactoryPixmap.h" +#include "../Map/ICell.h" +#include "../IContent.h" +#include "../../Controllers/Enums.h" + + +class Res : public IContent +{ +public: + virtual void draw(QPoint point) override; + virtual QWidget* window() const override; + virtual Calculations* calculations() const override; + virtual Contents what_content_I() const override { return Contents::Resource; } + virtual Resources what_resource_I() const = 0; + + virtual int get_count_of_res() const {return count_of_res;} + virtual void set_count_of_res(int _count_of_res) { count_of_res = _count_of_res; } + +protected: + Res(ICell* cell, int count_of_res = 0); + +private: + ICell* cell; + int count_of_res; + + std::unique_ptr pixmap_for_res; +}; + +#endif // RES_H diff --git a/Graphics/Resources/Silver.h b/Graphics/Resources/Silver.h new file mode 100644 index 0000000..3d7b34f --- /dev/null +++ b/Graphics/Resources/Silver.h @@ -0,0 +1,16 @@ +#ifndef SILVER_H +#define SILVER_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Silver : public Res +{ +public: + Silver(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Silver; } + virtual ~Silver() override {} +}; + +#endif // SILVER_H diff --git a/Graphics/Resources/Stone.h b/Graphics/Resources/Stone.h new file mode 100644 index 0000000..a2356a4 --- /dev/null +++ b/Graphics/Resources/Stone.h @@ -0,0 +1,16 @@ +#ifndef STONE_H +#define STONE_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Stone : public Res +{ +public: + Stone(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + + virtual Resources what_resource_I() const override { return Resources::Stone; } +}; + +#endif // STONE_H diff --git a/Graphics/Resources/Uranium.h b/Graphics/Resources/Uranium.h new file mode 100644 index 0000000..9e080c4 --- /dev/null +++ b/Graphics/Resources/Uranium.h @@ -0,0 +1,17 @@ +#ifndef URANIUM_H +#define URANIUM_H + +#include "Res.h" +#include "../../Controllers/Enums.h" + + +class Uranium : public Res +{ +public: + Uranium(ICell* cell, int count_of_res) : Res{cell, count_of_res}{} + virtual Resources what_resource_I() const override { return Resources::Uranium; } + virtual ~Uranium() override {} +}; + + +#endif // URANIUM_H diff --git a/Graphics/Units/Bowman.h b/Graphics/Units/Bowman.h new file mode 100644 index 0000000..f4bba18 --- /dev/null +++ b/Graphics/Units/Bowman.h @@ -0,0 +1,18 @@ +#ifndef BOWMAN_H +#define BOWMAN_H + +#include "Unit.h" +#include "../../Controllers/Enums.h" + + +class Bowman : public Unit +{ +public: + Bowman(ICell* cell) + : Unit{cell}{} + virtual Units what_unit_I() const override { return Units::Bowman; } + virtual TypeUnit what_my_type() const override { return RangedCombat; } +}; + + +#endif // BOWMAN_H diff --git a/Graphics/Units/Citizen.h b/Graphics/Units/Citizen.h new file mode 100644 index 0000000..f2301e7 --- /dev/null +++ b/Graphics/Units/Citizen.h @@ -0,0 +1,17 @@ +#ifndef CITIZEN_H +#define CITIZEN_H + +#include "Unit.h" +#include "../../Controllers/Enums.h" + + +class Citizen : public Unit +{ +public: + Citizen(ICell* cell) + : Unit{cell}{} + virtual Units what_unit_I() const override { return Units::Citizen; } + virtual TypeUnit what_my_type() const override { return Peaceful; } +}; + +#endif // CITIZEN_H diff --git a/Graphics/Units/Swordsman.h b/Graphics/Units/Swordsman.h new file mode 100644 index 0000000..edc1346 --- /dev/null +++ b/Graphics/Units/Swordsman.h @@ -0,0 +1,17 @@ +#ifndef SWORDSMAN_H +#define SWORDSMAN_H + +#include "Unit.h" +#include "../../Controllers/Enums.h" + + +class Swordsman : public Unit +{ +public: + Swordsman(ICell* cell) + : Unit{cell}{} + virtual Units what_unit_I() const override { return Units::Swordsman; } + virtual TypeUnit what_my_type() const override { return CloseCombat; } +}; + +#endif // SWORDSMAN_H diff --git a/Graphics/Units/Unit.cpp b/Graphics/Units/Unit.cpp new file mode 100644 index 0000000..e761b8f --- /dev/null +++ b/Graphics/Units/Unit.cpp @@ -0,0 +1,106 @@ +#include "Unit.h" + +Unit::Unit(ICell* _cell) + : cell{_cell} +{} + +void Unit::draw(QPoint point) +{ + if(!pixmap_for_unit) + pixmap_for_unit.reset(new QPixmap{FactoryPixmap().create_pixmap_for_unit_on_map(what_unit_I())}); + + int rad = calculations()->circle_radius(cell->count_units()); + + QPainter qp(window()); + QPen pen(Qt::black, 2, Qt::SolidLine); + qp.setBrush(QBrush(FactoryColor().country_color(country))); + qp.drawEllipse(point, rad, rad); + + QRectF source = FactoryPixmap().size_picture_content(); + int adjustment = 0; + int a = static_cast(round(rad/sqrt(2))); + QRectF target{(point.x() - a - adjustment)*1., (point.y() - a - adjustment)*1., 2.*(a+adjustment), 2.*(a+adjustment)}; + qp.drawPixmap(target, *pixmap_for_unit.get(), source); +} + +QWidget* Unit::window() const +{ + return cell->window(); +} + +Calculations* Unit::calculations() const +{ + return cell->calculations(); +} + +void Unit::set_standard_charaterichtics() +{ + auto uc = UnitsCharaterichtics(); + max_health = uc.get_unit_max_health(what_unit_I()); + health = uc.get_unit_max_health(what_unit_I()); + max_movement = uc.get_unit_max_movement(what_unit_I()); + movement = uc.get_unit_max_movement(what_unit_I()); + vision = uc.get_unit_vision(what_unit_I()); +} + + +void Unit::set_health(int _health) +{ + health = _health; +} + +int Unit::get_health() const +{ + return health; +} + +void Unit::set_max_health(int _max_health) +{ + max_health = _max_health; +} + +int Unit::get_max_health() const +{ + return max_health; +} + +void Unit::set_movement(int _movement) +{ + movement = _movement; +} + +int Unit::get_movement() const +{ + return movement; +} + +void Unit::set_max_movement(int _max_movement) +{ + max_movement = _max_movement; +} + +int Unit::get_max_movement() const +{ + return max_movement; +} + +void Unit::set_vision(int _vision) +{ + vision = _vision; +} + +int Unit::get_vision() const +{ + return vision; +} + +void Unit::set_country(Countries _country) +{ + country = _country; +} + +Countries Unit::get_country() const +{ + return country; +} + diff --git a/Graphics/Units/Unit.h b/Graphics/Units/Unit.h new file mode 100644 index 0000000..3f43925 --- /dev/null +++ b/Graphics/Units/Unit.h @@ -0,0 +1,60 @@ +#ifndef UNIT_H +#define UNIT_H + +#include + +#include "UnitsCharaterichtics.h" +#include "../IContent.h" +#include "../Factories/FactoryColor.h" +#include "../Factories/FactoryPixmap.h" +#include "../Map/ICell.h" +#include "../../Controllers/Enums.h" + + +class Unit : public IContent +{ +public: + enum TypeUnit + { + Peaceful, + RangedCombat, + CloseCombat, + Cavalry + }; + + Unit(ICell* _cell); + + virtual void draw(QPoint point) override; + virtual QWidget* window() const override; + virtual Calculations* calculations() const override; + virtual Contents what_content_I() const override {return Contents::Unit;} + virtual Units what_unit_I() const = 0; + virtual TypeUnit what_my_type() const = 0; + + virtual void set_standard_charaterichtics(); + void set_health(int health); + int get_health() const; + void set_max_health(int max_health); + int get_max_health() const; + void set_movement(int movement); + int get_movement() const; + void set_max_movement(int max_movement); + int get_max_movement() const; + void set_vision(int vision); + int get_vision() const; + + void set_country(Countries country); + Countries get_country() const; +private: + ICell* cell; + int max_health; + int health; + int max_movement; + int movement; + int vision; + Countries country; + + std::unique_ptr pixmap_for_unit; +}; + +#endif // UNIT_H diff --git a/Graphics/Units/UnitsCharaterichtics.h b/Graphics/Units/UnitsCharaterichtics.h new file mode 100644 index 0000000..6cf7fac --- /dev/null +++ b/Graphics/Units/UnitsCharaterichtics.h @@ -0,0 +1,48 @@ +#ifndef UNITSCHARATERICHTICS_H +#define UNITSCHARATERICHTICS_H + +#include + +#include "../../Controllers/Enums.h" +#include "../../IObject.h" + + +class UnitsCharaterichtics : public IObject +{ + std::map unit_max_health{ + {Units::Citizen, 10}, + {Units::Bowman, 10}, + {Units::Worker, 10}, + {Units::Swordsman, 10} + }; + + std::map unit_max_movement{ + {Units::Citizen, 2}, + {Units::Bowman, 3}, + {Units::Worker, 2}, + {Units::Swordsman, 2} + }; + + std::map unit_vision{ + {Units::Citizen, 2}, + {Units::Bowman, 2}, + {Units::Worker, 2}, + {Units::Swordsman, 2} + }; + +public: + int get_unit_max_health(Units type_unit) const + { return unit_max_health.at(type_unit); } + + int get_unit_max_movement(Units type_unit) const + { return unit_max_movement.at(type_unit); } + + int get_unit_vision(Units type_unit) const + { return unit_vision.at(type_unit); } + + int get_worker_build_speed() + { return 10; } +}; + + +#endif // UNITSCHARATERICHTICS_H diff --git a/Graphics/Units/Worker.cpp b/Graphics/Units/Worker.cpp new file mode 100644 index 0000000..859ee3a --- /dev/null +++ b/Graphics/Units/Worker.cpp @@ -0,0 +1,18 @@ +#include "Worker.h" + +void Worker::set_standard_charaterichtics() +{ + Unit::set_standard_charaterichtics(); + + build_speed = UnitsCharaterichtics().get_worker_build_speed(); +} + +void Worker::set_build_speed(int _build_speed) +{ + build_speed = _build_speed; +} + +int Worker::get_build_speed() const +{ + return build_speed; +} diff --git a/Graphics/Units/Worker.h b/Graphics/Units/Worker.h new file mode 100644 index 0000000..a6820ca --- /dev/null +++ b/Graphics/Units/Worker.h @@ -0,0 +1,23 @@ +#ifndef WORKER_H +#define WORKER_H + +#include "Unit.h" +#include "../../Controllers/Enums.h" + + +class Worker : public Unit +{ +public: + Worker(ICell* cell) + : Unit{cell}{} + virtual Units what_unit_I() const override { return Units::Worker; } + virtual TypeUnit what_my_type() const override { return Peaceful; } + + virtual void set_standard_charaterichtics() override; + void set_build_speed(int _build_speed); + int get_build_speed() const; +private: + int build_speed; +}; + +#endif // WORKER_H diff --git a/Graphics/image/building/Academy.png b/Graphics/image/building/Academy.png new file mode 100644 index 0000000..ec0bb9a Binary files /dev/null and b/Graphics/image/building/Academy.png differ diff --git a/Graphics/image/building/Camp.png b/Graphics/image/building/Camp.png new file mode 100644 index 0000000..fb10bfe Binary files /dev/null and b/Graphics/image/building/Camp.png differ diff --git a/Graphics/image/building/CustomsHouse.png b/Graphics/image/building/CustomsHouse.png new file mode 100644 index 0000000..ad3de6f Binary files /dev/null and b/Graphics/image/building/CustomsHouse.png differ diff --git a/Graphics/image/building/Farm.png b/Graphics/image/building/Farm.png new file mode 100644 index 0000000..292e962 Binary files /dev/null and b/Graphics/image/building/Farm.png differ diff --git a/Graphics/image/building/FishingBoats.png b/Graphics/image/building/FishingBoats.png new file mode 100644 index 0000000..aa13615 Binary files /dev/null and b/Graphics/image/building/FishingBoats.png differ diff --git a/Graphics/image/building/Fort.png b/Graphics/image/building/Fort.png new file mode 100644 index 0000000..44a7371 Binary files /dev/null and b/Graphics/image/building/Fort.png differ diff --git a/Graphics/image/building/LumberMill.png b/Graphics/image/building/LumberMill.png new file mode 100644 index 0000000..fb6fd6c Binary files /dev/null and b/Graphics/image/building/LumberMill.png differ diff --git a/Graphics/image/building/Manufactory.png b/Graphics/image/building/Manufactory.png new file mode 100644 index 0000000..d8c8d19 Binary files /dev/null and b/Graphics/image/building/Manufactory.png differ diff --git a/Graphics/image/building/Mine.png b/Graphics/image/building/Mine.png new file mode 100644 index 0000000..0bea5af Binary files /dev/null and b/Graphics/image/building/Mine.png differ diff --git a/Graphics/image/building/OilWell.png b/Graphics/image/building/OilWell.png new file mode 100644 index 0000000..0387d76 Binary files /dev/null and b/Graphics/image/building/OilWell.png differ diff --git a/Graphics/image/building/Pasture.png b/Graphics/image/building/Pasture.png new file mode 100644 index 0000000..cafc877 Binary files /dev/null and b/Graphics/image/building/Pasture.png differ diff --git a/Graphics/image/building/Quarry.png b/Graphics/image/building/Quarry.png new file mode 100644 index 0000000..b1865f5 Binary files /dev/null and b/Graphics/image/building/Quarry.png differ diff --git a/Graphics/image/building/Town.png b/Graphics/image/building/Town.png new file mode 100644 index 0000000..5074390 Binary files /dev/null and b/Graphics/image/building/Town.png differ diff --git a/Graphics/image/building/TradingPost.png b/Graphics/image/building/TradingPost.png new file mode 100644 index 0000000..8664957 Binary files /dev/null and b/Graphics/image/building/TradingPost.png differ diff --git a/Graphics/image/knowledges/Agriculture.png b/Graphics/image/knowledges/Agriculture.png new file mode 100644 index 0000000..82c7eb1 Binary files /dev/null and b/Graphics/image/knowledges/Agriculture.png differ diff --git a/Graphics/image/knowledges/AnimalHusbandry.png b/Graphics/image/knowledges/AnimalHusbandry.png new file mode 100644 index 0000000..02e1c57 Binary files /dev/null and b/Graphics/image/knowledges/AnimalHusbandry.png differ diff --git a/Graphics/image/knowledges/Archery.png b/Graphics/image/knowledges/Archery.png new file mode 100644 index 0000000..4acdb30 Binary files /dev/null and b/Graphics/image/knowledges/Archery.png differ diff --git a/Graphics/image/knowledges/BronzeProcessing.png b/Graphics/image/knowledges/BronzeProcessing.png new file mode 100644 index 0000000..01f3ee5 Binary files /dev/null and b/Graphics/image/knowledges/BronzeProcessing.png differ diff --git a/Graphics/image/knowledges/Compass.png b/Graphics/image/knowledges/Compass.png new file mode 100644 index 0000000..976b208 Binary files /dev/null and b/Graphics/image/knowledges/Compass.png differ diff --git a/Graphics/image/knowledges/DramaAndPoetry.png b/Graphics/image/knowledges/DramaAndPoetry.png new file mode 100644 index 0000000..cf5136c Binary files /dev/null and b/Graphics/image/knowledges/DramaAndPoetry.png differ diff --git a/Graphics/image/knowledges/Education.png b/Graphics/image/knowledges/Education.png new file mode 100644 index 0000000..4798df2 Binary files /dev/null and b/Graphics/image/knowledges/Education.png differ diff --git a/Graphics/image/knowledges/Engineering.png b/Graphics/image/knowledges/Engineering.png new file mode 100644 index 0000000..66621df Binary files /dev/null and b/Graphics/image/knowledges/Engineering.png differ diff --git a/Graphics/image/knowledges/Guilds.png b/Graphics/image/knowledges/Guilds.png new file mode 100644 index 0000000..7c78cd3 Binary files /dev/null and b/Graphics/image/knowledges/Guilds.png differ diff --git a/Graphics/image/knowledges/HorseRiding.png b/Graphics/image/knowledges/HorseRiding.png new file mode 100644 index 0000000..5496dba Binary files /dev/null and b/Graphics/image/knowledges/HorseRiding.png differ diff --git a/Graphics/image/knowledges/IronProcessing.png b/Graphics/image/knowledges/IronProcessing.png new file mode 100644 index 0000000..8e731a8 Binary files /dev/null and b/Graphics/image/knowledges/IronProcessing.png differ diff --git a/Graphics/image/knowledges/Knighthood.png b/Graphics/image/knowledges/Knighthood.png new file mode 100644 index 0000000..69cd992 Binary files /dev/null and b/Graphics/image/knowledges/Knighthood.png differ diff --git a/Graphics/image/knowledges/Language.png b/Graphics/image/knowledges/Language.png new file mode 100644 index 0000000..ba505a7 Binary files /dev/null and b/Graphics/image/knowledges/Language.png differ diff --git a/Graphics/image/knowledges/Machinery.png b/Graphics/image/knowledges/Machinery.png new file mode 100644 index 0000000..2b9f196 Binary files /dev/null and b/Graphics/image/knowledges/Machinery.png differ diff --git a/Graphics/image/knowledges/Mathematics.png b/Graphics/image/knowledges/Mathematics.png new file mode 100644 index 0000000..91d66d1 Binary files /dev/null and b/Graphics/image/knowledges/Mathematics.png differ diff --git a/Graphics/image/knowledges/Money.png b/Graphics/image/knowledges/Money.png new file mode 100644 index 0000000..15f573b Binary files /dev/null and b/Graphics/image/knowledges/Money.png differ diff --git a/Graphics/image/knowledges/Navigation.png b/Graphics/image/knowledges/Navigation.png new file mode 100644 index 0000000..63127c1 Binary files /dev/null and b/Graphics/image/knowledges/Navigation.png differ diff --git a/Graphics/image/knowledges/Optics.png b/Graphics/image/knowledges/Optics.png new file mode 100644 index 0000000..1829a3a Binary files /dev/null and b/Graphics/image/knowledges/Optics.png differ diff --git a/Graphics/image/knowledges/OreMining.png b/Graphics/image/knowledges/OreMining.png new file mode 100644 index 0000000..cdf05ea Binary files /dev/null and b/Graphics/image/knowledges/OreMining.png differ diff --git a/Graphics/image/knowledges/Philosophy.png b/Graphics/image/knowledges/Philosophy.png new file mode 100644 index 0000000..e921c1e Binary files /dev/null and b/Graphics/image/knowledges/Philosophy.png differ diff --git a/Graphics/image/knowledges/StoneProcessing.png b/Graphics/image/knowledges/StoneProcessing.png new file mode 100644 index 0000000..fa1c9cb Binary files /dev/null and b/Graphics/image/knowledges/StoneProcessing.png differ diff --git a/Graphics/image/knowledges/Theology.png b/Graphics/image/knowledges/Theology.png new file mode 100644 index 0000000..7550db6 Binary files /dev/null and b/Graphics/image/knowledges/Theology.png differ diff --git a/Graphics/image/knowledges/Wheel.png b/Graphics/image/knowledges/Wheel.png new file mode 100644 index 0000000..457ebe3 Binary files /dev/null and b/Graphics/image/knowledges/Wheel.png differ diff --git a/Graphics/image/knowledges/Writing.png b/Graphics/image/knowledges/Writing.png new file mode 100644 index 0000000..8f9344f Binary files /dev/null and b/Graphics/image/knowledges/Writing.png differ diff --git a/Graphics/image/landscapes/Coast.png b/Graphics/image/landscapes/Coast.png new file mode 100644 index 0000000..8c71911 Binary files /dev/null and b/Graphics/image/landscapes/Coast.png differ diff --git a/Graphics/image/landscapes/Desert.png b/Graphics/image/landscapes/Desert.png new file mode 100644 index 0000000..eb3bcc1 Binary files /dev/null and b/Graphics/image/landscapes/Desert.png differ diff --git a/Graphics/image/landscapes/FogOfWar.png b/Graphics/image/landscapes/FogOfWar.png new file mode 100644 index 0000000..6beb5da Binary files /dev/null and b/Graphics/image/landscapes/FogOfWar.png differ diff --git a/Graphics/image/landscapes/Forest.png b/Graphics/image/landscapes/Forest.png new file mode 100644 index 0000000..ca472f1 Binary files /dev/null and b/Graphics/image/landscapes/Forest.png differ diff --git a/Graphics/image/landscapes/Forest_hills.png b/Graphics/image/landscapes/Forest_hills.png new file mode 100644 index 0000000..9f0bb12 Binary files /dev/null and b/Graphics/image/landscapes/Forest_hills.png differ diff --git a/Graphics/image/landscapes/Hills.png b/Graphics/image/landscapes/Hills.png new file mode 100644 index 0000000..7b46bae Binary files /dev/null and b/Graphics/image/landscapes/Hills.png differ diff --git a/Graphics/image/landscapes/Ice.png b/Graphics/image/landscapes/Ice.png new file mode 100644 index 0000000..616cae0 Binary files /dev/null and b/Graphics/image/landscapes/Ice.png differ diff --git a/Graphics/image/landscapes/Jungles.png b/Graphics/image/landscapes/Jungles.png new file mode 100644 index 0000000..f79abc8 Binary files /dev/null and b/Graphics/image/landscapes/Jungles.png differ diff --git a/Graphics/image/landscapes/Jungles_hills.png b/Graphics/image/landscapes/Jungles_hills.png new file mode 100644 index 0000000..e381dd4 Binary files /dev/null and b/Graphics/image/landscapes/Jungles_hills.png differ diff --git a/Graphics/image/landscapes/Mountain.png b/Graphics/image/landscapes/Mountain.png new file mode 100644 index 0000000..f4b53fb Binary files /dev/null and b/Graphics/image/landscapes/Mountain.png differ diff --git a/Graphics/image/landscapes/Ocean.png b/Graphics/image/landscapes/Ocean.png new file mode 100644 index 0000000..016cec4 Binary files /dev/null and b/Graphics/image/landscapes/Ocean.png differ diff --git a/Graphics/image/landscapes/Plain.png b/Graphics/image/landscapes/Plain.png new file mode 100644 index 0000000..ef9b900 Binary files /dev/null and b/Graphics/image/landscapes/Plain.png differ diff --git a/Graphics/image/landscapes/Snow.png b/Graphics/image/landscapes/Snow.png new file mode 100644 index 0000000..1ce2cd1 Binary files /dev/null and b/Graphics/image/landscapes/Snow.png differ diff --git a/Graphics/image/landscapes/Tundra.png b/Graphics/image/landscapes/Tundra.png new file mode 100644 index 0000000..b30fcc7 Binary files /dev/null and b/Graphics/image/landscapes/Tundra.png differ diff --git a/Graphics/image/menu/ArrowDown.png b/Graphics/image/menu/ArrowDown.png new file mode 100644 index 0000000..2298d83 Binary files /dev/null and b/Graphics/image/menu/ArrowDown.png differ diff --git a/Graphics/image/menu/ArrowUp.png b/Graphics/image/menu/ArrowUp.png new file mode 100644 index 0000000..6d4dbe5 Binary files /dev/null and b/Graphics/image/menu/ArrowUp.png differ diff --git a/Graphics/image/menu/Build.png b/Graphics/image/menu/Build.png new file mode 100644 index 0000000..1ab664b Binary files /dev/null and b/Graphics/image/menu/Build.png differ diff --git a/Graphics/image/menu/Cancel.png b/Graphics/image/menu/Cancel.png new file mode 100644 index 0000000..92dff4c Binary files /dev/null and b/Graphics/image/menu/Cancel.png differ diff --git a/Graphics/image/menu/DelInQueue.png b/Graphics/image/menu/DelInQueue.png new file mode 100644 index 0000000..759e1d3 Binary files /dev/null and b/Graphics/image/menu/DelInQueue.png differ diff --git a/Graphics/image/menu/Exit.png b/Graphics/image/menu/Exit.png new file mode 100644 index 0000000..7a6ebd1 Binary files /dev/null and b/Graphics/image/menu/Exit.png differ diff --git a/Graphics/image/menu/Gold.png b/Graphics/image/menu/Gold.png new file mode 100644 index 0000000..9d6c08e Binary files /dev/null and b/Graphics/image/menu/Gold.png differ diff --git a/Graphics/image/menu/Map.png b/Graphics/image/menu/Map.png new file mode 100644 index 0000000..34b5f30 Binary files /dev/null and b/Graphics/image/menu/Map.png differ diff --git a/Graphics/image/menu/Move.png b/Graphics/image/menu/Move.png new file mode 100644 index 0000000..4ad4323 Binary files /dev/null and b/Graphics/image/menu/Move.png differ diff --git a/Graphics/image/menu/NextMotion.png b/Graphics/image/menu/NextMotion.png new file mode 100644 index 0000000..de520df Binary files /dev/null and b/Graphics/image/menu/NextMotion.png differ diff --git a/Graphics/image/menu/Science.png b/Graphics/image/menu/Science.png new file mode 100644 index 0000000..d57460a Binary files /dev/null and b/Graphics/image/menu/Science.png differ diff --git a/Graphics/image/menu/Slip.png b/Graphics/image/menu/Slip.png new file mode 100644 index 0000000..f871ba5 Binary files /dev/null and b/Graphics/image/menu/Slip.png differ diff --git a/Graphics/image/menu/TypeMap.png b/Graphics/image/menu/TypeMap.png new file mode 100644 index 0000000..5db7218 Binary files /dev/null and b/Graphics/image/menu/TypeMap.png differ diff --git a/Graphics/image/menu/Upgrade.png b/Graphics/image/menu/Upgrade.png new file mode 100644 index 0000000..1e4f445 Binary files /dev/null and b/Graphics/image/menu/Upgrade.png differ diff --git a/Graphics/image/resources/Aluminum.png b/Graphics/image/resources/Aluminum.png new file mode 100644 index 0000000..b119620 Binary files /dev/null and b/Graphics/image/resources/Aluminum.png differ diff --git a/Graphics/image/resources/Coal.png b/Graphics/image/resources/Coal.png new file mode 100644 index 0000000..14f4ea8 Binary files /dev/null and b/Graphics/image/resources/Coal.png differ diff --git a/Graphics/image/resources/Fish.png b/Graphics/image/resources/Fish.png new file mode 100644 index 0000000..fe4e9b2 Binary files /dev/null and b/Graphics/image/resources/Fish.png differ diff --git a/Graphics/image/resources/Gold.png b/Graphics/image/resources/Gold.png new file mode 100644 index 0000000..9890f92 Binary files /dev/null and b/Graphics/image/resources/Gold.png differ diff --git a/Graphics/image/resources/Horses.png b/Graphics/image/resources/Horses.png new file mode 100644 index 0000000..5b02edc Binary files /dev/null and b/Graphics/image/resources/Horses.png differ diff --git a/Graphics/image/resources/Iron.png b/Graphics/image/resources/Iron.png new file mode 100644 index 0000000..567e35c Binary files /dev/null and b/Graphics/image/resources/Iron.png differ diff --git a/Graphics/image/resources/Oil.png b/Graphics/image/resources/Oil.png new file mode 100644 index 0000000..7293f7d Binary files /dev/null and b/Graphics/image/resources/Oil.png differ diff --git a/Graphics/image/resources/Silver.png b/Graphics/image/resources/Silver.png new file mode 100644 index 0000000..85957f3 Binary files /dev/null and b/Graphics/image/resources/Silver.png differ diff --git a/Graphics/image/resources/Stone.png b/Graphics/image/resources/Stone.png new file mode 100644 index 0000000..2e310f8 Binary files /dev/null and b/Graphics/image/resources/Stone.png differ diff --git a/Graphics/image/resources/Uranium.png b/Graphics/image/resources/Uranium.png new file mode 100644 index 0000000..22c8f50 Binary files /dev/null and b/Graphics/image/resources/Uranium.png differ diff --git a/Graphics/image/town_building/Aqueduct.png b/Graphics/image/town_building/Aqueduct.png new file mode 100644 index 0000000..e88dac3 Binary files /dev/null and b/Graphics/image/town_building/Aqueduct.png differ diff --git a/Graphics/image/town_building/Bank.png b/Graphics/image/town_building/Bank.png new file mode 100644 index 0000000..677b43b Binary files /dev/null and b/Graphics/image/town_building/Bank.png differ diff --git a/Graphics/image/town_building/Factory.png b/Graphics/image/town_building/Factory.png new file mode 100644 index 0000000..ec49ca5 Binary files /dev/null and b/Graphics/image/town_building/Factory.png differ diff --git a/Graphics/image/town_building/Hospital.png b/Graphics/image/town_building/Hospital.png new file mode 100644 index 0000000..f8f4ffc Binary files /dev/null and b/Graphics/image/town_building/Hospital.png differ diff --git a/Graphics/image/town_building/Library.png b/Graphics/image/town_building/Library.png new file mode 100644 index 0000000..120bfaa Binary files /dev/null and b/Graphics/image/town_building/Library.png differ diff --git a/Graphics/image/town_building/Market.png b/Graphics/image/town_building/Market.png new file mode 100644 index 0000000..3daf628 Binary files /dev/null and b/Graphics/image/town_building/Market.png differ diff --git a/Graphics/image/town_building/Medical_Lab.png b/Graphics/image/town_building/Medical_Lab.png new file mode 100644 index 0000000..9ab5f0d Binary files /dev/null and b/Graphics/image/town_building/Medical_Lab.png differ diff --git a/Graphics/image/town_building/Monument.png b/Graphics/image/town_building/Monument.png new file mode 100644 index 0000000..1f256a7 Binary files /dev/null and b/Graphics/image/town_building/Monument.png differ diff --git a/Graphics/image/town_building/Museum.png b/Graphics/image/town_building/Museum.png new file mode 100644 index 0000000..9653037 Binary files /dev/null and b/Graphics/image/town_building/Museum.png differ diff --git a/Graphics/image/town_building/OperaHouse.png b/Graphics/image/town_building/OperaHouse.png new file mode 100644 index 0000000..aa454e0 Binary files /dev/null and b/Graphics/image/town_building/OperaHouse.png differ diff --git a/Graphics/image/town_building/PublicSchool.png b/Graphics/image/town_building/PublicSchool.png new file mode 100644 index 0000000..312a61d Binary files /dev/null and b/Graphics/image/town_building/PublicSchool.png differ diff --git a/Graphics/image/town_building/ResearchLab.png b/Graphics/image/town_building/ResearchLab.png new file mode 100644 index 0000000..395433c Binary files /dev/null and b/Graphics/image/town_building/ResearchLab.png differ diff --git a/Graphics/image/town_building/Shrine.png b/Graphics/image/town_building/Shrine.png new file mode 100644 index 0000000..31f20ab Binary files /dev/null and b/Graphics/image/town_building/Shrine.png differ diff --git a/Graphics/image/town_building/Stadium.png b/Graphics/image/town_building/Stadium.png new file mode 100644 index 0000000..09d7164 Binary files /dev/null and b/Graphics/image/town_building/Stadium.png differ diff --git a/Graphics/image/town_building/StockExchange.png b/Graphics/image/town_building/StockExchange.png new file mode 100644 index 0000000..85582c6 Binary files /dev/null and b/Graphics/image/town_building/StockExchange.png differ diff --git a/Graphics/image/town_building/University.png b/Graphics/image/town_building/University.png new file mode 100644 index 0000000..4a9e503 Binary files /dev/null and b/Graphics/image/town_building/University.png differ diff --git a/Graphics/image/town_building/Walls.png b/Graphics/image/town_building/Walls.png new file mode 100644 index 0000000..05a1809 Binary files /dev/null and b/Graphics/image/town_building/Walls.png differ diff --git a/Graphics/image/town_building/Windmill.png b/Graphics/image/town_building/Windmill.png new file mode 100644 index 0000000..bd5d856 Binary files /dev/null and b/Graphics/image/town_building/Windmill.png differ diff --git a/Graphics/image/town_building/Workshop.png b/Graphics/image/town_building/Workshop.png new file mode 100644 index 0000000..93dc737 Binary files /dev/null and b/Graphics/image/town_building/Workshop.png differ diff --git a/Graphics/image/town_building/Zoo.png b/Graphics/image/town_building/Zoo.png new file mode 100644 index 0000000..9b60976 Binary files /dev/null and b/Graphics/image/town_building/Zoo.png differ diff --git a/Graphics/image/units/Citizen.png b/Graphics/image/units/Citizen.png new file mode 100644 index 0000000..0b4f865 Binary files /dev/null and b/Graphics/image/units/Citizen.png differ diff --git a/Graphics/image/units/Swordsman.png b/Graphics/image/units/Swordsman.png new file mode 100644 index 0000000..3cb8aa9 Binary files /dev/null and b/Graphics/image/units/Swordsman.png differ diff --git a/Graphics/image/units/bowman.png b/Graphics/image/units/bowman.png new file mode 100644 index 0000000..6626d6d Binary files /dev/null and b/Graphics/image/units/bowman.png differ diff --git a/Graphics/image/units/worker.png b/Graphics/image/units/worker.png new file mode 100644 index 0000000..1c80fa7 Binary files /dev/null and b/Graphics/image/units/worker.png differ diff --git a/Graphics/image/units_on_map/Bowman.png b/Graphics/image/units_on_map/Bowman.png new file mode 100644 index 0000000..860182b Binary files /dev/null and b/Graphics/image/units_on_map/Bowman.png differ diff --git a/Graphics/image/units_on_map/Citizen.png b/Graphics/image/units_on_map/Citizen.png new file mode 100644 index 0000000..3ec250e Binary files /dev/null and b/Graphics/image/units_on_map/Citizen.png differ diff --git a/Graphics/image/units_on_map/Swordsman.png b/Graphics/image/units_on_map/Swordsman.png new file mode 100644 index 0000000..300a0a4 Binary files /dev/null and b/Graphics/image/units_on_map/Swordsman.png differ diff --git a/Graphics/image/units_on_map/Worker.png b/Graphics/image/units_on_map/Worker.png new file mode 100644 index 0000000..0028379 Binary files /dev/null and b/Graphics/image/units_on_map/Worker.png differ diff --git a/Graphics/image/units_on_map/pngegg (1).png b/Graphics/image/units_on_map/pngegg (1).png new file mode 100644 index 0000000..7513200 Binary files /dev/null and b/Graphics/image/units_on_map/pngegg (1).png differ diff --git a/Graphics/image/units_on_map/pngegg (3).png b/Graphics/image/units_on_map/pngegg (3).png new file mode 100644 index 0000000..4fb2a58 Binary files /dev/null and b/Graphics/image/units_on_map/pngegg (3).png differ diff --git a/Graphics/image/units_on_map/pngegg (4).png b/Graphics/image/units_on_map/pngegg (4).png new file mode 100644 index 0000000..a6c950d Binary files /dev/null and b/Graphics/image/units_on_map/pngegg (4).png differ diff --git a/Graphics/image/units_on_map/pngegg (5).png b/Graphics/image/units_on_map/pngegg (5).png new file mode 100644 index 0000000..1fb0d45 Binary files /dev/null and b/Graphics/image/units_on_map/pngegg (5).png differ diff --git a/IObject.h b/IObject.h new file mode 100644 index 0000000..f431044 --- /dev/null +++ b/IObject.h @@ -0,0 +1,48 @@ +#ifndef IOBJECT_H +#define IOBJECT_H + +#include + + +struct Position +{ + size_t x; + size_t y; + Position(size_t _x, size_t _y) + :x{_x}, y{_y} {} + Position() + :x{0}, y{0} {} + Position(std::pair pos) + :x{pos.first}, y{pos.second} + {} + + bool operator==(Position other) + { return x == other.x and y == other.y; } + + bool operator!=(Position other) + { return x != other.x or y != other.y; } +}; + + +struct Size +{ + int width; + int height; + Size(int _width, int _height) + :width{_width}, height{_height} {} + Size() + :width{0}, height{0} {} +}; + + +class IObject +{ +public: + virtual ~IObject(){} +protected: + IObject(){} +}; + + + +#endif // IOBJECT_H diff --git a/Images.qrc b/Images.qrc new file mode 100644 index 0000000..343b709 --- /dev/null +++ b/Images.qrc @@ -0,0 +1,113 @@ + + + Graphics/image/resources/Aluminum.png + Graphics/image/resources/Coal.png + Graphics/image/resources/Fish.png + Graphics/image/resources/Gold.png + Graphics/image/resources/Horses.png + Graphics/image/resources/Iron.png + Graphics/image/resources/Oil.png + Graphics/image/resources/Silver.png + Graphics/image/resources/Stone.png + Graphics/image/resources/Uranium.png + Graphics/image/building/Academy.png + Graphics/image/building/Camp.png + Graphics/image/building/Farm.png + Graphics/image/building/Fort.png + Graphics/image/building/Manufactory.png + Graphics/image/building/Mine.png + Graphics/image/building/Pasture.png + Graphics/image/building/Quarry.png + Graphics/image/building/Town.png + Graphics/image/landscapes/Plain.png + Graphics/image/landscapes/Mountain.png + Graphics/image/landscapes/Coast.png + Graphics/image/landscapes/Ocean.png + Graphics/image/landscapes/Tundra.png + Graphics/image/landscapes/Forest.png + Graphics/image/landscapes/Desert.png + Graphics/image/building/CustomsHouse.png + Graphics/image/building/FishingBoats.png + Graphics/image/building/LumberMill.png + Graphics/image/building/TradingPost.png + Graphics/image/building/OilWell.png + Graphics/image/landscapes/forest_hills.png + Graphics/image/landscapes/Jungles.png + Graphics/image/landscapes/Jungles_hills.png + Graphics/image/landscapes/Forest_hills.png + Graphics/image/menu/Exit.png + Graphics/image/landscapes/Ice.png + Graphics/image/landscapes/Snow.png + Graphics/image/menu/Move.png + Graphics/image/menu/Slip.png + Graphics/image/menu/Map.png + Graphics/image/menu/NextMotion.png + Graphics/image/landscapes/Hills.png + Graphics/image/menu/Build.png + Graphics/image/units_on_map/Bowman.png + Graphics/image/units_on_map/Citizen.png + Graphics/image/units_on_map/pngegg (1).png + Graphics/image/units_on_map/pngegg (3).png + Graphics/image/units_on_map/pngegg (4).png + Graphics/image/units_on_map/pngegg (5).png + Graphics/image/units_on_map/Swordsman.png + Graphics/image/units_on_map/Worker.png + Graphics/image/units/Bowman.png + Graphics/image/units/Citizen.png + Graphics/image/units/Swordsman.png + Graphics/image/units/Worker.png + Graphics/image/menu/Cancel.png + Graphics/image/town_building/Aqueduct.png + Graphics/image/town_building/Bank.png + Graphics/image/town_building/Factory.png + Graphics/image/town_building/Hospital.png + Graphics/image/town_building/Library.png + Graphics/image/town_building/Market.png + Graphics/image/town_building/Medical_Lab.png + Graphics/image/town_building/Monument.png + Graphics/image/town_building/Museum.png + Graphics/image/town_building/OperaHouse.png + Graphics/image/town_building/PublicSchool.png + Graphics/image/town_building/ResearchLab.png + Graphics/image/town_building/Shrine.png + Graphics/image/town_building/Stadium.png + Graphics/image/town_building/StockExchange.png + Graphics/image/town_building/University.png + Graphics/image/town_building/Walls.png + Graphics/image/town_building/Windmill.png + Graphics/image/town_building/Workshop.png + Graphics/image/town_building/Zoo.png + Graphics/image/menu/DelInQueue.png + Graphics/image/menu/ArrowDown.png + Graphics/image/menu/ArrowUp.png + Graphics/image/landscapes/FogOfWar.png + Graphics/image/menu/Gold.png + Graphics/image/menu/Science.png + Graphics/image/menu/Upgrade.png + Graphics/image/knowledges/Agriculture.png + Graphics/image/knowledges/AnimalHusbandry.png + Graphics/image/knowledges/Archery.png + Graphics/image/knowledges/BronzeProcessing.png + Graphics/image/knowledges/Compass.png + Graphics/image/knowledges/DramaAndPoetry.png + Graphics/image/knowledges/Education.png + Graphics/image/knowledges/Engineering.png + Graphics/image/knowledges/Guilds.png + Graphics/image/knowledges/HorseRiding.png + Graphics/image/knowledges/IronProcessing.png + Graphics/image/knowledges/Knighthood.png + Graphics/image/knowledges/Machinery.png + Graphics/image/knowledges/Mathematics.png + Graphics/image/knowledges/Money.png + Graphics/image/knowledges/Navigation.png + Graphics/image/knowledges/Optics.png + Graphics/image/knowledges/OreMining.png + Graphics/image/knowledges/Philosophy.png + Graphics/image/knowledges/StoneProcessing.png + Graphics/image/knowledges/Theology.png + Graphics/image/knowledges/Wheel.png + Graphics/image/knowledges/Writing.png + Graphics/image/knowledges/Language.png + Graphics/image/menu/TypeMap.png + + diff --git a/Landoria(diagram).png b/Landoria(diagram).png new file mode 100644 index 0000000..b432980 Binary files /dev/null and b/Landoria(diagram).png differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e959049 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include +#include +#include "Controllers/Game.h" + +using namespace std; + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Game game = Game(&a, 50, 30, 2, Mod::Show); + game.start(); + return a.exec(); +} diff --git "a/\320\235\320\260\321\203\320\272\320\260.xlsx" "b/\320\235\320\260\321\203\320\272\320\260.xlsx" new file mode 100644 index 0000000..f927240 Binary files /dev/null and "b/\320\235\320\260\321\203\320\272\320\260.xlsx" differ