├── .gitignore ├── .gitmodules ├── Engine ├── CMakeLists.txt ├── Editor │ ├── CMakeLists.txt │ ├── Ressources │ │ ├── Fonts │ │ │ ├── arial.ttf │ │ │ └── fontawesome-webfont.ttf │ │ ├── Icons │ │ │ ├── assetFolder.png │ │ │ ├── codeIcon.png │ │ │ ├── defaultIcon.png │ │ │ ├── icon.ico │ │ │ ├── icon.pdn │ │ │ ├── icon.png │ │ │ ├── pngIcon.png │ │ │ └── prefabIcon.png │ │ ├── Saves │ │ │ └── projects.txt │ │ ├── Shaders │ │ │ └── circulaer_gradient.frag │ │ ├── Sprites │ │ │ ├── CamColl.png │ │ │ ├── default.png │ │ │ └── transparent.png │ │ └── todo.txt │ └── Source │ │ ├── Editor.cpp │ │ ├── Editor.h │ │ ├── GUI │ │ ├── Color.h │ │ ├── GUIRepository.cpp │ │ ├── GUIRepository.h │ │ ├── ProjectSelector │ │ │ ├── UIProjectSelector.cpp │ │ │ └── UIProjectSelector.h │ │ ├── Property │ │ │ ├── Animations │ │ │ │ ├── UIAnimation.cpp │ │ │ │ ├── UIAnimation.h │ │ │ │ ├── UIAnimationEditor.cpp │ │ │ │ ├── UIAnimationEditor.h │ │ │ │ ├── UIAnimationKeyFrameAdder.cpp │ │ │ │ └── UIAnimationKeyFrameAdder.h │ │ │ ├── AssetFolder │ │ │ │ ├── UIAssetFolder.cpp │ │ │ │ ├── UIAssetFolder.h │ │ │ │ ├── UIAssetTools.cpp │ │ │ │ ├── UIAssetTools.h │ │ │ │ ├── UIIconData.cpp │ │ │ │ └── UIIconData.h │ │ │ ├── Inspector │ │ │ │ ├── UIInspector.cpp │ │ │ │ ├── UIInspector.h │ │ │ │ ├── UIInspectorBoxCollider.cpp │ │ │ │ ├── UIInspectorBoxCollider.h │ │ │ │ ├── UITagSelector.cpp │ │ │ │ └── UITagSelector.h │ │ │ ├── UIBase.h │ │ │ ├── UIHierarchy.cpp │ │ │ └── UIHierarchy.h │ │ ├── RealTime │ │ │ ├── UIRealTimeEditor.cpp │ │ │ ├── UIRealTimeEditor.h │ │ │ ├── UIRealTimeEditorNavigator.cpp │ │ │ ├── UIRealTimeEditorNavigator.h │ │ │ ├── UIRealTimeEditorTransform.cpp │ │ │ └── UIRealTimeEditorTransform.h │ │ ├── UIConsole.cpp │ │ ├── UIConsole.h │ │ ├── UITopbar.cpp │ │ ├── UITopbar.h │ │ ├── UIUtility │ │ │ ├── UIModels.h │ │ │ ├── UITransform.cpp │ │ │ ├── UITransform.h │ │ │ ├── UIUtility.cpp │ │ │ └── UIUtility.h │ │ ├── UIWindow.cpp │ │ └── UIWindow.h │ │ ├── Main.cpp │ │ ├── Savesystem.cpp │ │ └── Savesystem.h ├── Engine │ ├── CMakeLists.txt │ ├── Core │ │ ├── CMakeLists.txt │ │ └── Source │ │ │ ├── Camera │ │ │ ├── Camera.cpp │ │ │ └── Camera.h │ │ │ ├── Core │ │ │ ├── EngineData.cpp │ │ │ ├── EngineData.h │ │ │ ├── Event.cpp │ │ │ ├── Event.h │ │ │ ├── GameWindow.cpp │ │ │ ├── GameWindow.h │ │ │ ├── IApplication.h │ │ │ ├── Log.cpp │ │ │ ├── Log.h │ │ │ ├── Repository.h │ │ │ ├── SeceneHandler.cpp │ │ │ ├── SeceneHandler.h │ │ │ ├── Time.cpp │ │ │ └── Time.h │ │ │ ├── Input │ │ │ ├── Input.cpp │ │ │ ├── Input.h │ │ │ └── Keyboard.h │ │ │ ├── RessourceHandler │ │ │ ├── FileDataMacros.h │ │ │ ├── Initializer.cpp │ │ │ └── Initializer.h │ │ │ ├── Sprite │ │ │ ├── Components │ │ │ │ ├── Animator │ │ │ │ │ ├── Animation.cpp │ │ │ │ │ ├── Animation.h │ │ │ │ │ ├── Animator.cpp │ │ │ │ │ ├── Animator.h │ │ │ │ │ └── KeyFrame.h │ │ │ │ ├── BoxCollider.cpp │ │ │ │ ├── BoxCollider.h │ │ │ │ ├── Component.h │ │ │ │ ├── Light │ │ │ │ │ ├── Light.cpp │ │ │ │ │ ├── Light.h │ │ │ │ │ ├── LightRepository.cpp │ │ │ │ │ ├── LightRepository.h │ │ │ │ │ ├── LightSource.cpp │ │ │ │ │ └── LightSource.h │ │ │ │ ├── PhysicsBody.cpp │ │ │ │ ├── PhysicsBody.h │ │ │ │ ├── Prefab │ │ │ │ │ ├── Prefab.cpp │ │ │ │ │ ├── Prefab.h │ │ │ │ │ └── README.md │ │ │ │ ├── SpriteRenderer.cpp │ │ │ │ ├── SpriteRenderer.h │ │ │ │ ├── Transform.cpp │ │ │ │ └── Transform.h │ │ │ ├── Sprite.cpp │ │ │ ├── Sprite.h │ │ │ ├── SpriteRepository.cpp │ │ │ └── SpriteRepository.h │ │ │ └── Utility │ │ │ ├── FileDialoge.cpp │ │ │ ├── FileDialoge.h │ │ │ ├── Style.cpp │ │ │ └── Style.h │ └── Math │ │ ├── CMakeLists.txt │ │ ├── Vector2.cpp │ │ ├── Vector2.h │ │ ├── Vector3.cpp │ │ └── Vector3.h ├── Framework │ ├── CMakeLists.txt │ └── Source │ │ ├── GUI │ │ ├── GUI.cpp │ │ └── GUI.h │ │ ├── GameUtils │ │ ├── GameUtils.cpp │ │ └── GameUtils.h │ │ ├── Physics │ │ ├── Physics.cpp │ │ └── Physics.h │ │ └── PrefabRepository │ │ ├── PrefabRepository.cpp │ │ └── PrefabRepository.h ├── Scripts │ ├── Build.sh │ ├── CMake.sh │ └── Setup.sh ├── Template │ ├── .gitignore │ ├── Assets │ │ └── Scripts │ │ │ ├── Game.cpp │ │ │ └── Game.h │ ├── CMakeLists.txt │ ├── Engine │ │ ├── Ressources │ │ │ ├── Shaders │ │ │ │ └── circulaer_gradient.frag │ │ │ └── Sprites │ │ │ │ └── Default.png │ │ ├── Saves │ │ │ ├── Template │ │ │ │ ├── background.txt │ │ │ │ ├── camera.txt │ │ │ │ └── sprites.txt │ │ │ ├── enginepath.txt │ │ │ ├── index.txt │ │ │ ├── scene 1 │ │ │ │ ├── background.txt │ │ │ │ ├── camera.txt │ │ │ │ └── sprites.txt │ │ │ ├── scenes.scn │ │ │ ├── tags.txt │ │ │ └── verify.vsn │ │ └── Source │ │ │ ├── Engine.cpp │ │ │ ├── Engine.h │ │ │ ├── EngineConfig.h │ │ │ ├── IScript.h │ │ │ ├── Main.cpp │ │ │ └── SpriteEngine.h │ ├── RUNME.sh │ └── imgui.ini ├── ThirdParty │ ├── CMakeLists.txt │ └── utility │ │ ├── UtilityFunctions.cpp │ │ ├── UtilityFunctions.h │ │ ├── dirent.h │ │ └── icons.h └── imgui.ini ├── Github ├── Game.PNG └── repoplan.png ├── LICENSE.md ├── RUNME.sh └── Readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vs/ 3 | *.pdb 4 | *.tlog 5 | *.obj 6 | *.log 7 | *.exe 8 | *.recipe 9 | *.ilk 10 | *.idb 11 | **/build/ 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Engine/ThirdParty/sfml"] 2 | active = true 3 | url = https://github.com/SFML/SFML.git 4 | path = Engine/ThirdParty/sfml 5 | branch = 2.6.0 6 | [submodule "Engine/ThirdParty/imgui"] 7 | path = Engine/ThirdParty/imgui 8 | url = https://github.com/ocornut/imgui.git 9 | [submodule "Engine/ThirdParty/imgui-sfml"] 10 | path = Engine/ThirdParty/imgui-sfml 11 | url = https://github.com/SFML/imgui-sfml.git 12 | -------------------------------------------------------------------------------- /Engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(SpriteEngine) 3 | 4 | set(CORE_SOURCE_FOLDER_NAME Source) 5 | set(EDITOR_NAME Editor) 6 | 7 | set(EXTERNAL_LIBRARIES_FOLDER ${CMAKE_SOURCE_DIR}/ThirdParty) 8 | 9 | # Specify the C++ standard 10 | set(CMAKE_CXX_STANDARD 17) 11 | set(CMAKE_CXX_STANDARD_REQUIRED True) 12 | 13 | if (MSVC) 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") 15 | endif() 16 | 17 | # Add the subprojects 18 | add_subdirectory(Engine) 19 | add_subdirectory(Editor) 20 | 21 | # Thirdparty 22 | add_subdirectory(ThirdParty) 23 | -------------------------------------------------------------------------------- /Engine/Editor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Editor/CMakeLists.txt 2 | 3 | # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 4 | set(CMAKE_BUILD_TYPE Debug) # CHANGE WHEN BUILDING IN RELEASE TO Release 5 | # !!!!!!!!!!!!!!! 6 | 7 | file(GLOB_RECURSE EDITOR_SOURCE_FILES 8 | "Source/*.cpp" 9 | "Source/*.h" 10 | ) 11 | 12 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${EDITOR_SOURCE_FILES}) 13 | 14 | add_executable(${EDITOR_NAME} 15 | ${EDITOR_SOURCE_FILES} 16 | ) 17 | 18 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source) 19 | 20 | # Link libraries 21 | target_link_libraries(${EDITOR_NAME} PRIVATE 22 | Core 23 | ) 24 | 25 | # Set debug and release directories 26 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Editor/Debug) 27 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Editor/Release) 28 | 29 | # Path to the SFML DLLs after build 30 | set(SFML_DLL_DIR "${CMAKE_BINARY_DIR}/ThirdParty/sfml/lib") 31 | 32 | # Custom command to copy DLLs based on build configuration 33 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 34 | add_custom_command(TARGET ${EDITOR_NAME} POST_BUILD 35 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 36 | ${SFML_DLL_DIR}/Debug/sfml-audio-d-2.dll $ 37 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 38 | ${SFML_DLL_DIR}/Debug/sfml-graphics-d-2.dll $ 39 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 40 | ${SFML_DLL_DIR}/Debug/sfml-network-d-2.dll $ 41 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 42 | ${SFML_DLL_DIR}/Debug/sfml-system-d-2.dll $ 43 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 44 | ${SFML_DLL_DIR}/Debug/sfml-window-d-2.dll $ 45 | ) 46 | elseif(CMAKE_BUILD_TYPE STREQUAL "Release") 47 | add_custom_command(TARGET ${EDITOR_NAME} POST_BUILD 48 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 49 | ${SFML_DLL_DIR}/Release/sfml-audio-2.dll $ 50 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 51 | ${SFML_DLL_DIR}/Release/sfml-graphics-2.dll $ 52 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 53 | ${SFML_DLL_DIR}/Release/sfml-network-2.dll $ 54 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 55 | ${SFML_DLL_DIR}/Release/sfml-system-2.dll $ 56 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 57 | ${SFML_DLL_DIR}/Release/sfml-window-2.dll $ 58 | ) 59 | endif() 60 | 61 | if(MSVC) 62 | target_compile_options(${EDITOR_NAME} PRIVATE /W4) 63 | add_compile_options(/MP) 64 | endif() -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Fonts/arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Fonts/arial.ttf -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/assetFolder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/assetFolder.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/codeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/codeIcon.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/defaultIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/defaultIcon.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/icon.ico -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/icon.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/icon.pdn -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/icon.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/pngIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/pngIcon.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Icons/prefabIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Icons/prefabIcon.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Saves/projects.txt: -------------------------------------------------------------------------------- 1 | name;absulutePathStr;date;relativePath 2 | DasynceSE;C:\Dev\DasynceSE;2024/26/09 18:21:36;..\..\DasynceSE 3 | 4 | -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Shaders/circulaer_gradient.frag: -------------------------------------------------------------------------------- 1 | #define MAX_LIGHTS 255 2 | 3 | uniform sampler2D texture; 4 | uniform vec2 lightPositions[MAX_LIGHTS]; 5 | uniform float lightRadii[MAX_LIGHTS]; 6 | uniform float lightIntensities[MAX_LIGHTS]; 7 | uniform vec3 lightColors[MAX_LIGHTS]; 8 | uniform int lightAmount; 9 | uniform vec2 cameraPosition; 10 | uniform float cameraZoom; 11 | 12 | void main() 13 | { 14 | vec4 finalColor = vec4(0.0, 0.0, 0.0, 1.0); 15 | 16 | vec2 screenSize = vec2(1920, 1080); // Replace with your screen dimensions 17 | 18 | vec2 fragmentPosition = gl_FragCoord.xy; 19 | fragmentPosition.y = screenSize.y - fragmentPosition.y; // Flip the y-coordinate 20 | 21 | vec2 adjustedCameraPosition = cameraPosition / cameraZoom; // Adjusted camera position 22 | 23 | fragmentPosition += adjustedCameraPosition; 24 | 25 | for(int i = 0; i < lightAmount; i++) 26 | { 27 | vec2 lightPosition = (lightPositions[i] - adjustedCameraPosition) / cameraZoom; // Adjusted light position 28 | float lightRadius = lightRadii[i] / cameraZoom; 29 | float lightIntensity = lightIntensities[i]; 30 | vec3 lightColor = lightColors[i]; 31 | 32 | lightPosition += adjustedCameraPosition / cameraZoom; 33 | 34 | float distanceToLight = length(fragmentPosition - lightPosition); 35 | 36 | float intensity = 1.0 - smoothstep(0.0, lightRadius, distanceToLight); 37 | intensity *= lightIntensity; 38 | intensity = clamp(intensity, 0.0, 1.0); 39 | 40 | vec4 texColor = texture2D(texture, gl_TexCoord[0].xy); 41 | finalColor += texColor * vec4(lightColor, 1.0) * intensity; 42 | 43 | if (texColor.a > 0.9f) { 44 | finalColor += texColor * vec4(lightColor, 1.0) * intensity; 45 | } else { 46 | finalColor = texColor; 47 | } 48 | } 49 | 50 | gl_FragColor = finalColor; 51 | } -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Sprites/CamColl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Sprites/CamColl.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Sprites/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Sprites/default.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/Sprites/transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Editor/Ressources/Sprites/transparent.png -------------------------------------------------------------------------------- /Engine/Editor/Ressources/todo.txt: -------------------------------------------------------------------------------- 1 | Drag and drop pics from 3rd party 2 | open pics 3 | update animation 4 | Rename stuff 5 | spriterenderer copy ctor xd 6 | 7 | ! IMORTANT 8 | Save the animations like prefabs 9 | Performance issues content browser -------------------------------------------------------------------------------- /Engine/Editor/Source/Editor.cpp: -------------------------------------------------------------------------------- 1 | #include "Editor.h" 2 | 3 | // Ctor / dctor 4 | 5 | spe::Editor::Editor() 6 | { 7 | this->m_Window = spe::GameWindow(spe::Vector2(1920, 1080), "SpriteEngine"); 8 | 9 | // Load the image for the window icon 10 | sf::Image icon; 11 | if (!icon.loadFromFile("Editor\\Ressources\\Icons\\icon.png")) { 12 | spe::Log::LogString("Couldnt load icon!!"); 13 | } 14 | 15 | // Set the window icon 16 | this->m_Window.GetRenderWindow()->setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); 17 | 18 | // Loading the sprites from the user directory will be permaent here! 19 | spe::Utility::SetCurrentDir(spe::EngineData::s_PathUserProject); 20 | this->m_SceneHandler.Init(PATH_TO_LIGHT_SHADER); 21 | 22 | 23 | // Sprite/Background/Camera 24 | this->Init(); 25 | 26 | this->m_Window.SetCamera(&this->m_GUIRepository.Camera); 27 | this->m_Window.SetBackgroundColor(&this->m_GUIRepository.BackgroundColor); 28 | 29 | this->m_UIWindow.SetRepos(this->m_GUIRepository, this->m_SceneHandler.SpriteRepository, this->m_SceneHandler, this->m_SceneHandler.LightRepository); 30 | 31 | spe::Style::Init(); 32 | spe::Style::RenderStyle(); 33 | 34 | spe::UIUtility::SetEvent(&this->m_Window.Event); 35 | spe::UIUtility::SetRenderWinodw(this->m_Window.GetRenderWindow()); 36 | spe::Input::SetEvent(&this->m_Window.Event); 37 | 38 | this->m_GUIRepository.ptr_Event = &this->m_Window.Event; 39 | this->m_GUIRepository.ptr_SFEvent = &this->m_Window.WindowEvent; 40 | 41 | this->m_GUIRepository.InitHierarchySprites(this->m_SceneHandler.SpriteRepository.GetSprites()); 42 | this->m_SceneHandler.SpriteRepository.SortSpritesByLayer(); 43 | 44 | this->m_UIRealTimeEditor = spe::UIRealTimeEditor(&this->m_Window, this->m_SceneHandler.SpriteRepository, this->m_GUIRepository); 45 | 46 | spe::Log::LogString("============="); 47 | spe::Log::LogString("Finished init..."); 48 | spe::Log::LogString("Building the project.."); 49 | spe::EngineData::BuildProjectFiles(); 50 | 51 | spe::BoxCollider::InitCameraCollider(this->m_SceneHandler.LightRepository); 52 | } 53 | 54 | spe::Editor::~Editor() 55 | { 56 | spe::BoxCollider::DeleteCameraCollider(); 57 | this->m_Window.Shutdown(); 58 | this->m_SceneHandler.SpriteRepository.CleanUp(); 59 | } 60 | 61 | // Private 62 | 63 | void spe::Editor::Init() 64 | { 65 | spe::Initializer::InitTags(this->m_SceneHandler.SpriteRepository, PATH_TO_TAG_FILE); 66 | spe::Initializer::InitScenes(this->m_SceneHandler, PATH_TO_SCENE_FILE); 67 | spe::Initializer::IntiHighestSpriteID(this->m_SceneHandler.SpriteRepository, PATH_TO_HIGHEST_INDEX); 68 | 69 | // Load the first scene in the file 70 | this->m_SceneHandler.LoadScene(this->m_SceneHandler.TotalScenes[0], this->m_GUIRepository.Camera, this->m_GUIRepository.BackgroundColor); 71 | } 72 | 73 | void spe::Editor::UpdateUI() 74 | { 75 | ImGui::PushFont(spe::Style::s_DefaultFont); 76 | spe::UIUtility::UpdateCursor(); 77 | this->m_UIWindow.Update(); 78 | 79 | if (this->m_Window.ContainsCursor()) 80 | { 81 | this->m_UIRealTimeEditor.Update(); 82 | } 83 | 84 | ImGui::PopFont(); 85 | } 86 | 87 | void spe::Editor::UpdateComponents() 88 | { 89 | this->m_Window.PollEvents(); 90 | 91 | this->UpdateUI(); 92 | 93 | std::list& sprites = this->m_SceneHandler.SpriteRepository.GetSprites(); 94 | 95 | this->m_Window.Clear(); 96 | 97 | for (auto it = sprites.begin(); it != sprites.end(); ++it) 98 | { 99 | spe::Sprite* sprite = *it; 100 | 101 | if (!spe::BoxCollider::ProcessSprite(sprite, this->m_GUIRepository.Camera)) 102 | { 103 | sprite->Process = false; 104 | continue; 105 | } 106 | sprite->Process = true; 107 | 108 | this->m_SceneHandler.LightRepository.UpdateLightSource(sprite, &this->m_GUIRepository.Camera); 109 | sprite->Animator.Update(); 110 | 111 | if (this->m_GUIRepository.SimulatePhysics) 112 | { 113 | sprite->Collider.Update(this->m_SceneHandler.SpriteRepository); 114 | sprite->Physicsbody.Update(); 115 | } 116 | 117 | this->m_Window.DrawEngine(sprite, &this->m_SceneHandler.LightRepository.GetShader(), this->m_GUIRepository.RenderAlwaysWithoutLight); 118 | } 119 | this->m_SceneHandler.LightRepository.UpdateArrays(); 120 | 121 | this->m_GUIRepository.Render(this->m_Window.GetRenderWindow()); 122 | this->m_Window.Display(); 123 | } 124 | 125 | // Public 126 | 127 | void spe::Editor::Update() 128 | { 129 | spe::Time::Update(); 130 | this->UpdateComponents(); 131 | this->m_GUIRepository.Camera.Update(&this->m_SceneHandler.LightRepository); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /Engine/Editor/Source/Editor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Core/GameWindow.h" 7 | #include "UtilityFunctions.h" 8 | #include "RessourceHandler/FileDataMacros.h" 9 | #include "Input/Input.h" 10 | 11 | #include "GUI/GUIRepository.h" 12 | #include "Sprite/SpriteRepository.h" 13 | #include "RessourceHandler/Initializer.h" 14 | #include "Core/IApplication.h" 15 | #include "Core/SeceneHandler.h" 16 | #include "GUI/UIUtility/UIUtility.h" 17 | #include "GUI/RealTime/UIRealTimeEditor.h" 18 | 19 | #include "GUI/UIWindow.h" 20 | 21 | namespace spe 22 | { 23 | class Editor : public spe::IAppliaction 24 | { 25 | private: 26 | spe::GameWindow m_Window; 27 | spe::GUIRepository m_GUIRepository; 28 | spe::SceneHandler m_SceneHandler; 29 | spe::UIWindow m_UIWindow; 30 | spe::UIRealTimeEditor m_UIRealTimeEditor; 31 | 32 | void UpdateUI(); 33 | void UpdateComponents() override; 34 | void Init() override; 35 | public: 36 | Editor(); 37 | ~Editor(); 38 | 39 | void Update() override; 40 | bool IsOpen() { return m_Window.IsOpen(); } 41 | }; 42 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #pragma region PROJECT_SELECTOR 6 | 7 | #define SELECTOR_MAIN_COLOR ImVec4(25.0f / 255.0f, 25.0f / 255.0f, 25.0f / 255.0f, 1.0f) 8 | 9 | #define SELECTOR_CREATE_BUTTONS_COLOR SELECTOR_MAIN_COLOR 10 | #define SELECTOR_LIST_BOX_HEADER_BACKGROUND_COLOR SELECTOR_MAIN_COLOR 11 | #define SELECTOR_LEFT_BUTTONS_COLOR SELECTOR_MAIN_COLOR 12 | #define SELECTOR_BUTTON_HOVERED ImVec4(17.0f / 255.0f, 17.0f / 255.0f, 17.0f / 255.0f, 1.0f) 13 | 14 | #define SELECTOR_FILEDIALOGE_BUTTON_COLOR SELECTOR_MAIN_COLOR 15 | #define SELECTOR_LISTBOX_BACKGROUND_COLOR SELECTOR_MAIN_COLOR 16 | 17 | #define SELECTOR_HEADER_COLOR SELECTOR_MAIN_COLOR 18 | #define SELECTOR_TOP_BAR_COLOR ImVec4(22.0f / 255.0f, 22.0f / 255.0f, 22.0f / 255.0f, 1.0f) 19 | 20 | #pragma endregion 21 | 22 | #pragma region REAL_TIME_EDITOR 23 | 24 | #define REAL_EDITOR_BUTTON_BG_COLOR ImVec4(55.0f / 255.0f, 55.0f / 255.0f, 55.0f / 255.0f, 0.5f) 25 | 26 | #pragma endregion 27 | 28 | #pragma region PROPERTY 29 | 30 | #define SPRITE_SELECTED_COLOR ImVec4(139.0f / 255.0f, 180.0f / 255.0f, 234.0f / 255.0f,1.0f) 31 | #define SPRITE_BACKGROUND_COLOR ImColor(30, 30, 30, 255) 32 | 33 | #define COMPONENT_SELECTED_COLOR SPRITE_BACKGROUND_COLOR 34 | 35 | #pragma endregion 36 | 37 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/GUIRepository.cpp: -------------------------------------------------------------------------------- 1 | #include "guiRepository.h" 2 | 3 | #include "Sprite/Sprite.h" 4 | 5 | // Constrcutor 6 | 7 | spe::GUIRepository::GUIRepository() 8 | { 9 | this->RenderAlwaysWithoutLight = false; 10 | this->ptr_Event = nullptr; 11 | this->ptr_SFEvent = nullptr; 12 | this->HierarchyHoveredSprite = nullptr; 13 | this->InspectorSprite = nullptr; 14 | this->ChildToParent = nullptr; 15 | this->RightClickedSprite = nullptr; 16 | 17 | this->m_HighestLayer = 0; 18 | this->m_HighestId = 0; 19 | 20 | this->DragAndDropPath = " "; 21 | this->DragAndDropName = " "; 22 | 23 | this->SimulatePhysics = false; 24 | this->SpawnInCenter = false; 25 | this->Tools = spe::EditorTools::PositionTool; 26 | } 27 | 28 | // Public functions 29 | 30 | void spe::GUIRepository::Add(spe::Rectangle* rectangle) 31 | { 32 | rectangle->ID = this->m_HighestId; 33 | this->m_Rectangles.push_back(rectangle); 34 | this->m_HighestId++; 35 | } 36 | 37 | void spe::GUIRepository::UpdateLayerIndex() 38 | { 39 | for (size_t i = 0; i < this->m_Rectangles.size(); i++) 40 | { 41 | spe::Rectangle* const rec = this->m_Rectangles[i]; 42 | if (rec->SortingLayerIdx > this->m_HighestLayer) 43 | this->m_HighestLayer = rec->SortingLayerIdx; 44 | } 45 | } 46 | 47 | void spe::GUIRepository::Render(sf::RenderWindow* ptr_render_window) 48 | { 49 | for (size_t i = 0; i < this->m_HighestLayer + 1; i++) 50 | { 51 | for (size_t j = 0; j < this->GetAmount(); j++) 52 | { 53 | spe::Rectangle* rec = this->GetByVecPos((uint32_t)j); 54 | if (this->m_Rectangles[j]->Render 55 | && rec->SortingLayerIdx == i) 56 | { 57 | ptr_render_window->draw(this->m_Rectangles[j]->Shape); 58 | } 59 | } 60 | } 61 | } 62 | 63 | void spe::GUIRepository::EraseSpriteWithName(const std::string& name) 64 | { 65 | for (size_t i = 0; i < this->HierarchySprites.size(); i++) 66 | { 67 | if (name == this->HierarchySprites[i]->Name) 68 | { 69 | spe::Sprite* ptr_delete = HierarchySprites[i]; 70 | 71 | this->HierarchySprites.erase(this->HierarchySprites.begin() + i); 72 | 73 | std::vector childs_to_delete = std::vector(0); 74 | 75 | this->AddChildsToDelete(childs_to_delete, ptr_delete); 76 | 77 | for (size_t j = 0; j < childs_to_delete.size(); j++) 78 | { 79 | this->EraseSpriteWithId(childs_to_delete[j]->GetId()); 80 | } 81 | 82 | return; 83 | } 84 | } 85 | } 86 | 87 | spe::Rectangle* spe::GUIRepository::GetByName(const std::string& name) 88 | { 89 | for (int i = 0; i < this->m_Rectangles.size(); i++) 90 | { 91 | if (this->m_Rectangles[i]->Name == name) 92 | { 93 | return this->m_Rectangles[i]; 94 | } 95 | } 96 | throw std::out_of_range("Name was not found"); 97 | } 98 | 99 | spe::Rectangle* spe::GUIRepository::GetById(uint32_t id) 100 | { 101 | for (size_t i = 0; i < this->m_Rectangles.size(); i++) 102 | { 103 | if (this->m_Rectangles[i]->ID == id) 104 | { 105 | return this->m_Rectangles[i]; 106 | } 107 | } 108 | 109 | throw std::out_of_range("ID was not found"); 110 | } 111 | 112 | spe::Rectangle* spe::GUIRepository::GetByVecPos(uint32_t vec) 113 | { 114 | for (size_t i = 0; i < this->m_Rectangles.size(); i++) 115 | { 116 | if (i == vec) 117 | { 118 | return this->m_Rectangles[i]; 119 | } 120 | } 121 | throw std::out_of_range("Vecpos was not found"); 122 | } 123 | 124 | void spe::GUIRepository::CleanUp() 125 | { 126 | this->HierarchySprites.clear(); 127 | this->HierarchyHoveredSprite = nullptr; 128 | this->InspectorSprite = nullptr; 129 | this->ChildToParent = nullptr; 130 | this->m_HighestId = 0; 131 | } 132 | 133 | void spe::GUIRepository::InitHierarchySprites(std::list& sprites) 134 | { 135 | for (auto it = sprites.begin(); it != sprites.end(); ++it) 136 | { 137 | spe::Sprite* sprite = *it; 138 | this->HierarchySprites.push_back(sprite); 139 | } 140 | } 141 | 142 | // Private 143 | 144 | void spe::GUIRepository::AddChildsToDelete(std::vector& ids, Sprite* parent) 145 | { 146 | for (int i = 0; i < parent->ptr_Childs.size(); i++) 147 | { 148 | ids.push_back(parent->ptr_Childs[i]); 149 | AddChildsToDelete(ids, parent->ptr_Childs[i]); 150 | } 151 | } 152 | 153 | void spe::GUIRepository::EraseSpriteWithId(uint32_t id) 154 | { 155 | for (int i = 0; i < this->HierarchySprites.size(); i++) 156 | { 157 | if ((uint32_t)this->HierarchySprites[i]->GetId() == id) 158 | { 159 | this->HierarchySprites.erase(this->HierarchySprites.begin() + i); 160 | return; 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/GUIRepository.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Math/Vector2.h" 7 | #include "Camera/Camera.h" 8 | #include "Core/Repository.h" 9 | #include "UIUtility/UIModels.h" 10 | #include "UIUtility/UIModels.h" 11 | #include "Core/Event.h" 12 | 13 | namespace spe 14 | { 15 | 16 | class GUIRepository : public spe::Repository 17 | { 18 | private: 19 | std::vector m_Rectangles; 20 | 21 | void AddChildsToDelete(std::vector& spr, spe::Sprite* parent); 22 | void EraseSpriteWithId(uint32_t id); 23 | public: 24 | spe::UIWindowData HierarchyData; 25 | spe::UIWindowData InspectorData; 26 | spe::UIWindowData AssetFolderData; 27 | spe::UIWindowData AnimationData; 28 | 29 | spe::EditorTools Tools; 30 | 31 | std::string DragAndDropPath; 32 | std::string DragAndDropName; 33 | 34 | spe::Sprite* ChildToParent; 35 | spe::Sprite* RightClickedSprite; 36 | spe::Sprite* InspectorSprite; 37 | spe::Sprite* HierarchyHoveredSprite; 38 | 39 | 40 | /// 41 | /// Apparently the data structure for sprites is a list and the sorting layer 42 | /// gets sorted automaticly but the user wants to see displayed the sprite linear 43 | /// and when he creates anew sprite it shouldnt be sorted. 44 | /// 45 | std::vector HierarchySprites; 46 | 47 | /// 48 | /// Usally ptrs to the events of the window class 49 | /// 50 | spe::Event* ptr_Event; 51 | sf::Event* ptr_SFEvent; 52 | 53 | spe::Vector3 BackgroundColor; 54 | spe::Camera Camera; 55 | 56 | bool SimulatePhysics; 57 | bool RenderAlwaysWithoutLight; 58 | bool SpawnInCenter; 59 | 60 | GUIRepository(); 61 | 62 | void Render(sf::RenderWindow* ptr_render_window); 63 | void EraseSpriteWithName(const std::string& name); 64 | 65 | spe::Rectangle* GetByName(const std::string& name) override; 66 | spe::Rectangle* GetById(uint32_t id) override; 67 | spe::Rectangle* GetByVecPos(uint32_t vec); 68 | 69 | void CleanUp(); 70 | void InitHierarchySprites(std::list& sprites); 71 | 72 | uint32_t GetAmount() const override { return (uint32_t)this->m_Rectangles.size(); } 73 | void Add(spe::Rectangle* rec) override; 74 | void UpdateLayerIndex() override; 75 | }; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/ProjectSelector/UIProjectSelector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include "GUI/Color.h" 7 | #include "GUI/UIUtility/UIModels.h" 8 | #include "Core/GameWindow.h" 9 | #include "Utility/Style.h" 10 | #include "Utility/FileDialoge.h" 11 | #include "Core/Log.h" 12 | #include "Savesystem.h" 13 | 14 | #define SELECTOR_WINDOW_SIZE ImVec2(960, 540) 15 | #define SELECTOR_FILE_DIALOG_SIZE ImVec2(700, 400) 16 | #define SELECTOR_FONT_SCALE spe::Style::s_DefaultFontSize + 0.2f 17 | 18 | #define DATA_PADDING_TOP 10.0f 19 | 20 | namespace spe 21 | { 22 | class UIProjectSelector 23 | { 24 | private: 25 | spe::GameWindow m_Window; 26 | std::vector m_Projects; 27 | spe::FileDialog m_CreateFileDialoge; 28 | spe::FileDialog m_OpenFileDialog; 29 | float m_FontScale; 30 | bool m_IsOpen; 31 | std::string m_CreateProjectName; 32 | std::string m_FullProjectPath; 33 | 34 | std::vectorReadProjectData(); 35 | void RenderProjectData(); 36 | void RrenderInfoOverProjects(float pad); 37 | 38 | void RenderWindow(); 39 | 40 | bool IsProjectPathValid(const std::string& path); 41 | void RenderFileDialogAndButtons(); 42 | void CreatePopupToCreateProject(); 43 | bool CheckIfprojectExists(const std::string& path); 44 | void CreateProject(); 45 | void CreateProjectFiles(const std::string& path, const std::string& name); 46 | 47 | void AddProject(const std::string& full, const std::string& name); 48 | bool TryToOpenProject(); 49 | 50 | public: 51 | 52 | UIProjectSelector(); 53 | 54 | bool IsOpen() const { return this->m_IsOpen; } 55 | void Update(); 56 | void Shutdown(); 57 | }; 58 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Animations/UIAnimation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Utility/Style.h" 8 | #include "Utility/FileDialoge.h" 9 | #include "GUI/Property/UIBase.h" 10 | #include "GUI/UIUtility/UIUtility.h" 11 | #include "Sprite/Sprite.h" 12 | #include "GUI/Color.h" 13 | #include "Savesystem.h" 14 | #include "Input/Input.h" 15 | #include "GUI/Property/Animations/UIAnimationEditor.h" 16 | 17 | #define WINDOW_SIZE_ANIMATION_CREATE ImVec2(500, 500) 18 | #define START_CNT_BG 1 19 | 20 | namespace spe 21 | { 22 | class UIAnimation : public spe::IUIBase 23 | { 24 | private: 25 | //Setting display to false and shit in its own class 26 | spe::UIAnimationEditor m_UIAnimationEditor; 27 | std::string m_FileName; 28 | 29 | spe::FileDialog m_OpenFileDialoge; 30 | spe::FileDialog m_CreateFileDialoge; 31 | 32 | ImGuiTextFilter m_FilterSearch; 33 | 34 | uint8_t m_BackgroundCounter; 35 | char m_AnimationFile[150]; 36 | 37 | void GetFileNameInput(); 38 | void DisplayAnimations(); 39 | void AddAnimationsToAnimator(); 40 | void EnterAnimation(spe::Animation& animation); 41 | void DrawBackgroundBehinAnimation(); 42 | void RenderAnimationUIOptions() noexcept; 43 | 44 | void Init() override; 45 | public: 46 | UIAnimation(); 47 | 48 | void Render() override; 49 | }; 50 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Animations/UIAnimationEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "GUI/Property/UIBase.h" 6 | #include "GUI/UIUtility/UIUtility.h" 7 | #include "GUI/Color.h" 8 | #include "GUI/Property/Animations/UIAnimationKeyFrameAdder.h" 9 | 10 | #include "Sprite/Sprite.h" 11 | #include "Savesystem.h" 12 | 13 | #define WINDOW_SIZE_ANIMATION_EDITOR ImVec2(900, 350) 14 | 15 | namespace spe 16 | { 17 | class UIAnimationEditor : public spe::IUIBase 18 | { 19 | private: 20 | const float MIN_CURSOR_SPACE = 2.0f; 21 | const float MAX_CURSOR_SPACE = 10; 22 | const float SMALL_INCREMENT = 0.5f; 23 | const float LARGE_INCREMENT = 2; 24 | 25 | int m_KeyFrameSelectedPos; 26 | 27 | int m_KeyFramePos; 28 | std::string m_KeyFramePathStd; 29 | 30 | float m_CursorSpace; 31 | int m_KeyFramesToEdit; 32 | spe::UIAnimationKeyFrameAdder m_FrameAdder; 33 | 34 | void RenderTimeLineRealTimePoint(); 35 | void ZoomEditorTimeLine(); 36 | void RenderKeyFrames(); 37 | void AddKeyFrame(); 38 | void BeginWindow(); 39 | void CloseWindow(); 40 | void EditorTimeLine(); 41 | void DisplayKeyFrameInfo(); 42 | bool RenderTextBasedOnScroll(size_t i); 43 | void SaveAnimation(); 44 | void RenameAnimation(); 45 | 46 | bool DisplayTimeFrameBasedOnCursorSpace(size_t i_pos); 47 | 48 | spe::Animation* m_ptr_Anim; 49 | spe::KeyFrameSelected m_KeyFrameSelected; 50 | 51 | void Init() override; 52 | public: 53 | bool Display; 54 | 55 | UIAnimationEditor(); 56 | 57 | void SetAnim(spe::Animation* anim); 58 | void ResetAnim(); 59 | 60 | void Render() override; 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Animations/UIAnimationKeyFrameAdder.cpp: -------------------------------------------------------------------------------- 1 | #include "UIAnimationKeyFrameAdder.h" 2 | 3 | // Constructor 4 | 5 | spe::UIAnimationKeyFrameAdder::UIAnimationKeyFrameAdder() 6 | { 7 | this->Init(); 8 | } 9 | 10 | void spe::UIAnimationKeyFrameAdder::Init() 11 | { 12 | this->m_KeyFramePos = 0; 13 | this->Hovered = false; 14 | this->IsKeyFrameMenuOpen = false; 15 | this->KeyFramePath = PATH_TO_DEFAULT_SPRITE; 16 | } 17 | 18 | // Private methods 19 | 20 | void spe::UIAnimationKeyFrameAdder::BeginWindow() 21 | { 22 | ImGui::Begin("##KeyFrameEditor", NULL, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); 23 | ImGui::SetWindowSize(ImVec2(350, 200)); 24 | 25 | ImGui::Text("Keyframe Adder"); 26 | ImGui::SameLine(); 27 | ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + 135, ImGui::GetCursorPosY() - 10)); 28 | 29 | //Close button -> it will destroy it (no new keyframe is added) 30 | if (ImGui::Button("x")) 31 | { 32 | this->IsKeyFrameMenuOpen = false; 33 | } 34 | ImGui::Spacing(); 35 | ImGui::Separator(); 36 | ImGui::Spacing(); 37 | 38 | } 39 | 40 | void spe::UIAnimationKeyFrameAdder::InputData() 41 | { 42 | ImGui::Text("Position"); 43 | ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + 107, ImGui::GetCursorPosY() - 30)); 44 | ImGui::SetNextItemWidth(50); 45 | ImGui::InputInt("##Position", &m_KeyFramePos, 0, 0); 46 | 47 | ImGui::Dummy(ImVec2(0, 7)); 48 | 49 | 50 | ImGui::Text("Sprite"); 51 | ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + 107, ImGui::GetCursorPosY() - 30)); 52 | ImGui::InputText("##spriteAdder", this->m_KeyFramePath, CHAR_MAX); 53 | 54 | if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlapped) && ImGui::IsMouseReleased(0) && this->m_ptr_GUIRepo->DragAndDropPath != " ") 55 | { 56 | this->KeyFramePath = this->m_ptr_GUIRepo->DragAndDropPath; 57 | strcpy_s(this->m_KeyFramePath, spe::Utility::GetNamePathSplit(this->m_ptr_GUIRepo->DragAndDropPath).c_str()); 58 | } 59 | else 60 | { 61 | strcpy_s(this->m_KeyFramePath, spe::Utility::GetNamePathSplit(this->KeyFramePath.c_str()).c_str()); 62 | } 63 | } 64 | 65 | void spe::UIAnimationKeyFrameAdder::CloseWindowAndSafeKeyFrame() 66 | { 67 | this->Hovered = spe::UIUtility::IsHovered(ImGui::GetWindowSize(), ImGui::GetWindowPos()); 68 | 69 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 8); 70 | if (ImGui::Button("Done")) 71 | { 72 | this->AddKeyFrameToAnimation(); 73 | this->Reset(); 74 | } 75 | 76 | ImGui::End(); 77 | } 78 | 79 | void spe::UIAnimationKeyFrameAdder::AddKeyFrameToAnimation() 80 | { 81 | if (this->m_KeyFramePos < 0) 82 | { 83 | std::cout << "LOG: [ERROR] Tried to add a keyframe at a invalid position!"; 84 | return; 85 | } 86 | if (spe::Utility::GetFileExtension(this->KeyFramePath) != "png") 87 | { 88 | std::cout << "LOG: [ERROR] Tried to add a invalid file type!"; 89 | return; 90 | } 91 | 92 | float delay = 0; 93 | std::vector& ref = this->m_ptr_Anim->GetkeyFrames(); 94 | int size = (int)ref.size(); 95 | int vecpos = 0; 96 | bool invalid = false; 97 | 98 | for (int i = 0; i < size; i++) 99 | { 100 | if (delay < this->m_KeyFramePos) 101 | { 102 | delay += ref[i].delay; 103 | vecpos++; 104 | } 105 | } 106 | 107 | vecpos--; 108 | 109 | if (this->m_KeyFramePos == 0 && ref.size() == 0 110 | || this->m_KeyFramePos == 0 && ref.size() != 0 && ref[0].position != 0) 111 | { 112 | spe::KeyFrame add = spe::KeyFrame(this->KeyFramePath, 0); 113 | add.position = this->m_KeyFramePos; 114 | 115 | this->m_ptr_Anim->AddKeyFrameAt(0, add); 116 | return; 117 | } 118 | 119 | 120 | if (this->m_KeyFramePos == delay) 121 | { 122 | std::cout << "LOG: [ERROR] Tried to add a keyframe at a position where already a keyframe exists!"; 123 | vecpos *= -1; 124 | return; 125 | } 126 | if (this->m_KeyFramePos > delay) 127 | { 128 | invalid = true; 129 | vecpos++; 130 | } 131 | 132 | float fndelay = 0; 133 | if (vecpos > 0 && this->m_KeyFramePos < delay) 134 | { 135 | int before = vecpos - 1; 136 | fndelay = (float)this->m_KeyFramePos - ref[before].position; 137 | 138 | if (vecpos == 1) 139 | { 140 | fndelay = (float)this->m_KeyFramePos; 141 | } 142 | } 143 | else 144 | { 145 | fndelay = this->m_KeyFramePos - delay; 146 | } 147 | 148 | if (!invalid) 149 | { 150 | ref[vecpos].delay = (this->m_KeyFramePos - delay) * -1; 151 | } 152 | 153 | spe::KeyFrame add = spe::KeyFrame(this->KeyFramePath, fndelay); 154 | add.position = this->m_KeyFramePos; 155 | 156 | this->m_ptr_Anim->AddKeyFrameAt(vecpos, add); 157 | 158 | if (ref[0].delay < 0) 159 | { 160 | ref[0].delay = (float)ref[0].position; 161 | } 162 | } 163 | 164 | 165 | // Public functions 166 | 167 | void spe::UIAnimationKeyFrameAdder::Render() 168 | { 169 | this->BeginWindow(); 170 | this->InputData(); 171 | this->CloseWindowAndSafeKeyFrame(); 172 | } 173 | 174 | void spe::UIAnimationKeyFrameAdder::SetAnimation(spe::Animation* anim) 175 | { 176 | this->m_ptr_Anim = anim; 177 | } 178 | 179 | void spe::UIAnimationKeyFrameAdder::Reset() 180 | { 181 | this->m_KeyFramePos = -1; 182 | this->KeyFramePath = ""; 183 | this->m_ptr_Anim = nullptr; 184 | this->IsKeyFrameMenuOpen = false; 185 | this->Hovered = false; 186 | } 187 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Animations/UIAnimationKeyFrameAdder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Sprite/Components/Animator/Animation.h" 6 | #include "GUI/Property/UIBase.h" 7 | 8 | #include "GUI/UIUtility/UIUtility.h" 9 | 10 | 11 | namespace spe 12 | { 13 | class UIAnimationKeyFrameAdder : public spe::IUIBase 14 | { 15 | private: 16 | spe::Animation* m_ptr_Anim; 17 | 18 | void BeginWindow(); 19 | void InputData(); 20 | void CloseWindowAndSafeKeyFrame(); 21 | void AddKeyFrameToAnimation(); 22 | 23 | int m_KeyFramePos; 24 | char m_KeyFramePath[100]; // 100 is the path array size (string can only be 100 chars long!) 25 | 26 | void Init() override; 27 | public: 28 | bool IsKeyFrameMenuOpen; 29 | std::string KeyFramePath; 30 | 31 | UIAnimationKeyFrameAdder(); 32 | 33 | void Render() override; 34 | void SetAnimation(spe::Animation* anim); 35 | void Reset(); 36 | }; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/AssetFolder/UIAssetFolder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "dirent.h" 8 | 9 | #include "RessourceHandler/FileDataMacros.h" 10 | #include "GUI/UIUtility/UIModels.h" 11 | #include "GUI/Property/UIBase.h" 12 | #include "Utility/Style.h" 13 | #include "GUI/UIUtility/UIUtility.h" 14 | #include "Core/Time.h" 15 | #include "GUI/Color.h" 16 | #include "Utility/FileDialoge.h" 17 | 18 | #include "Sprite/Sprite.h" 19 | #include "GUI/Property/AssetFolder/UIAssetTools.h" 20 | #include "GUI/Property/AssetFolder/UIIconData.h" 21 | #include "GUI/Property/AssetFolder/UIAssetFolder.h" 22 | 23 | #include "Savesystem.h" 24 | 25 | #define CLOSE_RECTANGLE_PADDIND_X 50 26 | #define FOLDER_HIERARCHY_PADDING 32 27 | #define UIASSET_FOLDER_WIDTH 200 28 | #define FILE_DISPLAYER_COLOR 30.0f 29 | 30 | #define MAX_COLUMNS 9 31 | #define PADDING_BETWEEN_ROWS 20 32 | #define PADDING_BETWEEN_COLUMS 130 33 | #define ICONS_SIZE 70 34 | #define ASSET_FOLDER_DEFAULT_WINDOW_SIZE ImVec2(1280 + 250, 400) 35 | 36 | namespace spe 37 | { 38 | class UIAssetFolder : public spe::IUIBase 39 | { 40 | private: 41 | spe::ResizeWindowData m_ResizeWindow; 42 | spe::UIAssetTools m_Tools; 43 | spe::UIIconData m_IconData; 44 | 45 | std::string m_HoverItemName; 46 | bool m_IsItemHovered; 47 | bool m_IsAssetFolderOpen; 48 | std::string m_CurrentPath; 49 | std::string m_CurrentName; 50 | float m_FileContentPadding; 51 | ImGuiTextFilter m_FileFilter; 52 | bool m_HoveredOverItem; 53 | bool m_DraggingItem; 54 | bool m_Interacted; 55 | 56 | std::unordered_map m_AlreadyOpenedPaths; 57 | 58 | void GetAllFilesInDir(const char* path); 59 | void SetDragAndDrop(std::string path, std::string name); 60 | void BeginColumns(); 61 | void GoBackToBeforeFolder(); 62 | void AddPrefab(); 63 | void RenderFolderHierarchy(); 64 | void RenderCloseRectangle(); 65 | void RenderFolderHierarchyRecursiv(const char* path, const char* name, bool open_next_tree_node); 66 | void RenderFilesWithChildWindow(const std::string& name, const std::string& new_path, const std::string& entry_path 67 | , bool is_folder, uint32_t texture_id, uint8_t colum_cnt); 68 | 69 | /// 70 | /// Renders the selected path (NOT RECURSIV) 71 | /// 72 | void RenderContentBrowser(); 73 | void SetCurrentPath(const std::string& path, const std::string& name); 74 | void ResizeWindow(); 75 | void Init() override; 76 | 77 | public: 78 | UIAssetFolder(); 79 | 80 | void Render() override; 81 | }; 82 | } 83 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/AssetFolder/UIAssetTools.cpp: -------------------------------------------------------------------------------- 1 | #include "UIAssetTools.h" 2 | 3 | // Constructor 4 | 5 | spe::UIAssetTools::UIAssetTools() 6 | { 7 | this->m_IsPopupOpen = false; 8 | this->m_WindowFontSize = 1; 9 | this->m_ptr_HoveredIconName = nullptr; 10 | this->m_ptr_CurrentAssetPath = nullptr; 11 | this->m_ClassFileName[0] = '\0'; 12 | this->m_OpenFileInput = false; 13 | } 14 | 15 | spe::UIAssetTools::UIAssetTools(const std::string* currentAssetPath, std::string* hoveredIconName) 16 | { 17 | this->m_IsPopupOpen = false; 18 | this->m_ClassFileName[0] = '\0'; 19 | this->m_OpenFileInput = false; 20 | this->m_ptr_CurrentAssetPath = currentAssetPath; 21 | this->m_ptr_HoveredIconName = hoveredIconName; 22 | this->m_WindowFontSize = 1; 23 | } 24 | 25 | // Public functions 26 | 27 | void spe::UIAssetTools::Update(bool& hovered) 28 | { 29 | if (this->m_OpenFileInput) 30 | { 31 | hovered = true; 32 | } 33 | else if (!hovered) 34 | { 35 | return; 36 | } 37 | else 38 | { 39 | hovered = false; 40 | } 41 | 42 | this->GetFileName(); 43 | 44 | ImGui::SetWindowFontScale(this->m_WindowFontSize); 45 | if (ImGui::IsMouseReleased(1)) 46 | { 47 | ImGui::OpenPopup(INPUT_POPUP_NAME); 48 | } 49 | 50 | if (ImGui::IsPopupOpen(INPUT_POPUP_NAME)) 51 | { 52 | this->m_IsPopupOpen = true; 53 | ImGui::BeginPopup(INPUT_POPUP_NAME); 54 | if (ImGui::BeginMenu("Create")) 55 | { 56 | if (ImGui::MenuItem("C++ Script")) 57 | { 58 | // Create a scirpt, link it into the user project 59 | this->m_OpenFileInput = true; 60 | } 61 | ImGui::EndMenu(); 62 | } 63 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7); 64 | if (ImGui::Button("Delete")) 65 | { 66 | const std::string d = *this->m_ptr_CurrentAssetPath; 67 | std::string m = *this->m_ptr_HoveredIconName; 68 | 69 | if (m != "") 70 | { 71 | std::string file_name = ""; 72 | 73 | for (int i = 2; i < m.size(); i++) 74 | { 75 | file_name.push_back(m[i]); 76 | } 77 | 78 | const std::string delete_path = d + "\\" + file_name; 79 | 80 | spe::Utility::Delete(delete_path); 81 | 82 | *this->m_ptr_HoveredIconName = ""; 83 | } 84 | } 85 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7); 86 | if (ImGui::Button("Open in file dialoge")) 87 | { 88 | const std::string command = "start explorer " + *this->m_ptr_CurrentAssetPath; 89 | system(command.c_str()); 90 | } 91 | ImGui::EndPopup(); 92 | } 93 | else 94 | { 95 | this->m_IsPopupOpen = false; 96 | } 97 | ImGui::SetWindowFontScale(spe::Style::s_DefaultFontSize); 98 | } 99 | 100 | void spe::UIAssetTools::GetFileName() 101 | { 102 | if (!this->m_OpenFileInput) 103 | { 104 | return; 105 | } 106 | 107 | if (ImGui::Begin("##input_file_name", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) 108 | { 109 | ImGui::SetNextItemWidth(290); 110 | ImGui::InputTextWithHint("##file_input", "", this->m_ClassFileName, CHAR_MAX); 111 | if (ImGui::Button("Create##F")) 112 | { 113 | this->CreateFileContent(); 114 | 115 | this->m_OpenFileInput = false; 116 | this->m_IsPopupOpen = false; 117 | this->m_ClassFileName[0] = '\0'; 118 | } 119 | spe::UIUtility::SetWindowScreenMiddle(ImVec2(300, 100)); 120 | ImGui::End(); 121 | } 122 | } 123 | 124 | void spe::UIAssetTools::CreateFileContent() 125 | { 126 | const std::string header_content = 127 | "#pragma once\n\n" 128 | "// Included from the editor-src\n" 129 | "#include \n\n" 130 | "class " + std::string(this->m_ClassFileName) + " : public spe::IScript\n" 131 | "{\n" 132 | "public:\n" 133 | " " + std::string(this->m_ClassFileName) + "() = default;\n\n" 134 | " // Can get called on start by the game/sub class\n" 135 | " void Start();\n\n" 136 | " // Can get called 1 time per frame by the game/sub class\n" 137 | " void Update();\n" 138 | "};\n"; 139 | 140 | const std::string cpp_content = 141 | "#include \"" + std::string(this->m_ClassFileName) + ".h\"\n\n" 142 | "void " + std::string(this->m_ClassFileName) + "::Start()\n" 143 | "{\n" 144 | "\n" 145 | "}\n" 146 | "\n" 147 | "void " + std::string(this->m_ClassFileName) + "::Update()\n" 148 | "{\n" 149 | "\n" 150 | "}\n" 151 | "\n"; 152 | 153 | const std::string path = *this->m_ptr_CurrentAssetPath + "\\" + this->m_ClassFileName; 154 | 155 | const std::string cpp_name = std::string(this->m_ClassFileName); 156 | const std::string header_name = std::string(this->m_ClassFileName); 157 | 158 | const std::string cpp_file_path = *this->m_ptr_CurrentAssetPath + "\\" + header_name + ".cpp"; 159 | const std::string hpp_file_path = *this->m_ptr_CurrentAssetPath + "\\" + header_name + ".h"; 160 | 161 | spe::Utility::CreateFileWithContent(header_content, hpp_file_path); 162 | spe::Utility::CreateFileWithContent(cpp_content, cpp_file_path); 163 | 164 | // Building the project of the user when he inserts a new thingy 165 | spe::EngineData::BuildProject(); 166 | } 167 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/AssetFolder/UIAssetTools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "UtilityFunctions.h" 8 | #include "GUI/UIUtility/UIUtility.h" 9 | #include "RessourceHandler/FileDataMacros.h" 10 | #include "Input/Input.h" 11 | 12 | #define CPP_FILE_NAME_SIZE 80 13 | #define INPUT_POPUP_NAME "inputPopup" 14 | 15 | namespace spe 16 | { 17 | class UIAssetTools 18 | { 19 | private: 20 | const std::string* m_ptr_CurrentAssetPath; 21 | 22 | /// 23 | /// Need to change value on delete 24 | /// 25 | std::string* m_ptr_HoveredIconName; 26 | char m_ClassFileName[CPP_FILE_NAME_SIZE]; 27 | 28 | void GetFileName(); 29 | void CreateFileContent(); 30 | 31 | bool m_IsPopupOpen; 32 | bool m_OpenFileInput; 33 | float m_WindowFontSize; 34 | public: 35 | UIAssetTools(); 36 | UIAssetTools(const std::string* current_asset_path, std::string* hovered_icon_name); 37 | 38 | void Update(bool& hovered); 39 | 40 | bool IsPopUpOpen() const { return this->m_IsPopupOpen; } 41 | }; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/AssetFolder/UIIconData.cpp: -------------------------------------------------------------------------------- 1 | #include "UIIconData.h" 2 | 3 | spe::UIIconData::UIIconData() 4 | { 5 | const std::vector icons = 6 | { 7 | PATH_TO_RESSOURCES"\\Icons\\defaultIcon.png", 8 | PATH_TO_RESSOURCES"\\Icons\\assetFolder.png", 9 | PATH_TO_RESSOURCES"\\Icons\\prefabIcon.png", 10 | PATH_TO_RESSOURCES"\\Icons\\codeIcon.png", 11 | PATH_TO_RESSOURCES"\\Icons\\pngIcon.png", 12 | }; 13 | 14 | this->m_Textures = std::vector(icons.size()); 15 | this->m_IDs = std::vector(icons.size()); 16 | 17 | for (int i = 0; i < icons.size(); i++) 18 | { 19 | this->m_Textures[i].loadFromFile(icons[i]); 20 | this->m_IDs[i] = this->m_Textures[i].getNativeHandle(); 21 | } 22 | } 23 | 24 | uint32_t spe::UIIconData::GetId(std::string fileExtension) 25 | { 26 | if (fileExtension == "folder") 27 | { 28 | return this->m_IDs[1]; 29 | } 30 | else if (fileExtension == "prfb") 31 | { 32 | return this->m_IDs[2]; 33 | } 34 | else if (fileExtension == "cpp" || fileExtension == "h") 35 | { 36 | return this->m_IDs[3]; 37 | } 38 | else if (fileExtension == "png") 39 | { 40 | return this->m_IDs[4]; 41 | } 42 | else 43 | { 44 | return this->m_IDs[0]; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/AssetFolder/UIIconData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "RessourceHandler/FileDataMacros.h" 7 | 8 | namespace spe 9 | { 10 | class UIIconData 11 | { 12 | private: 13 | std::vector m_Textures; 14 | std::vector m_IDs; 15 | 16 | public: 17 | // Init all textures and get the paths from UIInfo 18 | UIIconData(); 19 | 20 | uint32_t GetId(std::string fileExtension); 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Inspector/UIInspector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "RessourceHandler/FileDataMacros.h" 9 | #include "GUI/Property/Inspector/UITagSelector.h" 10 | #include "GUI/Property/Inspector/UIInspectorBoxCollider.h" 11 | #include "GUI/UIUtility/UIModels.h" 12 | #include "GUI/Property/UIBase.h" 13 | #include "Utility/Style.h" 14 | #include "GUI/UIUtility/UIUtility.h" 15 | #include "Core/Time.h" 16 | #include "GUI/Color.h" 17 | #include "Savesystem.h" 18 | 19 | #include "Sprite/Sprite.h" 20 | 21 | #define DEFAULT_BACKGROUND_COLOR spe::Vector3(139, 165, 187) 22 | #define INSPECTOR_WINDOW_POS ImVec2(1530, 53) 23 | #define INSPECTOR_DEFAULT_WINDOW_SIZE ImVec2(390, 550) 24 | #define ADD_COMPONENTS_MARGIN 300 25 | #define SEARCH_BAR_MARGIN 290 26 | #define COMPONENT_PADDING_LEFT 20 27 | #define COMPONENT_SELECTED_COLOR SPRITE_BACKGROUND_COLOR 28 | #define DUMMY_COMPONENT ImGui::Dummy(ImVec2(0, 8)) 29 | #define DUPE_NAME_TIME_EDIT 0.3f 30 | 31 | namespace spe 32 | { 33 | enum class InspectorState 34 | { 35 | None = -1, 36 | GameWindowEditor = 0, 37 | SpriteEditorWindow = 1 38 | }; 39 | class UIInspector : public spe::IUIBase 40 | { 41 | private: 42 | // gui repo (rectangles) 43 | spe::Rectangle* m_ptr_ColliderRec; 44 | spe::Rectangle* m_ptr_SpriteRec; 45 | 46 | spe::UITagSelector m_TagSelector; 47 | spe::UIInspectorBoxCollider m_Collider; 48 | 49 | spe::ResizeWindowData m_WindowData; 50 | std::string m_MenuName; 51 | std::string m_SpriteName; 52 | ; 53 | ImVec2 m_PopUpCursorPos; 54 | float m_SpriteInputWidth; 55 | float m_DupeNameEditorTimer; 56 | std::vector m_ComponentsName; 57 | 58 | //When the box collider component is open we want to display the rectangle as a box collider and not as a rectangle 59 | float m_WindowSizeWidth; 60 | std::string m_ComponentSelected; 61 | char* m_InputName; 62 | 63 | float m_LightRadius; 64 | float m_LightIntensity; 65 | float m_CamZoom; 66 | 67 | void RenderOptions(); 68 | void ResizeWindow(); 69 | void SetupComponents(); 70 | 71 | void TransformComponent(); 72 | void SpriteRendererComponent(); 73 | void BoxColliderComponent(); 74 | void PhysicsBodyComponent(); 75 | void AnimatorComponent(); 76 | void PrefabComponent(); 77 | void LightComponent(); 78 | 79 | void DisplayDefaultInspectorView(); 80 | 81 | void InputXY(const char* label, float& inputX, float& inputY, float x, float y); 82 | 83 | void RenameSprite(); 84 | void ComponentSelector(); 85 | void SetCompontents(); 86 | void DrawRectangleOverCurrentObject(); 87 | void RenderBackgroundBehindComponent(); 88 | void BackgroundSetting(); 89 | void GameEngineViewSetting(); 90 | void RenderComponentOptions(spe::Component& component, const std::string& name); 91 | void GeneralSettings(); 92 | 93 | void Init() override; 94 | 95 | public: 96 | UIInspector(); 97 | 98 | spe::InspectorState State; 99 | 100 | void Render() override; 101 | }; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Inspector/UIInspectorBoxCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GUI/Property/UIBase.h" 4 | #include "GUI/UIUtility/UIModels.h" 5 | #include "Sprite/Sprite.h" 6 | #include "Utility/Style.h" 7 | #include "icons.h" 8 | #include "GUI/UIUtility/UIUtility.h" 9 | 10 | 11 | #define SCALE_DOTTS_COLLIDER 4 12 | #define INVALID_AERA 1 13 | #define DEFAULT_DOTT_SCALE 35 14 | 15 | namespace spe 16 | { 17 | class UIInspectorBoxCollider 18 | { 19 | private: 20 | spe::ScaleDott m_ScaleDotts[SCALE_DOTTS_COLLIDER]; 21 | bool m_EditMode; 22 | 23 | /// 24 | /// Hardcoded to much shit 25 | /// 26 | void RenderScaleDotts(spe::Sprite* sprite); 27 | void RenderDotts(); 28 | void UnrenderDotts(); 29 | void Reset(); 30 | public: 31 | UIInspectorBoxCollider(); 32 | 33 | void LeaveEditMode(); 34 | void Edit(float& x, float& y); 35 | void Solid(float& x, float& y, spe::Sprite* sprite); 36 | void Width(float x, float y, spe::Sprite* sprite); 37 | void Controller(spe::Sprite* sprite); 38 | void Height(spe::Sprite* sprite); 39 | void DrawBoxCollider(spe::Sprite* sprite, spe::Rectangle* ptr_rectangle); 40 | 41 | void InitScaleDottsUI(spe::GUIRepository& repo); 42 | }; 43 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Inspector/UITagSelector.cpp: -------------------------------------------------------------------------------- 1 | #include "UITagSelector.h" 2 | 3 | // Constructor / Destructor 4 | 5 | spe::UITagSelector::UITagSelector() 6 | { 7 | this->Init(); 8 | } 9 | 10 | void spe::UITagSelector::Init() 11 | { 12 | this->m_TagName[0] = '\0'; 13 | this->m_OpenNamePopup = false; 14 | } 15 | 16 | // Public functions 17 | 18 | void spe::UITagSelector::Render() 19 | { 20 | this->RenderSelector(); 21 | this->RenderPopup(); 22 | } 23 | 24 | // Private functions 25 | 26 | void spe::UITagSelector::RenderSelector() 27 | { 28 | const std::vector& items = this->m_ptr_Repo->Tags; 29 | static int selectedItem = 0; 30 | 31 | ImGui::SetCursorPos(ImVec2(ImGui::GetWindowContentRegionMax().x - 120, 40)); 32 | 33 | ImGui::SetNextItemWidth(110); 34 | const char* tag = this->m_ptr_GUIRepo->InspectorSprite->Tag.c_str(); 35 | if (ImGui::BeginCombo("##dropdown-tags", tag)) 36 | { 37 | for (int i = 0; i < items.size(); i++) 38 | { 39 | bool isSelected = (selectedItem == i); 40 | 41 | ImGui::SetNextItemWidth(110); 42 | if (ImGui::Selectable(items[i].c_str(), isSelected)) 43 | { 44 | selectedItem = i; 45 | this->m_ptr_GUIRepo->InspectorSprite->Tag = items[i]; 46 | } 47 | if (isSelected) 48 | { 49 | ImGui::SetItemDefaultFocus(); 50 | } 51 | } 52 | ImGui::Separator(); 53 | if (ImGui::Button("Add tag")) 54 | { 55 | this->m_OpenNamePopup = true; 56 | ImGui::SetNextWindowFocus(); 57 | } 58 | ImGui::EndCombo(); 59 | } 60 | } 61 | 62 | void spe::UITagSelector::RenderPopup() 63 | { 64 | if (!this->m_OpenNamePopup) 65 | { 66 | return; 67 | } 68 | const ImVec2 size = ImVec2(200, 50); 69 | 70 | ImGui::Begin("##tag-adder", NULL, DEFAULT_FLAGS); 71 | 72 | ImGui::SetNextItemWidth(size.x); 73 | ImGui::InputTextWithHint("##add-text-input", "", this->m_TagName, CHAR_MAX); 74 | 75 | spe::UIUtility::SetWindowScreenMiddle(size); 76 | ImGui::SetWindowSize(size); 77 | this->Hovered = spe::UIUtility::IsHovered(ImGui::GetWindowPos(), size); 78 | ImGui::End(); 79 | 80 | if (ImGui::IsKeyReleased(ImGuiKey_Enter)) 81 | { 82 | this->m_ptr_Repo->Tags.push_back(std::string(this->m_TagName)); 83 | this->Hovered = false; 84 | this->m_OpenNamePopup = '\0'; 85 | this->m_OpenNamePopup = false; 86 | } 87 | 88 | if (ImGui::IsKeyReleased(ImGuiKey_Escape)) 89 | { 90 | this->m_OpenNamePopup = '\0'; 91 | this->m_OpenNamePopup = false; 92 | } 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/Inspector/UITagSelector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GUI/UIUtility/UIModels.h" 4 | #include "GUI/UIUtility/UIUtility.h" 5 | #include "GUI/Property/UIBase.h" 6 | 7 | #include "Sprite/Sprite.h" 8 | 9 | #include 10 | 11 | namespace spe 12 | { 13 | class UITagSelector : public spe::IUIBase 14 | { 15 | private: 16 | bool m_OpenNamePopup; 17 | char m_TagName[150]; 18 | 19 | void RenderSelector(); 20 | void RenderPopup(); 21 | 22 | void Init() override; 23 | 24 | public: 25 | UITagSelector(); 26 | 27 | void Render() override; 28 | }; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/UIBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Math/Vector2.h" 4 | #include "Sprite/SpriteRepository.h" 5 | #include "GUI/GUIRepository.h" 6 | 7 | namespace spe 8 | { 9 | class IUIBase 10 | { 11 | protected: 12 | ImVec2 m_Size; 13 | spe::SpriteRepository* m_ptr_Repo; 14 | spe::GUIRepository* m_ptr_GUIRepo; 15 | 16 | virtual void Init() = 0; 17 | IUIBase() : Hovered(false), m_ptr_Repo(nullptr), m_ptr_GUIRepo(nullptr) { } 18 | public: 19 | bool Hovered; 20 | 21 | virtual void Render() = 0; 22 | 23 | void SetRepos(spe::SpriteRepository* sprites, spe::GUIRepository* gui) 24 | { 25 | this->m_ptr_Repo = sprites; 26 | this->m_ptr_GUIRepo = gui; 27 | this->Init(); 28 | } 29 | 30 | }; 31 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/Property/UIHierarchy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "UIBase.h" 7 | #include "Sprite/Sprite.h" 8 | #include "GUI/GUIRepository.h" 9 | #include "GUI/UIUtility/UIUtility.h" 10 | #include "Utility/Style.h" 11 | #include "GUI/UIUtility/UIModels.h" 12 | #include "icons.h" 13 | #include "RessourceHandler/Initializer.h" 14 | 15 | #define SPRITE_SELECTED_COLOR ImVec4(139.0f / 255.0f, 180.0f / 255.0f, 234.0f / 255.0f,1.0f) 16 | 17 | #define POPUP_NAME "CONTEXT_MENU" 18 | #define WINDOW_SIZE_HIERARCHY_Y 1080 - WINDOW_POS.y 19 | #define FOLDER_SPRITE_HIERARCHY_PADDING 50 20 | 21 | #define MENU_ITEM_PADDING 50 22 | #define TREE_NODE_PADDING 40 23 | 24 | #define ADD_WHEN_SPRITE_HAS_PARENT 30 25 | 26 | #define SPRITE_BACKGROUND_COLOR ImColor(30, 30, 30, 255) 27 | 28 | #define WINDOW_POS ImVec2(0.0f, WINDOW_SIZE_Y_TOOL_BUTTONS + 38) 29 | #define HIERARCHY_DEFAULT_WINDOW_SIZE ImVec2(300.0f, 1080.0f - 350.0f) 30 | // x amount of s to select a child to parent 31 | #define TIME_TO_CAN_SELECT_CHILD 0.3f 32 | 33 | namespace spe 34 | { 35 | class UIHierarchy : public spe::IUIBase 36 | { 37 | private: 38 | spe::ResizeWindowData m_ResizeData; 39 | bool m_WaitFrame; 40 | ImGuiTextFilter m_SearchFilter; 41 | 42 | bool m_FoundHovering; 43 | bool m_FoundSelected; 44 | float m_ChildSelectTimer; 45 | uint8_t m_BackgroundColorCnt; 46 | 47 | spe::LightRepository* m_ptr_LightRepo; 48 | 49 | void DisplayContextPopup(); 50 | bool DisplaySprites(); 51 | void DisplaySprites(spe::Sprite* parent, bool& any_hovered); 52 | void DisplayChildToParent(); 53 | void DisplaySpriteSeperated(spe::Sprite* d, bool& any_hovered); 54 | 55 | void SetSelectedBackgroundColor(spe::Sprite* sprite, bool& pop_style); 56 | void SetSpriteAsChild(); 57 | 58 | void AddSprite(); 59 | void DeleteSprite(); 60 | void Unparent(); 61 | void CleanRepoSpritesUp(bool any_hovered); 62 | void SetMenuitemHovered(bool& any_hovered, spe::Sprite* sprite); 63 | 64 | void AddPrefab(); 65 | void RenderCloseRectangle(); 66 | void RenderHierarchyOptions(); 67 | void ResizeWindow(); 68 | 69 | void DrawbackgroundRectangle(); 70 | void SetSpriteOnClick(spe::Sprite* sprite); 71 | void DrawUIRactangleWhenHovered(spe::Sprite* sprite); 72 | 73 | void DrawRenderSymbol(spe::Sprite* child); 74 | 75 | void OnSpriteAdd(spe::Sprite* spr); 76 | 77 | /// 78 | /// Checks for specfic things which get hovered 79 | /// 80 | void SetHovering(spe::Sprite* sprite, bool& any_hovered); 81 | 82 | void CopySprite(); 83 | 84 | /// 85 | /// Gets called from base class 86 | /// 87 | void Init() override; 88 | public: 89 | UIHierarchy(); 90 | 91 | void Render() override; 92 | 93 | void SetLightRepository(spe::LightRepository& light) { this->m_ptr_LightRepo = &light; } 94 | }; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/RealTime/UIRealTimeEditor.cpp: -------------------------------------------------------------------------------- 1 | #include "UIRealTimeEditor.h" 2 | 3 | //Constructor 4 | 5 | spe::UIRealTimeEditor::UIRealTimeEditor() 6 | { 7 | this->m_Navigator = spe::UIRealTimeEditorNavigator(); 8 | } 9 | 10 | spe::UIRealTimeEditor::UIRealTimeEditor(spe::GameWindow* windowm, spe::SpriteRepository& spriteRepo, spe::GUIRepository& gui_rep) 11 | { 12 | this->m_Navigator.SetRepos(&spriteRepo, &gui_rep); 13 | this->m_Navigator.SetGameWindow(windowm); 14 | 15 | this->m_TransformChanger.SetRepos(&spriteRepo, &gui_rep); 16 | this->m_TransformChanger.SetGameWindow(windowm); 17 | } 18 | 19 | //Public functions 20 | 21 | void spe::UIRealTimeEditor::Update() 22 | { 23 | this->m_Navigator.Render(); 24 | this->m_TransformChanger.Render(); 25 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/RealTime/UIRealTimeEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GUI/RealTime/UIRealTimeEditorNavigator.h" 4 | #include "GUI/RealTime/UIRealTimeEditorTransform.h" 5 | #include "Core/GameWindow.h" 6 | 7 | namespace spe 8 | { 9 | class UIRealTimeEditor 10 | { 11 | private: 12 | spe::UIRealTimeEditorNavigator m_Navigator; 13 | spe::UIRealTimeEditorTransform m_TransformChanger; 14 | 15 | public: 16 | UIRealTimeEditor(); 17 | UIRealTimeEditor(spe::GameWindow* windowm, spe::SpriteRepository& spriteRepo, spe::GUIRepository& gui_rep); 18 | 19 | void Update(); 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/RealTime/UIRealTimeEditorNavigator.cpp: -------------------------------------------------------------------------------- 1 | #include "UIRealTimeEditorNavigator.h" 2 | 3 | 4 | //Constructor 5 | 6 | 7 | void spe::UIRealTimeEditorNavigator::Init() 8 | { 9 | // White box :D 10 | spe::Rectangle* rec = new spe::Rectangle(sf::Vector2f(0, 0), sf::Vector2f(1920, 1080), sf::Color(255, 255, 255), 3.5f, 11 | PATH_TO_TRANSPARENT_PIC, "game-rec"); 12 | 13 | this->m_ptr_GUIRepo->Add(rec); 14 | } 15 | 16 | //Public functions 17 | 18 | void spe::UIRealTimeEditorNavigator::Render() 19 | { 20 | this->SetChangedPosition(); 21 | 22 | if (spe::UIUtility::s_IsAnyHovered) return; 23 | 24 | this->NavigateRightClick(); 25 | this->NavigateArrows(); 26 | this->NavigateScrollWheel(); 27 | this->NavigateKeys(); 28 | this->CalculateScrollWheelSpeed(); 29 | 30 | } 31 | 32 | //Private functions 33 | 34 | void spe::UIRealTimeEditorNavigator::NavigateRightClick() 35 | { 36 | if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) 37 | { 38 | sf::Vector2i mousePos = sf::Mouse::getPosition(*this->m_ptr_Window->GetRenderWindow()); 39 | 40 | if (this->m_Cursor.PositionChanged) 41 | { 42 | spe::Vector2 moved = this->m_Cursor.LastPosition - this->m_Cursor.Position; 43 | 44 | moved = moved * this->m_ptr_GUIRepo->Camera.GetZoom(); 45 | 46 | this->m_ptr_GUIRepo->Camera.Position += moved; 47 | } 48 | } 49 | } 50 | 51 | void spe::UIRealTimeEditorNavigator::NavigateScrollWheel() 52 | { 53 | if (this->m_ptr_Window->WindowEvent.type == sf::Event::MouseWheelScrolled) 54 | { 55 | this->m_ptr_Window->WindowEvent.type = sf::Event::GainedFocus; 56 | const float zoom = this->m_ptr_GUIRepo->Camera.GetZoom(); 57 | if (this->m_ptr_Window->WindowEvent.mouseWheel.x < 0) 58 | { 59 | if (zoom + this->m_ScrollSpeed < 4) 60 | { 61 | this->m_ptr_GUIRepo->Camera.SetZoom(zoom + this->m_ScrollSpeed * 30); 62 | } 63 | } 64 | else 65 | { 66 | if (zoom - this->m_ScrollSpeed > 0.04) 67 | { 68 | this->m_ptr_GUIRepo->Camera.SetZoom(zoom - this->m_ScrollSpeed * 30); 69 | } 70 | } 71 | } 72 | } 73 | 74 | void spe::UIRealTimeEditorNavigator::CalculateScrollWheelSpeed() 75 | { 76 | sf::Vector2f size = this->m_ptr_GUIRepo->Camera.CameraView.getSize(); 77 | 78 | if (size.x > 1500) 79 | { 80 | this->m_ScrollSpeed = 0.006f; 81 | } 82 | else if (size.x > 1000) 83 | { 84 | this->m_ScrollSpeed = 0.005f; 85 | } 86 | else if (size.x > 750) 87 | { 88 | this->m_ScrollSpeed = 0.004f; 89 | } 90 | else 91 | { 92 | this->m_ScrollSpeed = 0.0008f; 93 | } 94 | } 95 | 96 | void spe::UIRealTimeEditorNavigator::SetChangedPosition() 97 | { 98 | this->m_Cursor.Position = spe::Vector2(float(sf::Mouse::getPosition(*this->m_ptr_Window->GetRenderWindow()).x), 99 | float(sf::Mouse::getPosition(*this->m_ptr_Window->GetRenderWindow()).y)); 100 | 101 | this->m_Cursor.SetLastPosition(); 102 | } 103 | 104 | void spe::UIRealTimeEditorNavigator::NavigateArrows() 105 | { 106 | const float camera_speed = this->m_ptr_GUIRepo->Camera.CameraSpeed; 107 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::Right)) 108 | { 109 | this->m_ptr_GUIRepo->Camera.Position.X += camera_speed * spe::Time::s_DeltaTime; 110 | } 111 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::Left)) 112 | { 113 | this->m_ptr_GUIRepo->Camera.Position.X -= camera_speed * spe::Time::s_DeltaTime; 114 | } 115 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::Up)) 116 | { 117 | this->m_ptr_GUIRepo->Camera.Position.Y -= camera_speed * spe::Time::s_DeltaTime; 118 | } 119 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::Down)) 120 | { 121 | this->m_ptr_GUIRepo->Camera.Position.Y += camera_speed * spe::Time::s_DeltaTime; 122 | } 123 | } 124 | 125 | void spe::UIRealTimeEditorNavigator::NavigateKeys() 126 | { 127 | const float camera_speed = this->m_ptr_GUIRepo->Camera.CameraSpeed; 128 | 129 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::D)) 130 | { 131 | this->m_ptr_GUIRepo->Camera.Position.X += camera_speed * spe::Time::s_DeltaTime; 132 | } 133 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::A)) 134 | { 135 | this->m_ptr_GUIRepo->Camera.Position.X -= camera_speed * spe::Time::s_DeltaTime; 136 | } 137 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::W)) 138 | { 139 | this->m_ptr_GUIRepo->Camera.Position.Y -= camera_speed * spe::Time::s_DeltaTime; 140 | } 141 | if (spe::Input::OnKeyHold(spe::KeyBoardCode::S) && !spe::Input::OnKeyHold(spe::KeyBoardCode::LControl)) 142 | { 143 | this->m_ptr_GUIRepo->Camera.Position.Y += camera_speed * spe::Time::s_DeltaTime; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/RealTime/UIRealTimeEditorNavigator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Core/GameWindow.h" 6 | #include "GUI/Property/UIBase.h" 7 | #include "Input/Input.h" 8 | #include "GUI/UIUtility/UITransform.h" 9 | #include "RessourceHandler/FileDataMacros.h" 10 | #include "GUI/UIUtility/UIUtility.h" 11 | 12 | namespace spe 13 | { 14 | class UIRealTimeEditorNavigator : public spe::IUIBase 15 | { 16 | private: 17 | spe::UITransform m_Cursor; 18 | 19 | float m_ScrollSpeed; 20 | spe::GameWindow* m_ptr_Window; 21 | 22 | void NavigateRightClick(); 23 | void NavigateScrollWheel(); 24 | void NavigateArrows(); 25 | void NavigateKeys(); 26 | 27 | void CalculateScrollWheelSpeed(); 28 | 29 | void SetChangedPosition(); 30 | 31 | void Init() override; 32 | public: 33 | 34 | void SetGameWindow(spe::GameWindow* window) { this->m_ptr_Window = window; } 35 | void Render() override; 36 | }; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/RealTime/UIRealTimeEditorTransform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GUI/Property/UIBase.h" 4 | #include "Core/GameWindow.h" 5 | #include "GUI/UIUtility/UIUtility.h" 6 | #include "GUI/UIUtility/UIModels.h" 7 | 8 | #define SCALE_DOTTS 2 9 | #define DEFAULT_DOTT_SCALE 35 10 | 11 | namespace spe 12 | { 13 | class UIRealTimeEditorTransform : public spe::IUIBase 14 | { 15 | private: 16 | bool m_RealeasedCursorOnSprite; 17 | spe::GameWindow* m_ptr_Window; 18 | spe::Vector2 m_CursorWorldPos; 19 | ScaleDott m_ScaleDotts[SCALE_DOTTS]; 20 | spe::Vector2 m_CurrentCursorPos; 21 | 22 | spe::Sprite* m_ptr_ClickedSprite; 23 | int m_ClickedSpriteId; 24 | 25 | void MoveComponent(); 26 | 27 | bool CheckClick(spe::Sprite* const sprite); 28 | spe::Sprite* CheckIfMouseClickedOnSprite(); 29 | 30 | void ScaleChanger(spe::Sprite* focusedSprite); 31 | 32 | void Reset(); 33 | void SetPos(const sf::Vector2f pos[]); 34 | void GetPos(const spe::Sprite* focusedSprite, sf::Vector2f pos[]); 35 | 36 | void RenderDolls(); 37 | void RnrenderDolls(); 38 | 39 | void Init() override; 40 | public: 41 | void SetGameWindow(spe::GameWindow* ptr) { this->m_ptr_Window = ptr; } 42 | 43 | void Render() override; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIConsole.cpp: -------------------------------------------------------------------------------- 1 | #include "UIConsole.h" 2 | 3 | // Ctor 4 | 5 | spe::UIConsole::UIConsole() 6 | { 7 | this->Buffer = ""; 8 | } 9 | 10 | // Private 11 | 12 | void spe::UIConsole::Init() 13 | { 14 | spe::Log::SetStringBuffer(&this->Buffer); 15 | } 16 | 17 | // Public 18 | 19 | void spe::UIConsole::Render() 20 | { 21 | const float x = this->m_ptr_GUIRepo->InspectorData.ptr_Size->x; 22 | 23 | ImGui::Begin("##Console", NULL, DEFAULT_FLAGS); 24 | 25 | ImGui::Text("Console"); 26 | ImGui::Separator(); 27 | 28 | const ImVec2 temp = ImGui::GetCursorPos(); 29 | ImGui::SetCursorPosX(x - 125); 30 | ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 30); 31 | 32 | 33 | ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 1)); 34 | ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 1)); 35 | 36 | if(spe::Style::DisplaySymbolInMenuItemWithText(ICON_FA_TRASH, "Clear", 5)) 37 | { 38 | this->Buffer = ""; 39 | } 40 | if (ImGui::IsItemHovered()) 41 | { 42 | ImGui::SetTooltip("Clear the console"); 43 | } 44 | 45 | ImGui::PopStyleColor(2); 46 | ImGui::SetCursorPos(temp); 47 | 48 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10); 49 | ImGui::TextUnformatted(this->Buffer.c_str()); 50 | 51 | ImGui::SetWindowSize(ImVec2(x, 480)); 52 | 53 | ImGui::SetWindowPos(ImVec2(1920 - x, 600)); 54 | 55 | this->Hovered = spe::UIUtility::IsHovered(ImGui::GetWindowPos(), ImGui::GetWindowSize()); 56 | 57 | ImGui::End(); 58 | } 59 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIConsole.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Property/UIBase.h" 4 | #include "UIUtility/UIUtility.h" 5 | 6 | namespace spe 7 | { 8 | class UIConsole : public spe::IUIBase 9 | { 10 | private: 11 | 12 | void Init() override; 13 | public: 14 | std::string Buffer; 15 | 16 | UIConsole(); 17 | 18 | void Render() override; 19 | }; 20 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UITopbar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Property/UIBase.h" 4 | #include "Sprite/Sprite.h" 5 | #include "GUI/GUIRepository.h" 6 | #include "GUI/UIUtility/UIUtility.h" 7 | #include "Utility/Style.h" 8 | #include "GUI/UIUtility/UIModels.h" 9 | #include "icons.h" 10 | #include "GUI/Color.h" 11 | #include "Core/SeceneHandler.h" 12 | #include "Input/Input.h" 13 | #include "UIUtility/UIModels.h" 14 | 15 | #include "Savesystem.h" 16 | 17 | #define TOOLS_AMOUNT 2 18 | #define FILE_AMOUNT 6 19 | 20 | #define WINDOW_SIZE_Y_TOOL_BUTTONS 20.0f 21 | 22 | namespace spe 23 | { 24 | class UITopbar : public IUIBase 25 | { 26 | private: 27 | spe::SceneHandler* m_ptr_SceneHandler; 28 | 29 | void Init() override; 30 | 31 | spe::Tool m_Tools[TOOLS_AMOUNT]; 32 | spe::Vector3 m_WindowBackground; 33 | EditorTools m_EditorTools; 34 | 35 | char m_NewSceneName[150]; 36 | 37 | bool m_DisplayInfo; 38 | bool m_AddSceneMode; 39 | bool m_ClickedOnBtn; 40 | bool m_UpdateEventToSet; 41 | std::string m_SwitchSceneName; 42 | 43 | void CreateScene(); 44 | void PlayGameButton(); 45 | void ToolSelector(); 46 | void RemoveBackgroundFromButtons(); 47 | void BuildProjectIntoFolder(); 48 | void Hotkeys(); 49 | void RenderWindowSelecter(); 50 | void RenderMainMenuBar(); 51 | void RenderToolSelector(); 52 | void RenderSceneSelector(); 53 | void RemoveScene(const std::string& scene); 54 | void RenderSceneAddPopup(); 55 | void SwitchScene(const std::string& scene); 56 | void DisplayEngineInfo(); 57 | 58 | void ProjectSettings(); 59 | void SimulateButton(); 60 | 61 | public: 62 | UITopbar(); 63 | 64 | void Render() override; 65 | 66 | void SetSceneHandler(spe::SceneHandler& scene) { this->m_ptr_SceneHandler = &scene; } 67 | 68 | }; 69 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIUtility/UIModels.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Sprite/Components/Animator/KeyFrame.h" 9 | #include "Sprite/Components/Animator/Animation.h" 10 | 11 | #include "Utility/Style.h" 12 | 13 | #define DEFAULT_FLAGS ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar 14 | 15 | namespace spe 16 | { 17 | struct KeyFrameSelected 18 | { 19 | int Position; 20 | const spe::KeyFrame* KeyFrameSelected; 21 | bool IsClicked; 22 | }; 23 | enum class EditorTools 24 | { 25 | None = -1, 26 | PositionTool = 0, 27 | ScaleTool = 1, 28 | }; 29 | struct Tool 30 | { 31 | EditorTools tool; 32 | bool Background; 33 | std::string Icon; 34 | std::string Name; 35 | 36 | Tool(const EditorTools tool, const std::string& icon, const std::string& name) 37 | { 38 | this->Name = name; 39 | this->Background = false; 40 | this->tool = tool; 41 | this->Icon = icon; 42 | } 43 | 44 | Tool() 45 | { 46 | this->Name = ""; 47 | this->Background = false; 48 | this->tool = spe::EditorTools::PositionTool; 49 | this->Icon = ""; 50 | } 51 | }; 52 | struct UIWindowData 53 | { 54 | bool Reload; 55 | bool IsOpen; 56 | ImVec2* ptr_Size; 57 | 58 | UIWindowData() : ptr_Size(nullptr), Reload(true), IsOpen(true) { } 59 | UIWindowData(bool reload, bool open, ImVec2* size) : Reload(reload), IsOpen(open), ptr_Size(size) { } 60 | 61 | void SetOpen() 62 | { 63 | Reload = true; 64 | IsOpen = true; 65 | } 66 | }; 67 | struct ResizeWindowData 68 | { 69 | float AdditionalAdd; 70 | bool ClickedOnResizeButton; 71 | 72 | ResizeWindowData() 73 | : AdditionalAdd(0), ClickedOnResizeButton(false) { } 74 | }; 75 | struct Rectangle 76 | { 77 | uint32_t SortingLayerIdx; 78 | uint32_t ID; 79 | std::string Name; 80 | sf::RectangleShape Shape; 81 | sf::Texture Texture; 82 | bool Render; 83 | 84 | Rectangle(const sf::Vector2f& pos, 85 | const sf::Vector2f& size, const sf::Color& outline_color, 86 | float outline_thickness, const std::string& path_to_texture, const std::string& name) 87 | { 88 | this->SortingLayerIdx = 0; 89 | this->Render = true; 90 | this->ID = 0; 91 | this->Name = name; 92 | 93 | this->Texture.loadFromFile(path_to_texture); 94 | 95 | this->Shape.setTexture(&this->Texture); 96 | this->Shape.setPosition(pos); 97 | this->Shape.setSize(size); 98 | this->Shape.setOutlineColor(outline_color); 99 | this->Shape.setOutlineThickness(outline_thickness); 100 | } 101 | }; 102 | 103 | struct UserProjectInfo 104 | { 105 | std::string AbsulutePath; 106 | std::string relativePath; 107 | std::string Name; 108 | std::string LastOpened; 109 | 110 | UserProjectInfo() 111 | { 112 | this->LastOpened = "none"; 113 | this->AbsulutePath = "none"; 114 | this->Name = "none"; 115 | } 116 | UserProjectInfo(std::string name, std::string abspath, std::string lastOpened, std::string relativePath) 117 | { 118 | this->LastOpened = lastOpened; 119 | this->Name = name; 120 | this->AbsulutePath = abspath; 121 | this->relativePath = relativePath; 122 | 123 | } 124 | }; 125 | struct ScaleDott 126 | { 127 | spe::Rectangle* ptr_ScalingRec; 128 | bool Clicked; 129 | }; 130 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIUtility/UITransform.cpp: -------------------------------------------------------------------------------- 1 | #include "UITransform.h" 2 | 3 | void spe::UITransform::SetLastPosition() 4 | { 5 | if (this->NextPosition != this->Position) 6 | { 7 | this->LastPosition = this->NextPosition; 8 | this->NextPosition = this->Position; 9 | this->PositionChanged = true; 10 | } 11 | else 12 | { 13 | this->PositionChanged = false; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIUtility/UITransform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Math/Vector2.h" 4 | 5 | namespace spe 6 | { 7 | class UITransform 8 | { 9 | public: 10 | spe::Vector2 Position; 11 | spe::Vector2 LastPosition; 12 | spe::Vector2 NextPosition; 13 | bool PositionChanged; 14 | 15 | void SetLastPosition(); 16 | }; 17 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIUtility/UIUtility.cpp: -------------------------------------------------------------------------------- 1 | #include "UIUtility.h" 2 | 3 | // Private 4 | 5 | float spe::UIUtility::scaleChanger(spe::ScaleDott& dott, float default_size, float pos_o, bool x) 6 | { 7 | if (spe::UIUtility::IsCursorClickedOnRectangle(dott.ptr_ScalingRec->Shape)) 8 | { 9 | dott.Clicked = true; 10 | } 11 | if (dott.Clicked && sf::Mouse::isButtonPressed(sf::Mouse::Left)) 12 | { 13 | sf::Vector2f pos = (x) 14 | ? sf::Vector2f(spe::UIUtility::GetWorldCordinates().X, dott.ptr_ScalingRec->Shape.getPosition().y) 15 | : sf::Vector2f(dott.ptr_ScalingRec->Shape.getPosition().x,spe::UIUtility::GetWorldCordinates().Y); 16 | 17 | dott.ptr_ScalingRec->Shape.setPosition(pos); 18 | float scale = INVALID_SCALE; 19 | if (x) 20 | { 21 | pos.x -= 960; 22 | scale = (pos.x - pos_o) / (default_size / 2); 23 | } 24 | else 25 | { 26 | pos.y -= 540; 27 | scale = (pos.y + pos_o) / (default_size / 2); 28 | } 29 | return scale; 30 | } 31 | return INVALID_SCALE; 32 | } 33 | 34 | // Public 35 | 36 | void spe::UIUtility::UpdateCursor() 37 | { 38 | spe::UIUtility::WorldCursor.Position = spe::UIUtility::GetWorldCordinates(); 39 | spe::UIUtility::WorldCursor.SetLastPosition(); 40 | 41 | spe::UIUtility::GUICursor.Position = spe::Vector2(ImGui::GetMousePos().x, ImGui::GetMousePos().y); 42 | spe::UIUtility::GUICursor.SetLastPosition(); 43 | } 44 | 45 | float spe::UIUtility::xScaleChanger(spe::ScaleDott& dott, float default_size, float pos_x) 46 | { 47 | return spe::UIUtility::scaleChanger(dott, default_size, pos_x, true); 48 | } 49 | 50 | float spe::UIUtility::yScaleChanger(spe::ScaleDott& dott, float default_size, float pos_y) 51 | { 52 | return spe::UIUtility::scaleChanger(dott, default_size, pos_y, false); 53 | } 54 | 55 | bool spe::UIUtility::IsCursorClickedOnSprite(const spe::Sprite* check) 56 | { 57 | if (!sf::Mouse::isButtonPressed(sf::Mouse::Left)) 58 | { 59 | return false; 60 | } 61 | sf::Vector2i cursorPos = sf::Mouse::getPosition(*spe::UIUtility::s_m_ptr_Window); 62 | spe::UIUtility::WorldCursor.Position = spe::UIUtility::s_m_ptr_Window->mapPixelToCoords(cursorPos); 63 | 64 | float getPosX = check->Transform.GetOrigininalPosition().X; 65 | float getPosY = check->Transform.GetOrigininalPosition().Y; 66 | 67 | float otherGetPosX = spe::UIUtility::WorldCursor.Position.X; 68 | float otherGetPosY = spe::UIUtility::WorldCursor.Position.Y; 69 | 70 | return (getPosX + check->Transform.TextureSize.X >= otherGetPosX 71 | && getPosX <= otherGetPosX + CURSOR_HITBOX 72 | && getPosY + check->Transform.TextureSize.Y >= otherGetPosY 73 | && getPosY <= otherGetPosY + CURSOR_HITBOX); 74 | } 75 | 76 | spe::Vector2 spe::UIUtility::GetWorldCordinates() 77 | { 78 | const sf::Vector2i cursorPos = sf::Mouse::getPosition(*spe::UIUtility::s_m_ptr_Window); 79 | const sf::Vector2f cursorWorldPos = spe::UIUtility::s_m_ptr_Window->mapPixelToCoords(cursorPos); 80 | 81 | return spe::Vector2(cursorWorldPos.x, cursorWorldPos.y); 82 | } 83 | 84 | bool spe::UIUtility::IsCursorClickedOnRectangle(const sf::RectangleShape& shape) 85 | { 86 | if (spe::Event::MousePressedLeft != spe::UIUtility::s_m_ptr_Event->Type) 87 | { 88 | return false; 89 | } 90 | 91 | float getPosX = shape.getPosition().x; 92 | float getPosY = shape.getPosition().y; 93 | 94 | float getTextureSizeX = shape.getSize().x; 95 | float getTextureSizeY = shape.getSize().y; 96 | 97 | float otherGetPosX = spe::UIUtility::WorldCursor.Position.X; 98 | float otherGetPosY = spe::UIUtility::WorldCursor.Position.Y; 99 | 100 | bool collided = (getPosX + getTextureSizeX >= otherGetPosX 101 | && getPosX <= otherGetPosX + CURSOR_HITBOX 102 | && getPosY + getTextureSizeY >= otherGetPosY 103 | && getPosY <= otherGetPosY + CURSOR_HITBOX); 104 | 105 | if (collided) 106 | spe::UIUtility::s_m_ptr_Event->Type = spe::Event::None; 107 | 108 | return collided; 109 | } 110 | 111 | void spe::UIUtility::SetWindowScreenMiddle(const ImVec2& ref) 112 | { 113 | ImVec2 size = spe::Vector2::toImVec2(ref); 114 | ImVec2 newPos = ImVec2(spe::Vector2:: 115 | toImVec2(spe::Vector2(spe::Vector2::SCREEN_MIDDLE.X - size.x / 2, 116 | spe::Vector2::SCREEN_MIDDLE.Y - size.y / 2))); 117 | 118 | ImGui::SetWindowSize(size); 119 | ImGui::SetWindowPos(newPos); 120 | } 121 | 122 | void spe::UIUtility::SameLine(float width) 123 | { 124 | ImGui::SameLine(); 125 | 126 | ImGui::SetCursorPosY(ImGui::GetCursorPosY() + width); 127 | } 128 | 129 | bool spe::UIUtility::RenderCloseRectangle(float padding_left, const char* icon, const std::string& id, const std::string& content, float cursor_pos) 130 | { 131 | bool close = true; 132 | const static float CLOSE_RECTANGLE_INNER_PADDING = 7; 133 | const static ImVec2 SIZE = ImVec2(150, 32); 134 | 135 | ImGui::SetCursorPosX(padding_left); 136 | ImGui::SetCursorPosY(cursor_pos); 137 | ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.085f, 0.085f, 0.085f, 1.0f)); 138 | ImGui::BeginChild(id.c_str(), SIZE); 139 | ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + CLOSE_RECTANGLE_INNER_PADDING, ImGui::GetCursorPosY() + CLOSE_RECTANGLE_INNER_PADDING)); 140 | 141 | spe::Style::DisplaySmybolAsText(icon); 142 | ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + 30 143 | , ImGui::GetCursorPosY() - ImGui::CalcTextSize(icon).y - 1)); 144 | ImGui::Text(content.c_str()); 145 | ImGui::SetCursorPos(ImVec2(ImGui::GetWindowSize().x - 30, 0)); 146 | if (ImGui::Button("x")) 147 | { 148 | // Returns false so we can do ourWindow = renderCloseRectangle() and when ourWindow is false it will stop rendering 149 | close = false; 150 | } 151 | ImGui::PopStyleColor(); 152 | ImGui::EndChild(); 153 | return close; 154 | } 155 | 156 | void spe::UIUtility::DrawRectangleInGUIWIndow(const ImVec2& size, const ImVec2& top_left, const ImColor& color) 157 | { 158 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 159 | draw_list->AddRectFilled(top_left, ImVec2(top_left.x + size.x, top_left.y - size.y), color); 160 | } 161 | 162 | bool spe::UIUtility::IsHovered(const ImVec2& windowPos, const ImVec2& windowSize) 163 | { 164 | ImVec2 mousePos = ImVec2(spe::UIUtility::GUICursor.Position.X, spe::UIUtility::GUICursor.Position.Y); 165 | 166 | return mousePos.x >= windowPos.x && mousePos.x <= windowPos.x + windowSize.x && 167 | mousePos.y >= windowPos.y && mousePos.y <= windowPos.y + windowSize.y; 168 | } 169 | 170 | bool spe::UIUtility::HandleCloseAndReloadWindow(spe::UIWindowData& data, bool& hovered, const ImVec2& original_size) 171 | { 172 | bool must_return = false; 173 | if (!data.IsOpen) 174 | { 175 | must_return = true; 176 | hovered = false; 177 | } 178 | if (data.Reload) 179 | { 180 | // Default window size 181 | *data.ptr_Size = original_size; 182 | data.Reload = false; 183 | } 184 | return must_return; 185 | } 186 | 187 | // Static init 188 | 189 | spe::UITransform spe::UIUtility::GUICursor;; 190 | spe::UITransform spe::UIUtility::WorldCursor; 191 | 192 | spe::Event* spe::UIUtility::s_m_ptr_Event = nullptr; 193 | sf::RenderWindow* spe::UIUtility::s_m_ptr_Window = nullptr; 194 | bool spe::UIUtility::s_IsAnyHovered = false; 195 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIUtility/UIUtility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Sprite/Components/Transform.h" 7 | #include "Math/Vector2.h" 8 | #include "GUI/UIUtility/UIModels.h" 9 | #include "Utility/Style.h" 10 | #include "Core/Event.h" 11 | #include "GUI/UIUtility/UITransform.h" 12 | #include "Sprite/Sprite.h" 13 | 14 | #define INVALID_SCALE 1.11f 15 | #define CURSOR_HITBOX 20 16 | 17 | namespace spe 18 | { 19 | class UIUtility 20 | { 21 | private: 22 | static spe::Event* s_m_ptr_Event; 23 | static sf::RenderWindow* s_m_ptr_Window; 24 | 25 | static float scaleChanger(spe::ScaleDott& dott, float default_size, float pos_o, bool x); 26 | public: 27 | static spe::UITransform GUICursor; 28 | static spe::UITransform WorldCursor; 29 | 30 | UIUtility() = delete; 31 | 32 | static void UpdateCursor(); 33 | 34 | static float xScaleChanger(spe::ScaleDott& dott, float default_size, float pos_x); 35 | static float yScaleChanger(spe::ScaleDott& dott, float default_size, float pos_y); 36 | 37 | static bool IsCursorClickedOnSprite(const spe::Sprite* check); 38 | static spe::Vector2 GetWorldCordinates(); 39 | static bool IsCursorClickedOnRectangle(const sf::RectangleShape& shape); 40 | 41 | static void SetWindowScreenMiddle(const ImVec2& ref); 42 | static void SameLine(float width); 43 | static bool RenderCloseRectangle(float padding_left, const char* icon, const std::string& id, 44 | const std::string& content, float cursor_pos); 45 | static void DrawRectangleInGUIWIndow(const ImVec2& size, const ImVec2& top_left, const ImColor& color); 46 | static bool IsHovered(const ImVec2& windowPos, const ImVec2& windowSize); 47 | static bool HandleCloseAndReloadWindow(spe::UIWindowData& data, bool& hovered, const ImVec2& original_size); 48 | 49 | static void SetEvent(spe::Event* evnt) { spe::UIUtility::s_m_ptr_Event = evnt; } 50 | static void SetRenderWinodw(sf::RenderWindow* window) { spe::UIUtility::s_m_ptr_Window = window; } 51 | 52 | static bool s_IsAnyHovered; 53 | }; 54 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "UIWindow.h" 2 | 3 | // Public 4 | 5 | void spe::UIWindow::Update() 6 | { 7 | this->m_UIHierarchy.Render(); 8 | this->m_UITopbar.Render(); 9 | this->m_UIInspector.Render(); 10 | this->m_UIAnimation.Render(); 11 | this->m_UIAssetFolder.Render(); 12 | this->m_UIConsole.Render(); 13 | 14 | 15 | if (this->m_UIHierarchy.Hovered || this->m_UITopbar.Hovered || this->m_UIInspector.Hovered 16 | || this->m_UIAnimation.Hovered || this->m_UIAssetFolder.Hovered || this->m_UIConsole.Hovered) 17 | { 18 | spe::UIUtility::s_IsAnyHovered = true; 19 | } 20 | else 21 | { 22 | spe::UIUtility::s_IsAnyHovered = false; 23 | } 24 | } 25 | 26 | void spe::UIWindow::SetRepos(spe::GUIRepository& gui, spe::SpriteRepository& sprite, spe::SceneHandler& scene, spe::LightRepository& light) 27 | { 28 | this->m_UIHierarchy.SetRepos(&sprite, &gui); 29 | 30 | this->m_UIHierarchy.SetLightRepository(light); 31 | 32 | this->m_UITopbar.SetRepos(&sprite, &gui); 33 | this->m_UIInspector.SetRepos(&sprite, &gui); 34 | this->m_UIAnimation.SetRepos(&sprite, &gui); 35 | this->m_UIAssetFolder.SetRepos(&sprite, &gui); 36 | 37 | this->m_UITopbar.SetSceneHandler(scene); 38 | 39 | this->m_UIConsole.SetRepos(nullptr, &gui); 40 | } 41 | -------------------------------------------------------------------------------- /Engine/Editor/Source/GUI/UIWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "UITopbar.h" 4 | 5 | #include "Sprite/SpriteRepository.h" 6 | #include "GUIRepository.h" 7 | #include "Property/UIHierarchy.h" 8 | #include "Core/SeceneHandler.h" 9 | #include "Property/Inspector/UIInspector.h" 10 | #include "Property/Animations/UIAnimation.h" 11 | #include "Property/AssetFolder/UIAssetFolder.h" 12 | #include "UIConsole.h" 13 | 14 | namespace spe 15 | { 16 | class UIWindow 17 | { 18 | private: 19 | spe::UITopbar m_UITopbar; 20 | spe::UIHierarchy m_UIHierarchy; 21 | spe::UIInspector m_UIInspector; 22 | spe::UIAnimation m_UIAnimation; 23 | spe::UIAssetFolder m_UIAssetFolder; 24 | spe::UIConsole m_UIConsole; 25 | 26 | public: 27 | 28 | void Update(); 29 | 30 | void SetRepos(spe::GUIRepository& gui, spe::SpriteRepository& sprite, spe::SceneHandler& scene, spe::LightRepository& light); 31 | }; 32 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Editor.h" 2 | #include "GUI/ProjectSelector/UIProjectSelector.h" 3 | 4 | int main() 5 | { 6 | // Sets the engine data to load the game 7 | spe::UIProjectSelector selector; 8 | 9 | while (selector.IsOpen()) 10 | { 11 | selector.Update(); 12 | } 13 | 14 | selector.Shutdown(); 15 | 16 | if (spe::EngineData::s_PathUserProject == "") 17 | { 18 | spe::Log::LogString("Closing engine, no project selected"); 19 | return 0; 20 | } 21 | 22 | spe::Editor editr; 23 | 24 | while (editr.IsOpen()) 25 | { 26 | editr.Update(); 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Engine/Editor/Source/Savesystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Sprite/SpriteRepository.h" 7 | #include "GUI/GUIRepository.h" 8 | #include "Core/SeceneHandler.h" 9 | #include "GUI/UIUtility/UIModels.h" 10 | 11 | #define ALERT_IF_CANT_SAVE if(!spe::Savesystem::s_CanSave) \ 12 | { \ 13 | spe::Log::LogString("Can't save while in no-save mode"); \ 14 | return; \ 15 | } \ 16 | 17 | namespace spe 18 | { 19 | /// 20 | /// This class assumes your are in th engine dir 21 | /// 22 | class Savesystem 23 | { 24 | public: 25 | Savesystem() = delete; 26 | 27 | static void CreateAnimationSaveFile(const spe::Sprite* ptr_sprite, const spe::Animation& animationToSave); 28 | 29 | static void UpdateSceneFile(const spe::SceneHandler& handler); 30 | static void UpdateSpriteFile(const spe::SpriteRepository& repo); 31 | static void UpdateBackgroundFile(const spe::Vector3& bg); 32 | static void UpdateHighestIndexFile(uint32_t idx); 33 | static void UpdateCameraFile(const spe::Camera& camera); 34 | static void UpdateTagsFile(const spe::SpriteRepository& repo); 35 | static void UpdateAnimationFile(const spe::SpriteRepository& repo); 36 | 37 | /// 38 | /// Saves everything 39 | /// 40 | /// The sprites 41 | /// Camera, background 42 | /// The scenes 43 | static void SaveEverything(const spe::SpriteRepository& sprites, 44 | const spe::Camera& gui, 45 | const spe::Vector3& bg, 46 | const spe::SceneHandler& scene); 47 | 48 | static void SaveProjects(const std::vector& projects); 49 | 50 | static std::string GetPropertyLineWithSeperator(const spe::Sprite* sprite); 51 | 52 | static void CreateOrUpdatePrefabFile(const spe::Sprite* content, const std::string& pathToFile, const std::string& oldFilePath); 53 | 54 | static bool s_CanSave; 55 | }; 56 | } -------------------------------------------------------------------------------- /Engine/Engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Engine/CMakeLists.txt 2 | 3 | add_subdirectory(Core) 4 | add_subdirectory(Math) -------------------------------------------------------------------------------- /Engine/Engine/Core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Core/CMakeLists.txt 2 | 3 | file(GLOB_RECURSE CORE_SOURCE_FILES 4 | "Source/*.h" 5 | "Source/*.cpp" 6 | ) 7 | 8 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${CORE_SOURCE_FILES}) 9 | 10 | set(SFML_DIR "${EXTERNAL_LIBRARIES_FOLDER}/sfml") 11 | 12 | # Create the Core library and add the source files to it 13 | add_library(Core STATIC ${CORE_SOURCE_FILES}) 14 | 15 | target_include_directories(Core PUBLIC "Source") 16 | target_include_directories(Core PUBLIC "${EXTERNAL_LIBRARIES_FOLDER}/imgui") 17 | target_include_directories(Core PUBLIC "${EXTERNAL_LIBRARIES_FOLDER}/imgui-sfml") 18 | target_include_directories(Core PUBLIC "${EXTERNAL_LIBRARIES_FOLDER}/utility") 19 | target_include_directories(Core PUBLIC ${EXTERNAL_LIBRARIES_FOLDER}) 20 | target_include_directories(Core PUBLIC "${SFML_DIR}/include") 21 | target_include_directories(Core PUBLIC ${CMAKE_SOURCE_DIR}/Engine) 22 | 23 | target_link_libraries(Core PUBLIC 24 | sfml-graphics 25 | sfml-window 26 | sfml-system 27 | sfml-audio 28 | sfml-network 29 | utility 30 | imgui_sfml 31 | imgui 32 | opengl32.lib 33 | Math 34 | ) 35 | 36 | set_target_properties(Core PROPERTIES FOLDER "Engine") 37 | 38 | if(MSVC) 39 | target_compile_options(Core PUBLIC /W4) 40 | add_compile_options(/MP) 41 | endif() -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Camera/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Camera.h" 2 | 3 | //Constructor 4 | 5 | spe::Camera::Camera() 6 | { 7 | this->Position = spe::Vector2(0, 0); 8 | this->m_CameraZoom = 1.0f; 9 | this->CameraSpeed = 2000.0f; 10 | this->m_ZoomChanged = false; 11 | } 12 | 13 | spe::Camera::Camera(spe::SpriteRepository& repo) 14 | { 15 | spe::Vector2 defaultPos = this->GetDefaultPosition(); 16 | 17 | this->m_CameraZoom = 1.0f; 18 | this->Position = spe::Vector2(0, 0); 19 | this->CameraView = sf::View(sf::Vector2f(defaultPos.X, defaultPos.Y), sf::Vector2f(1920, 1080)); 20 | } 21 | 22 | void spe::Camera::SetZoom(float zoom) noexcept 23 | { 24 | if (zoom == this->m_CameraZoom) 25 | { 26 | return; 27 | } 28 | // need to update the light shader here !! 29 | this->m_CameraZoom = zoom; 30 | this->m_ZoomChanged = true; 31 | } 32 | 33 | void spe::Camera::Reset() noexcept 34 | { 35 | this->Position = spe::Vector2(0, 0); 36 | this->m_CameraZoom = 1.0f; 37 | } 38 | 39 | void spe::Camera::Update(spe::LightRepository* lightrepo) 40 | { 41 | this->CameraView.setSize(sf::Vector2f(1920 * this->m_CameraZoom, 1080 * this->m_CameraZoom)); 42 | 43 | spe::Vector2 defaultPos = this->GetDefaultPosition(); 44 | 45 | defaultPos.X += this->Position.X; 46 | defaultPos.Y += this->Position.Y; 47 | 48 | this->CameraView.setCenter(sf::Vector2f(defaultPos.X, defaultPos.Y)); 49 | 50 | sf::Shader& shader = lightrepo->GetShader(); 51 | 52 | sf::Vector2f a = sf::Vector2f(defaultPos.X - 960, defaultPos.Y - 540); 53 | shader.setUniform("cameraPosition", a); 54 | shader.setUniform("cameraZoom", this->m_CameraZoom); 55 | 56 | this->m_ZoomChanged = false; 57 | } 58 | 59 | spe::Vector2 spe::Camera::GetDefaultPosition() noexcept 60 | { 61 | return spe::Vector2(960, 540); 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Camera/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | #include "Math/Vector2.h" 7 | #include "Sprite/SpriteRepository.h" 8 | #include "Sprite/Components/Transform.h" 9 | #include "Sprite/Components/Light/LightRepository.h" 10 | 11 | namespace spe 12 | { 13 | class Camera 14 | { 15 | private: 16 | float m_CameraZoom; 17 | bool m_ZoomChanged; 18 | spe::Vector2 GetDefaultPosition() noexcept; 19 | 20 | public: 21 | spe::Vector2 Position; 22 | sf::View CameraView; 23 | float CameraSpeed; 24 | 25 | Camera(); 26 | Camera(spe::SpriteRepository& repository); 27 | 28 | [[nodiscard]] bool HasZoomChanged() const noexcept { return this->m_ZoomChanged; } 29 | void SetZoomFlag() noexcept { this->m_ZoomChanged = false; } 30 | 31 | float GetZoom() const noexcept { return this->m_CameraZoom; } 32 | void SetZoom(float zoom) noexcept; 33 | void Reset() noexcept; 34 | void Update(spe::LightRepository* lightrepo); 35 | }; 36 | } -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/EngineData.cpp: -------------------------------------------------------------------------------- 1 | #include "EngineData.h" 2 | 3 | std::string spe::EngineData::s_PathUserProject = ""; 4 | std::string spe::EngineData::s_PathOfEngine = ""; 5 | std::string spe::EngineData::s_NameOfUser = ""; 6 | std::string spe::EngineData::s_Scene = ""; 7 | bool spe::EngineData::s_BuildDebug = true; 8 | bool spe::EngineData::s_BuildRelease = false; 9 | 10 | void spe::EngineData::BuildProjectFiles() 11 | { 12 | const std::string current = spe::Utility::GetCurrentDir(); 13 | 14 | spe::Utility::SetCurrentDir("Build"); 15 | 16 | spe::Log::LogString("Building project files.."); 17 | spe::Log::LogString(spe::Utility::RunCommand("cmake ..")); 18 | spe::Log::LogString("========FINISHED=========="); 19 | 20 | spe::Utility::SetCurrentDir(current); 21 | } 22 | 23 | void spe::EngineData::BuildProject() 24 | { 25 | const std::string current = spe::Utility::GetCurrentDir(); 26 | 27 | spe::Utility::SetCurrentDir("Build"); 28 | 29 | spe::Log::LogString("Building project files.."); 30 | spe::Log::LogString(spe::Utility::RunCommand("cmake ..")); 31 | spe::Log::LogString("========FINISHED=========="); 32 | 33 | if (spe::EngineData::s_BuildRelease) 34 | { 35 | spe::Log::LogString("Compiling in Release.."); 36 | spe::Log::LogString(spe::Utility::RunCommand("cmake --build . --config Release")); 37 | spe::Log::LogString("========FINISHED======"); 38 | } 39 | 40 | if (spe::EngineData::s_BuildDebug) { 41 | spe::Log::LogString("Compiling in Debug.."); 42 | spe::Log::LogString(spe::Utility::RunCommand("cmake --build . --config Debug")); 43 | spe::Log::LogString("========FINISHED======"); 44 | } 45 | 46 | spe::Utility::SetCurrentDir(current); 47 | } 48 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/EngineData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Core/Log.h" 5 | #include 6 | 7 | #include "UtilityFunctions.h" 8 | 9 | namespace spe 10 | { 11 | class EngineData 12 | { 13 | public: 14 | EngineData() = delete; 15 | 16 | static void BuildProjectFiles(); 17 | static void BuildProject(); 18 | 19 | static std::string s_PathOfEngine; 20 | static std::string s_PathUserProject; 21 | static std::string s_NameOfUser; 22 | static std::string s_Scene; 23 | 24 | static bool s_BuildDebug; 25 | static bool s_BuildRelease; 26 | }; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/Event.cpp: -------------------------------------------------------------------------------- 1 | #include "event.h" 2 | 3 | spe::Event::Event() 4 | { 5 | Type = spe::Event::None; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Input/Keyboard.h" 4 | 5 | namespace spe 6 | { 7 | class Event 8 | { 9 | public: 10 | enum Type 11 | { 12 | None = -1, 13 | KeyReleased = 0, 14 | KeyPressed, 15 | MousePressedLeft, 16 | MouseReleasedLeft, 17 | }; 18 | 19 | spe::KeyBoardCode Key; 20 | Type Type; 21 | 22 | Event(); 23 | 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/GameWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "GameWindow.h" 2 | 3 | // Ctor 4 | 5 | spe::GameWindow::GameWindow() 6 | { 7 | this->m_IsOpen = false; 8 | this->m_BackgroundColor = nullptr; 9 | this->m_Camera = nullptr; 10 | this->WindowEvent.type = sf::Event::GainedFocus; 11 | this->m_ptr_Window = nullptr; 12 | } 13 | 14 | spe::GameWindow::GameWindow(const spe::Vector2& size, const std::string& name) 15 | { 16 | this->m_BackgroundColor = nullptr; 17 | this->m_Size = size; 18 | this->m_Camera = nullptr; 19 | this->WindowEvent.type = sf::Event::GainedFocus; 20 | this->m_ptr_Window = new sf::RenderWindow(sf::VideoMode((int)size.X, (int)size.Y), name, sf::Style::Default); 21 | this->m_IsOpen = true; 22 | 23 | this->m_WindowBounds = sf::IntRect(0, 0, this->m_ptr_Window->getSize().x, this->m_ptr_Window->getSize().y); 24 | 25 | this->m_ptr_Window->setKeyRepeatEnabled(false); 26 | 27 | ImGui::SFML::Init(*this->m_ptr_Window); 28 | } 29 | 30 | // Private 31 | 32 | void spe::GameWindow::UpdateCamera() 33 | { 34 | if (this->m_Camera != nullptr) 35 | { 36 | this->m_Camera->CameraView.setSize(this->m_Size.X * this->m_Camera->GetZoom(), this->m_Size.Y * this->m_Camera->GetZoom()); 37 | this->m_ptr_Window->setView(this->m_Camera->CameraView); 38 | } 39 | } 40 | 41 | void spe::GameWindow::Draw(spe::Sprite* ptr, const sf::Shader* shader, bool ignoreLight) 42 | { 43 | if (shader != nullptr && ptr->SpriteRenderer.EffectedByLight && !ignoreLight) 44 | { 45 | this->m_ptr_Window->draw(ptr->GetSprite(), shader); 46 | } 47 | else 48 | { 49 | this->m_ptr_Window->draw(ptr->GetSprite()); 50 | } 51 | } 52 | 53 | // Public 54 | 55 | void spe::GameWindow::PollEvents() 56 | { 57 | bool EventChanged = false; 58 | Event.Type = spe::Event::None; 59 | 60 | while (this->m_ptr_Window->pollEvent(this->WindowEvent)) 61 | { 62 | ImGui::SFML::ProcessEvent(this->WindowEvent); 63 | 64 | if (this->WindowEvent.type == sf::Event::Closed) 65 | { 66 | this->m_IsOpen = false; 67 | this->m_ptr_Window->close(); 68 | } 69 | if (!EventChanged) 70 | { 71 | if (this->WindowEvent.type == sf::Event::KeyReleased) 72 | { 73 | Event.Type = spe::Event::KeyReleased; 74 | EventChanged = true; 75 | } 76 | else if (this->WindowEvent.type == sf::Event::KeyPressed) 77 | { 78 | EventChanged = true; 79 | Event.Type = spe::Event::KeyPressed; 80 | } 81 | else if (this->WindowEvent.type == sf::Event::MouseButtonPressed) 82 | { 83 | if (this->WindowEvent.mouseButton.button == sf::Mouse::Left) 84 | { 85 | Event.Type = spe::Event::MousePressedLeft; 86 | EventChanged = true; 87 | } 88 | } 89 | else if (this->WindowEvent.type == sf::Event::MouseButtonReleased) 90 | { 91 | if (this->WindowEvent.mouseButton.button == sf::Mouse::Left) 92 | { 93 | Event.Type = spe::Event::MouseReleasedLeft; 94 | EventChanged = true; 95 | } 96 | } 97 | else 98 | { 99 | EventChanged = true; 100 | Event.Type = spe::Event::None; 101 | } 102 | Event.Key = static_cast(static_cast(this->WindowEvent.key.code)); 103 | } 104 | } 105 | ImGui::SFML::Update(*m_ptr_Window, Time::s_DeltaClock.restart()); 106 | } 107 | 108 | void spe::GameWindow::DrawEngine(spe::Sprite* ptr, const sf::Shader* shader, bool ignoreLight) 109 | { 110 | this->Draw(ptr, shader, ignoreLight); 111 | } 112 | 113 | void spe::GameWindow::DrawGame(spe::Sprite* ptr, const sf::Shader* shader, bool ignoreLight) 114 | { 115 | if (!ptr->SpriteRenderer.Render) 116 | { 117 | return; 118 | } 119 | this->Draw(ptr, shader, ignoreLight); 120 | } 121 | 122 | 123 | void spe::GameWindow::Display() 124 | { 125 | ImGui::SFML::Render(*this->m_ptr_Window); 126 | 127 | this->UpdateCamera(); 128 | this->m_ptr_Window->display(); 129 | } 130 | 131 | void spe::GameWindow::Clear() 132 | { 133 | sf::Color backgroundColor = sf::Color(0, 0, 0); 134 | 135 | if (this->m_BackgroundColor != nullptr) 136 | { 137 | backgroundColor = sf::Color(sf::Uint8(this->m_BackgroundColor->X), 138 | sf::Uint8(this->m_BackgroundColor->Y), 139 | sf::Uint8(this->m_BackgroundColor->Z)); 140 | } 141 | this->m_ptr_Window->clear(backgroundColor); 142 | } 143 | 144 | void spe::GameWindow::Shutdown() 145 | { 146 | 147 | ImGui::SFML::Shutdown(); 148 | delete this->m_ptr_Window; 149 | this->m_IsOpen = false; 150 | } 151 | 152 | bool spe::GameWindow::ContainsCursor() 153 | { 154 | sf::Vector2i mousePosition = sf::Mouse::getPosition(*this->m_ptr_Window); 155 | return this->m_WindowBounds.contains(mousePosition); 156 | } 157 | 158 | 159 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/GameWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Camera/Camera.h" 8 | #include "Core/Event.h" 9 | #include "Sprite/Components/Light/LightRepository.h" 10 | #include "Sprite/Sprite.h" 11 | #include "Math/Vector2.h" 12 | #include "Math/Vector3.h" 13 | 14 | namespace spe 15 | { 16 | class GameWindow 17 | { 18 | private: 19 | sf::RenderWindow* m_ptr_Window; 20 | spe::Camera* m_Camera; 21 | spe::Vector2 m_Size; 22 | spe::Vector3* m_BackgroundColor; 23 | bool m_IsOpen; 24 | sf::IntRect m_WindowBounds; 25 | 26 | void UpdateCamera(); 27 | void Draw(spe::Sprite* ptr, const sf::Shader* shader, bool ignoreLight); 28 | 29 | public: 30 | sf::Event WindowEvent; 31 | spe::Event Event; 32 | 33 | GameWindow(); 34 | GameWindow(const spe::Vector2& size, const std::string& name); 35 | 36 | void PollEvents(); 37 | bool IsOpen() const noexcept { return this->m_IsOpen; } 38 | void DrawEngine(spe::Sprite* ptr, const sf::Shader* shader, bool ignoreLight); 39 | void DrawGame(spe::Sprite* ptr, const sf::Shader* shader, bool ignoreLight); 40 | 41 | void Display(); 42 | void Clear(); 43 | void Shutdown(); 44 | 45 | bool ContainsCursor(); 46 | 47 | sf::RenderWindow* GetRenderWindow() noexcept { return this->m_ptr_Window; } 48 | 49 | void SetCamera(spe::Camera* camera) noexcept { this->m_Camera = camera; } 50 | void SetBackgroundColor(spe::Vector3* bck) noexcept { this->m_BackgroundColor = bck; } 51 | }; 52 | } -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/IApplication.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace spe 4 | { 5 | class IAppliaction 6 | { 7 | protected: 8 | virtual void UpdateComponents() = 0; 9 | virtual void Init() = 0; 10 | IAppliaction() { }; 11 | 12 | public: 13 | 14 | virtual void Update() = 0; 15 | }; 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/Log.cpp: -------------------------------------------------------------------------------- 1 | #include "Log.h" 2 | 3 | // Public 4 | 5 | void spe::Log::LogString(const std::string& msg) 6 | { 7 | std::cout << msg << std::endl; 8 | 9 | if (spe::Log::s_m_ptr_LogBuffer != nullptr) 10 | { 11 | *spe::Log::s_m_ptr_LogBuffer += msg + "\n"; 12 | } 13 | } 14 | 15 | void spe::Log::SetStringBuffer(std::string* buffer) 16 | { 17 | spe::Log::s_m_ptr_LogBuffer = buffer; 18 | } 19 | 20 | // Static Private Init 21 | 22 | std::string* spe::Log::s_m_ptr_LogBuffer = nullptr; -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/Log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace spe 7 | { 8 | class Log 9 | { 10 | private: 11 | static std::string* s_m_ptr_LogBuffer; 12 | 13 | public: 14 | Log() = delete; 15 | 16 | static void LogString(const std::string& name); 17 | static void SetStringBuffer(std::string* buffer); 18 | }; 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/Repository.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace spe 6 | { 7 | template 8 | class Repository 9 | { 10 | protected: 11 | uint32_t m_HighestLayer; 12 | uint32_t m_HighestId; 13 | 14 | Repository() { this->m_HighestId = 0; this->m_HighestLayer = 0; } 15 | public: 16 | virtual void Add(T* t) = 0; 17 | virtual void UpdateLayerIndex() = 0; 18 | 19 | virtual uint32_t GetAmount() const = 0; 20 | virtual T* GetById(uint32_t id) = 0; 21 | virtual T* GetByName(const std::string& name) = 0; 22 | }; 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/SeceneHandler.cpp: -------------------------------------------------------------------------------- 1 | #include "SeceneHandler.h" 2 | 3 | void spe::SceneHandler::Init(const std::string& shader) 4 | { 5 | this->LightRepository.Init(shader); 6 | } 7 | 8 | void spe::SceneHandler::LoadScene(const std::string& name, spe::Camera& camera, spe::Vector3& bg) 9 | { 10 | for (const std::string& str : this->TotalScenes) 11 | { 12 | // Found a scene to load 13 | if (str == name) 14 | { 15 | this->SpriteRepository.CleanUp(); 16 | 17 | spe::EngineData::s_Scene = name; 18 | this->CurrentScene = str; 19 | 20 | spe::Initializer::InitSprites(this->SpriteRepository, PATH_TO_SPRITES, this->LightRepository); 21 | 22 | spe::Initializer::InitCamera(camera, PATH_TO_CAMERA); 23 | spe::Initializer::InitBackground(bg, PATH_TO_BACKGROUND); 24 | 25 | this->SpriteRepository.Initialized = true; 26 | } 27 | } 28 | } 29 | 30 | void spe::SceneHandler::DeleteScene(const std::string& name) 31 | { 32 | for (auto it = TotalScenes.begin(); it != TotalScenes.end(); ++it) { 33 | // Found a scene to delete 34 | if (*it == name) { 35 | it = TotalScenes.erase(it); 36 | 37 | const std::string path = PATH_TO_SAVE_FOLDER + std::string("\\") + name; 38 | 39 | std::filesystem::remove_all(path); 40 | 41 | return; 42 | } 43 | } 44 | } 45 | 46 | void spe::SceneHandler::CreateScene(const std::string& name) 47 | { 48 | spe::Utility::CopyDir("Engine\\Saves\\Template", "Engine\\Saves\\", name); 49 | this->TotalScenes.push_back(name); 50 | } 51 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/SeceneHandler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Core/EngineData.h" 7 | #include "Sprite/SpriteRepository.h" 8 | #include "RessourceHandler/Initializer.h" 9 | 10 | namespace spe 11 | { 12 | class SceneHandler 13 | { 14 | public: 15 | std::vector TotalScenes; 16 | std::string CurrentScene; 17 | 18 | spe::LightRepository LightRepository; 19 | spe::SpriteRepository SpriteRepository; 20 | 21 | void Init(const std::string& shader); 22 | 23 | void DeleteScene(const std::string& name); 24 | void CreateScene(const std::string& name); 25 | void LoadScene(const std::string& name, spe::Camera& camera, spe::Vector3& b); 26 | }; 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/Time.cpp: -------------------------------------------------------------------------------- 1 | #include "Time.h" 2 | 3 | void spe::Time::Update() 4 | { 5 | sf::Time dt = s_DeltaClock.restart(); 6 | spe::Time::s_DeltaTime = dt.asSeconds(); 7 | 8 | if (m_SecondCounter <= 1) { 9 | m_SecondCounter += s_DeltaTime; 10 | m_TempFPS++; 11 | } 12 | else 13 | { 14 | s_FPS = m_TempFPS; 15 | m_SecondCounter = 0; 16 | m_TempFPS = 0; 17 | } 18 | 19 | s_Ticks++; 20 | 21 | s_TimePassed += s_DeltaTime; 22 | } 23 | 24 | void spe::Time::Reset() noexcept 25 | { 26 | spe::Time::s_FPS = 0; 27 | spe::Time::s_DeltaTime = 0; 28 | spe::Time::m_SecondCounter = 0; 29 | spe::Time::m_TempFPS = 0; 30 | } 31 | 32 | float spe::Time::s_DeltaTime = 0; 33 | sf::Clock spe::Time::s_DeltaClock; 34 | 35 | float spe::Time::m_SecondCounter = 0; 36 | float spe::Time::m_TempFPS = 0; 37 | 38 | float spe::Time::s_FPS = 0; 39 | float spe::Time::s_Ticks = 0; 40 | float spe::Time::s_TimePassed = 0; 41 | 42 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Core/Time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace spe 7 | { 8 | class Time 9 | { 10 | private: 11 | static float m_SecondCounter; 12 | static float m_TempFPS; 13 | 14 | public: 15 | static float s_FPS; 16 | static float s_TimePassed; 17 | static float s_Ticks; 18 | 19 | static float s_DeltaTime; 20 | static sf::Clock s_DeltaClock; 21 | 22 | Time() = delete; 23 | 24 | static void Update(); 25 | static void Reset() noexcept; 26 | }; 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Input/Input.cpp: -------------------------------------------------------------------------------- 1 | #include "Input.h" 2 | 3 | bool spe::Input::OnKeyRelease(spe::KeyBoardCode key) 4 | { 5 | return spe::Input::Event->Type == spe::Event::KeyReleased && spe::Input::Event->Key == key; 6 | } 7 | 8 | bool spe::Input::OnKeyPress(spe::KeyBoardCode key) 9 | { 10 | return spe::Input::Event->Type == spe::Event::KeyPressed && spe::Input::Event->Key == key; 11 | } 12 | 13 | bool spe::Input::OnKeyHold(spe::KeyBoardCode key) 14 | { 15 | sf::Keyboard::Key keyd = static_cast(static_cast(key)); 16 | 17 | return sf::Keyboard::isKeyPressed(keyd); 18 | } 19 | 20 | void spe::Input::SetEvent(spe::Event* evnt) noexcept 21 | { 22 | spe::Input::Event = evnt; 23 | } 24 | 25 | spe::Event* spe::Input::Event = nullptr; -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Input/Input.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Core/Event.h" 6 | #include "Input/Keyboard.h" 7 | 8 | namespace spe 9 | { 10 | class Input 11 | { 12 | private: 13 | static spe::Event* Event; 14 | 15 | public: 16 | Input() = delete; 17 | 18 | 19 | static bool OnKeyRelease(spe::KeyBoardCode key); 20 | static bool OnKeyPress(spe::KeyBoardCode key); 21 | static bool OnKeyHold(spe::KeyBoardCode key); 22 | 23 | static void SetEvent(spe::Event* event) noexcept; 24 | }; 25 | } -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Input/Keyboard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace spe 4 | { 5 | enum class KeyBoardCode 6 | { 7 | Unknown = -1, A = 0, B, C, 8 | D, E, F, G, 9 | H, I, J, K, 10 | L, M, N, O, 11 | P, Q, R, S, 12 | T, U, V, W, 13 | X, Y, Z, Num0, 14 | Num1, Num2, Num3, Num4, 15 | Num5, Num6, Num7, Num8, 16 | Num9, Escape, LControl, LShift, 17 | LAlt, LSystem, RControl, RShift, 18 | RAlt, RSystem, Menu, LBracket, 19 | RBracket, Semicolon, Comma, Period, 20 | Quote, Slash, Backslash, Tilde, 21 | Equal, Hyphen, Space, Enter, 22 | Backspace, Tab, PageUp, PageDown, 23 | End, Home, Insert, Delete, 24 | Add, Subtract, Multiply, Divide, 25 | Left, Right, Up, Down, 26 | Numpad0, Numpad1, Numpad2, Numpad3, 27 | Numpad4, Numpad5, Numpad6, Numpad7, 28 | Numpad8, Numpad9, F1, F2, 29 | F3, F4, F5, F6, 30 | F7, F8, F9, F10, 31 | F11, F12, F13, F14, 32 | F15, Pause, KeyCount, Dash = Hyphen, 33 | BackSpace = Backspace, BackSlash = Backslash, SemiColon = Semicolon, Return = Enter 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/RessourceHandler/FileDataMacros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Core/EngineData.h" 3 | 4 | ///////////////////// 5 | // ENGINE (NAMES) 6 | #define DELIMITER ';' 7 | #define PREFAB_DELIMITER '|' 8 | #define EXTENSION_PREFAB_FILE ".prfb" 9 | #define EXTENSION_SAVE_FILE ".txt" 10 | #define EXTENSION_SCENE_SAVE_FILE ".scn" 11 | #define EXTENSION_ANIMATION_FILE ".txt" 12 | ///////////////////// 13 | 14 | #define PATH_TO_SAVE_FOLDER "Engine\\Saves" 15 | #define PATH_TO_SCENE_FOLDER "Engine\\Saves\\" + spe::EngineData::s_Scene 16 | 17 | #define USER_FOLDER_NAME "Assets" 18 | 19 | ////////// 20 | /// SPRITE 21 | #define PATH_TO_SPRITES PATH_TO_SCENE_FOLDER + "\\sprites.txt" 22 | // This macro points to a animation file the sprite can havem and in this file there are path of animations to actually load 23 | #define PATH_TO_CAMERA PATH_TO_SCENE_FOLDER + "\\camera.txt" 24 | #define PATH_TO_BACKGROUND PATH_TO_SCENE_FOLDER + "\\background.txt" 25 | 26 | #define PATH_TO_HIGHEST_INDEX "Engine\\Saves\\index.txt" 27 | #define PATH_TO_TAG_FILE "Engine\\Saves\\tags.txt" 28 | #define PATH_TO_SCENE_FILE "Engine\\Saves\\scenes.scn" 29 | 30 | #define PATH_TO_DEFAULT_SPRITE "Engine\\Ressources\\Sprites\\Default.png" 31 | 32 | // This is only editor specify btw 33 | 34 | /////////////// 35 | // RESSOURCES 36 | #define PATH_TO_RESSOURCES spe::EngineData::s_PathOfEngine + "\\Editor\\Ressources" 37 | #define PATH_TO_KNOWN_PROJECTS PATH_TO_RESSOURCES + "\\Saves\\projects.txt" 38 | #define PATH_TO_TRANSPARENT_PIC PATH_TO_RESSOURCES + "\\Sprites\\transparent.png" 39 | #define PATH_TO_LIGHT_SHADER PATH_TO_RESSOURCES + "\\Shaders\\circulaer_gradient.frag" 40 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/RessourceHandler/Initializer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Engine/Core/Source/RessourceHandler/Initializer.cpp -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/RessourceHandler/Initializer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Camera/Camera.h" 7 | #include "Sprite/SpriteRepository.h" 8 | #include "Sprite/Sprite.h" 9 | #include "RessourceHandler/FileDataMacros.h" 10 | 11 | namespace spe 12 | { 13 | class SceneHandler; 14 | 15 | /// 16 | /// This class assumes that the paths entered are from the user project 17 | /// 18 | class Initializer 19 | { 20 | public: 21 | Initializer() = delete; 22 | 23 | 24 | /// 25 | /// inits the prefab. Returns a new sprite on the heap. Can be pushed back to the sprite 26 | /// repoistory 27 | /// 28 | static spe::Sprite* InitPrefab(const std::string& path, spe::LightRepository& repo); 29 | 30 | static void InitTags(spe::SpriteRepository& repo, const std::string& path); 31 | static void InitScenes(spe::SceneHandler& handler, const std::string& path); 32 | static void IntiHighestSpriteID(spe::SpriteRepository& repo, const std::string& path); 33 | static void InitBackground(spe::Vector3& vec, const std::string& path); 34 | static spe::Sprite* InitSprite(const std::string& line, spe::LightRepository& lightrepo); 35 | static void InitSprites(spe::SpriteRepository& spriteRepo, const std::string& path, spe::LightRepository& lightrepo); 36 | static void InitCamera(spe::Camera& camera, const std::string& path); 37 | 38 | 39 | static void InitAnimation(const std::string& path, spe::Sprite* spr); 40 | static void InitAnimation(const std::string& path); 41 | }; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Animator/Animation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "RessourceHandler/FileDataMacros.h" 9 | #include "Core/EngineData.h" 10 | #include "Core/Time.h" 11 | #include "Sprite/Components/Animator/KeyFrame.h" 12 | #include "Sprite/SpriteRepository.h" 13 | #include "Core/Log.h" 14 | 15 | namespace spe 16 | { 17 | class Sprite; 18 | class Animation 19 | { 20 | private: 21 | std::vector m_Textures; 22 | std::vector m_Keyframes; 23 | std::string m_PathToFile; 24 | std::string m_Name; 25 | std::string m_BasePath; 26 | 27 | public: 28 | int CurrentFrame; 29 | float TimePassed; 30 | float TotalTimePassed; 31 | float TotalFramePassed; 32 | bool Loop; 33 | 34 | bool IsPlaying; 35 | 36 | Sprite* ptr_AppliedSprite; 37 | 38 | Animation(); 39 | Animation(Sprite* ptr_AppliedSprite, const std::string& Name, const std::string FileLocation, const std::vector& Frames); 40 | Animation(spe::Sprite* ptr_AppliedSprite, const spe::Animation& Animation); 41 | Animation(spe::Sprite* ptr_AppliedSprite, const spe::Animation& Animation, const std::string& Name); 42 | 43 | void InitCopyCtor(const spe::Animation& Animation); 44 | void RealoadTextures(); 45 | void DeleteKeyFrame(const int Pos); 46 | void Play(); 47 | void Update(); 48 | void Stop(); 49 | bool TryChangeKeyFramePos(int old, int newpos); 50 | 51 | spe::KeyFrame& GetKeyFrameAtMs(const float ms); 52 | int GetSize() const { return (int)this->m_Keyframes.size(); } 53 | int GetFrameSize() { return int(this->m_Keyframes.size()); } 54 | std::vector& GetkeyFrames() { return this->m_Keyframes; } 55 | const std::vector& GetkeyFrames() const { return this->m_Keyframes; } 56 | float GetAnimationTime() const; 57 | float GetTimeTillFrame(size_t Frame); 58 | const std::string& GetName() const { return this->m_Name; } 59 | const std::string GetPath() const { return this->m_PathToFile; } 60 | 61 | /// 62 | /// THIS METHOD DOES NOT SET THE KEYFRAME POSITION!!! 63 | /// 64 | /// 65 | /// 66 | void AddKeyFrameAt(const int Vecpos, const spe::KeyFrame& Frame); 67 | }; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Animator/Animator.cpp: -------------------------------------------------------------------------------- 1 | #include "Animator.h" 2 | 3 | #include "Sprite/Sprite.h" 4 | 5 | // Constructor / Destructor 6 | 7 | spe::Animator::Animator() 8 | { 9 | this->Init(); 10 | } 11 | 12 | spe::Animator::Animator(Sprite* ptr_attached_sprite) 13 | { 14 | this->Init(); 15 | this->ptr_attached_sprite = ptr_attached_sprite; 16 | } 17 | 18 | spe::Animator::Animator(spe::Sprite* ptr_attached_sprite, spe::Animator& animator) 19 | { 20 | this->Init(); 21 | this->Exist = animator.Exist; 22 | this->ptr_attached_sprite = ptr_attached_sprite; 23 | 24 | for (const auto& animation : animator.Animations) 25 | { 26 | // Copy animation 27 | spe::Animation anim = spe::Animation(this->ptr_attached_sprite, animation.second); 28 | Animations.insert({ anim.GetName(), anim}); 29 | } 30 | } 31 | 32 | void spe::Animator::Init() 33 | { 34 | this->BaseComponent = false; 35 | this->Exist = false; 36 | this->ptr_attached_sprite = nullptr; 37 | this->m_AnimationPlaying.IsPlaying = false; 38 | this->m_AnimationPlaying.Name = ""; 39 | } 40 | 41 | // Public functions 42 | 43 | void spe::Animator::CreateAnimation(const std::string& name, const std::string& file_loc, const std::vector& textures) 44 | { 45 | EXIST_COMPONENT; 46 | Animations.insert({ name, Animation(ptr_attached_sprite, name, file_loc, textures) }); 47 | } 48 | 49 | void spe::Animator::RemoveAnimation(const std::string& name) 50 | { 51 | EXIST_COMPONENT; 52 | auto it = this->Animations.find(name); 53 | Animations.erase(name); 54 | } 55 | 56 | void spe::Animator::Play(const std::string& name) 57 | { 58 | EXIST_COMPONENT; 59 | auto it = this->Animations.find(name); 60 | if (it != this->Animations.end()) 61 | { 62 | if (this->m_AnimationPlaying.IsPlaying) 63 | { 64 | this->Animations.find(this->m_AnimationPlaying.Name)->second.Stop(); 65 | } 66 | this->m_AnimationPlaying.Name = name; 67 | this->m_AnimationPlaying.IsPlaying = true; 68 | it->second.Play(); 69 | } 70 | } 71 | 72 | void spe::Animator::Stop(const std::string& name) 73 | { 74 | EXIST_COMPONENT; 75 | auto it = this->Animations.find(name); 76 | if (it != this->Animations.end()) 77 | { 78 | this->m_AnimationPlaying.Name = ""; 79 | this->m_AnimationPlaying.IsPlaying = false; 80 | it->second.Stop(); 81 | } 82 | } 83 | 84 | void spe::Animator::SetName(const std::string& new_name, const std::string& old_name) 85 | { 86 | EXIST_COMPONENT; 87 | 88 | auto it = Animations.find(old_name); 89 | if (it != Animations.end()) 90 | { 91 | // The animation copy constructor handles the path renaming 92 | Animation animation = spe::Animation(this->ptr_attached_sprite, it->second, new_name); 93 | 94 | // Getting the old file to delete it 95 | Animations.erase(it); 96 | 97 | Animations[new_name] = animation; 98 | } 99 | } 100 | 101 | void spe::Animator::Update() 102 | { 103 | EXIST_COMPONENT; 104 | for (auto& anim : this->Animations) 105 | { 106 | if (anim.second.IsPlaying) 107 | { 108 | anim.second.Update(); 109 | } 110 | } 111 | } 112 | 113 | void spe::Animator::Reset() 114 | { 115 | this->m_AnimationPlaying.Name = ""; 116 | this->m_AnimationPlaying.IsPlaying = false; 117 | this->Animations.clear(); 118 | } 119 | 120 | void spe::Animator::ReloadTextures() 121 | { 122 | EXIST_COMPONENT; 123 | for (auto& anim : this->Animations) 124 | { 125 | anim.second.RealoadTextures(); 126 | } 127 | } 128 | 129 | //Static functions 130 | 131 | //void spe::Animator::stopAllAnimations(spe::SpriteRepository& toUpdate) 132 | //{ 133 | // for (int i = 0; i < toUpdate.amount(); i++) 134 | // { 135 | // spe::Sprite* const sprite = toUpdate.readAt(i); 136 | // sprite->animator.stop(sprite->animator.m_animation_playing.name); 137 | // } 138 | //} 139 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Animator/Animator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Sprite/Components/Animator/Animation.h" 8 | #include "Sprite/Components/Component.h" 9 | 10 | #define EXIST_COMPONENT if (!this->Exist) return 11 | 12 | namespace spe 13 | { 14 | struct AnimationPlaying 15 | { 16 | std::string Name; 17 | bool IsPlaying; 18 | }; 19 | 20 | class Sprite; 21 | class Animator : public spe::Component 22 | { 23 | private: 24 | AnimationPlaying m_AnimationPlaying; 25 | 26 | void Init() override; 27 | public: 28 | Sprite* ptr_attached_sprite; 29 | std::unordered_map Animations; 30 | 31 | Animator(); 32 | Animator(Sprite* ptr_attachedSprite); 33 | Animator(spe::Sprite* ptr_attached_sprite, spe::Animator& animator); 34 | 35 | void CreateAnimation(const std::string& name, const std::string& fileLocation, const std::vector& frame); 36 | void RemoveAnimation(const std::string& name); 37 | 38 | void Play(const std::string& name); 39 | void Stop(const std::string& name); 40 | 41 | void SetName(const std::string& new_name, const std::string& old_name); 42 | void Update(); 43 | 44 | void Reset() override; 45 | void ReloadTextures(); 46 | 47 | const AnimationPlaying& GetAnimationPlaying() const noexcept { return this->m_AnimationPlaying; } 48 | }; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Animator/KeyFrame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace spe 6 | { 7 | struct KeyFrame 8 | { 9 | std::string path; 10 | float delay; 11 | uint32_t position; 12 | 13 | KeyFrame() { this->path = ""; this->delay = 0; this->position = 0; } 14 | KeyFrame(const std::string& path, const float delay) 15 | { 16 | this->position = 0; 17 | this->path = path; 18 | this->delay = delay; 19 | } 20 | }; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/BoxCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Math/Vector2.h" 8 | #include "Sprite/Components/Component.h" 9 | #include "Sprite/Components/Light/LightRepository.h" 10 | #include "Camera/Camera.h" 11 | 12 | namespace spe 13 | { 14 | class SpriteRepository; 15 | class Sprite; 16 | class BoxCollider : public spe::Component 17 | { 18 | private: 19 | int m_Start = -5; 20 | int m_end = 5; 21 | 22 | bool m_GotLeft; 23 | bool m_GotRight; 24 | bool m_GotUp; 25 | bool m_GotDown; 26 | 27 | void Init() override; 28 | bool CheckCollision(spe::BoxCollider& other); 29 | void CheckCollisionPosition(spe::BoxCollider& other) noexcept; 30 | void ResetPosition() noexcept; 31 | 32 | public: 33 | bool IsSolid; 34 | bool CanCollide; 35 | bool CollidedInFrame; 36 | std::unordered_map CollidedSprites; 37 | 38 | static spe::Sprite* s_ptr_CameraCollider; 39 | 40 | bool Left; 41 | bool Right; 42 | bool Up; 43 | bool Down; 44 | bool Collided; 45 | 46 | //Deleting the pointer in gameEngine.cpp! 47 | spe::Sprite* ptr_Sprite; 48 | 49 | Vector2 Width; 50 | Vector2 Height; 51 | bool Controller; 52 | 53 | BoxCollider(); 54 | BoxCollider(spe::Sprite* sprite, spe::BoxCollider& rhs); 55 | 56 | //Giving it a pointer, so we dont have to update it consistently 57 | BoxCollider(spe::Sprite* ptr_sprite); 58 | 59 | void Reset() override; 60 | void Update(spe::SpriteRepository& tocheck); 61 | 62 | // User utility 63 | 64 | /// 65 | /// Iterates over the collided sprites map to find if it collided with a ceratain tag (kinda inefficent) 66 | /// 67 | /// To search for 68 | /// True if the sprite collides with the provided tag 69 | spe::Sprite* CollidedWithTag(const std::string& tag); 70 | 71 | spe::Sprite* CollidedWithName(const std::string& name); 72 | 73 | static bool ProcessSprite(spe::Sprite* sprite, const spe::Camera& camera); 74 | static void InitCameraCollider(spe::LightRepository& repo); 75 | static void DeleteCameraCollider(); 76 | }; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Component.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace spe 4 | { 5 | class Component 6 | { 7 | public: 8 | bool Exist; 9 | bool BaseComponent; 10 | 11 | virtual void Reset() = 0; 12 | protected: 13 | virtual void Init() = 0; 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Light/Light.cpp: -------------------------------------------------------------------------------- 1 | #include "Light.h" 2 | #include "Sprite/Sprite.h" 3 | 4 | // Constructor 5 | 6 | void spe::Light::Init() 7 | { 8 | this->m_Intensity = 200; 9 | this->m_Color = sf::Vector3f(1, 1, 1); 10 | this->m_Radius = DEFAULT_LIGHT_RADIUS; 11 | this->Exist = false; 12 | this->BaseComponent = false; 13 | this->m_RadiusChanged = false; 14 | } 15 | 16 | spe::Light::Light() 17 | { 18 | this->Init(); 19 | } 20 | 21 | spe::Light::Light(Sprite* ptr_attached_sprite, spe::LightRepository* ptr) 22 | { 23 | this->Init(); 24 | this->ptr_attached_sprite = ptr_attached_sprite; 25 | this->m_ptr_LighRepository = ptr; 26 | this->m_ptr_LightSource = nullptr; 27 | } 28 | 29 | spe::Light::Light(Sprite* ptr_sprite, const spe::Light& rhs) 30 | { 31 | this->Exist = rhs.Exist; 32 | this->m_Color = rhs.GetColor(); 33 | this->m_Radius = rhs.GetRadius(); 34 | this->m_Intensity = rhs.GetIntensity(); 35 | this->m_ptr_LighRepository = rhs.m_ptr_LighRepository; 36 | this->ptr_attached_sprite = ptr_sprite; 37 | this->m_ptr_LightSource = nullptr; 38 | this->BaseComponent = false; 39 | this->m_RadiusChanged = false; 40 | 41 | if (this->Exist) 42 | { 43 | this->Exist = false; 44 | this->Enable(); 45 | } 46 | 47 | } 48 | 49 | // Public methods 50 | 51 | void spe::Light::DeleteLight() 52 | { 53 | THROW_IF_NO_LIGHT_REPO 54 | if (this->Exist) 55 | { 56 | this->m_ptr_LighRepository->Remove(this->m_LightIndex); 57 | this->m_LightIndex = 0; 58 | this->m_ptr_LightSource = nullptr; 59 | } 60 | } 61 | 62 | void spe::Light::Enable() 63 | { 64 | THROW_IF_NO_LIGHT_REPO 65 | if (this->Exist) 66 | { 67 | return; 68 | } 69 | this->Exist = true; 70 | this->m_ptr_LighRepository->Add(this->ptr_attached_sprite->Transform.GetPosition(), this->m_Radius, this->m_Intensity, this->m_Color); 71 | this->m_LightIndex = this->m_ptr_LighRepository->GetIndex(); 72 | this->m_ptr_LightSource = &this->m_ptr_LighRepository->GetLightSource(this->m_LightIndex); 73 | } 74 | 75 | void spe::Light::Reset() 76 | { 77 | this->m_Radius = DEFAULT_LIGHT_RADIUS; 78 | } 79 | 80 | void spe::Light::SetColor(const sf::Vector3f& color) noexcept 81 | { 82 | if (this->m_Color == color) 83 | { 84 | return; 85 | } 86 | this->m_Color = color; 87 | this->m_ColorChanged = true; 88 | } 89 | 90 | 91 | void spe::Light::SetIntensity(float intense) noexcept 92 | { 93 | if (this->m_Intensity == intense) 94 | { 95 | return; 96 | } 97 | this->m_Intensity = intense; 98 | this->m_IntensityChanged = true; 99 | } 100 | 101 | void spe::Light::SetRadius(float radius) noexcept 102 | { 103 | if (radius == this->m_Radius) 104 | { 105 | return; 106 | } 107 | this->m_Radius = radius; 108 | this->m_RadiusChanged = true; 109 | } 110 | 111 | void spe::Light::DisableFlags() 112 | { 113 | this->m_IntensityChanged = false; 114 | this->m_RadiusChanged = false; 115 | this->m_ColorChanged = false; 116 | } 117 | 118 | void spe::Light::DisableProcess() 119 | { 120 | if (this->m_ptr_LightSource != nullptr) 121 | { 122 | this->m_ptr_LightSource->Process = false; 123 | } 124 | } 125 | 126 | void spe::Light::EnableProcess() 127 | { 128 | if (this->m_ptr_LightSource != nullptr) 129 | { 130 | this->m_ptr_LightSource->Process = true; 131 | } 132 | } 133 | 134 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Light/Light.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sprite/Components/Component.h" 4 | #include "Sprite/Components/Light/LightRepository.h" 5 | 6 | #define DEFAULT_LIGHT_RADIUS 100 7 | 8 | #define THROW_IF_NO_LIGHT_REPO if (this->m_ptr_LighRepository == nullptr) \ 9 | {\ 10 | throw std::runtime_error("You are a dumbas you dont have a light repo ptr");\ 11 | } 12 | namespace spe 13 | { 14 | class Sprite; 15 | class Light : public spe::Component 16 | { 17 | private: 18 | uint32_t m_LightIndex; 19 | float m_Radius; 20 | bool m_RadiusChanged; 21 | sf::Vector3f m_Color; 22 | bool m_ColorChanged; 23 | spe::LightSource* m_ptr_LightSource; 24 | 25 | float m_Intensity; 26 | bool m_IntensityChanged; 27 | 28 | 29 | void Init() override; 30 | public: 31 | Sprite* ptr_attached_sprite; 32 | spe::LightRepository* m_ptr_LighRepository; 33 | 34 | Light(); 35 | Light(Sprite* ptr_sprite, spe::LightRepository* ptr); 36 | Light(Sprite* ptr_sprite, const spe::Light& rhs); 37 | 38 | uint32_t GetLightIndex() const noexcept { return this->m_LightIndex; } 39 | void DeleteLight(); 40 | void Enable(); 41 | void Reset() override; 42 | 43 | const sf::Vector3f& GetColor() const noexcept { return this->m_Color; } 44 | void SetColor(const sf::Vector3f& color) noexcept; 45 | bool HasColorChanged() const noexcept { return this->m_ColorChanged; } 46 | 47 | 48 | void SetIntensity(float intense) noexcept; 49 | float GetIntensity() const noexcept { return this->m_Intensity; } 50 | bool HasIntensityChanged() const noexcept { return this->m_IntensityChanged; } 51 | 52 | void SetRadius(float radius) noexcept; 53 | float GetRadius() const noexcept { return this->m_Radius; } 54 | bool HasRadiusChanged() const noexcept { return this->m_RadiusChanged; } 55 | 56 | void DisableFlags(); 57 | 58 | void DisableProcess(); 59 | void EnableProcess(); 60 | }; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Light/LightRepository.cpp: -------------------------------------------------------------------------------- 1 | #include "LightRepository.h" 2 | 3 | #include "Sprite/Sprite.h" 4 | #include "Camera/Camera.h" 5 | 6 | namespace spe 7 | { 8 | // Ctor 9 | LightRepository::LightRepository() 10 | { 11 | this->m_Index = 0; 12 | this->m_Update = false; 13 | } 14 | 15 | // Public 16 | 17 | void LightRepository::Init(const std::string& shader) 18 | { 19 | this->m_Update = true; 20 | this->m_Index = 0; 21 | if (!m_LightShader.loadFromFile(shader, sf::Shader::Fragment)) 22 | { 23 | spe::Log::LogString("Could not load light shader"); 24 | } 25 | } 26 | 27 | 28 | void LightRepository::UpdateLightSource(spe::Sprite* sprite, spe::Camera* cam) 29 | { 30 | if (!sprite->Light.Exist || !sprite->Process) 31 | { 32 | return; 33 | } 34 | 35 | m_Update = true; 36 | 37 | uint32_t idx = sprite->Light.GetLightIndex(); 38 | spe::LightSource& source = m_LightSources[idx]; 39 | 40 | if (sprite->Transform.PositionChanged || cam->HasZoomChanged()) 41 | { 42 | sprite->Transform.PositionChanged = false; 43 | 44 | float zoom = cam->GetZoom() - 1; 45 | 46 | const float a = ((sprite->Transform.GetPosition().Y * -1) + 540) + 540 * zoom; 47 | spe::Vector2 new_pos = spe::Vector2((sprite->Transform.GetPosition().X + 960) + 960 * zoom, a); 48 | 49 | source.Position = new_pos; 50 | } 51 | if (sprite->Light.HasRadiusChanged()) 52 | { 53 | source.Radius = sprite->Light.GetRadius(); 54 | } 55 | if (sprite->Light.HasIntensityChanged()) 56 | { 57 | source.LightIntensity = sprite->Light.GetIntensity(); 58 | 59 | } 60 | if (sprite->Light.HasColorChanged()) 61 | { 62 | source.Color = sprite->Light.GetColor(); 63 | } 64 | 65 | sprite->Light.DisableFlags(); 66 | } 67 | 68 | void LightRepository::UpdateSprite(spe::Sprite* sprite, spe::Camera* cam) 69 | { 70 | if (!sprite->Light.Exist) 71 | { 72 | return; 73 | } 74 | UpdateLightSource(sprite, cam); 75 | UpdateArrays(); 76 | } 77 | 78 | void LightRepository::Add(const spe::Vector2& pos, float radius, float intensity, const sf::Vector3f& color) 79 | { 80 | float zoom = 1; 81 | 82 | const float a = ((pos.Y * -1) + 540) + 540 * zoom; 83 | spe::Vector2 new_pos = spe::Vector2((pos.X + 960) + 960 * zoom, a); 84 | 85 | m_Index++; 86 | m_LightSources[m_Index] = spe::LightSource(new_pos, radius, intensity, color); 87 | 88 | m_Update = true; 89 | UpdateArrays(); 90 | } 91 | 92 | void LightRepository::Remove(uint32_t index) 93 | { 94 | m_LightSources.erase(index); 95 | 96 | m_Update = true; 97 | UpdateArrays(); 98 | } 99 | 100 | void LightRepository::MoveLightSource(uint32_t idx, const spe::Vector2& pos) 101 | { 102 | auto it = m_LightSources.find(idx); 103 | 104 | if (it != m_LightSources.end()) 105 | { 106 | it->second.Position = pos; 107 | 108 | sf::Vector2f* lightPositions = GetPositionArray(); 109 | 110 | m_LightShader.setUniformArray("lightPositions", lightPositions, m_LightSources.size()); 111 | 112 | delete[] lightPositions; 113 | } 114 | else 115 | { 116 | std::cout << "LOG [ERROR] Key does not exist " << idx << std::endl; 117 | } 118 | } 119 | 120 | void LightRepository::UpdateArrays() 121 | { 122 | if (!this->m_Update) 123 | { 124 | return; 125 | } 126 | 127 | m_Update = false; 128 | size_t size = 0; 129 | 130 | std::vector lightPositions(size); 131 | std::vector lightRadii(size); 132 | std::vector lightIntensities(size); 133 | std::vector lightColors(size); 134 | 135 | 136 | for (auto& pair : m_LightSources) 137 | { 138 | LightSource& source = pair.second; 139 | if (source.Process) 140 | { 141 | lightPositions.push_back(spe::Vector2::toSFVector(source.Position)); 142 | lightRadii.push_back(source.Radius); 143 | lightIntensities.push_back(source.LightIntensity); 144 | lightColors.push_back(sf::Vector3f(source.Color.x, source.Color.y, source.Color.z)); 145 | size++; 146 | } 147 | } 148 | 149 | if (size > 0) 150 | { 151 | m_LightShader.setUniform("lightAmount", static_cast(size)); 152 | m_LightShader.setUniformArray("lightPositions", lightPositions.data(), size); 153 | m_LightShader.setUniformArray("lightRadii", lightRadii.data(), size); 154 | m_LightShader.setUniformArray("lightIntensities", lightIntensities.data(), size); 155 | m_LightShader.setUniformArray("lightColors", lightColors.data(), size); 156 | } 157 | 158 | } 159 | 160 | sf::Vector2f* LightRepository::GetPositionArray() 161 | { 162 | const size_t size = m_LightSources.size(); 163 | sf::Vector2f* lightPositions = new sf::Vector2f[size]; 164 | 165 | size_t i = 0; 166 | for (const auto& pair : m_LightSources) 167 | { 168 | lightPositions[i] = spe::Vector2::toSFVector(pair.second.Position); 169 | i++; 170 | } 171 | 172 | return lightPositions; 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Light/LightRepository.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Sprite/Components/Light/LightSource.h" 8 | #include "RessourceHandler/FileDataMacros.h" 9 | 10 | namespace spe 11 | { 12 | class Camera; 13 | class Sprite; 14 | class LightRepository 15 | { 16 | private: 17 | std::unordered_map m_LightSources; 18 | sf::Shader m_LightShader; // Only 1 shader, (circle-ish) 19 | uint32_t m_Index; 20 | bool m_Update; 21 | 22 | 23 | sf::Vector2f* GetPositionArray(); 24 | 25 | public: 26 | LightRepository(); 27 | 28 | void Init(const std::string& shader); 29 | void UpdateArrays(); 30 | 31 | void UpdateLightSource(spe::Sprite* sprite, spe::Camera* cam); 32 | void UpdateSprite(spe::Sprite* sprite, spe::Camera* cam); 33 | 34 | void Add(const spe::Vector2& pos, float radius, float intensity, const sf::Vector3f& color); 35 | void Remove(uint32_t index); 36 | 37 | void MoveLightSource(uint32_t idx, const spe::Vector2& pos); 38 | 39 | spe::LightSource& GetLightSource(uint32_t index) noexcept { return m_LightSources[index]; } 40 | 41 | uint32_t GetIndex() const noexcept{ return m_Index; } 42 | sf::Shader& GetShader() noexcept { return m_LightShader; } 43 | }; 44 | } -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Light/LightSource.cpp: -------------------------------------------------------------------------------- 1 | #include "lightSource.h" 2 | 3 | spe::LightSource::LightSource() : Position(), Radius(0.0f), LightIntensity(0.0f), Color() { 4 | } 5 | 6 | spe::LightSource::LightSource(const spe::Vector2& pos, float radius, float intensiti, const sf::Vector3f& color) 7 | : Position(pos), Radius(radius), LightIntensity(intensiti), Color(color), Process(false) { 8 | } 9 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Light/LightSource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Math/Vector2.h" 4 | #include "Math/Vector3.h" 5 | 6 | namespace spe 7 | { 8 | class LightSource 9 | { 10 | public: 11 | LightSource(); 12 | LightSource(const spe::Vector2& pos, float radius, float intensiti, const sf::Vector3f& color); 13 | 14 | bool Process; 15 | spe::Vector2 Position; 16 | float Radius; 17 | float LightIntensity; 18 | sf::Vector3f Color ; 19 | }; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/PhysicsBody.cpp: -------------------------------------------------------------------------------- 1 | #include "physicsBody.h" 2 | 3 | #include "Sprite/Sprite.h" 4 | 5 | // Constructor / Destructor 6 | 7 | spe::PhsysicsBody::PhsysicsBody() 8 | { 9 | this->Init(); 10 | } 11 | 12 | spe::PhsysicsBody::PhsysicsBody(spe::Sprite* spr) 13 | { 14 | this->Init(); 15 | this->ptr_Sprite = spr; 16 | } 17 | 18 | spe::PhsysicsBody::PhsysicsBody(spe::Sprite* spr, const spe::PhsysicsBody& rhs) 19 | { 20 | this->ptr_Sprite = spr; 21 | this->Velocity = rhs.Velocity; 22 | this->Mass = rhs.Mass; 23 | this->Exist = rhs.Exist; 24 | this->Gravity = rhs.Gravity; 25 | this->Friction = rhs.Friction; 26 | this->UseAirFriction = rhs.UseAirFriction; 27 | } 28 | 29 | void spe::PhsysicsBody::Init() 30 | { 31 | this->BaseComponent = false; 32 | this->Exist = false; 33 | this->Velocity = spe::Vector2(0, 0); 34 | this->Gravity = 0.0f; 35 | this->Mass = 0.0f; 36 | this->Friction = 0.0f; 37 | this->UseAirFriction = false; 38 | } 39 | 40 | void spe::PhsysicsBody::UpdateFriction() 41 | { 42 | if (this->ptr_Sprite->Collider.Down || this->ptr_Sprite->Physicsbody.UseAirFriction) 43 | { 44 | // Apply friction based on deltaTime 45 | this->Velocity.X *= (1 - this->Friction * spe::Time::s_DeltaTime); 46 | 47 | // If the X velocity is very small, set it to 0 to stop the sliding 48 | if (std::abs(this->Velocity.X) < 0.01f) 49 | { 50 | this->Velocity.X = 0.0f; 51 | } 52 | } 53 | } 54 | 55 | // Public functions 56 | 57 | void spe::PhsysicsBody::Reset() 58 | { 59 | this->Exist = false; 60 | this->Mass = 0.0f; 61 | this->Velocity = spe::Vector2(0.0f, 0.0f); 62 | this->Gravity = 0.0f; 63 | this->Friction = 0.0f; 64 | } 65 | 66 | void spe::PhsysicsBody::Update() 67 | { 68 | if (!this->Exist || this->ptr_Sprite == nullptr) return; 69 | 70 | //ALl Physic calcutions will happen here! 71 | spe::Vector2 dir = this->Velocity * spe::Time::s_DeltaTime; 72 | dir += this->ptr_Sprite->Transform.GetPosition(); 73 | 74 | this->ptr_Sprite->Transform.SetPosition(dir); 75 | 76 | 77 | if (this->ptr_Sprite->Collider.Down && this->Velocity.Y <= 0) 78 | { 79 | this->Velocity.Y = 0.0f; 80 | } 81 | 82 | this->Velocity.Y -= this->Gravity * spe::Time::s_DeltaTime; 83 | 84 | if (this->Friction != 0) 85 | { 86 | this->UpdateFriction(); 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/PhysicsBody.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Time.h" 4 | #include "Math/Vector2.h" 5 | #include "Sprite/Components/Component.h" 6 | 7 | namespace spe 8 | { 9 | class Sprite; 10 | class PhsysicsBody : public spe::Component 11 | { 12 | private: 13 | void Init() override; 14 | void UpdateFriction(); 15 | 16 | public: 17 | float Mass; 18 | float Gravity; 19 | spe::Vector2 Velocity; 20 | spe::Sprite* ptr_Sprite; 21 | float Friction; 22 | bool UseAirFriction; 23 | 24 | PhsysicsBody(); 25 | PhsysicsBody(spe::Sprite* spr); 26 | PhsysicsBody(spe::Sprite* spr, const spe::PhsysicsBody& rhs); 27 | 28 | void Reset() override; 29 | void Update(); 30 | }; 31 | } -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Prefab/Prefab.cpp: -------------------------------------------------------------------------------- 1 | #include "prefab.h" 2 | 3 | #include "Sprite/Sprite.h" 4 | 5 | 6 | // Constructor 7 | 8 | spe::Prefab::Prefab() 9 | { 10 | this->Init(); 11 | } 12 | 13 | spe::Prefab::Prefab(spe::Sprite* m_attached) 14 | { 15 | this->Init(); 16 | this->m_ptr_Sprite = m_attached; 17 | } 18 | 19 | spe::Prefab::Prefab(spe::Sprite* m_attached, const spe::Prefab& rhs) 20 | { 21 | this->m_ptr_Sprite = m_attached; 22 | this->FileName = rhs.FileName; 23 | this->Exist = rhs.Exist; 24 | this->PathToOldFile = rhs.PathToOldFile; 25 | this->PathToFile = rhs.PathToFile; 26 | } 27 | 28 | void spe::Prefab::Init() 29 | { 30 | this->m_ptr_Sprite = nullptr; 31 | this->Exist = false; 32 | this->LoadInMemory = false; 33 | } 34 | 35 | // Public functions 36 | 37 | void spe::Prefab::Reset() 38 | { 39 | //TODO: delete file 40 | 41 | this->Exist = false; 42 | this->FileName = ""; 43 | this->LoadInMemory = false; 44 | this->PathToFile = ""; 45 | this->PathToOldFile = ""; 46 | } 47 | 48 | void spe::Prefab::UpdateProps(const std::string& userPath, const std::string& pathToOldFile, const std::string fileName) 49 | { 50 | this->Exist = true; 51 | this->PathToFile = userPath; 52 | this->FileName = fileName; 53 | this->PathToOldFile = pathToOldFile; 54 | } 55 | 56 | void spe::Prefab::UpdatePath() 57 | { 58 | if (!this->Exist) 59 | { 60 | return; 61 | } 62 | this->PathToOldFile = this->PathToFile; 63 | std::string newPath = ""; 64 | 65 | size_t erase = this->PathToFile.size() - FileName.size(); 66 | 67 | for (int i = 0; i < erase + 1; i++) 68 | { 69 | newPath.push_back(this->PathToFile[i]); 70 | } 71 | newPath.pop_back(); 72 | 73 | newPath += this->m_ptr_Sprite->Name + EXTENSION_PREFAB_FILE; 74 | this->PathToFile = newPath; 75 | } 76 | 77 | void spe::Prefab::UpdateName() 78 | { 79 | if (!this->Exist) 80 | { 81 | return; 82 | } 83 | std::vector parts = spe::Utility::Split(this->PathToFile, '\\'); 84 | this->FileName = parts[parts.size() - 1]; 85 | } 86 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Prefab/Prefab.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sprite/Components/Component.h" 4 | 5 | #include 6 | 7 | namespace spe 8 | { 9 | class Sprite; 10 | class Prefab : public spe::Component 11 | { 12 | private: 13 | spe::Sprite* m_ptr_Sprite; 14 | void Init() override; 15 | public: 16 | 17 | /// 18 | /// Path from the user to the file 19 | /// Example: assets\\prefabs\\hello.prfb 20 | /// 21 | std::string PathToFile; 22 | 23 | /// 24 | /// The file name of the active file. This may not be the actual prefab 25 | /// sprite name because it didnt get upated yet 26 | /// 27 | std::string PathToOldFile; 28 | 29 | std::string FileName; 30 | 31 | bool LoadInMemory; 32 | 33 | Prefab(); 34 | Prefab(spe::Sprite* m_attached); 35 | Prefab(spe::Sprite* m_attached, const spe::Prefab& rhs); 36 | 37 | /// 38 | /// Resets the data and deletes the FILE! 39 | /// 40 | void Reset() override; 41 | 42 | void UpdatePath(); 43 | void UpdateName(); 44 | 45 | void UpdateProps(const std::string& userPath, const std::string& pathToOldFile, const std::string fileName); 46 | }; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Prefab/README.md: -------------------------------------------------------------------------------- 1 | # Info 2 | 3 | In the asset project is prefab repository, thats why i store it in a folder -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/SpriteRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "SpriteRenderer.h" 2 | 3 | // Constructor / Destructor 4 | 5 | spe::SpriteRenderer::SpriteRenderer() 6 | { 7 | this->Init(); 8 | } 9 | 10 | spe::SpriteRenderer::SpriteRenderer(const spe::SpriteRenderer& rhs) 11 | { 12 | this->EffectedByLight = rhs.EffectedByLight; 13 | this->Path = rhs.Path; 14 | this->SortinLayerIdx = rhs.SortinLayerIdx; 15 | this->EffectedByLight = rhs.EffectedByLight; 16 | } 17 | 18 | void spe::SpriteRenderer::Init() 19 | { 20 | this->Render = true; 21 | this->BaseComponent = true; 22 | this->EffectedByLight = false; 23 | this->Path = ""; 24 | this->Exist = true; 25 | this->SortinLayerIdx = 0; 26 | } 27 | 28 | // Public functions 29 | 30 | void spe::SpriteRenderer::Reset() 31 | { 32 | this->Path = "defaultpath"; 33 | this->Exist = true; 34 | this->SortinLayerIdx = 0; 35 | } -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/SpriteRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Sprite/Components/Component.h" 7 | 8 | namespace spe 9 | { 10 | class Sprite; 11 | class SpriteRenderer : public spe::Component 12 | { 13 | private: 14 | void Init() override; 15 | public: 16 | std::string Path; 17 | uint32_t SortinLayerIdx; 18 | bool EffectedByLight; 19 | bool Render; 20 | 21 | SpriteRenderer(); 22 | SpriteRenderer(const spe::SpriteRenderer& rhs); 23 | 24 | void Reset() override; 25 | }; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Transform.cpp: -------------------------------------------------------------------------------- 1 | #include "Transform.h" 2 | #include "Sprite/Sprite.h" 3 | 4 | //Contructor 5 | 6 | spe::Transform::Transform() 7 | { 8 | this->Init(); 9 | } 10 | 11 | spe::Transform::Transform(spe::Sprite* attached) 12 | { 13 | this->Init(); 14 | this->ptr_Sprite = attached; 15 | } 16 | 17 | spe::Transform::Transform(spe::Sprite* attachedSprite, spe::Transform& transform) 18 | { 19 | this->Init(); 20 | this->ptr_Sprite = attachedSprite; 21 | this->m_Position = transform.m_Position; 22 | this->m_Rotation = transform.m_Rotation; 23 | this->m_Scale = transform.m_Scale; 24 | this->TextureSize = transform.TextureSize; 25 | this->PositionToParent = transform.PositionToParent; 26 | 27 | this->SetScale(this->m_Scale, true); 28 | this->SetOrigin(); 29 | this->SetTextureSize(this->m_Scale); 30 | } 31 | 32 | void spe::Transform::Init() 33 | { 34 | this->BaseComponent = true; 35 | this->ptr_Sprite = nullptr; 36 | this->m_Rotation = 0; 37 | this->m_Scale = spe::Vector2(1, 1); 38 | } 39 | 40 | // Private functions 41 | 42 | void spe::Transform::UpdateSpritePositionToParent(const spe::Vector2& position) 43 | { 44 | if (this->ptr_Sprite == nullptr) 45 | { 46 | return; 47 | } 48 | for (spe::Sprite* spr : this->ptr_Sprite->ptr_Childs) 49 | { 50 | spe::Vector2 distance = this->m_Position - position; 51 | 52 | distance.X *= -1; 53 | distance.Y *= -1; 54 | 55 | spe::Vector2 newpos = spr->Transform.GetPosition() +distance; 56 | spr->Transform.SetPosition(newpos); 57 | } 58 | 59 | } 60 | 61 | spe::Vector2 spe::Transform::HandleCollisions(const spe::Vector2& position) 62 | { 63 | spe::Vector2 new_position(position); 64 | 65 | if (this->ptr_Sprite == nullptr || !this->ptr_Sprite->Collider.Exist || !this->ptr_Sprite->Collider.Collided) 66 | { 67 | // No collision check 68 | return new_position; 69 | } 70 | 71 | const float current_y = this->ptr_Sprite->Transform.m_Position.Y; 72 | const float current_x = this->ptr_Sprite->Transform.m_Position.X; 73 | 74 | // Down 75 | if (this->ptr_Sprite->Collider.Down) 76 | { 77 | if (position.Y < this->m_Position.Y 78 | && this->ptr_Sprite->Physicsbody.Velocity.Y <= 0) 79 | { 80 | new_position.Y = current_y; 81 | } 82 | } 83 | 84 | // Up 85 | if (this->ptr_Sprite->Collider.Up) 86 | { 87 | if (position.Y > this->m_Position.Y 88 | && this->ptr_Sprite->Physicsbody.Velocity.Y >= 0) 89 | { 90 | new_position.Y = current_y; 91 | } 92 | } 93 | 94 | // Left 95 | if (this->ptr_Sprite->Collider.Left) 96 | { 97 | if (position.X < this->m_Position.X 98 | && this->ptr_Sprite->Physicsbody.Velocity.X <= 0) 99 | { 100 | new_position.X = current_x; 101 | } 102 | } 103 | 104 | // Right 105 | if (this->ptr_Sprite->Collider.Right) 106 | { 107 | if (position.X > this->m_Position.X 108 | && this->ptr_Sprite->Physicsbody.Velocity.X >= 0) 109 | { 110 | new_position.X = current_x; 111 | } 112 | } 113 | return new_position; 114 | //this->m_attached_sprite->collider.resetPositions(); 115 | } 116 | 117 | // Public functions 118 | 119 | void spe::Transform::SetPosition(const spe::Vector2& position) 120 | { 121 | if (this->m_Position == position) 122 | { 123 | this->PositionChanged = false; 124 | return; 125 | } 126 | 127 | const spe::Vector2 new_pos = this->HandleCollisions(position); 128 | 129 | this->UpdateSpritePositionToParent(new_pos); 130 | this->m_Position = new_pos; 131 | this->PositionChanged = true; 132 | 133 | if (this->ptr_Sprite != nullptr) 134 | { 135 | this->ptr_Sprite->GetSprite().setPosition(sf::Vector2f(new_pos.X + 960, 540 - new_pos.Y)); 136 | } 137 | } 138 | 139 | void spe::Transform::SetTextureSize(const spe::Vector2& scale) 140 | { 141 | spe::Vector2 multiply = scale; 142 | 143 | if (multiply.X < 0) 144 | { 145 | multiply.X = multiply.X * -1; 146 | } 147 | if (multiply.Y < 0) 148 | { 149 | multiply.Y = multiply.Y * -1; 150 | } 151 | 152 | sf::IntRect textureRect = this->ptr_Sprite->GetSprite().getTextureRect(); 153 | this->TextureSize = spe::Vector2(textureRect.width * multiply.X, textureRect.height * multiply.Y); 154 | this->SetOrigin(); 155 | } 156 | 157 | void spe::Transform::CalculateScaleXByWorldPosition(const float posX) 158 | { 159 | float scaleX = posX / this->TextureSize.X; 160 | 161 | this->SetScale(spe::Vector2(scaleX, this->m_Scale.Y)); 162 | } 163 | 164 | spe::Vector2 spe::Transform::GetDefaultTextureSize() const noexcept 165 | { 166 | spe::Vector2 scale = this->m_Scale; 167 | 168 | if (this->m_Scale.X < 0) 169 | { 170 | scale.X = scale.X * -1; 171 | } 172 | if (this->m_Scale.Y < 0) 173 | { 174 | scale.Y = scale.Y * -1; 175 | } 176 | return spe::Vector2(this->TextureSize.X / scale.X, this->TextureSize.Y / scale.Y); 177 | } 178 | 179 | void spe::Transform::SetRotation(uint32_t angle) 180 | { 181 | this->m_Rotation = angle % 360; 182 | this->ptr_Sprite->GetSprite().setRotation((float)this->m_Rotation); 183 | } 184 | 185 | void spe::Transform::Teleport(const spe::Vector2& position) 186 | { 187 | if (this->m_Position == position) 188 | { 189 | this->PositionChanged = false; 190 | return; 191 | } 192 | 193 | this->UpdateSpritePositionToParent(position); 194 | this->m_Position = position; 195 | this->PositionChanged = true; 196 | 197 | if (this->ptr_Sprite != nullptr) 198 | { 199 | this->ptr_Sprite->GetSprite().setPosition(sf::Vector2f(position.X + 960, 540 - position.Y)); 200 | } 201 | 202 | } 203 | 204 | void spe::Transform::SetOrigin() 205 | { 206 | sf::Sprite& spr = this->ptr_Sprite->GetSprite(); 207 | spr.setOrigin(sf::Vector2f(this->GetDefaultTextureSize().X / 2, this->GetDefaultTextureSize().Y / 2)); 208 | } 209 | 210 | void spe::Transform::SetScale(const spe::Vector2& scale, bool b) 211 | { 212 | if (this->m_Scale == scale && !b) 213 | { 214 | return; 215 | } 216 | 217 | this->SetTextureSize(scale); 218 | 219 | this->m_Scale = scale; 220 | this->ptr_Sprite->GetSprite().setScale(scale.X, scale.Y); 221 | this->SetOrigin(); 222 | } 223 | 224 | spe::Vector2 spe::Transform::GetOrigininalPosition() const 225 | { 226 | float x = this->ptr_Sprite->GetSprite().getPosition().x - this->TextureSize.X / 2; 227 | float y = this->ptr_Sprite->GetSprite().getPosition().y - this->TextureSize.Y / 2; 228 | 229 | return spe::Vector2(x, y); 230 | } 231 | 232 | void spe::Transform::Reset() 233 | { 234 | this->m_Position = spe::Vector2(0, 0); 235 | this->SetScale(spe::Vector2(1, 1)); 236 | } 237 | 238 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Components/Transform.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Engine/Core/Source/Sprite/Components/Transform.h -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Sprite.cpp: -------------------------------------------------------------------------------- 1 | #include "Sprite.h" 2 | 3 | #include "Camera/Camera.h" 4 | 5 | //Constructor 6 | 7 | spe::Sprite::Sprite(std::string name, spe::Vector2 spawnPosition, std::string path, spe::LightRepository& lightrep) 8 | : Name(name) 9 | { 10 | this->InitVariables(spawnPosition, path, lightrep); 11 | } 12 | 13 | spe::Sprite::Sprite(spe::Sprite& rhs) 14 | { 15 | this->InitVariables(rhs.Transform.GetPosition(), rhs.SpriteRenderer.Path, *rhs.Light.m_ptr_LighRepository); 16 | 17 | this->Collider = spe::BoxCollider(this, rhs.Collider); 18 | this->Transform = spe::Transform(this, rhs.Transform); 19 | this->Animator = spe::Animator(this, rhs.Animator); 20 | this->Physicsbody = spe::PhsysicsBody(this, rhs.Physicsbody); 21 | this->SpriteRenderer = spe::SpriteRenderer(rhs.SpriteRenderer); 22 | this->Light = spe::Light(this, rhs.Light); 23 | this->Prefab = spe::Prefab(this, rhs.Prefab); 24 | 25 | this->Name = rhs.Name; 26 | 27 | this->Tag = rhs.Tag; 28 | 29 | // Initing the childs 30 | for (size_t i = 0; i < rhs.ptr_Childs.size(); i++) 31 | { 32 | spe::Sprite* copy_child = new spe::Sprite(*rhs.ptr_Childs[i]); 33 | copy_child->ptr_Parent = this; 34 | this->ptr_Childs.push_back(copy_child); 35 | } 36 | 37 | this->Animator.Stop(this->Animator.GetAnimationPlaying().Name); 38 | } 39 | 40 | spe::Sprite::~Sprite() 41 | { 42 | this->ClearAllChilds(); 43 | this->ClearParentData(); 44 | 45 | this->Light.DeleteLight(); 46 | 47 | delete this->m_Texture; 48 | this->m_Texture = nullptr; 49 | this->ptr_Childs.clear(); 50 | } 51 | 52 | //Public functions 53 | 54 | ////////////////////////////////////// 55 | //// USER FUNCTIONS 56 | ///////////////////////////////////// 57 | 58 | void spe::Sprite::SetSpriteTexture(const std::string& path) 59 | { 60 | if (!this->m_Texture->loadFromFile(path)) 61 | { 62 | const std::string error = "File " + path + " was not found!, Sprite.cpp 59"; 63 | spe::Log::LogString(error); 64 | } 65 | this->SetSpriteTexture(*this->m_Texture, path); 66 | } 67 | 68 | void spe::Sprite::SetSpriteTexture(const std::string& path, const spe::Vector2& scale) 69 | { 70 | if (!this->m_Texture->loadFromFile(path)) 71 | { 72 | const std::string error = "File " + path + " was not found!, Sprite.cpp 68"; 73 | spe::Log::LogString(error); 74 | } 75 | this->SetSpriteTexture(*this->m_Texture, path); 76 | this->Transform.SetScale(scale, true); 77 | } 78 | 79 | void spe::Sprite::SetSpriteTexture(const sf::Texture& texture, const std::string& path) 80 | { 81 | this->m_Sprite.setTexture(texture, true); 82 | this->Transform.SetScale(this->Transform.GetScale(), true); 83 | this->SpriteRenderer.Path = path; 84 | 85 | this->Transform.SetOrigin(); 86 | } 87 | 88 | void spe::Sprite::SetId(const int32_t id) noexcept 89 | { 90 | this->m_ID = id; 91 | } 92 | 93 | void spe::Sprite::ClearParentData() 94 | { 95 | if (this->ptr_Parent != nullptr) 96 | { 97 | this->ptr_Parent->RemoveChild(this); 98 | this->ptr_Parent = nullptr; 99 | } 100 | this->m_ParentID = 0; 101 | } 102 | 103 | void spe::Sprite::SetParent(spe::Sprite* spriteParent) 104 | { 105 | if (spriteParent == nullptr) 106 | { 107 | return; 108 | } 109 | 110 | // Clean up (Before) parent 111 | if (this->ptr_Parent != nullptr) 112 | { 113 | this->ptr_Parent->RemoveChild(this); 114 | this->ptr_Parent = nullptr; 115 | } 116 | this->m_ParentID = spriteParent->GetId(); 117 | this->ptr_Parent = spriteParent; 118 | 119 | spe::Sprite* child = this; 120 | spe::Vector2 distance = spe::Vector2(spriteParent->Transform.GetPosition() - child->Transform.GetPosition()); 121 | child->Transform.PositionToParent = distance; 122 | 123 | spriteParent->ptr_Childs.push_back(this); 124 | } 125 | 126 | void spe::Sprite::RemoveChild(const spe::Sprite* child) 127 | { 128 | if (child == nullptr) 129 | { 130 | return; 131 | } 132 | for (size_t i = 0; i < this->ptr_Childs.size(); i++) 133 | { 134 | if (child->GetId() == this->ptr_Childs[i]->GetId()) 135 | { 136 | this->ptr_Childs.erase(this->ptr_Childs.begin() + i); 137 | return; 138 | } 139 | } 140 | } 141 | 142 | //Private functions 143 | 144 | void spe::Sprite::InitVariables(spe::Vector2 spawnPos, std::string path, spe::LightRepository& lightrep) 145 | { 146 | // Components 147 | this->Process = false; 148 | this->Transform = spe::Transform(this); 149 | this->Animator = spe::Animator(this); 150 | this->Collider = spe::BoxCollider(this); 151 | this->Physicsbody = spe::PhsysicsBody(this); 152 | this->Prefab = spe::Prefab(this); 153 | this->Light = spe::Light(this, &lightrep); 154 | 155 | // ID's get set in the sprite repo!! 156 | this->Tag = "none"; 157 | this->m_Texture = new sf::Texture(); 158 | this->m_ParentID = -1; 159 | this->m_ID = -1; 160 | this->ptr_Parent = nullptr; 161 | this->ptr_Childs = std::vector(0); 162 | this->Name = Name; 163 | this->SpriteRenderer.Path = path; 164 | this->m_SetId = false; 165 | this->DontDeleteOnSceneSwap = false; 166 | 167 | this->SpriteRenderer.SortinLayerIdx = 0; 168 | 169 | this->Transform.SetOrigin(); 170 | this->Transform.SetScale(spe::Vector2(1, 1), true); 171 | this->Transform.SetRotation(0); 172 | this->Transform.SetPosition(spawnPos); 173 | 174 | this->SetSpriteTexture(path); 175 | 176 | this->GetSprite().setPosition(sf::Vector2f(spawnPos.X + 960, 540 - spawnPos.Y)); 177 | 178 | } 179 | 180 | //Static functions 181 | 182 | spe::Sprite* spe::Sprite::GetNode() 183 | { 184 | if (this->ptr_Parent == nullptr) 185 | { 186 | return this; 187 | } 188 | return ptr_Parent->GetNode(); 189 | } 190 | 191 | bool spe::Sprite::ContainsChild(const spe::Sprite* child) const 192 | { 193 | if (child == nullptr) 194 | { 195 | return false; 196 | } 197 | bool contains = false; 198 | 199 | for (int i = 0; i < this->ptr_Childs.size(); i++) 200 | { 201 | const spe::Sprite* spr = this->ptr_Childs[i]; 202 | if (child->m_ID == spr->m_ID) 203 | { 204 | return true; 205 | } 206 | if (!contains) 207 | { 208 | contains = spr->ContainsChild(child); 209 | } 210 | } 211 | return contains; 212 | } 213 | 214 | bool spe::Sprite::ContainsChild(const ImGuiTextFilter& namefilter) const 215 | { 216 | bool contains = false; 217 | 218 | for (int i = 0; i < this->ptr_Childs.size(); i++) 219 | { 220 | const spe::Sprite* spr = this->ptr_Childs[i]; 221 | if (namefilter.PassFilter(spr->Name.c_str())) 222 | { 223 | return true; 224 | } 225 | contains = spr->ContainsChild(namefilter); 226 | } 227 | return contains; 228 | } 229 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/Sprite.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "Math/Vector2.h" 11 | #include "Sprite/Components/BoxCollider.h" 12 | #include "Sprite/Components/PhysicsBody.h" 13 | #include "Sprite/Components/SpriteRenderer.h" 14 | #include "Sprite/Components/Transform.h" 15 | #include "Sprite/Components/Light/Light.h" 16 | #include "Sprite/Components/Prefab/Prefab.h" 17 | #include "Sprite/Components/Animator/Animator.h" 18 | 19 | #define INVALID_SPRITE_SYMBOLS 1 20 | 21 | namespace spe 22 | { 23 | class Camera; 24 | class Sprite 25 | { 26 | private: 27 | int32_t m_ParentID; 28 | sf::Sprite m_Sprite; 29 | sf::Texture* m_Texture; 30 | int32_t m_ID; 31 | 32 | bool m_SetId; 33 | 34 | void InitVariables(spe::Vector2 spawnPos, std::string path, spe::LightRepository& lightrep); 35 | public: 36 | // General info 37 | std::string Name; 38 | std::string Tag; 39 | bool Process; 40 | 41 | /// 42 | /// very wierd; use with caution 43 | /// 44 | bool DontDeleteOnSceneSwap; 45 | 46 | // Components 47 | spe::SpriteRenderer SpriteRenderer; 48 | spe::BoxCollider Collider; 49 | spe::PhsysicsBody Physicsbody; 50 | spe::Transform Transform; 51 | spe::Animator Animator; 52 | spe::Prefab Prefab; 53 | spe::Light Light; 54 | 55 | //Parent / child infos 56 | std::vector ptr_Childs; 57 | spe::Sprite* ptr_Parent; 58 | 59 | Sprite() = default; 60 | Sprite(std::string name, spe::Vector2 spawnPosition, std::string path, spe::LightRepository& lightrepo); 61 | Sprite(spe::Sprite& rhs); 62 | ~Sprite(); 63 | 64 | ////////////////////////////////////// 65 | //// ENGINE FUNCTIONS 66 | ///////////////////////////////////// 67 | 68 | void SetParentId(const int32_t id) noexcept { this->m_ParentID = id; } 69 | void SetId(const int32_t id) noexcept; 70 | sf::Sprite& GetSprite() { return this->m_Sprite; } 71 | sf::Texture& GetTexture() { return *this->m_Texture; } 72 | 73 | void ClearParentData(); 74 | void ClearAllChilds() { this->ptr_Childs.clear(); } 75 | 76 | ////////////////////////////////////// 77 | //// USER FUNCTIONS 78 | ///////////////////////////////////// 79 | 80 | void SetParent(spe::Sprite* parent); 81 | 82 | /// 83 | /// Removes the child from the childs list 84 | /// 85 | /// Child 86 | void RemoveChild(const spe::Sprite* child); 87 | 88 | /// 89 | /// Gets the id of the parent 90 | /// 91 | 92 | /// 93 | /// Sets the new texture of the sprite 94 | /// 95 | /// The path of the new texture 96 | void SetSpriteTexture(const std::string& path); 97 | 98 | /// 99 | /// Sets the new sprite texture 100 | /// IT DOES NOT!!! LOAD THE TEXTURE FROM THE FILE 101 | /// 102 | /// The already loaded texture 103 | /// The new path which needs to be set 104 | void SetSpriteTexture(const sf::Texture& texture, const std::string& path); 105 | 106 | /// 107 | /// LOADS the texture from the file and sets it scale 108 | /// 109 | /// Path to the .png file 110 | /// Scale to set 111 | void SetSpriteTexture(const std::string& path, const spe::Vector2& sclae); 112 | 113 | /// 114 | /// Gets the absulute parent 115 | /// 116 | spe::Sprite* GetNode(); 117 | 118 | /// 119 | /// Get's the id of the current sprite 120 | /// 121 | /// 122 | int32_t GetId() const { return this->m_ID; } 123 | 124 | bool IsParent() const { return this->ptr_Childs.size() > 0; } 125 | 126 | bool ContainsChild(const spe::Sprite* child) const; 127 | 128 | bool ContainsChild(const ImGuiTextFilter& name) const; 129 | int GetParentId() const noexcept { return this->m_ParentID; } 130 | 131 | /// 132 | /// Gets the path to the texture file 133 | /// 134 | const std::string& getPathOfTextureFile() const { return this->SpriteRenderer.Path; } 135 | }; 136 | } 137 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Sprite/SpriteRepository.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Core/Repository.h" 10 | #include "Math/Vector2.h" 11 | 12 | namespace spe 13 | { 14 | class Sprite; // The sprite id wont reset over scenes 15 | class SpriteRepository : public spe::Repository 16 | { 17 | private: 18 | std::list m_Sprites; 19 | 20 | uint32_t GetIdWithName(const std::string& name) const; 21 | void AddChildsToDelete(std::vector& childs, spe::Sprite* parent); 22 | void EraseWithIdx(uint32_t id); 23 | void SortSpritesByLayer(spe::Sprite* spr); 24 | void ValidateAdd(spe::Sprite* spr); 25 | public: 26 | std::vector Tags; 27 | 28 | bool* IsFullScreened; 29 | bool Initialized; 30 | 31 | SpriteRepository(); 32 | ~SpriteRepository(); 33 | 34 | // Add / delete 35 | void DelteWithId(uint32_t id); 36 | void DeleteWithName(const std::string& name); 37 | void Add(spe::Sprite* ref) override; 38 | 39 | void SortSpritesByLayer(); 40 | 41 | // Utility 42 | void UpdateLayerIndex() override; 43 | void ReloadTextures(); 44 | void CleanUp(); 45 | void DeleteAll(); 46 | void SetHighestId(uint32_t id); 47 | 48 | // getter 49 | bool ExistWithId(uint32_t id); 50 | uint32_t GetListIndex(spe::Sprite* sprite); 51 | std::list& GetSprites() { return this->m_Sprites; } 52 | const std::list& GetSpritesC() const { return this->m_Sprites; } 53 | uint32_t GetAmount() const override { return (uint32_t)this->m_Sprites.size(); } 54 | spe::Sprite* GetById(uint32_t idx) override; 55 | spe::Sprite* GetByName(const std::string& name) override; 56 | uint32_t GetHighestLayer() const { return this->m_HighestLayer; } 57 | uint32_t GetHighestId() const { return this->m_HighestId; } 58 | void GetSpritesByTag(const std::string& tag, std::vector& sprites); 59 | 60 | /// 61 | /// Kinda inefficent. Try not to use much 62 | /// 63 | /// 64 | /// 65 | void SetSpriteSortingLayer(uint32_t layer, spe::Sprite* id); 66 | 67 | public: 68 | static void GetAllChilds(std::vector& childs, const spe::Sprite* parent); 69 | static spe::Sprite* GetWithId(std::vector& collection, uint32_t id); 70 | }; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Utility/FileDialoge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace spe 12 | { 13 | enum class CurrentFileDialog 14 | { 15 | None = -1, 16 | Open = 0, 17 | Create 18 | }; 19 | 20 | /// 21 | /// File dialogs coll the "disableWindow();" function when the "x" button is pressed 22 | /// Absulute and relative paths will work 23 | /// 24 | class FileDialog 25 | { 26 | private: 27 | bool m_CloseWindow; 28 | bool m_DisplayTitle; 29 | std::string m_Icon; 30 | std::string m_Path; 31 | std::string m_FirstNodeText; 32 | ImVec2 m_WindowSize; 33 | std::string m_Title; 34 | bool m_IsOpen; 35 | float m_FontScale; 36 | bool m_ShowFiles; 37 | 38 | /// 39 | /// Opens a file and displays the folder recursivly with , needs to be called by 40 | /// 41 | void OpenFile(const char* dir_path); 42 | 43 | bool DisplaySymbol(const std::string& icon, float windowSizeX); 44 | public: 45 | std::string PathClicked; 46 | std::string ItemClicked; 47 | bool WindowFocus; 48 | 49 | FileDialog(); 50 | 51 | /// 52 | /// Creats the file dialoge. Only folders 53 | /// 54 | /// The path where the file dialoge while start. For exmaple C:\\ DO USE THE \\!! Absulute and relative paths will work 55 | /// The icon next to the FOLDER 56 | /// The title in the top left corner 57 | /// The window size of the file dialoge window 58 | FileDialog(std::string path, std::string icon, std::string title, ImVec2 windowSize, bool show_files, float font_scale); 59 | 60 | /// 61 | /// Resets the data of the File Dialog 62 | /// 63 | void DisableWindow(); 64 | 65 | /// 66 | /// Displays all the nodes including the path you provide 67 | /// 68 | void DisplayNodes(); 69 | 70 | /// 71 | /// Closes the window, so it basicly resets all fields 72 | /// 73 | /// 74 | bool IsWindowClosed() const { return this->m_CloseWindow; } 75 | 76 | /// 77 | /// Enables the window, cant be drawn without this function 78 | /// 79 | void EnableWindow(); 80 | 81 | /// 82 | /// Enables the window, cant be drawn without this function 83 | /// 84 | void EnableWindow(const std::string& title); 85 | 86 | /// 87 | /// Sets the first node of the file dialoge, ONLY CHANGES THE LOOK!! 88 | /// 89 | void SetFirstNode(const std::string& top) { this->m_FirstNodeText = top; } 90 | 91 | void Update(); 92 | 93 | bool IsItemSelected(); 94 | 95 | public: 96 | static std::string GetEmptyStringBetween(const std::string& content, const std::string& name, float padding); 97 | static bool CheckIfADirHasSubItems(const std::string& dir, bool show_files); 98 | }; 99 | } 100 | 101 | 102 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Utility/Style.cpp: -------------------------------------------------------------------------------- 1 | #include "Style.h" 2 | 3 | bool spe::Style::DisplaySymbolAsButtonWithWidthAndCursorPos(const char* symbol, const ImVec2& cursor, const ImVec2& width, const std::string& identy) 4 | { 5 | ImGui::SetCursorPos(cursor); 6 | bool clicked = false; 7 | ImGui::PopFont(); 8 | ImGui::PushFont(spe::Style::s_SymbolFont); 9 | 10 | const std::string identy_button = identy + "-button"; 11 | 12 | clicked = ImGui::Button(identy_button.c_str(), width); 13 | 14 | ImGui::SetCursorPos(ImVec2(cursor.x + 7, ImGui::GetCursorPosY() - 25)); 15 | ImGui::Text(symbol); 16 | 17 | ImGui::PopFont(); 18 | ImGui::PushFont(spe::Style::s_DefaultFont); 19 | return clicked; 20 | } 21 | 22 | bool spe::Style::DisplaySymbolInMenuItem(const char* symbol) 23 | { 24 | ImGui::PopFont(); 25 | ImGui::PushFont(spe::Style::s_SymbolFont); 26 | bool clicked = ImGui::MenuItem(symbol); 27 | 28 | ImGui::PopFont(); 29 | ImGui::PushFont(spe::Style::s_DefaultFont); 30 | 31 | return clicked; 32 | } 33 | 34 | void spe::Style::DisplaySmybolAsText(const char* symbol) 35 | { 36 | ImGui::PopFont(); 37 | ImGui::PushFont(spe::Style::s_SymbolFont); 38 | 39 | ImGui::Text(symbol); 40 | 41 | ImGui::PopFont(); 42 | ImGui::PushFont(spe::Style::s_DefaultFont); 43 | } 44 | 45 | bool spe::Style::DisplaySmybolAsButton(const char* symbol, ImFont* font) 46 | { 47 | ImGui::PopFont(); 48 | 49 | bool clicked = false; 50 | 51 | if (font != nullptr) 52 | { 53 | ImGui::PushFont(font); 54 | 55 | clicked = ImGui::Button(symbol, ImVec2(50, 50)); 56 | } 57 | else 58 | { 59 | ImGui::PushFont(spe::Style::s_SymbolFont); 60 | 61 | clicked = ImGui::Button(symbol); 62 | } 63 | 64 | 65 | ImGui::PopFont(); 66 | ImGui::PushFont(spe::Style::s_DefaultFont); 67 | 68 | return clicked; 69 | } 70 | 71 | bool spe::Style::DisplaySmybolAsButton(const char* symbol, float defaultFontSize) 72 | { 73 | ImGui::SetWindowFontScale(defaultFontSize); 74 | 75 | bool clicked = false; 76 | ImGui::PopFont(); 77 | ImGui::PushFont(spe::Style::s_SymbolFont); 78 | 79 | clicked = ImGui::Button(symbol); 80 | 81 | ImGui::PopFont(); 82 | ImGui::PushFont(spe::Style::s_DefaultFont); 83 | 84 | return clicked; 85 | } 86 | 87 | bool spe::Style::DisplaySmybolAsButton(const char* symbol, ImVec2 cursorPos) 88 | { 89 | ImGui::SetCursorPos(ImVec2(cursorPos.x, cursorPos.y)); 90 | return DisplaySmybolAsButton(symbol); 91 | } 92 | 93 | bool spe::Style::DisplaySymbolInTreeNode(const char* symbol, std::string name, bool openNode) 94 | { 95 | const ImVec2 cursor = ImVec2(ImGui::GetCursorPos().x, ImGui::GetCursorPosY()); 96 | ImGui::SetCursorPos(ImVec2(cursor.x + 35, cursor.y)); 97 | spe::Style::DisplaySmybolAsText(symbol); 98 | ImGui::SetCursorPos(cursor); 99 | 100 | const std::string whiteSpaces = std::string(" ") + name; 101 | name = whiteSpaces.c_str(); 102 | if (openNode) 103 | ImGui::SetNextItemOpen(true); 104 | return ImGui::TreeNodeEx(name.c_str(), ImGuiTreeNodeFlags_OpenOnArrow); 105 | } 106 | 107 | bool spe::Style::DisplaySymbolInMenuItemWithText(const char* symbol, std::string name, uint32_t dist) 108 | { 109 | const ImVec2 cursor = ImVec2(ImGui::GetCursorPos().x, ImGui::GetCursorPosY()); 110 | ImGui::SetCursorPos(ImVec2(cursor.x + dist, cursor.y)); 111 | spe::Style::DisplaySmybolAsText(symbol); 112 | ImGui::SetCursorPos(cursor); 113 | 114 | const std::string whiteSpaces = std::string(" ") + name; 115 | name = whiteSpaces.c_str(); 116 | return ImGui::MenuItem(name.c_str()); 117 | } 118 | 119 | 120 | void spe::Style::Init() 121 | { 122 | ImGuiIO& io = ImGui::GetIO(); 123 | ImFontConfig CustomFont; 124 | ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; 125 | ImFontConfig icons_config; 126 | 127 | io.IniFilename = nullptr; 128 | CustomFont.FontDataOwnedByAtlas = false; 129 | 130 | icons_config.MergeMode = true; 131 | icons_config.PixelSnapH = true; 132 | icons_config.OversampleH = 3; 133 | icons_config.OversampleV = 3; 134 | 135 | ImFontConfig config; 136 | 137 | static const ImWchar ranges[] = 138 | { 139 | 0xf0c7, 0xf0c7, // Save 140 | 0xf06e, 0xf06e, // Eye 141 | 0xf070, 0xf070, // Eye slashed 142 | 0xf013, 0xf013, // Zahnrad 143 | 0xf1b2, 0xf1b2, // Cube 144 | 0xf060, 0xf060, // Arrow left 145 | 0xf061, 0xf061, // Arrow right 146 | 0xf062, 0xf062, // Arrow up 147 | 0xf1c9, 0xf1c9, // File Codes 148 | 0xf37e, 0xf37e, // Browser 149 | 0xf07b, 0xf07b, // Folder 150 | 0xf0c8, 0xf0c8, // Square 151 | 0xf04b, 0xf04b, // Play 152 | 0xf047, 0xf047, // Arrows 153 | 0xf002, 0xf002, // Search 154 | 0xf067, 0xf067, // Plus 155 | 0xf044, 0xf044, // Edit 156 | 0xf1f8, 0xf1f8, // Trash 157 | 0xf079, 0xf079, // Retweet 158 | 0xf04b, 0xf04b, // Play button 159 | 0xf03e, 0xf03e, // Image 160 | 0xf15b, 0xf15b, // File 161 | 0, 162 | }; 163 | 164 | config.GlyphRanges = ranges; 165 | 166 | //Add the fonts (remember to fill in the correct path of your font 167 | 168 | const std::string arial = PATH_TO_RESSOURCES + "\\Fonts\\arial.ttf"; 169 | const std::string fonta = PATH_TO_RESSOURCES + "\\Fonts\\fontawesome-webfont.ttf"; 170 | 171 | spe::Style::s_DefaultFont = io.Fonts->AddFontFromFileTTF(arial.c_str(), spe::Style::s_FontSize); 172 | spe::Style::s_SymbolFont = io.Fonts->AddFontFromFileTTF(fonta.c_str(), spe::Style::s_FontSize - 4, &config); 173 | 174 | //This function is important else the program will crash with an assertion 175 | ImGui::SFML::UpdateFontTexture(); 176 | } 177 | 178 | void spe::Style::RenderStyle() 179 | { 180 | ImGuiStyle* style = &ImGui::GetStyle(); 181 | 182 | ImVec4 shadow_color = ImVec4(0.0f, 0.0f, 0.0f, 0.5f); 183 | 184 | //Setting it centered 185 | style->WindowTitleAlign = ImVec2(0.5f, 0.5f); 186 | style->FramePadding = ImVec2(8, 6); 187 | 188 | style->Colors[ImGuiCol_TitleBg] = ImColor(49, 49, 76); 189 | style->Colors[ImGuiCol_TitleBgActive] = ImColor(49, 49, 76); 190 | style->Colors[ImGuiCol_TitleBgCollapsed] = ImColor(217, 101, 53, 255); 191 | 192 | //the sprite selected 193 | style->Colors[ImGuiCol_Header] = ImColor(0, 0, 0, 0); 194 | style->Colors[ImGuiCol_HeaderHovered] = ImColor(100, 90, 100, 100); 195 | style->Colors[ImGuiCol_HeaderActive] = ImColor(0, 0, 0, 0); 196 | 197 | style->Colors[ImGuiCol_Button] = ImColor(0, 0, 0, 0); 198 | style->Colors[ImGuiCol_ButtonActive] = ImColor(48, 48, 48, 0); 199 | style->Colors[ImGuiCol_ButtonHovered] = ImColor(100, 90, 100, 100); 200 | 201 | //The background of (input) 202 | style->Colors[ImGuiCol_FrameBg] = shadow_color; 203 | style->Colors[ImGuiCol_FrameBgActive] = ImColor(45, 45, 45); 204 | style->Colors[ImGuiCol_FrameBgHovered] = ImColor(50, 50, 50); 205 | 206 | style->Colors[ImGuiCol_WindowBg] = ImColor(36, 36, 36); 207 | 208 | style->Colors[ImGuiCol_TextSelectedBg] = ImColor(30, 30, 30); 209 | 210 | style->Colors[ImGuiCol_SliderGrab] = ImColor(30, 30, 30); 211 | style->Colors[ImGuiCol_SliderGrabActive] = ImColor(25, 25, 25); 212 | 213 | style->Colors[ImGuiCol_CheckMark] = ImColor(255, 255, 255); 214 | 215 | style->Colors[ImGuiCol_ChildBg] = ImColor(26, 26, 26); 216 | style->Colors[ImGuiCol_MenuBarBg] = ImColor(26, 26, 26, 1); 217 | 218 | style->FrameRounding = 4.0f; 219 | style->GrabRounding = 4.0f; 220 | } 221 | 222 | 223 | ImFont* spe::Style::s_DefaultFont = nullptr; 224 | ImFont* spe::Style::s_SymbolFont = nullptr; 225 | float spe::Style::s_FontSize = 20.0f; 226 | float spe::Style::s_DefaultFontSize = 0.9f; 227 | 228 | -------------------------------------------------------------------------------- /Engine/Engine/Core/Source/Utility/Style.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "RessourceHandler/FileDataMacros.h" 5 | #include "imgui-SFML.h" 6 | 7 | namespace spe 8 | { 9 | class Style 10 | { 11 | public: 12 | Style() = delete; 13 | 14 | static void Init(); 15 | static void RenderStyle(); 16 | 17 | static bool DisplaySymbolAsButtonWithWidthAndCursorPos(const char* symbol, const ImVec2& cursor, const ImVec2& width, const std::string& identy); 18 | static bool DisplaySymbolInMenuItem(const char* symbol); 19 | static void DisplaySmybolAsText(const char* symbol); 20 | static bool DisplaySmybolAsButton(const char* symbol, ImFont* font = nullptr); 21 | static bool DisplaySmybolAsButton(const char* symbol, float defaultFontSize); 22 | static bool DisplaySmybolAsButton(const char* symbol, ImVec2 cursorPos); 23 | static bool DisplaySymbolInTreeNode(const char* symbol, std::string name, bool openNode); 24 | static bool DisplaySymbolInMenuItemWithText(const char* symbol, std::string name, uint32_t dist); 25 | 26 | static ImFont* s_DefaultFont; 27 | static ImFont* s_SymbolFont; 28 | static float s_FontSize; 29 | static float s_DefaultFontSize; 30 | }; 31 | } -------------------------------------------------------------------------------- /Engine/Engine/Math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Math/CMakeLists.txt 2 | 3 | file(GLOB_RECURSE MATH_SOURCE_FILES 4 | "*.h" 5 | "*.cpp" 6 | ) 7 | 8 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${MATH_SOURCE_FILES}) 9 | 10 | add_library(Math STATIC ${MATH_SOURCE_FILES}) 11 | 12 | target_include_directories(Math PRIVATE "${EXTERNAL_LIBRARIES_FOLDER}/imgui") 13 | 14 | target_link_libraries(Math PRIVATE 15 | sfml-graphics 16 | sfml-window 17 | sfml-system 18 | sfml-audio 19 | sfml-network 20 | imgui 21 | ) 22 | 23 | set_target_properties(Math PROPERTIES FOLDER "Engine") 24 | 25 | if(MSVC) 26 | target_compile_options(Math PUBLIC /W4) 27 | add_compile_options(/MP) 28 | endif() -------------------------------------------------------------------------------- /Engine/Engine/Math/Vector2.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector2.h" 2 | 3 | spe::Vector2::Vector2() 4 | { 5 | this->X = 0.0f; 6 | this->Y = 0.0f; 7 | } 8 | 9 | spe::Vector2::Vector2(float x, float y) 10 | { 11 | this->X = x; 12 | this->Y = y; 13 | } 14 | 15 | spe::Vector2::Vector2(const ImVec2& vec) 16 | { 17 | this->X = vec.x; 18 | this->Y = vec.y; 19 | } 20 | 21 | spe::Vector2::Vector2(const spe::Vector2& rhs) 22 | { 23 | this->X = rhs.X; 24 | this->Y = rhs.Y; 25 | } 26 | 27 | spe::Vector2::Vector2(const sf::Vector2f& rhs) 28 | { 29 | this->X = rhs.x; 30 | this->Y = rhs.y; 31 | } 32 | 33 | bool spe::Vector2::operator==(const Vector2& rhs) const 34 | { 35 | return(rhs.X == this->X 36 | && rhs.Y == this->Y); 37 | } 38 | 39 | bool spe::Vector2::operator!=(const Vector2& rhs) const 40 | { 41 | return(rhs.X != this->X 42 | || rhs.Y != this->Y); 43 | } 44 | 45 | spe::Vector2 spe::Vector2::operator+=(const spe::Vector2& rhs) 46 | { 47 | return spe::Vector2(this->X += rhs.X, this->Y += rhs.Y); 48 | } 49 | 50 | spe::Vector2 spe::Vector2::operator*(const float& rhs) const 51 | { 52 | return spe::Vector2(this->X * rhs, this->Y * rhs); 53 | } 54 | 55 | spe::Vector2 spe::Vector2::operator-(const spe::Vector2& rhs) const 56 | { 57 | return spe::Vector2(this->X - rhs.X, this->Y - rhs.Y); 58 | } 59 | 60 | spe::Vector2 spe::Vector2::operator+(const spe::Vector2& rhs) const 61 | { 62 | return spe::Vector2(this->X + rhs.X, this->Y + rhs.Y); 63 | } 64 | 65 | spe::Vector2 spe::Vector2::operator*=(const spe::Vector2& rhs) 66 | { 67 | return spe::Vector2(this->X *= rhs.X, this->Y *= rhs.Y); 68 | } 69 | 70 | spe::Vector2 spe::Vector2::operator/=(const spe::Vector2& rhs) 71 | { 72 | return spe::Vector2(this->X /= rhs.X, this->Y /= rhs.Y); 73 | } 74 | 75 | spe::Vector2 spe::Vector2::operator/=(const float rhs) 76 | { 77 | return spe::Vector2(this->X /= rhs, this->Y /= rhs); 78 | } 79 | spe::Vector2 spe::Vector2::operator*(const spe::Vector2& rhs) const 80 | { 81 | return spe::Vector2(this->X * rhs.X, this->Y * rhs.Y); 82 | } 83 | 84 | ImVec2 spe::Vector2::toImVec2(const spe::Vector2& vec) 85 | { 86 | return ImVec2(vec.X, vec.Y); 87 | } 88 | 89 | sf::Vector2f spe::Vector2::toSFVector(const spe::Vector2& vec) 90 | { 91 | return sf::Vector2f(vec.X, vec.Y); 92 | } 93 | 94 | 95 | std::ostream& spe::operator<<(std::ostream& os, const spe::Vector2& rhs) 96 | { 97 | os << rhs.X << " x " << rhs.Y << " y "; 98 | return os; 99 | } 100 | 101 | const spe::Vector2 spe::Vector2::SCREEN_MIDDLE = spe::Vector2(1920 / 2, 1080 / 2); -------------------------------------------------------------------------------- /Engine/Engine/Math/Vector2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "imgui.h" 6 | 7 | namespace spe 8 | { 9 | class Vector2 10 | { 11 | public: 12 | float X, Y; 13 | 14 | Vector2(); 15 | Vector2(float x, float y); 16 | Vector2(const ImVec2& vec); 17 | Vector2(const spe::Vector2& rhs); 18 | Vector2(const sf::Vector2f& rhs); 19 | 20 | bool operator==(const Vector2& rhs) const; 21 | bool operator!=(const Vector2& rhs) const; 22 | spe::Vector2 operator+=(const spe::Vector2& rhs); 23 | spe::Vector2 operator*(const float& rhs) const; 24 | spe::Vector2 operator-(const spe::Vector2& rhs) const; 25 | spe::Vector2 operator+(const spe::Vector2& rhs) const; 26 | spe::Vector2 operator*=(const spe::Vector2& rhs); 27 | spe::Vector2 operator/=(const spe::Vector2& rhs); 28 | spe::Vector2 operator/=(const float rhs); 29 | spe::Vector2 operator*(const spe::Vector2& rhs) const; 30 | 31 | friend std::ostream& operator<<(std::ostream& os, const spe::Vector2& rhs); 32 | 33 | public: 34 | static const spe::Vector2 SCREEN_MIDDLE; 35 | static ImVec2 toImVec2(const spe::Vector2& vec); 36 | static sf::Vector2f toSFVector(const spe::Vector2& vec); 37 | }; 38 | 39 | std::ostream& operator<<(std::ostream& os, const spe::Vector2& rhs); 40 | } -------------------------------------------------------------------------------- /Engine/Engine/Math/Vector3.cpp: -------------------------------------------------------------------------------- 1 | #include "vector3.h" 2 | 3 | 4 | spe::Vector3::Vector3() 5 | : X(0), Y(0), Z(0) { } 6 | 7 | 8 | spe::Vector3::Vector3(float x, float y, float z) 9 | : X(x) , Y(y), Z(z) { } 10 | 11 | 12 | sf::Vector3f spe::Vector3::ToSFVector3(const spe::Vector3& vec) 13 | { 14 | return sf::Vector3f(vec.X, vec.Y, vec.Z); 15 | } 16 | -------------------------------------------------------------------------------- /Engine/Engine/Math/Vector3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace spe 6 | { 7 | class Vector3 8 | { 9 | public: 10 | float X, Y, Z; 11 | 12 | Vector3(); 13 | Vector3(float x, float y, float z); 14 | 15 | static sf::Vector3f ToSFVector3(const spe::Vector3& rhs); 16 | }; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Engine/Framework/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Framework/CMakeLists.txt 2 | # The gamengine lib contains functions like AddForce 3 | 4 | file(GLOB_RECURSE ENGINE_SOURCE_FILES 5 | "Source/*.h" 6 | "Source/*.cpp" 7 | ) 8 | 9 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ENGINE_SOURCE_FILES}) 10 | 11 | add_library(Framework STATIC ${ENGINE_SOURCE_FILES}) 12 | 13 | target_link_libraries(Framework PUBLIC 14 | Core 15 | ) 16 | set_target_properties(Framework PROPERTIES FOLDER "Engine") 17 | 18 | if(MSVC) 19 | target_compile_options(Framework PUBLIC /W4) 20 | add_compile_options(/MP) 21 | endif() 22 | -------------------------------------------------------------------------------- /Engine/Framework/Source/GUI/GUI.cpp: -------------------------------------------------------------------------------- 1 | #include "GUI.h" 2 | 3 | bool spe::GUI::Button(const std::string& content) 4 | { 5 | return ImGui::Button(content.c_str()); 6 | } 7 | 8 | void spe::GUI::SetCursorCamera(const spe::Vector2& position) 9 | { 10 | ImVec2 new_cursor = ImVec2(spe::GUI::s_ptr_Camera->Position.X * -1 + 960, 540 + spe::GUI::s_ptr_Camera->Position.Y * -1); 11 | new_cursor.x += position.X; 12 | new_cursor.y -= position.Y; 13 | 14 | ImGui::SetCursorPos(new_cursor); 15 | } 16 | 17 | void spe::GUI::SetCursor(const spe::Vector2& position) 18 | { 19 | ImVec2 new_cursor = ImVec2(960, 540); 20 | new_cursor.x += position.X; 21 | new_cursor.y -= position.Y; 22 | 23 | ImGui::SetCursorPos(new_cursor); 24 | } 25 | 26 | void spe::GUI::SetFontScale(float scale) 27 | { 28 | ImGui::SetWindowFontScale(scale); 29 | } 30 | 31 | void spe::GUI::Window(const std::string& id, const spe::Vector2& pos, const spe::Vector2& size) 32 | { 33 | ImGui::Begin(id.c_str(), NULL, DEFAULT_FLAGS); 34 | ImGui::SetWindowSize(spe::Vector2::toImVec2(size)); 35 | ImGui::SetWindowPos(ImVec2(960 + pos.X, 540 - pos.Y)); 36 | } 37 | 38 | void spe::GUI::End() 39 | { 40 | ImGui::End(); 41 | } 42 | 43 | const spe::Camera* spe::GUI::s_ptr_Camera = nullptr; -------------------------------------------------------------------------------- /Engine/Framework/Source/GUI/GUI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Utility/Style.h" 6 | 7 | #include "Math/Vector2.h" 8 | #include "Camera/Camera.h" 9 | #include "imgui.h" 10 | 11 | #define D_SCALE spe::Style::s_DefaultFontSize 12 | #define DEFAULT_FLAGS ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar 13 | 14 | namespace spe 15 | { 16 | /// 17 | /// Uses the ImGUI library 18 | /// 19 | class GUI 20 | { 21 | private: 22 | static const spe::Camera* s_ptr_Camera; 23 | 24 | public: 25 | GUI() = delete; 26 | 27 | static bool Button(const std::string& content); 28 | 29 | static void SetCursorCamera(const spe::Vector2& position); 30 | 31 | static void SetCursor(const spe::Vector2& pos); 32 | 33 | static void SetFontScale(float scale); 34 | 35 | static void SetCamera(const spe::Camera* ptr) { spe::GUI::s_ptr_Camera = ptr; } 36 | 37 | static void Window(const std::string& id, const spe::Vector2& pos, const spe::Vector2& size); 38 | 39 | static void End(); 40 | }; 41 | } -------------------------------------------------------------------------------- /Engine/Framework/Source/GameUtils/GameUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "GameUtils.h" 2 | 3 | bool spe::GameUtils::IsLeft(spe::Sprite* maybe_left, spe::Sprite* maybe_right) 4 | { 5 | // Get the X coordinates of both sprites 6 | float x_left = maybe_left->Transform.GetPosition().X; 7 | float x_right = maybe_right->Transform.GetPosition().X; 8 | 9 | // Return true if maybe_left is to the left of maybe_right 10 | return x_left < x_right; 11 | } 12 | 13 | int32_t spe::GameUtils::Random(int32_t min, int32_t max) 14 | { 15 | std::random_device rd; 16 | 17 | std::mt19937 gen(rd()); 18 | 19 | // Define the distribution range 20 | std::uniform_int_distribution<> distr(min, max); 21 | 22 | // Generate a random number within the range 23 | return distr(gen); 24 | } -------------------------------------------------------------------------------- /Engine/Framework/Source/GameUtils/GameUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sprite/Sprite.h" 4 | #include 5 | 6 | namespace spe 7 | { 8 | class GameUtils 9 | { 10 | public: 11 | 12 | GameUtils() = delete; 13 | 14 | static bool IsLeft(spe::Sprite* maybe_left, spe::Sprite* maybe_right); 15 | static int32_t Random(int32_t mix, int32_t max); 16 | }; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Engine/Framework/Source/Physics/Physics.cpp: -------------------------------------------------------------------------------- 1 | #include "Physics.h" 2 | 3 | void spe::Physics::AddForce(spe::Sprite* sprite, const spe::Vector2& direction, float force) 4 | { 5 | float mass = sprite->Physicsbody.Mass; 6 | float speed = force / mass; 7 | const spe::Vector2 velocity = spe::Vector2(direction.X * speed, direction.Y * speed); 8 | sprite->Physicsbody.Velocity += velocity; 9 | } 10 | 11 | float spe::Physics::Lerp(float a, float b, float t) 12 | { 13 | return a + (b - a) * t; 14 | } 15 | 16 | spe::Vector2 spe::Physics::Lerp(const spe::Vector2& a, const spe::Vector2& b, float t) 17 | { 18 | float x = a.X + (b.X - a.X) * t; 19 | float y = a.Y + (b.Y - a.Y) * t; 20 | return spe::Vector2(x, y); 21 | } 22 | -------------------------------------------------------------------------------- /Engine/Framework/Source/Physics/Physics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sprite/Sprite.h" 4 | 5 | namespace spe 6 | { 7 | class Physics 8 | { 9 | public: 10 | 11 | Physics() = delete; 12 | 13 | static void AddForce(spe::Sprite* sprite, const spe::Vector2& direction, float force); 14 | 15 | static float Lerp(float a, float b, float t); 16 | 17 | static spe::Vector2 Lerp(const spe::Vector2& a, const spe::Vector2& b, float t); 18 | }; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Engine/Framework/Source/PrefabRepository/PrefabRepository.cpp: -------------------------------------------------------------------------------- 1 | #include "PrefabRepository.h" 2 | 3 | // public static functions 4 | 5 | spe::Sprite* spe::PrefabRepository::GetPrefabByName(const std::string& name) 6 | { 7 | for (size_t i = 0; i < spe::PrefabRepository::s_prefabs.size(); i++) 8 | { 9 | if (spe::PrefabRepository::s_prefabs[i]->Name == name) 10 | { 11 | // return a COPY 12 | spe::Sprite* copy = new spe::Sprite(*spe::PrefabRepository::s_prefabs[i]); 13 | return copy; 14 | } 15 | } 16 | return nullptr; 17 | } 18 | 19 | void spe::PrefabRepository::LoadPrefabsInMemory(spe::LightRepository& lightRepo) 20 | { 21 | std::vector prefab_paths; 22 | spe::Utility::GetFilePathWithExtensionInFolder("Assets", EXTENSION_PREFAB_FILE, prefab_paths); 23 | 24 | for (size_t i = 0; i < prefab_paths.size(); i++) 25 | { 26 | try 27 | { 28 | spe::Sprite* prefab = spe::Initializer::InitPrefab(prefab_paths[i], lightRepo); 29 | if (prefab->Prefab.LoadInMemory) 30 | { 31 | 32 | spe::PrefabRepository::s_prefabs.push_back(prefab); 33 | } 34 | else 35 | { 36 | delete prefab; 37 | } 38 | } 39 | catch (const std::exception& e) 40 | { 41 | std::string err = e.what(); 42 | spe::Log::LogString("An exception occurred: " + err); 43 | continue; 44 | } 45 | 46 | } 47 | } 48 | 49 | // statics 50 | 51 | std::vector spe::PrefabRepository::s_prefabs = std::vector(0); 52 | 53 | 54 | -------------------------------------------------------------------------------- /Engine/Framework/Source/PrefabRepository/PrefabRepository.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sprite/Sprite.h" 4 | #include "UtilityFunctions.h" 5 | #include "RessourceHandler/Initializer.h" 6 | #include "Sprite/Components/Light/LightRepository.h" 7 | 8 | #include 9 | 10 | namespace spe 11 | { 12 | class PrefabRepository 13 | { 14 | private: 15 | static std::vector s_prefabs; 16 | 17 | 18 | public: 19 | /// 20 | /// Gets the prefab 21 | /// Will not be addded to the sprites in the scene 22 | /// 23 | /// You specified in the editor 24 | /// The prefab or nullptr if you enter a invalid name 25 | static spe::Sprite* GetPrefabByName(const std::string& name); 26 | 27 | static void AddPrefab(spe::Sprite* prefab) { spe::PrefabRepository::s_prefabs.push_back(prefab); } 28 | 29 | static void LoadPrefabsInMemory(spe::LightRepository& lightRepo); 30 | }; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Engine/Scripts/Build.sh: -------------------------------------------------------------------------------- 1 | cd ../Build 2 | cmake --build . --config Release 3 | cmake --build . --config Debug -------------------------------------------------------------------------------- /Engine/Scripts/CMake.sh: -------------------------------------------------------------------------------- 1 | cd .. 2 | rm -rf Build 3 | mkdir Build 4 | cd Build 5 | cmake .. 6 | 7 | cd ../Scripts 8 | ls -------------------------------------------------------------------------------- /Engine/Scripts/Setup.sh: -------------------------------------------------------------------------------- 1 | echo "Building cmake.." 2 | ./CMake.sh 3 | echo "Building cpp files..." 4 | ./Build.sh -------------------------------------------------------------------------------- /Engine/Template/.gitignore: -------------------------------------------------------------------------------- 1 | **/.vs/ 2 | **/build/ 3 | -------------------------------------------------------------------------------- /Engine/Template/Assets/Scripts/Game.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | 3 | void Game::Start() 4 | { 5 | 6 | } 7 | 8 | void Game::Update() 9 | { 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Engine/Template/Assets/Scripts/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Included from the editor-src 4 | #include 5 | 6 | 7 | class Game : public spe::IScript 8 | { 9 | 10 | public: 11 | spe::EngineConfig EngineConfig; 12 | 13 | // Gets called on start of the engine 14 | void Start() override; 15 | 16 | // Gets called once per frame 17 | void Update() override; 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /Engine/Template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Template Solution 2 | # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | set(CMAKE_BUILD_TYPE Debug) # CHANGE WHEN BUILDING IN RELEASE TO Release 4 | # !!!!!!!!!!!!!!! 5 | 6 | cmake_minimum_required(VERSION 3.10) 7 | 8 | get_filename_component(PROJECT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME) 9 | 10 | project(${PROJECT_FOLDER}) 11 | set(CMAKE_CXX_STANDARD 17) 12 | 13 | file(GLOB_RECURSE GAME_SOURCES 14 | "Engine/Source/*.cpp" 15 | "Engine/Source/*.h" 16 | "Assets/*.h" 17 | "Assets/*.cpp" 18 | ) 19 | 20 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${GAME_SOURCES}) 21 | 22 | add_executable(${PROJECT_FOLDER} ${GAME_SOURCES}) 23 | 24 | # Reading the path to the engine, and optimizing it for CMAKE string use 25 | file(READ "Engine\\Saves\\enginepath.txt" FILE_CONTENT) 26 | file(TO_CMAKE_PATH "${FILE_CONTENT}" FILE_CONTENT) 27 | string(STRIP "${FILE_CONTENT}" FILE_CONTENT) 28 | 29 | set(ADDITIONAL_INCLUDE_PATHS 30 | Engine/Core/Source 31 | Framework/Source 32 | Engine 33 | ThirdParty 34 | ThirdParty/imgui 35 | ThirdParty/utility 36 | ThirdParty/imgui-sfml 37 | ) 38 | 39 | foreach(PATH ${ADDITIONAL_INCLUDE_PATHS}) 40 | list(APPEND FULL_PATHS "${FILE_CONTENT}/${PATH}") 41 | endforeach() 42 | 43 | include_directories(${FULL_PATHS}) 44 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Assets) 45 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Engine) 46 | 47 | # Link libs 48 | target_link_libraries(${PROJECT_FOLDER} PRIVATE 49 | Framework 50 | ) 51 | 52 | if(MSVC) 53 | target_compile_options(${PROJECT_FOLDER} PRIVATE /W4) 54 | endif() 55 | 56 | # The libraries that are in the game engine 57 | add_subdirectory(${FILE_CONTENT}/Engine Engine) 58 | add_subdirectory(${FILE_CONTENT}/ThirdParty ThirdParty) 59 | add_subdirectory(${FILE_CONTENT}/Framework Framework) 60 | 61 | set(SFML_DLL_DIR "${CMAKE_BINARY_DIR}/ThirdParty/sfml/lib") 62 | 63 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 64 | add_custom_command(TARGET ${PROJECT_FOLDER} POST_BUILD 65 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 66 | ${SFML_DLL_DIR}/Debug/sfml-audio-d-2.dll $ 67 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 68 | ${SFML_DLL_DIR}/Debug/sfml-graphics-d-2.dll $ 69 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 70 | ${SFML_DLL_DIR}/Debug/sfml-network-d-2.dll $ 71 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 72 | ${SFML_DLL_DIR}/Debug/sfml-system-d-2.dll $ 73 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 74 | ${SFML_DLL_DIR}/Debug/sfml-window-d-2.dll $ 75 | ) 76 | elseif(CMAKE_BUILD_TYPE STREQUAL "Release") 77 | add_custom_command(TARGET ${PROJECT_FOLDER} POST_BUILD 78 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 79 | ${SFML_DLL_DIR}/Release/sfml-audio-2.dll $ 80 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 81 | ${SFML_DLL_DIR}/Release/sfml-graphics-2.dll $ 82 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 83 | ${SFML_DLL_DIR}/Release/sfml-network-2.dll $ 84 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 85 | ${SFML_DLL_DIR}/Release/sfml-system-2.dll $ 86 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 87 | ${SFML_DLL_DIR}/Release/sfml-window-2.dll $ 88 | ) 89 | endif() 90 | 91 | if (MSVC) 92 | add_compile_options(/MP) 93 | endif() 94 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Ressources/Shaders/circulaer_gradient.frag: -------------------------------------------------------------------------------- 1 | #define MAX_LIGHTS 255 2 | 3 | uniform sampler2D texture; 4 | uniform vec2 lightPositions[MAX_LIGHTS]; 5 | uniform float lightRadii[MAX_LIGHTS]; 6 | uniform float lightIntensities[MAX_LIGHTS]; 7 | uniform vec3 lightColors[MAX_LIGHTS]; 8 | uniform int lightAmount; 9 | uniform vec2 cameraPosition; 10 | uniform float cameraZoom; 11 | 12 | void main() 13 | { 14 | vec4 finalColor = vec4(0.0, 0.0, 0.0, 1.0); 15 | 16 | vec2 screenSize = vec2(1920, 1080); // Replace with your screen dimensions 17 | 18 | vec2 fragmentPosition = gl_FragCoord.xy; 19 | fragmentPosition.y = screenSize.y - fragmentPosition.y; // Flip the y-coordinate 20 | 21 | vec2 adjustedCameraPosition = cameraPosition / cameraZoom; // Adjusted camera position 22 | 23 | fragmentPosition += adjustedCameraPosition; 24 | 25 | for(int i = 0; i < lightAmount; i++) 26 | { 27 | vec2 lightPosition = (lightPositions[i] - adjustedCameraPosition) / cameraZoom; // Adjusted light position 28 | float lightRadius = lightRadii[i] / cameraZoom; 29 | float lightIntensity = lightIntensities[i]; 30 | vec3 lightColor = lightColors[i]; 31 | 32 | lightPosition += adjustedCameraPosition / cameraZoom; 33 | 34 | float distanceToLight = length(fragmentPosition - lightPosition); 35 | 36 | float intensity = 1.0 - smoothstep(0.0, lightRadius, distanceToLight); 37 | intensity *= lightIntensity; 38 | intensity = clamp(intensity, 0.0, 1.0); 39 | 40 | vec4 texColor = texture2D(texture, gl_TexCoord[0].xy); 41 | finalColor += texColor * vec4(lightColor, 1.0) * intensity; 42 | 43 | if (texColor.a > 0.9f) { 44 | finalColor += texColor * vec4(lightColor, 1.0) * intensity; 45 | } else { 46 | finalColor = texColor; 47 | } 48 | } 49 | 50 | gl_FragColor = finalColor; 51 | } -------------------------------------------------------------------------------- /Engine/Template/Engine/Ressources/Sprites/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Template/Engine/Ressources/Sprites/Default.png -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/Template/background.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Template/Engine/Saves/Template/background.txt -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/Template/camera.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Template/Engine/Saves/Template/camera.txt -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/Template/sprites.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Template/Engine/Saves/Template/sprites.txt -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/enginepath.txt: -------------------------------------------------------------------------------- 1 | C:\Dev\SpriteEngineUI\Engine 2 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/index.txt: -------------------------------------------------------------------------------- 1 | highestIndex 2 | 7392 3 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/scene 1/background.txt: -------------------------------------------------------------------------------- 1 | Red;Blue;Green 2 | 0.000000;0.000000;0.000000 3 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/scene 1/camera.txt: -------------------------------------------------------------------------------- 1 | TransformPoxX;TransformPosY;Zoom;Speed 2 | 107.968582;401.150116;2.349998;0.000000 3 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/scene 1/sprites.txt: -------------------------------------------------------------------------------- 1 | name;vecpos;transformPosX;transformPosY;ScaleX;ScaleY;rotation;filepath;boxColliderWidthLeftOrRightX;boxColliderWidthLeftOrRighY;boxColliderHeightUpOrDownX;boxColliderHeightUpOrDownY;boxColliderExists;solid;sortingLayer;gravity;mass;physicsBodyExists;id;parentId;nextPosX;nextPosY;lastPosX;lastPosY;listPos;highestChild;positionToParentX;positionToParentY;animatorExists;prefabExist;loadInMemory;pathToPrefab;tag;lightExist;lightRadius;lightIntensity;render 2 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/scenes.scn: -------------------------------------------------------------------------------- 1 | Scenes 2 | scene 1 3 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/tags.txt: -------------------------------------------------------------------------------- 1 | Tags 2 | none 3 | Floor 4 | Player 5 | Note-Main 6 | computer-teleport 7 | kanal-teleport 8 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Saves/verify.vsn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Engine/Template/Engine/Saves/verify.vsn -------------------------------------------------------------------------------- /Engine/Template/Engine/Source/Engine.cpp: -------------------------------------------------------------------------------- 1 | #include "Engine.h" 2 | 3 | // Ctor / Dtor 4 | 5 | spe::Engine::Engine() 6 | { 7 | this->m_Window = spe::GameWindow(spe::Vector2(1920, 1080), "Game"); 8 | 9 | this->Init(); 10 | 11 | this->m_Window.SetCamera(&this->m_Camera); 12 | this->m_Window.SetBackgroundColor(&this->m_BackgroundColor); 13 | 14 | this->m_Game.EngineConfig = spe::EngineConfig(&this->m_SceneHandler, &this->m_Camera, &this->m_BackgroundColor); 15 | 16 | spe::Input::SetEvent(&this->m_Window.Event); 17 | spe::Style::RenderStyle(); 18 | 19 | spe::GUI::SetCamera(&this->m_Camera); 20 | 21 | this->m_Game.Start(); 22 | } 23 | 24 | spe::Engine::~Engine() 25 | { 26 | spe::BoxCollider::DeleteCameraCollider(); 27 | this->m_SceneHandler.SpriteRepository.DeleteAll(); 28 | this->m_Window.Shutdown(); 29 | } 30 | 31 | void spe::Engine::Init() 32 | { 33 | const std::string path = spe::Utility::GetDefaultDir(1); 34 | spe::Log::LogString(path); 35 | spe::Utility::SetCurrentDir(path); 36 | 37 | this->m_SceneHandler.Init("Engine\\Ressources\\Shaders\\circulaer_gradient.frag"); 38 | 39 | spe::Initializer::InitTags(this->m_SceneHandler.SpriteRepository, PATH_TO_TAG_FILE); 40 | spe::Initializer::InitScenes(this->m_SceneHandler, PATH_TO_SCENE_FILE); 41 | spe::Initializer::IntiHighestSpriteID(this->m_SceneHandler.SpriteRepository, PATH_TO_HIGHEST_INDEX); 42 | 43 | spe::PrefabRepository::LoadPrefabsInMemory(this->m_SceneHandler.LightRepository); 44 | 45 | this->m_SceneHandler.LoadScene(this->m_SceneHandler.TotalScenes[0], this->m_Camera, this->m_BackgroundColor); 46 | 47 | spe::BoxCollider::InitCameraCollider(this->m_SceneHandler.LightRepository); 48 | // this->m_Camera.reset(); 49 | } 50 | 51 | // Private 52 | 53 | void spe::Engine::UpdateComponents() 54 | { 55 | this->m_Window.PollEvents(); 56 | 57 | // Updating the user here 58 | ImGui::Begin("##MainWindow", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove); 59 | this->m_Game.Update(); 60 | 61 | ImGui::SetWindowSize(ImVec2(1920, 1080)); 62 | ImGui::SetWindowPos(ImVec2(0, 0)); 63 | ImGui::SetWindowFontScale(spe::Style::s_DefaultFontSize + 0.5f); 64 | ImGui::End(); 65 | 66 | std::list& sprites = this->m_SceneHandler.SpriteRepository.GetSprites(); 67 | 68 | this->m_Window.Clear(); 69 | 70 | for (auto it = sprites.begin(); it != sprites.end(); ++it) 71 | { 72 | spe::Sprite* sprite = *it; 73 | 74 | if (!spe::BoxCollider::ProcessSprite(sprite, this->m_Camera)) 75 | { 76 | sprite->Process = false; 77 | continue; 78 | } 79 | sprite->Process = true; 80 | 81 | this->m_SceneHandler.LightRepository.UpdateLightSource(sprite, &this->m_Camera); 82 | 83 | sprite->Animator.Update(); 84 | sprite->Collider.Update(this->m_SceneHandler.SpriteRepository); 85 | sprite->Physicsbody.Update(); 86 | 87 | this->m_Window.DrawGame(sprite, &this->m_SceneHandler.LightRepository.GetShader(), false); 88 | } 89 | this->m_SceneHandler.LightRepository.UpdateArrays(); 90 | 91 | this->m_Window.Display(); 92 | } 93 | 94 | 95 | // Public 96 | 97 | void spe::Engine::Update() 98 | { 99 | spe::Time::Update(); 100 | if (spe::Time::s_TimePassed <= 1.0f) 101 | { 102 | return; 103 | } 104 | this->UpdateComponents(); 105 | this->m_Camera.Update(&this->m_SceneHandler.LightRepository); 106 | } -------------------------------------------------------------------------------- /Engine/Template/Engine/Source/Engine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Core/GameWindow.h" 6 | #include "RessourceHandler/Initializer.h" 7 | #include "Core/IApplication.h" 8 | #include "Core/SeceneHandler.h" 9 | #include "Utility/Style.h" 10 | #include "PrefabRepository/PrefabRepository.h" 11 | 12 | #include "Scripts/Game.h" 13 | 14 | namespace spe 15 | { 16 | class Engine : public spe::IAppliaction 17 | { 18 | private: 19 | // 1 Instance of the user game class 20 | Game m_Game; 21 | 22 | spe::GameWindow m_Window; 23 | spe::Camera m_Camera; 24 | spe::Vector3 m_BackgroundColor; 25 | 26 | spe::SceneHandler m_SceneHandler; 27 | 28 | void UpdateComponents() override; 29 | 30 | void Init() override; 31 | 32 | public: 33 | Engine(); 34 | ~Engine(); 35 | 36 | void Update() override; 37 | bool IsOpen() const { return this->m_Window.IsOpen(); } 38 | }; 39 | } -------------------------------------------------------------------------------- /Engine/Template/Engine/Source/EngineConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/SeceneHandler.h" 4 | 5 | namespace spe 6 | { 7 | struct EngineConfig 8 | { 9 | spe::SceneHandler* ptr_SceneHandler; 10 | spe::Camera* ptr_Camera; 11 | spe::Vector3* ptr_BackgroundColor; 12 | spe::SpriteRepository* ptr_Sprites; 13 | bool ReloadSortingLayersOnSceneSwap; 14 | 15 | EngineConfig() = default; 16 | 17 | EngineConfig(spe::SceneHandler* sceneHandler, spe::Camera* camera, spe::Vector3* backgroundColor) 18 | : ptr_SceneHandler(sceneHandler), ptr_Camera(camera), ptr_BackgroundColor(backgroundColor), ReloadSortingLayersOnSceneSwap(false) 19 | { 20 | this->ptr_Sprites = &this->ptr_SceneHandler->SpriteRepository; 21 | } 22 | 23 | void DontDeleteOnSceneSwap(spe::Sprite* spr) 24 | { 25 | spr->DontDeleteOnSceneSwap = true; 26 | this->ReloadSortingLayersOnSceneSwap = true; 27 | 28 | for (size_t i = 0; i < spr->ptr_Childs.size(); i++) 29 | { 30 | this->DontDeleteOnSceneSwap(spr->ptr_Childs[i]); 31 | } 32 | } 33 | 34 | void LoadScene(const std::string& scene) 35 | { 36 | this->ptr_SceneHandler->LoadScene(scene, *this->ptr_Camera, *this->ptr_BackgroundColor); 37 | if (this->ReloadSortingLayersOnSceneSwap) 38 | { 39 | this->ptr_Sprites->SortSpritesByLayer(); 40 | } 41 | } 42 | }; 43 | } -------------------------------------------------------------------------------- /Engine/Template/Engine/Source/IScript.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace spe 4 | { 5 | class IScript 6 | { 7 | public: 8 | 9 | // Do not declare them as pure virtual because maybe user wants to pass a reference 10 | virtual void Update() { }; 11 | virtual void Start() { }; 12 | }; 13 | } -------------------------------------------------------------------------------- /Engine/Template/Engine/Source/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Engine.h" 4 | 5 | int main() 6 | { 7 | spe::Engine engine; 8 | while (engine.IsOpen()) 9 | { 10 | engine.Update(); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Engine/Template/Engine/Source/SpriteEngine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Includes general files for users 4 | 5 | // Info for naming convenction 6 | // D_MACRO -> D stands for DEFAULT_ 7 | 8 | #define UI spe::GUI 9 | 10 | // Game 11 | #include "Sprite/Sprite.h" 12 | #include "IScript.h" 13 | #include "EngineConfig.h" 14 | #include "Physics/Physics.h" 15 | #include "GUI/GUI.h" 16 | #include "PrefabRepository/PrefabRepository.h" 17 | 18 | // Core 19 | #include "Input/Input.h" 20 | -------------------------------------------------------------------------------- /Engine/Template/RUNME.sh: -------------------------------------------------------------------------------- 1 | mkdir Build -------------------------------------------------------------------------------- /Engine/Template/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Debug##Default] 2 | Pos=60,60 3 | Size=400,400 4 | 5 | [Window][user-window] 6 | Pos=60,60 7 | Size=180,146 8 | 9 | [Window][##MainWindow] 10 | Pos=0,0 11 | Size=1920,1080 12 | 13 | [Window][##window] 14 | Pos=960,340 15 | Size=200,500 16 | 17 | -------------------------------------------------------------------------------- /Engine/ThirdParty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ThirdParty/CMakeLists.txt 2 | 3 | file(GLOB IMGUI_SOURCES 4 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/*.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/*.cpp 6 | ) 7 | 8 | file(GLOB IMGUI_SFML_SOURCES 9 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui-sfml/*.h 10 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui-sfml/*.cpp 11 | ) 12 | 13 | file(GLOB UTILITY_SOURCES 14 | ${CMAKE_CURRENT_SOURCE_DIR}/utility/dirent.h 15 | ${CMAKE_CURRENT_SOURCE_DIR}/utility/icons.h 16 | ${CMAKE_CURRENT_SOURCE_DIR}/utility/UtilityFunctions.cpp 17 | ${CMAKE_CURRENT_SOURCE_DIR}/utility/UtilityFunctions.h 18 | ) 19 | 20 | 21 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${IMGUI_SOURCES}) 22 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${IMGUI_SFML_SOURCES}) 23 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${UTILITY_SOURCES}) 24 | 25 | add_library(imgui STATIC ${IMGUI_SOURCES}) 26 | add_library(imgui_sfml STATIC ${IMGUI_SFML_SOURCES}) 27 | add_library(utility STATIC ${UTILITY_SOURCES}) 28 | 29 | set_target_properties(imgui PROPERTIES FOLDER "ThirdParty") 30 | set_target_properties(imgui_sfml PROPERTIES FOLDER "ThirdParty") 31 | set_target_properties(utility PROPERTIES FOLDER "ThirdParty") 32 | 33 | # SFML 34 | add_subdirectory(sfml) 35 | 36 | set_target_properties(sfml-window PROPERTIES FOLDER "ThirdParty/SFML") 37 | set_target_properties(sfml-audio PROPERTIES FOLDER "ThirdParty/SFML") 38 | set_target_properties(sfml-graphics PROPERTIES FOLDER "ThirdParty/SFML") 39 | set_target_properties(sfml-main PROPERTIES FOLDER "ThirdParty/SFML") 40 | set_target_properties(sfml-network PROPERTIES FOLDER "ThirdParty/SFML") 41 | set_target_properties(sfml-system PROPERTIES FOLDER "ThirdParty/SFML") 42 | 43 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/imgui") 44 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/imgui-sfml") 45 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/sfml/include") 46 | 47 | if(MSVC) 48 | target_compile_options(imgui PUBLIC /W4) 49 | target_compile_options(imgui_sfml PUBLIC /W4) 50 | target_compile_options(utility PUBLIC /W4) 51 | add_compile_options(/MP) 52 | endif() -------------------------------------------------------------------------------- /Engine/ThirdParty/utility/UtilityFunctions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace spe 11 | { 12 | class Utility 13 | { 14 | public: 15 | Utility() = delete; 16 | 17 | static std::string BoolToStr(bool b); 18 | static void CreateFileWithContent(const std::string& content, const std::string& pathAndName); 19 | 20 | static bool Contains(const std::string& str, const std::vector& arr); 21 | static std::string VectorToString(const std::vector& vec, char del, const std::string& ext); 22 | static std::string RenamePartOnPath(const std::string& path, const std::string& new_name, char del, const std::string& ext, uint32_t pos); 23 | static void SetCurrentDir(const std::string& path); 24 | static std::string getUserProjectPathSeperatetFromEnginePath(const std::string& path, const std::string& nameOFUsr); 25 | static std::vector Split(const std::string& s, char delim); 26 | static void WriteFile(const std::string& name, const std::string& path); 27 | 28 | static std::string GetFileExtension(const std::string& file); 29 | static std::string GetNamePathSplit(std::string path); 30 | static void Delete(const std::string& path); 31 | 32 | static std::string RunCommand(const char* commad); 33 | 34 | /// 35 | /// Should only be used 1 time. 36 | /// 37 | static std::string GetDefaultDir(uint32_t depth); 38 | 39 | static std::string GetCurrentDir(); 40 | 41 | static bool IsStringValid(const std::string& path); 42 | 43 | static bool IsFolder(const std::string& path); 44 | 45 | static std::string RemoveExtension(const std::string& file); 46 | 47 | static std::string CopyDir(const std::string& inputDir, const std::string& outputdir, const std::string& name); 48 | 49 | static void GetFilePathWithExtensionInFolder(const std::filesystem::path& path, const std::string& extension, std::vector& to); 50 | }; 51 | } -------------------------------------------------------------------------------- /Engine/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Debug##Default] 2 | Pos=60,60 3 | Size=400,400 4 | Collapsed=0 5 | 6 | [Window][UIHierarchy] 7 | Pos=60,60 8 | Size=550,482 9 | Collapsed=0 10 | 11 | [Window][##ui-hierarchy] 12 | Pos=60,60 13 | Size=300,730 14 | Collapsed=0 15 | 16 | -------------------------------------------------------------------------------- /Github/Game.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Github/Game.PNG -------------------------------------------------------------------------------- /Github/repoplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkatsanis/SpriteEngineUI/b1740295e99594b1f23d784b45e79ab21d6d0827/Github/repoplan.png -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Jannis Katsanis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /RUNME.sh: -------------------------------------------------------------------------------- 1 | git submodule update --init --recursive 2 | 3 | cd Engine/ThirdParty/sfml 4 | git checkout 2.6.0 5 | cd ../../../ 6 | 7 | mkdir -p Engine/Build 8 | mkdir -p Engine/Template/Build 9 | cd Engine/Scripts 10 | ./Setup.sh --------------------------------------------------------------------------------