Skip to content

Commit

Permalink
Update imgui, hook, ui, mouse fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Dec 2, 2021
1 parent 4abdd29 commit e3f7089
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Debug.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off
premake5.exe vs2022
cd build
call "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat"
call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
MsBuild MapEditorSA.sln /property:Configuration=Debug
cd ..
2 changes: 1 addition & 1 deletion Release.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off
premake5.exe vs2022
cd build
call "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat"
call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
MsBuild MapEditorSA.sln /property:Configuration=Release
cd ..
117 changes: 55 additions & 62 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,73 +99,66 @@ void Editor::ApplyStyle()
ImGuiStyle* style = &ImGui::GetStyle();
ImVec4* colors = style->Colors;

style->WindowRounding = 1;
style->ScrollbarRounding = 1;
style->GrabRounding = 1;
style->WindowRounding = 1;
style->ChildRounding = 1;
style->ScrollbarRounding = 1;
style->GrabRounding = 1;
style->FrameRounding = 0;
style->TabRounding = 1.0;
style->AntiAliasedLines = true;
style->AntiAliasedFill = true;
style->Alpha = 1;
style->WindowTitleAlign = ImVec2(0.5f, 0.5f);
style->WindowPadding = ImVec2(8, 8);
style->WindowRounding = 5.0f;
style->FramePadding = ImVec2(8, 8);
style->FrameRounding = 5.0f;
style->PopupRounding = 5.0f;
style->ItemSpacing = ImVec2(7, 7);
style->ItemInnerSpacing = ImVec2(7, 7);
style->IndentSpacing = 25.0f;
style->ScrollbarSize = 12.0f;
style->ScrollbarRounding = 10.0f;
style->GrabMinSize = 5.0f;
style->GrabRounding = 3.0f;

style->FrameBorderSize = 0;
style->ChildBorderSize = 0;
style->TabBorderSize = 0;
style->WindowBorderSize = 0;
style->FrameBorderSize = 0;
style->TabBorderSize = 0;
style->PopupBorderSize = 0;

colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.29f, 0.48f, 0.54f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.29f, 0.48f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.0f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.35f, 0.58f, 0.86f);
colors[ImGuiCol_TabHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.41f, 0.68f, 1.00f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.07f, 0.10f, 0.15f, 0.97f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.26f, 0.42f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
style->Colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f);
style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.35f, 0.33f, 0.3f, 1.00f);
style->Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.05f, 0.06f, 0.95f);
style->Colors[ImGuiCol_ChildBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
style->Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 0.95f);
style->Colors[ImGuiCol_Border] = ImVec4(0.12f, 0.12f, 0.12f, 1.0f);
style->Colors[ImGuiCol_BorderShadow] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_FrameBg] = ImVec4(0.12f, 0.12f, 0.12f, 0.95f);
style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
style->Colors[ImGuiCol_FrameBgActive] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style->Colors[ImGuiCol_TitleBg] = ImVec4(0.12f, 0.12f, 0.12f, 0.94f);
style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f);
style->Colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
style->Colors[ImGuiCol_MenuBarBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.8f, 0.8f, 0.8f, 0.3f);
style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.5f, 0.5f, 0.5f, 0.3f);
style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.2f, 0.2f, 0.2f, 1.00f);
style->Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
style->Colors[ImGuiCol_SliderGrab] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_Separator] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style->Colors[ImGuiCol_Button] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style->Colors[ImGuiCol_ButtonHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
style->Colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_Tab] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style->Colors[ImGuiCol_TabHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
style->Colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_Header] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
style->Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.12f, 0.12f, 0.12f, 0.00f);
style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
style->Colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.6f);
}

