Commit 00251ac5 authored by Elias Leinenweber's avatar Elias Leinenweber
Browse files

Ca compile avec Texturable !!!

parent 10d62e08
......@@ -3,7 +3,9 @@
#include <string>
class Actor
#include "view/Texturable.h"
class Actor : public Texturable
{
private:
std::string name;
......@@ -16,8 +18,7 @@ class Actor
* @param name Prénom du personnage
* @param surname Nom de famille du personnage
*/
Actor(const std::string &name, const std::string &surname);
~Actor();
Actor(const std::string &name, const std::string &surname, const std::string &texturePath);
/**
* @brief Renvoie le prénom du personnage.
......
#ifndef CLASS_H
#define CLASS_H
#include <iostream>
#include <string>
#include <vector>
#include "controller/Game.h"
#include "view/Texturable.h"
class Student;
class Teacher;
class Classroom
class Classroom : public Texturable
{
private:
static const int MAX_SIZE = 50; /**< taille maximum de la classe */
std::vector<Student *> students; /**< élèves de la classe */
Teacher *teacher; /**< enseignant de la classe */
public:
/**
* @brief Construct a new Classroom object
*
* @param teacher Professeur de la classe
*/
Classroom(Teacher &teacher);
Classroom(int n, Teacher *teacher) : Texturable(RESOURCES_FOLDER "images/salles/salle" + std::to_string(n) + ".png"), teacher(teacher) {
std::cout << "créé une classroom" << std::endl;
}
~Classroom();
/**
......@@ -48,6 +56,12 @@ class Classroom
* @return int nombre d'élève
*/
int size() { return students.size(); }
void render() const;
const std::string &getTexturePath() const override final {
return texturePath;
}
};
#endif
......@@ -4,47 +4,45 @@
#include <string>
#include <vector>
#include "view/Texturable.h"
class Classroom;
class School
class School : public Component
{
private:
/**
* @brief Nom de l'école
*
*/
/** @brief Nom de l'école */
std::string name;
/**
* @brief Classes dans l'école
*
*/
std::vector<Classroom *> classes;
/** @brief Classes dans l'école */
std::vector<Classroom *> classrooms;
public:
School() = delete;
School(std::string name);
School(const std::string &name);
~School();
/**
* @brief Set le nom de l'école
*
* @param name Nom de l'école
*/
void setName(const std::string &name) { this->name = name; };
void setName(const std::string &name) { this->name = name; }
/**
* @brief Get le nom de l'école
*
* @return std::string Nom de l'école
*/
std::string getName() { return this->name; };
std::string getName() { return this->name; }
/**
* @brief Ajoute une classe à l'école
*
* @param classe Classe à ajouter
*/
void addClass(Classroom *classe) { classes.push_back(classe); };
void addClass(Classroom *classe) { classrooms.push_back(classe); }
void render() const;
};
#endif
#ifndef TEACHER_H
#define TEACHER_H
#include <iostream>
#include <string>
#include "model/Actor.h"
class Teacher : Actor
......@@ -27,9 +30,8 @@ class Teacher : Actor
* @param pedagogie Niveau de pédagogie du professeur
* @param meritocratic Niveau de méritocratie du professeur
*/
Teacher(std::string name, std::string surname, double pedagogie,
Teacher(const std::string &name, const std::string &surname, double pedagogie,
double meritocratic);
~Teacher();
/**
* @brief Get le niveau de pédagogie du professeur
......@@ -61,6 +63,11 @@ class Teacher : Actor
{
this->meritocratic = meritocratic;
}
const std::string &getTexturePath() const override final {
std::cout << "about to return texturepath : " << texturePath << std::endl;
return texturePath;
}
};
#endif
......@@ -5,17 +5,17 @@
#include <SFML/Graphics.hpp>
#include "Component.h"
#include "model/School.h"
#include "view/Component.h"
class MainView : public Component
{
private:
std::vector<sf::Texture *> classrooms;
const School *school;
public:
MainView();
~MainView();
void render() const;
};
......
#ifndef TEXTURABLE_H
#define TEXTURABLE_H
#include <string>
#include <SFML/Graphics.hpp>
#include "controller/Game.h"
#include "view/Component.h"
class Texturable : public Component {
protected:
std::string texturePath;
sf::Texture texture;
public:
Texturable(const std::string &filename);
virtual void render() const;
virtual const std::string &getTexturePath() const;
};
#endif /* TEXTURABLE_H */
#include <iostream>
#include "model/Actor.h"
Actor::Actor(const std::string &name, const std::string &surname, const std::string &texturePath) : Texturable(texturePath), name(name), surname(surname)
{
std::cout << "créé un actor" << std::endl;
}
#include "model/Class.h"
#include "imgui/imgui-SFML.h"
#include "imgui/imgui.h"
#include "model/Classroom.h"
#include "model/Student.h"
#include "model/Teacher.h"
void
Classroom::render() const
{
ImGui::ImageButton(texture, ImVec2(ImGui::GetIO().DisplaySize.x / 2.1,
ImGui::GetIO().DisplaySize.y / 2.2));
}
Classroom::~Classroom()
{
while (!students.empty()) {
delete students.back();
students.pop_back();
}
delete teacher;
}
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include "imgui/imgui-SFML.h"
#include "imgui/imgui.h"
#include "model/Classroom.h"
#include "model/School.h"
#include "model/Teacher.h"
#include "view/Utils.h"
School::School(const std::string &name) : name(name)
{
std::cout << "en train de créer une school" << std::endl;
Teacher *teacher = new Teacher("H.", "Julien", 70, 40);
std::cout << "créé H" << std::endl;
for (int i = 1; i <= 4; ++i)
classrooms.push_back(new Classroom(i, teacher));
std::cout << "créé une school" << std::endl;
}
School::~School()
{
while (!classrooms.empty()) {
delete classrooms.back();
classrooms.pop_back();
}
}
void
School::render() const
{
maximizeNextWindow();
if (ImGui::Begin(name.c_str(), nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
ImGui::Columns(2, NULL);
ImGui::Separator();
for (int i = 0; i < 4; ++i) {
if (i > 0 && i % 2 == 0)
ImGui::Separator();
classrooms[i % classrooms.size()]->render();
ImGui::NextColumn();
}
ImGui::Columns(1);
ImGui::Separator();
}
ImGui::End();
}
#include <iostream>
#include "model/Actor.h"
#include "model/Teacher.h"
Teacher::Teacher(const std::string &name, const std::string &surname, double pedagogie,
double meritocratic) : Actor(name, surname, "resources/images/profs/prof1.png"),
pedagogue(pedagogie), meritocratic(meritocratic)
{
std::cout << "créé un teacher" << std::endl;
}
......@@ -11,45 +11,18 @@
#include "view/MainView.h"
#include "view/Utils.h"
MainView::MainView()
MainView::MainView() : school(new School("L'école infernale"))
{
sf::Texture *classroom = new sf::Texture;
char path[35];
sprintf(path, RESOURCES_FOLDER "images/salles/salle1.png");
while (classroom->loadFromFile(path)) {
classrooms.push_back(classroom);
classroom = new sf::Texture;
++path[29]; // grosse magie noire mythique ici.
}
std::cout << "créé la mainview" << std::endl;
}
MainView::~MainView()
{
while (!classrooms.empty()) {
delete classrooms.back();
classrooms.pop_back();
}
delete school;
}
void
MainView::render() const
{
maximizeNextWindow();
if (ImGui::Begin("École", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
ImGui::Columns(2, NULL);
ImGui::Separator();
ImVec2 size(ImGui::GetIO().DisplaySize.x / 2.1,
ImGui::GetIO().DisplaySize.y / 2.2);
for (int i = 0; i < 4; ++i) {
if (i > 0 && i % 2 == 0)
ImGui::Separator();
ImGui::ImageButton(*classrooms[i % classrooms.size()], size);
ImGui::NextColumn();
}
ImGui::Columns(1);
ImGui::Separator();
}
ImGui::End();
school->render();
}
#include "assert.h"
#include <iostream>
#include "imgui/imgui-SFML.h"
#include "imgui/imgui.h"
#include "view/Texturable.h"
Texturable::Texturable(const std::string &filename) : texturePath(filename), texture(sf::Texture())
{
std::cout << "About to load texture..." << std::endl;
std::cout << "texturePath = \"" << texturePath << "\"" << std::endl;
assert(texture.loadFromFile(texturePath));
}
void
Texturable::render() const
{
ImGui::ImageButton(texture);
}
// a redefinir !!!!
const std::string &
Texturable::getTexturePath() const
{
return "";
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment