diff --git a/Editor/IconDefinitions.h b/Editor/IconDefinitions.h index 0122c3385..cd00f690b 100644 --- a/Editor/IconDefinitions.h +++ b/Editor/IconDefinitions.h @@ -106,4 +106,5 @@ #define ICON_EYE ICON_FA_EYE #define ICON_PROJECT_CREATE ICON_FA_FILE_EXPORT #define ICON_THEME_EDITOR ICON_FA_PEN_TO_SQUARE +#define ICON_REFRESH ICON_FA_ROTATE diff --git a/Editor/ProjectCreatorWindow.cpp b/Editor/ProjectCreatorWindow.cpp index 88cb6991f..4719b00d7 100644 --- a/Editor/ProjectCreatorWindow.cpp +++ b/Editor/ProjectCreatorWindow.cpp @@ -15,7 +15,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) infoLabel.Create("projectCreatorInfo"); infoLabel.SetFitTextEnabled(true); - infoLabel.SetText("Here you can create a new Wicked Engine application project. It will create a new folder with the project name, and set up an executable, lua script startup, custom icon, thumbnail and base colors."); + infoLabel.SetText("Here you can create a new Wicked Engine application project. It will create a new folder with the project name, and set up an executable, lua script startup, custom icon, thumbnail and base colors. Lua script will not be overwritten if it already exists in the destination folder with .lua."); AddWidget(&infoLabel); projectNameInput.Create("projectName"); @@ -24,6 +24,78 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) projectNameInput.SetCancelInputEnabled(false); AddWidget(&projectNameInput); + reloadButton.Create(ICON_FA_ROTATE); + reloadButton.SetTooltip("Reload last project"); + reloadButton.SetSize(XMFLOAT2(reloadButton.GetSize().y, reloadButton.GetSize().y)); + reloadButton.OnClick([this](wi::gui::EventArgs args) { + projectNameInput.SetText(editor->main->config.GetSection("project").GetText("name")); + iconFilename = editor->main->config.GetSection("project").GetText("icon"); + thumbnailFilename = editor->main->config.GetSection("project").GetText("thumbnail"); + splashScreenFilename = editor->main->config.GetSection("project").GetText("splash_screen"); + cursorFilename = editor->main->config.GetSection("project").GetText("cursor"); + hotspotX = editor->main->config.GetSection("project").GetFloat("cursor_hotspotX"); + hotspotY = editor->main->config.GetSection("project").GetFloat("cursor_hotspotY"); + fontColorPicker.SetPickColor(editor->main->config.GetSection("project").GetUint("font_color")); + backgroundColorPicker.SetPickColor(editor->main->config.GetSection("project").GetUint("background_color")); + + if (iconFilename.empty()) + { + iconResource = {}; + iconButton.SetImage(iconResource); + } + else + { + wi::Resource res = wi::resourcemanager::Load(iconFilename); + if (!res.IsValid()) + return; + iconResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 128, 128, true)); + iconButton.SetImage(iconResource); + } + + if (thumbnailFilename.empty()) + { + thumbnailResource = {}; + thumbnailButton.SetImage(thumbnailResource); + } + else + { + wi::Resource res = wi::resourcemanager::Load(thumbnailFilename); + if (!res.IsValid()) + return; + thumbnailResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 480, 270, true)); + thumbnailButton.SetImage(thumbnailResource); + } + + if (splashScreenFilename.empty()) + { + splashScreenResource = {}; + splashScreenButton.SetImage(splashScreenResource); + } + else + { + wi::Resource res = wi::resourcemanager::Load(splashScreenFilename); + if (!res.IsValid()) + return; + splashScreenResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 1280, 720, true)); + splashScreenButton.SetImage(splashScreenResource); + } + + if (cursorFilename.empty()) + { + cursorResource = {}; + cursorButton.SetImage(cursorResource); + } + else + { + wi::Resource res = wi::resourcemanager::Load(cursorFilename); + if (!res.IsValid()) + return; + cursorResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 64, 64, true)); + cursorButton.SetImage(cursorResource); + } + }); + AddWidget(&reloadButton); + iconButton.Create("projectIcon"); iconButton.SetText(""); iconButton.SetDescription("Icon: "); @@ -36,6 +108,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) { iconResource = {}; iconButton.SetImage(iconResource); + iconFilename = {}; } else { @@ -50,6 +123,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) return; iconResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 128, 128, true)); iconButton.SetImage(iconResource); + iconFilename = fileName; }); }); } @@ -68,6 +142,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) { thumbnailResource = {}; thumbnailButton.SetImage(thumbnailResource); + thumbnailFilename = {}; } else { @@ -82,6 +157,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) return; thumbnailResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 480, 270)); thumbnailButton.SetImage(thumbnailResource); + thumbnailFilename = fileName; }); }); } @@ -101,6 +177,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) splashScreenResource = {}; splashScreenResourceCroppedPreview = {}; splashScreenButton.SetImage(splashScreenResourceCroppedPreview); + splashScreenFilename = {}; } else { @@ -116,6 +193,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) splashScreenResource = res; splashScreenResourceCroppedPreview.SetTexture(editor->CreateThumbnail(splashScreenResource.GetTexture(), 1280, 720, true)); splashScreenButton.SetImage(splashScreenResourceCroppedPreview); + splashScreenFilename = fileName; }); }); } @@ -138,6 +216,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) { cursorResource = {}; cursorButton.SetImage(cursorResource); + cursorFilename = {}; } else { @@ -152,6 +231,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor) return; cursorResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 64, 64, true)); cursorButton.SetImage(cursorResource); + cursorFilename = fileName; }); }); } @@ -529,6 +609,18 @@ end) } } } + + editor->main->config.GetSection("project").Set("name", name); + editor->main->config.GetSection("project").Set("icon", iconFilename); + editor->main->config.GetSection("project").Set("thumbnail", thumbnailFilename); + editor->main->config.GetSection("project").Set("splash_screen", splashScreenFilename); + editor->main->config.GetSection("project").Set("cursor", cursorFilename); + editor->main->config.GetSection("project").Set("cursor_hotspotX", hotspotX); + editor->main->config.GetSection("project").Set("cursor_hotspotY", hotspotY); + editor->main->config.GetSection("project").Set("font_color", fontColorPicker.GetPickColor().rgba); + editor->main->config.GetSection("project").Set("background_color", backgroundColorPicker.GetPickColor().rgba); + editor->main->config.Commit(); + editor->RegisterRecentlyUsed(directory + scriptfilename); wi::helper::OpenUrl(directory); }); @@ -566,6 +658,10 @@ void ProjectCreatorWindow::ResizeLayout() layout.add_fullwidth(infoLabel); layout.add(projectNameInput); + projectNameInput.SetSize(XMFLOAT2(projectNameInput.GetSize().x - reloadButton.GetSize().x - layout.padding * 2, projectNameInput.GetSize().y)); + layout.y -= reloadButton.GetSize().y + reloadButton.GetShadowRadius() * 2 + layout.padding; + layout.add_right(reloadButton); + layout.jump(); layout.add_right(iconButton, thumbnailButton, splashScreenButton); diff --git a/Editor/ProjectCreatorWindow.h b/Editor/ProjectCreatorWindow.h index 6ae8e1880..6eda6adb2 100644 --- a/Editor/ProjectCreatorWindow.h +++ b/Editor/ProjectCreatorWindow.h @@ -10,6 +10,7 @@ public: wi::gui::Label infoLabel; wi::gui::TextInputField projectNameInput; + wi::gui::Button reloadButton; wi::gui::Button iconButton; wi::gui::Button thumbnailButton; wi::gui::Button splashScreenButton; @@ -29,6 +30,11 @@ public: wi::Resource splashScreenResourceCroppedPreview; wi::Resource cursorResource; + std::string iconFilename; + std::string thumbnailFilename; + std::string splashScreenFilename; + std::string cursorFilename; + float hotspotX = 0.5f; float hotspotY = 0.5f; diff --git a/WickedEngine/wiConfig.cpp b/WickedEngine/wiConfig.cpp index 729f0105b..e7de47b81 100644 --- a/WickedEngine/wiConfig.cpp +++ b/WickedEngine/wiConfig.cpp @@ -45,6 +45,23 @@ namespace wi::config } return std::stoi(it->second); } + uint32_t Section::GetUint(const char* name) const + { + auto it = values.find(name); + if (it == values.end()) + { + return 0u; + } + if (!it->second.compare("true")) + { + return 1u; + } + if (!it->second.compare("false")) + { + return 0u; + } + return (uint32_t)std::stoul(it->second); + } float Section::GetFloat(const char* name) const { auto it = values.find(name); @@ -80,6 +97,10 @@ namespace wi::config { values[name] = std::to_string(value); } + void Section::Set(const char* name, uint32_t value) + { + values[name] = std::to_string(value); + } void Section::Set(const char* name, float value) { values[name] = std::to_string(value); diff --git a/WickedEngine/wiConfig.h b/WickedEngine/wiConfig.h index f2d61f86c..62e4edaa4 100644 --- a/WickedEngine/wiConfig.h +++ b/WickedEngine/wiConfig.h @@ -20,12 +20,14 @@ namespace wi::config // Get the associated value for the key: bool GetBool(const char* name) const; int GetInt(const char* name) const; + uint32_t GetUint(const char* name) const; float GetFloat(const char* name) const; std::string GetText(const char* name) const; // Set the associated value for the key: void Set(const char* name, bool value); void Set(const char* name, int value); + void Set(const char* name, uint32_t value); void Set(const char* name, float value); void Set(const char* name, const char* value); void Set(const char* name, const std::string& value); diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index ad0fe2b85..95c5b9f5a 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -1790,7 +1790,7 @@ namespace wi::helper found = str.find_last_not_of(" /t"); if (found == std::string::npos) return str; - return str.substr(0, found + 1); + return str.substr(0, found + 2); } void DebugOut(const std::string& str, DebugLevel level) diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index ec5281e54..eb26c72d3 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 824; + const int revision = 825; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);