W pliku maj stworzyłem obiekt "options_object" bo chciałbym go użyć do wywołania funkcji draw w main.
Jednocześnie chciałbym użyć tego obiektu w menu.cpp w metodzie "menu_option_index", przy if == 3 do wywołania metody w pliku option_page metody "basic".
Oczywiście proszę o wyrozumiałość w sprawie czytelności kodu i wykorzystanych rozwiązań.
Jeżeli macie jakieś inne pomysły jak mogę to wykonać, będę wdzięczny za propozycje.
Main:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include "menu.h"
#include "option_page.h"
int main()
{
int width = 1200, height = 900, menu_option=0;
auto mode_screen = sf::Style::Default;
sf::RenderWindow window(sf::VideoMode(width, height), "Magic Board", mode_screen);
window.setFramerateLimit(60);
Option_page options_object(window);
Menu menu(window);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
sf::Vector2i mouse = sf::Mouse::getPosition(window);
menu.menu_option_index(window, mouse, menu_option);
menu_option = menu.menu_option;
window.clear();
menu.draw_menu(window, mouse, menu_option);
options_object.draw_option_page(window);
window.display();
}
return 0;
}
menu.cpp: https://github.com/lukasz-kukulka/Magic_board/blob/master/menu.cpp
menu.h:
#ifndef MENU_H
#define MENU_H
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <vector>
class Menu
{
private:
sf::Text new_game, highScore, options, credits, exit, closing, back_text, lukasz_kukulka, lukasz_copy1, lukasz_copy2,
lukasz_copy3, director, screenplan, project, editor;
sf::Font font, otama_font;
sf::Sprite backgroud_menu;
sf::Texture backgroud;
sf::RectangleShape rec1, rec2, rec3, rec4, rec5, back_button;
sf::Color base_menu_change, base_menu_regular, red_menu, green_menu, black_menu;
int rec_size_x, rec_size_y, transparent_color, y, space_block;
sf::Clock clock;
sf::Time time;
public:
Menu(sf::RenderWindow &window);
~Menu();
int menu_option;
void menu_base(sf::RenderWindow &window, sf::Vector2i, int);
void menu_animation(sf::RenderWindow &window, sf::Vector2i, int);
void menu_newGame(sf::RenderWindow &window, sf::Vector2i, int);
void menu_highScore(sf::RenderWindow &window, sf::Vector2i, int);
void menu_options(sf::RenderWindow &window, sf::Vector2i, int);
void menu_credits(sf::RenderWindow &window, sf::Vector2i, int);
void menu_exit(sf::RenderWindow &window, sf::Vector2i, int);
void menu_form_to_play(sf::RenderWindow &window, sf::Vector2i, int);
void menu_option_index(sf::RenderWindow &window, sf::Vector2i, int);
void draw_menu(sf::RenderWindow &window, sf::Vector2i, int);
};
#endif
option_page.cpp:
#include "option_page.h"
Option_page::Option_page(sf::RenderWindow &window)
{
this->otama_font.loadFromFile("Fonts/otama.otf");
this->center_x = window.getSize().x/2;
this->center_y = window.getSize().y/2;
this->size_block = 32;
this->start_draw_x = (center_x % size_block) + (size_block*3);
this->end_draw_x = window.getSize().x - ((center_x % size_block) + (size_block*3));
this->start_draw_y = (center_y % size_block) + (size_block*3);
this->end_draw_y = window.getSize().y - ((center_y % size_block) + (size_block*3));;
this->width_screen = window.getSize().x - ((center_x % size_block) + (size_block*3)*2);
this->height_screen = window.getSize().y - ((center_y % size_block) + (size_block*3)*2);
this->no_blocks_x = width_screen/size_block;
this->no_blocks_y = height_screen/size_block;
this->block_texture_corner.loadFromFile("Textures/corner-board.png");
this->block_texture_middle.loadFromFile("Textures/middle.png");
this->block_texture_board.loadFromFile("Textures/middle-board.png");
this->screen_resolution.setFont(otama_font);
this->screen_resolution.setCharacterSize(0);
this->screen_resolution.setFillColor(sf::Color(255, 255, 0));
this->screen_resolution.setString("NEW GAME");
this->screen_resolution.setOutlineThickness(2);
this->screen_resolution.setPosition(100, 100);
}
Option_page::~Option_page(){}
void Option_page::basic(sf::RenderWindow &window, sf::Vector2i mouse, int menu_option)
{
screen_resolution.setCharacterSize(150);
std::cout<<"..................................................."<<std::endl;
}
void Option_page::animation(sf::RenderWindow &window, sf::Vector2i mouse, int menu_option)
{
}
void Option_page::draw_option_page(sf::RenderWindow &window)
{
window.draw(screen_resolution);
}
option_page.h:
#include <iostream>
#include <SFML/Graphics.hpp>
class Option_page
{
private:
sf::Text screen_resolution, screen_resolution800x600, screen_resolution1280x1024, screen_resolution1920x1080,
windowed_mode, fullscreen_mode, high_score, high_score_no, save_button_text, back_button_text;
int width_screen, height_screen, center_x, center_y, size_block, start_draw_x, end_draw_x, start_draw_y, end_draw_y, no_blocks_x, no_blocks_y;
sf::Font otama_font;
sf::Sprite block;
sf::RectangleShape back_button, save_button, line;
sf::Texture block_texture_corner, block_texture_middle, block_texture_board;
std::vector<sf::Sprite>blocks;
public:
Option_page(sf::RenderWindow &window);
~Option_page();
void animation(sf::RenderWindow &window, sf::Vector2i, int);
void draw_option_page(sf::RenderWindow &window);
void basic(sf::RenderWindow &window, sf::Vector2i, int);
};