Skip to content

Commit

Permalink
Feature/rb 142 menu de connection (#129)
Browse files Browse the repository at this point in the history
* ECS: Add button that can change scene
Merge
MINOR

* CLIENT-GAME/DOCUMENTATION: Add first functional version of menu + some docs
MINOR

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME/DOCUMENTATION: Update client game and error management

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Fix coderabbit review
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now menu can init entity with the singletone MenuFactory
MINOR

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Update src/Client/Systems/Menu/ButtonCallbacks.cpp

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* CLIENT-GAME: Modif script to debug compil
PATCH

* CLIENT-GAME: Update code to make it cleaner
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME/DOCUMENTATION: Add some docs for menu builder class
Modif some static method inside the menu.cpp file
MINOR

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Update setAllInputBoxFalse to be more optimized
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Fix some bad includes
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now use template Json function
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now use template Json function
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now use template Json function
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* DOCUMENTATION: Update json doc
Modif compil.ps1 to compil as before
MINOR

* SCRIPTS: Modif scripts to do the same things as before
PATCH

* ECS: Add button that can change scene
Merge
MINOR

* CLIENT-GAME/DOCUMENTATION: Add first functional version of menu + some docs
MINOR

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME/DOCUMENTATION: Update client game and error management

* CLIENT-GAME: Fix coderabbit review
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now menu can init entity with the singletone MenuFactory
MINOR

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Update src/Client/Systems/Menu/ButtonCallbacks.cpp

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* CLIENT-GAME: Modif script to debug compil
PATCH

* CLIENT-GAME: Update code to make it cleaner
PATCH

* CLIENT-GAME/DOCUMENTATION: Add some docs for menu builder class
Modif some static method inside the menu.cpp file
MINOR

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Update setAllInputBoxFalse to be more optimized
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Fix some bad includes
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now use template Json function
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now use template Json function
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* CLIENT-GAME: Modif now use template Json function
PATCH

* FORMAT-AUTO: automatic format on pull request #129

* DOCUMENTATION: Update json doc
Modif compil.ps1 to compil as before
MINOR

* FORMAT-AUTO: automatic format on pull request #129

* SCRIPTS: Modif scripts to do the same things as before
PATCH

* FORMAT-AUTO: automatic format on pull request #129

---------

Co-authored-by: Github Actions <github-actions[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 28, 2023
1 parent 2d64fe2 commit eda3bc9
Show file tree
Hide file tree
Showing 23 changed files with 789 additions and 66 deletions.
121 changes: 121 additions & 0 deletions assets/Json/menu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"menu": {
"connect": {
"type": "button",
"spritePath": "assets/R-TypeSheet/r-typesheet1.gif",
"width": 500,
"height" : 500,
"rect": {
"x": 101.0,
"y": 0.0,
"width": 32.0,
"height": 19.0
},
"position" : {
"x": 1000,
"y": 1000
},
"collisionRect": {
"width": 500,
"height": 500
},
"animRect": [
{
"type": "hover",
"time": 80,
"noIncr": true,
"list": [
{
"x" : 233.0,
"y": 2.0,
"width": 32.0,
"height": 14.0
}
]
}
]
},
"ip": {
"name": "ip",
"type": "input",
"font": "assets/Fonts/soliden/SolidenTrial-Black.otf",
"spritePath": "assets/R-TypeSheet/r-typesheet1.gif",
"text": "localhost",
"color": "red",
"textSize": 3,
"maxChar": 10,
"width": 500,
"height" : 500,
"position" : {
"x": 2000,
"y": 2000
},
"rect": {
"x": 101.0,
"y": 0.0,
"width": 32.0,
"height": 19.0
},
"collisionRect": {
"width": 2000,
"height": 500
},
"animRect": [
{
"type": "hover",
"time": 80,
"noIncr": true,
"list": [
{
"x" : 233.0,
"y": 2.0,
"width": 32.0,
"height": 14.0
}
]
}
]
},
"host": {
"name": "port",
"type": "input",
"font": "assets/Fonts/soliden/SolidenTrial-Black.otf",
"spritePath": "assets/R-TypeSheet/r-typesheet1.gif",
"text": "4242",
"color": "red",
"textSize": 3,
"maxChar": 10,
"width": 20,
"height" : 5,
"position" : {
"x": 3700,
"y": 6000
},
"collisionRect": {
"width": 2000,
"height": 500
},
"rect": {
"x": 101.0,
"y": 0.0,
"width": 32.0,
"height": 19.0
},
"animRect": [
{
"type": "hover",
"time": 80,
"noIncr": true,
"list": [
{
"x" : 233.0,
"y": 2.0,
"width": 32.0,
"height": 14.0
}
]
}
]
}
}
}
2 changes: 2 additions & 0 deletions docs/developer-guide/client/graphic/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void Raylib::Text::setFontSize(float fontSize);
Raylib::Vector2 Raylib::Text::getPosition() const;
void Raylib::Text::setPixelPosition(Raylib::Vector2 position);
void Raylib::Text::setCurrentFontSize(float fontSize);
std::string &Text::getCurrentText();
void Text::setCurrentText(const std::string &text)
```

getPosition is in percentage of the screen size. For each draw, we recommand to compute and set the position in pixel with setPixelPosition to have a responsive text.
Expand Down
7 changes: 1 addition & 6 deletions docs/developer-guide/ecs/json/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ This function is useful when you want to take a json list inside your json becau
std::vector<nlohmann::json> Json::getDatasByJsonType(const std::vector<std::string> &indexes, JsonType dataType);
```

- Get a data from an existing json data :
```cpp
nlohmann::json &Json::getDataFromJson(nlohmann::json jsonData, const std::string &index);
```
- Get a data but precise the type of what you want with template :
```cpp
template <typename T>
Expand Down Expand Up @@ -133,7 +128,7 @@ std::vector<nlohmann::json> enemyData =
And now you can iterate on your datas :
```cpp
for (auto &data : enemyData) {
std::cout << Json::getInstance().getDataFromJson(elem, "spritePath") <<
std::cout << Json::getInstance().getDataFromJson<std::string>(elem, "spritePath") <<
std::endl;
}
```
Expand Down
1 change: 1 addition & 0 deletions src/Client/Raylib/Events/Inputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ namespace Raylib {
MOUSE_BTN_FORWARD = MOUSE_BUTTON_FORWARD,
MOUSE_BTN_BACK = MOUSE_BUTTON_BACK,
};

} // namespace Raylib
17 changes: 17 additions & 0 deletions src/Client/Raylib/Graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ namespace Raylib {
TakeScreenshot(fileName.c_str());
}

// Collision check functions

bool checkCollisionPointRec(Vector2 point, Rectangle rec)
{
return (CheckCollisionPointRec({point.x, point.y}, {rec.x, rec.y, rec.width, rec.height}));
}

// Input-related functions: keyboard

bool isKeyPressed(KeyboardKey key)
Expand Down Expand Up @@ -695,4 +702,14 @@ namespace Raylib {
_currentFontSize = fontSize;
}

std::string &Text::getCurrentText()
{
return (_text);
}

void Text::setCurrentText(const std::string &text)
{
_text = text;
}

} // namespace Raylib
5 changes: 5 additions & 0 deletions src/Client/Raylib/Graphics/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ namespace Raylib {
// Misc. functions
void takeScreenshot(const std::string &fileName);

// Collision check functions
bool checkCollisionPointRec(Vector2 point, Rectangle rec);

// Input-related functions: keyboard
bool isKeyPressed(KeyboardKey key);
bool isKeyDown(KeyboardKey key);
Expand Down Expand Up @@ -192,6 +195,8 @@ namespace Raylib {
Color getColor() const;
void setColor(Color color);
void setCurrentFontSize(float fontSize);
std::string &getCurrentText();
void setCurrentText(const std::string &text);

private:
std::string _text;
Expand Down
7 changes: 2 additions & 5 deletions src/Client/SceneManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Scene {

enum class Scene { MENU, MAIN_GAME, SCENE_MAX };

enum class SystemManagers { GAME, EVENTS, DISPLAY, NETWORK };
enum class SystemManagers { GAME, EVENTS, DISPLAY, NETWORK, MENU };

class SceneManager {
public:
Expand All @@ -34,10 +34,7 @@ namespace Scene {
Scene _currentScene;
bool _stop;
const std::array<std::vector<SystemManagers>, 2> _scenes = {
{{SystemManagers::EVENTS,
SystemManagers::GAME,
SystemManagers::DISPLAY,
SystemManagers::NETWORK},
{{SystemManagers::DISPLAY, SystemManagers::MENU},
{SystemManagers::EVENTS,
SystemManagers::GAME,
SystemManagers::DISPLAY,
Expand Down
1 change: 1 addition & 0 deletions src/Client/Systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ add_subdirectory(Graphic)
add_subdirectory(Events)
add_subdirectory(Network)
add_subdirectory(CustomTypes)
add_subdirectory(Menu)
6 changes: 4 additions & 2 deletions src/Client/Systems/ClientSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
#include "ClientNetwork.hpp"
#include "EventsSystems.hpp"
#include "GraphicSystems.hpp"
#include "MenuSystems.hpp"
#include "Systems.hpp"

namespace Systems {
std::array<std::vector<std::function<void(std::size_t, std::size_t)>>, 4> getSystemsGroups()
std::array<std::vector<std::function<void(std::size_t, std::size_t)>>, 5> getSystemsGroups()
{
return {
getECSSystems(),
EventsSystems::getEventSystems(),
GraphicSystems::getGraphicsSystems(),
getNetworkSystems()};
getNetworkSystems(),
Menu::getMenuSystems()};
}
} // namespace Systems
2 changes: 1 addition & 1 deletion src/Client/Systems/ClientSystems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
#include <vector>

namespace Systems {
std::array<std::vector<std::function<void(std::size_t, std::size_t)>>, 4> getSystemsGroups();
std::array<std::vector<std::function<void(std::size_t, std::size_t)>>, 5> getSystemsGroups();
} // namespace Systems
48 changes: 48 additions & 0 deletions src/Client/Systems/CustomTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,58 @@ namespace Types {
float size;
};

struct Button {
Button(std::function<void()> &fct) : callback(fct) {};
std::function<void()> callback;
};

struct InputBox {
InputBox(
std::string &textStr,
std::string &boxName,
std::size_t &maxCharacters,
bool isSelected = false)
: name(boxName),
text(textStr),
maxChar(maxCharacters),
selected(isSelected) {};
std::string name;
std::string text;
std::size_t maxChar;
bool selected;
};

#ifdef CLIENT
struct Color {
Raylib::Color color;
};

static const std::unordered_map<std::string, Raylib::Color> colorMatchStrings({
{"darkgray", Raylib::DarkGray },
{"yellow", Raylib::Yellow },
{"gold", Raylib::Gold },
{"orange", Raylib::Orange },
{"pink", Raylib::Pink },
{"red", Raylib::Red },
{"maroon", Raylib::Maroon },
{"green", Raylib::Green },
{"lime", Raylib::Lime },
{"darkgreen", Raylib::DarkGreen },
{"skyblue", Raylib::SkyBlue },
{"blue", Raylib::Blue },
{"darkblue", Raylib::DarkBlue },
{"purple", Raylib::Purple },
{"violet", Raylib::Violet },
{"darkpurple", Raylib::DarkPurple},
{"beige", Raylib::Beige },
{"brown", Raylib::Brown },
{"darkbrown", Raylib::DarkBrown },
{"white", Raylib::White },
{"black", Raylib::Black },
{"blank", Raylib::Blank },
{"magenta", Raylib::Magenta },
{"raywhite", Raylib::RayWhite }
});
#endif

} // namespace Types
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Systems/CustomTypes/AnimRect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Types {
{LEFT, "left" },
});

enum RectListType { UNDEFINED, DEFAULT_RECT, MOVE, ATTACK, DEAD };
enum RectListType { UNDEFINED, DEFAULT_RECT, MOVE, ATTACK, DEAD, HOVER };

NLOHMANN_JSON_SERIALIZE_ENUM(
RectListType,
Expand All @@ -42,6 +42,7 @@ namespace Types {
{MOVE, "move" },
{ATTACK, "attack" },
{DEAD, "dead" },
{HOVER, "hover" }
});

class AnimRect {
Expand Down
6 changes: 1 addition & 5 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ namespace Systems {
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_J)) {
auto &sceneManager = Scene::SceneManager::getInstance();
if (sceneManager.getCurrentScene() == Scene::Scene::MAIN_GAME) {
sceneManager.changeScene(Scene::Scene::MENU);
} else {
sceneManager.changeScene(Scene::Scene::MAIN_GAME);
}
sceneManager.changeScene(Scene::Scene::MENU);
}
}

Expand Down
Loading

0 comments on commit eda3bc9

Please sign in to comment.