Commit 1af296af authored by Elias Leinenweber's avatar Elias Leinenweber
Browse files

ImageButton pour eleve, formatage de code, etc

parent a3df0af1
......@@ -6,8 +6,9 @@ project(HeadmasterSimulator
HOMEPAGE_URL "https://git.unistra.fr/barre-oblique-v3/t432_sab20_t3_b"
LANGUAGES CXX)
# specify the C++ standard
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
......
......@@ -5,6 +5,8 @@
#include <SFML/System.hpp>
#include "imgui/imgui.h"
#include "view/Component.h"
#include "view/GameWindow.h"
......@@ -15,6 +17,7 @@ class Game {
private:
static GameWindow *mainWindow;
static std::vector<Component *> components;
static ImGuiID componentID;
/** @brief Démarre le jeu. */
static void start();
......@@ -29,6 +32,8 @@ class Game {
/** @brief Termine le jeu. */
static void end();
static void resetComponentID();
public:
Game() = delete;
......@@ -68,6 +73,8 @@ class Game {
/** @brief Supprime tous les composants graphiques du jeu. */
static void clearComponents();
static ImGuiID getComponentID();
};
#endif /* GAME_H */
......@@ -10,34 +10,33 @@
#include "model/Student.h"
/** @brief Classe permettant de génerer des noms pour les élèves */
class StudentFactory{
private:
class StudentFactory {
private:
/**
* @brief liste de élèves
*
*
*/
static std::vector<Student *> studentFactory;
/**
* @brief nom du fichier
*
*
*/
static std::string filename;
/**
* @brief Get the Next Line And Split Into Tokens object
*
*
* @param str input stream
* @return std::vector<std::string> ligne de string contenant les infos
*/
static std::vector<std::string> getNextLineAndSplitIntoTokens(std::istream& stream);
public:
static std::vector<std::string> getNextLineAndSplitIntoTokens(
std::istream &stream);
public:
StudentFactory() = delete;
~StudentFactory();
static void loadStudentFactory();
static Student * getRandomStudent();
static Student *getRandomStudent();
};
#endif /* STUDENTFACTORY_H */
\ No newline at end of file
#endif /* STUDENTFACTORY_H */
......@@ -33,7 +33,10 @@ class Actor : public Texturable {
*
* @param name le nouveau prénom du personnage
*/
void setFirstName(const std::string &firstname) { this->firstname = firstname; }
void setFirstName(const std::string &firstname)
{
this->firstname = firstname;
}
/**
* @brief Renvoie le nom de famille du personnage
......
......@@ -37,8 +37,8 @@ class Student : public Actor {
* @param motivation Motivation de l'élève
* @param skill Qualité de l'élève
*/
Student(const std::string &firstname, const std::string &surname, double mood,
double motivation, double skill);
Student(const std::string &firstname, const std::string &surname,
double mood, double motivation, double skill);
~Student();
/**
......
......@@ -16,6 +16,7 @@
GameWindow *Game::mainWindow = nullptr;
std::vector<Component *> Game::components = std::vector<Component *>();
ImGuiID Game::componentID = 1;
void
Game::play(sf::Clock &clock)
......@@ -49,6 +50,7 @@ Game::loop(sf::Clock &clock)
{
assert(mainWindow);
while (mainWindow->isOpen()) {
resetComponentID();
mainWindow->handleEvents();
ImGui::SFML::Update(*mainWindow, clock.restart());
for (const Component *component : components)
......@@ -106,3 +108,15 @@ Game::clearComponents()
for (Component *component : components)
removeComponent(component);
}
ImGuiID
Game::getComponentID()
{
return componentID++;
}
void
Game::resetComponentID()
{
componentID = 1;
}
......@@ -9,54 +9,61 @@
#include "model/Student.h"
std::vector<Student *> StudentFactory::studentFactory;
std::string StudentFactory::filename(RESOURCES_FOLDER "actors/DataStudents.csv");
std::string StudentFactory::filename(RESOURCES_FOLDER
"actors/DataStudents.csv");
std::vector<std::string> StudentFactory::getNextLineAndSplitIntoTokens(std::istream& stream){
std::vector<std::string> result;
std::string line;
std::getline(stream,line);
std::vector<std::string>
StudentFactory::getNextLineAndSplitIntoTokens(std::istream &stream)
{
std::vector<std::string> result;
std::string line;
std::getline(stream, line);
std::stringstream lineStream(line);
std::string cell;
std::stringstream lineStream(line);
std::string cell;
while(std::getline(lineStream,cell, ','))
{
while (std::getline(lineStream, cell, ',')) {
result.push_back(cell);
}
// This checks for a trailing comma with no data after it.
if (!lineStream && cell.empty())
{
if (!lineStream && cell.empty()) {
// If there was a trailing comma then add an empty element.
result.push_back("");
}
return result;
}
void StudentFactory::loadStudentFactory(){
void
StudentFactory::loadStudentFactory()
{
// ouvre le fichier
std::ifstream ifs (filename,std::ifstream::in);
std::ifstream ifs(filename, std::ifstream::in);
std::vector<std::string> studentline;
while( ifs.good()){
while (ifs.good()) {
studentline = getNextLineAndSplitIntoTokens(ifs);
if( studentline.size() == 6)
studentFactory.push_back(new Student(studentline[1],studentline[2],atof(studentline[3].c_str()),atof(studentline[4].c_str()),atof(studentline[5].c_str())));
if (studentline.size() == 6)
studentFactory.push_back(new Student(
studentline[1], studentline[2], atof(studentline[3].c_str()),
atof(studentline[4].c_str()), atof(studentline[5].c_str())));
}
ifs.close();
auto rng = std::default_random_engine{};
std::shuffle(std::begin(studentFactory), std::end(studentFactory),rng);
std::shuffle(std::begin(studentFactory), std::end(studentFactory), rng);
}
Student * StudentFactory::getRandomStudent(){
Student *
StudentFactory::getRandomStudent()
{
assert(!studentFactory.empty());
Student * rndstudent = studentFactory.back(); // la liste est mélangé point
Student *rndstudent = studentFactory.back(); // la liste est mélangé point
studentFactory.pop_back();
return rndstudent;
}
StudentFactory::~StudentFactory(){
StudentFactory::~StudentFactory()
{
while (!studentFactory.empty()) {
delete studentFactory.back();
studentFactory.pop_back();
......
#include <cstring>
#include <iostream>
#include <SFML/OpenGL.hpp>
#include "imgui/imgui-SFML.h"
#include "imgui/imgui.h"
......@@ -13,16 +18,31 @@ Classroom::Classroom(int n, Teacher *teacher)
{
}
ImTextureID
convertGLTextureHandleToImTextureID(GLuint glTextureHandle)
{
ImTextureID textureID = (ImTextureID)NULL;
std::memcpy(&textureID, &glTextureHandle, sizeof(GLuint));
return textureID;
}
void
Classroom::render() const
{
if (ImGui::BeginChild(++lastID,
ImVec2(ImGui::GetIO().DisplaySize.x / 2.1,
ImGui::GetIO().DisplaySize.y / 2.2))) {
ImGui::Image(texture);
ImGui::SameLine();
for (const Student *student : students)
ImVec2 size(ImGui::GetIO().DisplaySize.x / 2.5,
ImGui::GetIO().DisplaySize.y / 2.5);
if (ImGui::BeginChild(Game::getComponentID(), size)) {
// ImGui::SameLine();
ImGui::GetBackgroundDrawList()->AddImage(
convertGLTextureHandleToImTextureID(texture.getNativeHandle()),
ImGui::GetWindowPos(),
ImVec2(ImGui::GetWindowPos().x + ImGui::GetContentRegionAvail().x,
ImGui::GetWindowPos().y + ImGui::GetContentRegionAvail().y));
// ImGui::Image(texture, size);
for (const Student *student : students) {
// std::cout << "rendering student" << std::endl;
student->render();
}
}
ImGui::EndChild();
}
......
......@@ -14,9 +14,13 @@
School::School(const std::string &name)
: name(name)
{
for (int i = 1; i <= 4; ++i)
classrooms.push_back(
new Classroom(i, new Teacher("H.", "Julien", 70, 40)));
Classroom *classroom;
for (int i = 1; i <= 4; ++i) {
classroom = new Classroom(i, new Teacher("H.", "Julien", 70, 40));
classroom->addStudent(new Student("de Noel", "Golden", 80, 70, 70));
classrooms.push_back(classroom);
}
}
School::~School()
......
......@@ -22,10 +22,8 @@ MainView::MainView()
// ajout élèves
StudentFactory::loadStudentFactory();
for(int i(0);i< NB_STUDENT;i++){
for (int i(0); i < NB_STUDENT; i++)
g12->addStudent(StudentFactory::getRandomStudent());
std::cout << g12->getStudents().back()->getFirstName() << std::endl;
}
}
MainView::~MainView()
......
Markdown is supported
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