Playfield !

This commit is contained in:
Stepland 2019-01-13 22:29:29 +01:00
parent 68a65ccbf8
commit 3b65d1d4f0
10 changed files with 143 additions and 87 deletions

View File

@ -12,7 +12,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS
set(SOURCE_FILES
main.cpp
screen.cpp
Widgets.cpp
Marker.cpp
Fumen.cpp
Note.cpp

View File

@ -55,6 +55,9 @@ void EditorState::reloadJacket() {
}
void EditorState::displayPlayfield() {
}
/*
* Display all metadata in an editable form
*/
@ -170,28 +173,27 @@ void EditorState::displayTimeline() {
ImGui::PopStyleVar(3);
}
void EditorState::save() {
void ESHelper::save(EditorState& ed) {
try {
fumen.autoSaveAsMemon();
ed.fumen.autoSaveAsMemon();
} catch (const std::exception& e) {
tinyfd_messageBox("Error",e.what(),"ok","error",1);
}
}
void EditorState::open() {
void ESHelper::open(std::optional<EditorState> &ed) {
const char* _filepath = tinyfd_openFileDialog("Open File",nullptr,0,nullptr,nullptr,false);
if (_filepath != nullptr) {
openFromFile(_filepath);
ESHelper::openFromFile(ed,_filepath);
}
}
void EditorState::openFromFile(std::filesystem::path path) {
void ESHelper::openFromFile(std::optional<EditorState> &ed, std::filesystem::path path) {
try {
Fumen f(path);
f.autoLoadFromMemon();
fumen = f;
reloadFromFumen();
Toolbox::pushNewRecentFile(std::filesystem::canonical(fumen.path));
ed.emplace(f);
Toolbox::pushNewRecentFile(std::filesystem::canonical(ed->fumen.path));
} catch (const std::exception &e) {
tinyfd_messageBox("Error", e.what(), "ok", "error", 1);
}

View File

@ -9,11 +9,13 @@
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include "Fumen.h"
#include "Marker.h"
class EditorState {
public:
Fumen fumen;
Marker marker;
std::optional<sf::Music> music;
std::optional<sf::Texture> jacket;
std::optional<std::string> selectedChart;
@ -22,22 +24,26 @@ public:
void reloadMusic();
void reloadJacket();
bool showPlayfield = true;
bool showProperties;
bool showStatus;
bool showPlaybackStatus = true;
bool showTimeline = true;
void displayPlayfield();
void displayProperties();
void displayStatus();
void displayPlaybackStatus();
void displayTimeline();
void save();
void open();
void openFromFile(std::filesystem::path path);
explicit EditorState(Fumen& fumen);
};
namespace ESHelper {
void save(EditorState& ed);
void open(std::optional<EditorState>& ed);
void openFromFile(std::optional<EditorState>& ed, std::filesystem::path path);
}
#endif //FEIS_EDITORSTATE_H

View File

@ -41,7 +41,7 @@ Marker::Marker(std::string folder) {
}
}
sf::Sprite Marker::getSprite(Etat etat, int frame) {
sf::Texture Marker::getSprite(Etat etat, int frame) {
int lower;
int upper;
@ -60,7 +60,6 @@ sf::Sprite Marker::getSprite(Etat etat, int frame) {
throw std::runtime_error("Requested access to a non-existent marker frame : " +std::to_string(frame));
}
sf::Sprite sprite;
std::string tex_key;
switch (etat) {
case APPROCHE:
@ -84,8 +83,6 @@ sf::Sprite Marker::getSprite(Etat etat, int frame) {
tex_key += "0";
}
sprite.setTexture(textures[tex_key+std::to_string(frame)]);
return sprite;
return textures[tex_key+std::to_string(frame)];
}

View File

@ -25,7 +25,7 @@ class Marker {
public:
Marker(std::string folder = "mk0013");
sf::Sprite getSprite(Etat etat, int frame);
sf::Texture getSprite(Etat etat, int frame);
private:

View File

@ -5,6 +5,8 @@
#ifndef FEIS_TOOLBOX_H
#define FEIS_TOOLBOX_H
#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
#include <SFML/Window.hpp>
#include <filesystem>
@ -12,6 +14,15 @@ namespace Toolbox {
bool isShortcutPressed(std::initializer_list<sf::Keyboard::Key> anyOf, std::initializer_list<sf::Keyboard::Key> allOf);
void pushNewRecentFile(std::filesystem::path path);
std::vector<std::string> getRecentFiles();
struct CustomConstraints {
static void ContentSquare(ImGuiSizeCallbackData* data) {
float TitlebarHeight = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.f;
float y = data->DesiredSize.y - TitlebarHeight;
float x = data->DesiredSize.x;
data->DesiredSize = ImVec2(IM_MAX(x,y), IM_MAX(x,y) + TitlebarHeight);
}
};
}
#endif //FEIS_TOOLBOX_H

64
Widgets.cpp Normal file
View File

@ -0,0 +1,64 @@
//
// Created by Syméon on 17/08/2017.
//
#include "Widgets.h"
#include "Toolbox.h"
Ecran_attente::Ecran_attente() : gris_de_fond(sf::Color(38,38,38)) {
if(!tex_FEIS_logo.loadFromFile("assets/textures/FEIS_logo.png"))
{
throw std::string("Unable to load assets/textures/FEIS_logo.png");
}
tex_FEIS_logo.setSmooth(true);
FEIS_logo.setTexture(tex_FEIS_logo);
FEIS_logo.setColor(sf::Color(255, 255, 255, 32)); // un huitième opaque
}
void Ecran_attente::render(sf::RenderWindow& window) {
// effacement de la fenêtre en noir
window.clear(gris_de_fond);
// c'est ici qu'on dessine tout
FEIS_logo.setPosition(sf::Vector2f(static_cast<float>((window.getSize().x-tex_FEIS_logo.getSize().x)/2),
static_cast<float>((window.getSize().y-tex_FEIS_logo.getSize().y)/2)));
window.draw(FEIS_logo);
}
Playfield::Playfield() {
marker = Marker();
if (!button.loadFromFile(button_path,{0,0,192,192})) {
std::cerr << "Unable to load texture " << button_path;
throw std::runtime_error("Unable to load texture " + button_path);
}
if (!button_pressed.loadFromFile(button_path,{192,0,192,192})) {
std::cerr << "Unable to load texture " << button_path;
throw std::runtime_error("Unable to load texture " + button_path);
}
}
void Playfield::render(sf::RenderWindow &window, EditorState& editorState) {
ImGui::SetNextWindowSizeConstraints(ImVec2(0,0),ImVec2(FLT_MAX,FLT_MAX),Toolbox::CustomConstraints::ContentSquare);
ImGui::Begin("Playfield",&editorState.showPlayfield,ImGuiWindowFlags_NoScrollbar);
{
float squareSize = ImGui::GetWindowSize().x / 4.f;
float TitlebarHeight = ImGui::GetWindowSize().y - ImGui::GetWindowSize().x;
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
ImGui::PushID(x+4*y);
ImGui::SetCursorPos({x*squareSize,TitlebarHeight + y*squareSize});
ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(0,0,0,0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(0,0,1.f,0.1f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(0,0,1.f,0.5f));
ImGui::ImageButton(button,{squareSize,squareSize},0);
ImGui::PopStyleColor(3);
ImGui::PopID();
}
}
}
ImGui::End();
}

View File

@ -7,17 +7,10 @@
#include <SFML/Graphics.hpp>
#include <imgui.h>
#include <imgui-SFML.h>
#include "Marker.h"
#include "EditorState.h"
class Screen {
public:
virtual void render(sf::RenderWindow &window, EditorState editorState) = 0;
};
class Ecran_attente {
public:
@ -33,18 +26,19 @@ private:
};
class Ecran_edition : public Screen {
class Playfield {
public:
Ecran_edition();
void render(sf::RenderWindow &window, EditorState editorState);
Playfield();
void render(sf::RenderWindow &window, EditorState& editorState);
Marker marker;
sf::Texture button;
sf::Texture button_pressed;
private:
sf::Color couleur_de_fond;
Marker marker;
std::string button_path = "assets/textures/edit_textures/game_front_edit_tex_1.tex.png";
};
#endif //FEIS_SCREEN_H

View File

@ -2,7 +2,7 @@
#include <imgui.h>
#include <imgui-SFML.h>
#include <imgui_stdlib.h>
#include "screen.h"
#include "Widgets.h"
#include "EditorState.h"
#include "tinyfiledialogs.h"
#include "Toolbox.h"
@ -24,6 +24,7 @@ int main(int argc, char** argv) {
Ecran_attente bg;
Playfield playfield;
std::optional<EditorState> editorState;
sf::Clock deltaClock;
@ -63,6 +64,9 @@ int main(int argc, char** argv) {
// Dessin du fond
if (editorState) {
if (editorState->showPlayfield) {
playfield.render(window,*editorState);
}
if (editorState->showProperties) {
editorState->displayProperties();
}
@ -81,13 +85,21 @@ int main(int argc, char** argv) {
}
// Gestion des Raccourcis Clavier
if (Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::S})) {
editorState->save();
// Ctrl+S
if (editorState and Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::S})) {
ESHelper::save(*editorState);
// Ctrl+O
} else if (Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::O})) {
ESHelper::open(editorState);
// Shift+P
} else if (editorState and Toolbox::isShortcutPressed({sf::Keyboard::LShift,sf::Keyboard::RShift},{sf::Keyboard::P})) {
editorState->showProperties = true;
}
// Dessin de l'interface
// Dessin de l'interface
ImGui::BeginMainMenuBar();
{
if (ImGui::BeginMenu("File")) {
@ -106,25 +118,29 @@ int main(int argc, char** argv) {
}
}
ImGui::Separator();
if (ImGui::MenuItem("Open","Ctrl+O") or Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::O})) {
editorState->open();
if (ImGui::MenuItem("Open","Ctrl+O")) {
ESHelper::open(editorState);
}
if (ImGui::BeginMenu("Recent Files")) {
int i = 0;
for (const auto& file : Toolbox::getRecentFiles()) {
ImGui::PushID(i);
if (ImGui::MenuItem(file.c_str())) {
editorState->openFromFile(file);
ESHelper::openFromFile(editorState,file);
}
ImGui::PopID();
++i;
}
ImGui::EndMenu();
}
if (ImGui::MenuItem("Save","Ctrl+S")) {
editorState->save();
if (ImGui::MenuItem("Close","",false,editorState.has_value())) {
editorState.reset();
}
if (ImGui::MenuItem("Save As")) {
ImGui::Separator();
if (ImGui::MenuItem("Save","Ctrl+S",false,editorState.has_value())) {
ESHelper::save(*editorState);
}
if (ImGui::MenuItem("Save As","",false,editorState.has_value())) {
char const * options[1] = {"*.memon"};
const char* _filepath(tinyfd_saveFileDialog("Save File",nullptr,1,options,nullptr));
if (_filepath != nullptr) {
@ -136,17 +152,18 @@ int main(int argc, char** argv) {
}
}
}
ImGui::Separator();
if (ImGui::MenuItem("Properties","Shift+P",false,editorState.has_value())) {
editorState->showProperties = true;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit")) {
if (ImGui::MenuItem("Properties",nullptr,false,editorState.has_value())) {
editorState->showProperties = true;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View",editorState.has_value())) {
if (ImGui::MenuItem("Editor Status",nullptr,editorState->showStatus)) {
editorState->showStatus = not editorState->showStatus;
if (ImGui::MenuItem("Playfield", nullptr,editorState->showPlayfield)) {
editorState->showPlayfield = not editorState->showPlayfield;
}
if (ImGui::MenuItem("Playback Status",nullptr,editorState->showPlaybackStatus)) {
editorState->showPlaybackStatus = not editorState->showPlaybackStatus;
@ -154,6 +171,9 @@ int main(int argc, char** argv) {
if (ImGui::MenuItem("Timeline",nullptr,editorState->showTimeline)) {
editorState->showTimeline = not editorState->showTimeline;
}
if (ImGui::MenuItem("Editor Status",nullptr,editorState->showStatus)) {
editorState->showStatus = not editorState->showStatus;
}
ImGui::EndMenu();
}
}

View File

@ -1,38 +0,0 @@
//
// Created by Syméon on 17/08/2017.
//
#include "screen.h"
Ecran_attente::Ecran_attente() : gris_de_fond(sf::Color(38,38,38)) {
if(!tex_FEIS_logo.loadFromFile("assets/textures/FEIS_logo.png"))
{
throw std::string("Unable to load assets/textures/FEIS_logo.png");
}
tex_FEIS_logo.setSmooth(true);
FEIS_logo.setTexture(tex_FEIS_logo);
FEIS_logo.setColor(sf::Color(255, 255, 255, 32)); // un huitième opaque
}
void Ecran_attente::render(sf::RenderWindow& window) {
// effacement de la fenêtre en noir
window.clear(gris_de_fond);
// c'est ici qu'on dessine tout
FEIS_logo.setPosition(sf::Vector2f(static_cast<float>((window.getSize().x-tex_FEIS_logo.getSize().x)/2),
static_cast<float>((window.getSize().y-tex_FEIS_logo.getSize().y)/2)));
window.draw(FEIS_logo);
}
Ecran_edition::Ecran_edition() : couleur_de_fond(sf::Color(0,0,0)) {
marker = Marker();
}
void Ecran_edition::render(sf::RenderWindow &window, EditorState editorState) {
}