mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-29 04:42:18 -05:00
LUS Cleanup: GameOverlay and moves various GUI related files to it's own filter.
This commit is contained in:
parent
2d60c772bf
commit
8431cddb14
@ -10,7 +10,8 @@
|
||||
#include "Lib/ImGui/imgui_internal.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
void Ship::GameOverlay::LoadFont(const std::string& name, const std::string& path, float fontSize) {
|
||||
namespace Ship {
|
||||
void GameOverlay::LoadFont(const std::string& name, const std::string& path, float fontSize) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
std::shared_ptr<Archive> base = GlobalCtx2::GetInstance()->GetResourceManager()->GetArchive();
|
||||
std::shared_ptr<File> font = std::make_shared<File>();
|
||||
@ -22,7 +23,7 @@ void Ship::GameOverlay::LoadFont(const std::string& name, const std::string& pat
|
||||
}
|
||||
}
|
||||
|
||||
void Ship::GameOverlay::TextDraw(float x, float y, bool shadow, ImVec4 color, const char* fmt, ...) {
|
||||
void GameOverlay::TextDraw(float x, float y, bool shadow, ImVec4 color, const char* fmt, ...) {
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
@ -44,7 +45,7 @@ void Ship::GameOverlay::TextDraw(float x, float y, bool shadow, ImVec4 color, co
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
void Ship::GameOverlay::TextDrawNotification(float duration, bool shadow, const char* fmt, ...) {
|
||||
void GameOverlay::TextDrawNotification(float duration, bool shadow, const char* fmt, ...) {
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
@ -55,33 +56,34 @@ void Ship::GameOverlay::TextDrawNotification(float duration, bool shadow, const
|
||||
NeedsCleanup = true;
|
||||
}
|
||||
|
||||
void Ship::GameOverlay::CleanupNotifications() {
|
||||
void GameOverlay::CleanupNotifications() {
|
||||
if (!NeedsCleanup) return;
|
||||
for (auto it = this->RegisteredOverlays.begin(); it != this->RegisteredOverlays.end(); ) {
|
||||
if (it->second->type == OverlayType::NOTIFICATION && it->second->duration <= 0.0f) {
|
||||
it = this->RegisteredOverlays.erase(it);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
NeedsCleanup = false;
|
||||
}
|
||||
|
||||
float Ship::GameOverlay::GetScreenWidth() {
|
||||
float GameOverlay::GetScreenWidth() {
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
return viewport->Size.x;
|
||||
}
|
||||
|
||||
float Ship::GameOverlay::GetScreenHeight() {
|
||||
float GameOverlay::GetScreenHeight() {
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
return viewport->Size.y;
|
||||
}
|
||||
|
||||
float Ship::GameOverlay::GetStringWidth(const char* text) {
|
||||
float GameOverlay::GetStringWidth(const char* text) {
|
||||
return CalculateTextSize(text).x;
|
||||
}
|
||||
|
||||
ImVec2 Ship::GameOverlay::CalculateTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) {
|
||||
ImVec2 GameOverlay::CalculateTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) {
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
const char* text_display_end;
|
||||
@ -108,7 +110,7 @@ ImVec2 Ship::GameOverlay::CalculateTextSize(const char* text, const char* text_e
|
||||
return text_size;
|
||||
}
|
||||
|
||||
void Ship::GameOverlay::Init() {
|
||||
void GameOverlay::Init() {
|
||||
this->LoadFont("Press Start 2P", "assets/ship_of_harkinian/fonts/PressStart2P-Regular.ttf", 12.0f);
|
||||
this->LoadFont("Fipps", "assets/ship_of_harkinian/fonts/Fipps-Regular.otf", 32.0f);
|
||||
const std::string DefaultFont = this->Fonts.begin()->first;
|
||||
@ -125,7 +127,7 @@ void Ship::GameOverlay::Init() {
|
||||
SohImGui::console->Commands["overlay"] = { OverlayCommand, "Draw an overlay using a cvar value" };
|
||||
}
|
||||
|
||||
void Ship::GameOverlay::DrawSettings() {
|
||||
void GameOverlay::DrawSettings() {
|
||||
ImGui::Text("Overlays Text Font");
|
||||
if (ImGui::BeginCombo("##TextFont", this->CurrentFont.c_str())) {
|
||||
for (auto& [name, font] : this->Fonts) {
|
||||
@ -141,7 +143,7 @@ void Ship::GameOverlay::DrawSettings() {
|
||||
}
|
||||
|
||||
|
||||
void Ship::GameOverlay::Draw() {
|
||||
void GameOverlay::Draw() {
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
|
||||
ImGui::SetNextWindowPos(viewport->Pos, ImGuiCond_Always);
|
||||
@ -197,7 +199,7 @@ void Ship::GameOverlay::Draw() {
|
||||
}
|
||||
|
||||
|
||||
bool Ship::OverlayCommand(const std::vector<std::string>& args) {
|
||||
bool OverlayCommand(const std::vector<std::string>& args) {
|
||||
if (args.size() < 3) {
|
||||
return CMD_FAILED;
|
||||
}
|
||||
@ -209,20 +211,25 @@ bool Ship::OverlayCommand(const std::vector<std::string>& args) {
|
||||
if (!overlay->RegisteredOverlays.contains(key)) {
|
||||
overlay->RegisteredOverlays[key] = new Overlay({ OverlayType::TEXT, ImStrdup(key), -1.0f });
|
||||
INFO("Added overlay: %s ", key);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ERROR("Overlay already exists: %s", key);
|
||||
}
|
||||
} else if (args[1] == "remove") {
|
||||
}
|
||||
else if (args[1] == "remove") {
|
||||
if (overlay->RegisteredOverlays.contains(key)) {
|
||||
overlay->RegisteredOverlays.erase(key);
|
||||
INFO("Removed overlay: %s ", key);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ERROR("Overlay not found: %s ", key);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ERROR("CVar %s does not exist", args[2].c_str());
|
||||
}
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,10 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Lib/ImGui/imgui.h"
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Ship {
|
||||
|
||||
enum class OverlayType {
|
||||
TEXT, IMAGE, NOTIFICATION
|
||||
};
|
||||
@ -17,7 +18,6 @@ struct Overlay {
|
||||
float duration;
|
||||
};
|
||||
|
||||
namespace Ship {
|
||||
class GameOverlay {
|
||||
public:
|
||||
std::unordered_map<std::string, Overlay*> RegisteredOverlays;
|
||||
|
@ -82,9 +82,6 @@
|
||||
<Filter Include="Source Files\Logging">
|
||||
<UniqueIdentifier>{bd6557f1-9480-413b-b0cd-843f8efc1939}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CustomImpl\Overlay">
|
||||
<UniqueIdentifier>{3285ab8a-06d8-4dac-9af9-efb2a9723ab1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Lib\dr_libs">
|
||||
<UniqueIdentifier>{db6e02cc-fc4c-4138-8219-1d281ad93ec2}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@ -97,6 +94,9 @@
|
||||
<Filter Include="Source Files\Controller\InputEditor">
|
||||
<UniqueIdentifier>{010dc29b-d1f6-4793-a4e7-4156aa4fcdd6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\GUI">
|
||||
<UniqueIdentifier>{5d68254f-662d-4e8c-a57f-de0d8e1d4a58}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Factories\MaterialFactory.cpp">
|
||||
@ -300,12 +300,6 @@
|
||||
<ClCompile Include="Lib\ImGui\backends\imgui_impl_sdl.cpp">
|
||||
<Filter>Source Files\Lib\ImGui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ImGuiImpl.cpp">
|
||||
<Filter>Source Files\CustomImpl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Console.cpp">
|
||||
<Filter>Source Files\CustomImpl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Lib\ImGui\backends\imgui_impl_dx11.cpp">
|
||||
<Filter>Source Files\Lib\ImGui</Filter>
|
||||
</ClCompile>
|
||||
@ -342,9 +336,6 @@
|
||||
<ClCompile Include="GameSettings.cpp">
|
||||
<Filter>Source Files\CustomImpl</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GameOverlay.cpp">
|
||||
<Filter>Source Files\CustomImpl\Overlay</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Audio.cpp">
|
||||
<Filter>Source Files\Resources\Files</Filter>
|
||||
</ClCompile>
|
||||
@ -360,6 +351,15 @@
|
||||
<ClCompile Include="Lib\Mercury\Mercury.cpp">
|
||||
<Filter>Source Files\Lib\Mercury</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Console.cpp">
|
||||
<Filter>Source Files\GUI</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GameOverlay.cpp">
|
||||
<Filter>Source Files\GUI</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ImGuiImpl.cpp">
|
||||
<Filter>Source Files\GUI</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Lib\tinyxml2\tinyxml2.h">
|
||||
@ -587,12 +587,6 @@
|
||||
<ClInclude Include="Lib\ImGui\backends\imgui_impl_sdl.h">
|
||||
<Filter>Source Files\Lib\ImGui</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ImGuiImpl.h">
|
||||
<Filter>Source Files\CustomImpl</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Console.h">
|
||||
<Filter>Source Files\CustomImpl</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Lib\ImGui\backends\imgui_impl_dx11.h">
|
||||
<Filter>Source Files\Lib\ImGui</Filter>
|
||||
</ClInclude>
|
||||
@ -647,9 +641,6 @@
|
||||
<ClInclude Include="color.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameOverlay.h">
|
||||
<Filter>Source Files\CustomImpl\Overlay</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Audio.h">
|
||||
<Filter>Header Files\Resources\Files</Filter>
|
||||
</ClInclude>
|
||||
@ -677,5 +668,14 @@
|
||||
<ClInclude Include="VirtualController.h">
|
||||
<Filter>Source Files\Controller</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Console.h">
|
||||
<Filter>Source Files\GUI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameOverlay.h">
|
||||
<Filter>Source Files\GUI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ImGuiImpl.h">
|
||||
<Filter>Source Files\GUI</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user