void Editor::CheckForUpdate()
Expand Down
174 changes: 87 additions & 87 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ void Interface::ImportMenu()
if (std::filesystem::exists(path))
{
ImGui::Spacing();
ImGui::Text("Notes,");
ImGui::TextWrapped("Files are imported from '(game dir)/MapEditor' directory");
ImGui::TextWrapped("Imported objects will be merged with current ones!");
ImGui::TextWrapped("Use a limit adjuster if you're going to load a lot of objects!");
ImGui::Text("Info,");
ImGui::TextWrapped("- Place ipl files in 'MapEditor' directory");
ImGui::TextWrapped("- Use limit adjuster if you're gonna load a lot of objects!");
ImGui::Spacing();
ImGui::TextWrapped("You game may freeze while loading!");
ImGui::Dummy(ImVec2(0, 20));
static std::string selectedFileName = "";
Expand All @@ -71,7 +71,7 @@ void Interface::ImportMenu()
m_bShowPopup = false;
}
ImGui::SameLine();
if (ImGui::Button("Clear objects", Utils::GetSize(2)))
if (ImGui::Button("Clear placed objects", Utils::GetSize(2)))
{
for (auto &pObj : ObjManager::m_pVecEntities)
{
Expand Down Expand Up @@ -179,7 +179,7 @@ void Interface::QuickObjectCreateMenu()
{
static int modelId = DEFAULT_MODEL_ID;
static std::string modelName = ObjManager::FindNameFromModel(modelId);

ImGui::Text("Name: %s", modelName.c_str());
if (ImGui::InputInt("Model", &modelId))
{
Expand Down Expand Up @@ -513,6 +513,34 @@ void Interface::DrawMainMenuBar()
patch::SetFloat(0x8A5B20, 1.0f);
}
}
if (ImGui::BeginMenu("Weather"))
{
if (ImGui::MenuItem("Foggy"))
{
Call<0x438F80>();
}
if (ImGui::MenuItem("Overcast"))
{
Call<0x438F60>();
}
if (ImGui::MenuItem("Rainy"))
{
Call<0x438F70>();
}
if (ImGui::MenuItem("Sandstorm"))
{
Call<0x439590>();
}
if (ImGui::MenuItem("Thunderstorm"))
{
Call<0x439570>();
}
if (ImGui::MenuItem("Very sunny"))
{
Call<0x438F50>();
}
ImGui::EndMenu();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View"))
Expand Down Expand Up @@ -562,40 +590,6 @@ void Interface::DrawMainMenuBar()
}
}

void Interface::PrintObjInfo(CEntity *pEntity)
{
int model = pEntity->m_nModelIndex;
ImGui::Text("Model: %d", model);

switch(pEntity->m_nType)
{
case ENTITY_TYPE_OBJECT:
ImGui::Text("Type: Object");
break;
case ENTITY_TYPE_BUILDING:
ImGui::Text("Type: Building");
break;
default:
ImGui::Text("Type: Unknown");
}

if (pEntity->m_nType == ENTITY_TYPE_OBJECT
|| pEntity->m_nType == ENTITY_TYPE_BUILDING)
{
static int bmodel = 0;
static std::string name = "";

// lets not go over 20000 models each frame
if (bmodel != model)
{
name = ObjManager::FindNameFromModel(model);
bmodel = model;
}

ImGui::Text("Name: %s", name.c_str());
}
}

void Interface::DrawInfoMenu()
{
if (!m_bShowInfoMenu)
Expand Down Expand Up @@ -632,16 +626,45 @@ void Interface::DrawInfoMenu()
ImGui::Text("Object selection");
ImGui::Separator();
ImGui::Spacing();
if (m_bAutoSnapToGround)
{
ImGui::Text("Auto snap is enabled.");
}
ImGui::Spacing();

int hObj = CPools::GetObjectRef(ObjManager::m_pSelected);
CVector *objPos = &ObjManager::m_pSelected->GetPosition();
auto &data = ObjManager::m_objData.Get(ObjManager::m_pSelected);
PrintObjInfo(ObjManager::m_pSelected);
int model = ObjManager::m_pSelected->m_nModelIndex;
if (ObjManager::m_pSelected->m_nType == ENTITY_TYPE_OBJECT
|| ObjManager::m_pSelected->m_nType == ENTITY_TYPE_BUILDING)
{
static int bmodel = 0;
static std::string name = "";

// lets not go over 20000 models each frame
if (bmodel != model)
{
name = ObjManager::FindNameFromModel(model);
bmodel = model;
}

ImGui::Spacing();
ImGui::SameLine();
ImGui::Text("Name: %s", name.c_str());
}

ImGui::Columns(2, NULL, false);
ImGui::Text("Model: %d", model);
ImGui::NextColumn();
switch(ObjManager::m_pSelected->m_nType)
{
case ENTITY_TYPE_OBJECT:
ImGui::Text("Type: Dynamic");
break;
case ENTITY_TYPE_BUILDING:
ImGui::Text("Type: Static");
break;
default:
ImGui::Text("Type: Unknown");
}
ImGui::Columns(1);

ImGui::Spacing();
CVector rot = data.GetRotation();

Expand Down Expand Up @@ -734,46 +757,6 @@ void Interface::DrawInfoMenu()
}
ImGui::SliderInt("Move speed", &Viewport::m_nMul, 1, 10);
ImGui::Spacing();

// ---------------------------------------------------
// Weather
ImGui::Text("Weather");
ImGui::Separator();

if (ImGui::Button("Foggy", Utils::GetSize(3)))
{
Call<0x438F80>();
}

ImGui::SameLine();
if (ImGui::Button("Overcast", Utils::GetSize(3)))
{
Call<0x438F60>();
}

ImGui::SameLine();
if (ImGui::Button("Rainy", Utils::GetSize(3)))
{
Call<0x438F70>();
}

if (ImGui::Button("Sandstorm", Utils::GetSize(3)))
{
Call<0x439590>();
}

ImGui::SameLine();
if (ImGui::Button("Thunderstorm", Utils::GetSize(3)))
{
Call<0x439570>();
}

ImGui::SameLine();
if (ImGui::Button("Very sunny", Utils::GetSize(3)))
{
Call<0x438F50>();
}
ImGui::Spacing();

// ---------------------------------------------------
// Time
Expand Down Expand Up @@ -863,6 +846,10 @@ void Interface::DrawInfoMenu()
if (ObjManager::m_pVecEntities.size() < 500 || bShowAnyway)
{
filter.Draw("Search");
if (ImGui::IsItemActive())
{
m_bIsInputLocked = true;
}
ImGui::Spacing();
if (ImGui::BeginChild("Objects child"))
{
Expand All @@ -880,7 +867,20 @@ void Interface::DrawInfoMenu()

if (filter.PassFilter(buf) && ImGui::MenuItem(buf))
{
Viewport::SetCameraPosn(pObj->GetPosition());
// Setting the camera pos to bounding box
CMatrix *matrix = pObj->GetMatrix();
CColModel *pColModel = pObj->GetColModel();
CVector min = pColModel->m_boundBox.m_vecMin;
CVector max = pColModel->m_boundBox.m_vecMax;

CVector workVec = min;
workVec.x = max.x;
workVec.z = max.z;
CVector vec = *matrix * workVec;

// TODO: Rotate the camera to face the object

Viewport::SetCameraPosn(vec);
ObjManager::m_pSelected = pObj;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Interface
static void DrawPopupMenu();
static void ImportMenu();
static void ExportMenu();
static void PrintObjInfo(CEntity *pEntity);

// Custom popup menu codes
static void QuickObjectCreateMenu();
Expand Down
Loading

0 comments on commit e3f7089

Please sign in to comment.