Skip to content

Commit

Permalink
* Removed the "group" tab from the edit panel.
Browse files Browse the repository at this point in the history
* Removed "output" from the info panel.
* Moved "output" to below the viewport.
* Made the output resizable and collapsable.
* Added tabs to the output.
* "Reload" now works.
* Added stubs for needed menu items.
  • Loading branch information
luciusDXL committed Feb 20, 2024
1 parent 4143b27 commit 0f8dde0
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 38 deletions.
6 changes: 6 additions & 0 deletions TheForceEngine/Shaders/line2d.frag
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ void main()
float dFxy = 1.5 * max(dFx, dFy);
float alpha = smoothstep(0.0, -dFxy, dist-Frag_Width) * Frag_Color.a;

#ifdef OPT_DASHED_LINE
float L = length(t * dir);
float fade = smoothstep(0.45, 0.5, fract(L*0.1));
alpha *= fade;
#endif

Out_Color.rgb = Frag_Color.rgb * alpha;
Out_Color.a = alpha;

Expand Down
7 changes: 6 additions & 1 deletion TheForceEngine/Shaders/line3d.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ float distToLine(vec2 pt1, vec2 pt2, vec2 testPt)
void main()
{
float dist = distToLine(Frag_Uv.xy, Frag_Uv.zw, gl_FragCoord.xy);

float alpha = smoothstep(1.0, 0.0, dist*Frag_Width) * Frag_Color.a;

#ifdef OPT_DASHED_LINE
float L = length(gl_FragCoord.xy - Frag_Uv.xy);
alpha *= smoothstep(0.45, 0.5, fract(L*0.1));
#endif

Out_Color = vec4(Frag_Color.rgb * alpha, alpha);
}
141 changes: 114 additions & 27 deletions TheForceEngine/TFE_Editor/LevelEditor/infoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ namespace LevelEditor
{
TAB_INFO = 0,
TAB_ITEM,
TAB_GROUPS,
TAB_COUNT
};
const char* c_infoTabs[TAB_COUNT] = { "Info", "Item", "Groups" };
const char* c_infoTabs[TAB_COUNT] = { "Info", "Item" };
const char* c_infoToolTips[TAB_COUNT] =
{
"Level Info.\nManual grid height setting.\nMessage, warning, and error output.",
"Hovered or selected item property editor,\nblank when no item (sector, wall, object) is selected.",
"Editor groups, used to group sectors - \nwhich can be used to hide or lock them, \ncolor code them or set whether they are exported.",
};
const ImVec4 tabSelColor = { 0.25f, 0.75f, 1.0f, 1.0f };
const ImVec4 tabStdColor = { 1.0f, 1.0f, 1.0f, 0.5f };

struct LeMessage
{
Expand All @@ -47,18 +47,23 @@ namespace LevelEditor
};
static std::vector<LeMessage> s_outputMsg;
static u32 s_outputFilter = LFILTER_DEFAULT;
static s32 s_outputTabSel = 0;
static f32 s_infoWith;
static s32 s_infoHeight;
static Vec2f s_infoPos;
static InfoTab s_infoTab = TAB_INFO;

static s32 s_outputHeight = 26 * 5;
static s32 s_outputPrevHeight = 26 * 5;
static bool s_collapsed = false;

static Feature s_prevVertexFeature = {};
static Feature s_prevWallFeature = {};
static Feature s_prevSectorFeature = {};
static Feature s_prevObjectFeature = {};
static bool s_wallShownLast = false;
static s32 s_prevCategoryFlags = 0;

void infoPanelClearMessages()
{
s_outputMsg.clear();
Expand Down Expand Up @@ -162,6 +167,108 @@ namespace LevelEditor
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 4);
ImGui::Separator();
}

bool mouseInsideItem()
{
ImVec2 mousePos = ImGui::GetMousePos();
ImVec2 minCoord = ImGui::GetItemRectMin();
ImVec2 maxCoord = ImGui::GetItemRectMax();

return mousePos.x >= minCoord.x && mousePos.x < maxCoord.x && mousePos.y >= minCoord.y && mousePos.y < maxCoord.y;
}

s32 infoPanelOutput(s32 width)
{
s32 height = s_outputHeight;

DisplayInfo info;
TFE_RenderBackend::getDisplayInfo(&info);

ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoFocusOnAppearing;
ImGui::SetNextWindowPos({ 0.0f, f32(info.height - height + 1) });
ImGui::SetNextWindowSize({ f32(width), f32(height) });

ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImGui::GetStyleColorVec4(ImGuiCol_TitleBg));
if (ImGui::Begin("Output##MapInfo", nullptr, window_flags))
{
bool restoreHeight = s_collapsed;
s_collapsed = false;

const size_t count = s_outputMsg.size();
const LeMessage* msg = s_outputMsg.data();
const ImVec4 c_typeColor[] = { {1.0f, 1.0f, 1.0f, 0.7f}, {1.0f, 1.0f, 0.25f, 1.0f}, {1.0f, 0.25f, 0.25f, 1.0f} };

for (size_t i = 0; i < count; i++, msg++)
{
u32 typeFlag = 1 << msg->type;
if (!(typeFlag & s_outputFilter)) { continue; }

ImGui::TextColored(c_typeColor[msg->type], "%s", msg->msg.c_str());
}

if (restoreHeight)
{
s_outputHeight = s_outputPrevHeight;
}
else
{
s_outputPrevHeight = s_outputHeight;
s_outputHeight = max(26 * 3, (s32)ImGui::GetWindowSize().y);
}
}
else
{
s_outputHeight = 26;
s_collapsed = true;
}
ImGui::End();

if (!s_collapsed)
{
const bool mousePressed = TFE_Input::mousePressed(MBUTTON_LEFT);

ImGuiWindowFlags window_flags_tab = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_Tooltip;
ImGui::SetNextWindowPos({ 128.0f, f32(info.height - height + 1) });
if (ImGui::Begin("##MapInfoTab", nullptr, window_flags_tab))
{
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 4);
ImGui::PushStyleColor(ImGuiCol_Text, s_outputTabSel == 0 ? tabSelColor : tabStdColor);
ImGui::Text("All");
ImGui::PopStyleColor();
if (mouseInsideItem() && mousePressed)
{
s_outputTabSel = 0;
s_outputFilter = LFILTER_DEFAULT;
}

ImGui::SameLine(0.0f, 16.0f);
ImGui::PushStyleColor(ImGuiCol_Text, s_outputTabSel == 1 ? tabSelColor : tabStdColor);
ImGui::Text("Warnings");
ImGui::PopStyleColor();
if (mouseInsideItem() && mousePressed)
{
s_outputTabSel = 1;
s_outputFilter = LFILTER_WARNING;
}

ImGui::SameLine(0.0f, 16.0f);
ImGui::PushStyleColor(ImGuiCol_Text, s_outputTabSel == 2 ? tabSelColor : tabStdColor);
ImGui::Text("Errors");
ImGui::PopStyleColor();
if (mouseInsideItem() && mousePressed)
{
s_outputTabSel = 2;
s_outputFilter = LFILTER_ERROR;
}
}
ImGui::End();
}

ImGui::PopStyleColor();

return s_outputHeight;
}

void infoPanelMap()
{
Expand All @@ -181,31 +288,15 @@ namespace LevelEditor
ImGui::SameLine(128.0f);
ImGui::SetNextItemWidth(196.0f);
ImGui::InputFloat("##GridHeight", &s_gridHeight, 0.0f, 0.0f, "%0.2f", ImGuiInputTextFlags_CharsDecimal);
ImGui::Separator();

// Display messages here?
ImGui::CheckboxFlags("Info", &s_outputFilter, LFILTER_INFO); ImGui::SameLine(0.0f, 32.0f);
ImGui::CheckboxFlags("Warnings", &s_outputFilter, LFILTER_WARNING); ImGui::SameLine(0.0f, 32.0f);
ImGui::CheckboxFlags("Errors", &s_outputFilter, LFILTER_ERROR);


ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoFocusOnAppearing;

ImVec2 pos = ImGui::GetCursorPos();
ImGui::SetNextWindowSize({ s_infoWith, s_infoHeight - pos.y });
ImGui::SetNextWindowPos({ s_infoPos.x, pos.y + s_infoPos.z });
ImGui::Begin("Output##MapInfo", nullptr, window_flags);
const size_t count = s_outputMsg.size();
const LeMessage* msg = s_outputMsg.data();
const ImVec4 c_typeColor[] = { {1.0f, 1.0f, 1.0f, 0.7f}, {1.0f, 1.0f, 0.25f, 1.0f}, {1.0f, 0.25f, 0.25f, 1.0f} };

for (size_t i = 0; i < count; i++, msg++)
{
u32 typeFlag = 1 << msg->type;
if (!(typeFlag & s_outputFilter)) { continue; }

ImGui::TextColored(c_typeColor[msg->type], "%s", msg->msg.c_str());
}
ImGui::Begin("Groups##MapInfo", nullptr, window_flags);
// TODO
ImGui::End();
}

Expand Down Expand Up @@ -1546,10 +1637,6 @@ namespace LevelEditor
{
infoPanelMap();
}
else if (s_infoTab == TAB_GROUPS && show)
{
// TODO
}
}
infoToolEnd();
}
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_Editor/LevelEditor/infoPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace LevelEditor
void infoPanelClearMessages();
void infoPanelAddMsg(LeMsgType type, const char* msg, ...);
void infoPanelSetMsgFilter(u32 filter=LFILTER_DEFAULT);
s32 infoPanelOutput(s32 width);

void infoPanelClearFeatures();
s32 infoPanelGetHeight();
Expand Down
59 changes: 50 additions & 9 deletions TheForceEngine/TFE_Editor/LevelEditor/levelEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ namespace LevelEditor
};
ContextMenu s_contextMenu = CONTEXTMENU_NONE;

static Asset* s_levelAsset = nullptr;
static WallMoveMode s_wallMoveMode = WMM_NORMAL;
static s32 s_outputHeight = 26*6;

// The TFE Level Editor format is different than the base format and contains extra
// metadata, etc.
Expand Down Expand Up @@ -280,6 +282,8 @@ namespace LevelEditor

bool init(Asset* asset)
{
s_levelAsset = asset;

// Reset output messages.
infoPanelClearMessages();
infoPanelSetMsgFilter();
Expand Down Expand Up @@ -4798,10 +4802,18 @@ namespace LevelEditor
{
saveLevel();
}
if (ImGui::MenuItem("Snapshot", "Ctrl+N", (bool*)NULL))
if (ImGui::MenuItem("Reload", "Ctrl+R", (bool*)NULL))
{
loadLevelFromAsset(s_levelAsset);
}
if (ImGui::MenuItem("Save Snapshot", "Ctrl+N", (bool*)NULL))
{
// Bring up a pop-up where the snapshot can be named.
}
if (ImGui::MenuItem("Load Snapshot", "Ctrl+L", (bool*)NULL))
{
// Bring up a pop-up where the desired named snapshot can be found.
}
if (!projectActive) { enableNextItem(); }

if (ImGui::MenuItem("Close", NULL, (bool*)NULL))
Expand All @@ -4810,6 +4822,35 @@ namespace LevelEditor
disableAssetEditor();
}
ImGui::Separator();
if (ImGui::MenuItem("Test Options", NULL, (bool*)NULL))
{
// TODO
}
ImGui::Separator();
if (ImGui::MenuItem("INF Items", NULL, (bool*)NULL))
{
// TODO
}
disableNextItem(); // TODO
if (ImGui::MenuItem("Goals", NULL, (bool*)NULL))
{
// TODO
}
if (ImGui::MenuItem("Mission Briefing", NULL, (bool*)NULL))
{
// TODO
}
enableNextItem(); // End TODO
ImGui::Separator();
if (ImGui::MenuItem("Find Sector", NULL, (bool*)NULL))
{
// TODO
}
if (ImGui::MenuItem("Find/Replace Texture", NULL, (bool*)NULL))
{
// TODO
}
ImGui::Separator();
// TODO: Add GOTO option (to go to a sector or other object).
if (ImGui::MenuItem("Undo", "Ctrl+Z", (bool*)NULL))
{
Expand Down Expand Up @@ -4941,12 +4982,6 @@ namespace LevelEditor
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("INF"))
{
// TODO

ImGui::EndMenu();
}

return menuActive;
}
Expand Down Expand Up @@ -5363,6 +5398,11 @@ namespace LevelEditor
}
}

void updateOutput()
{
s_outputHeight = infoPanelOutput(s_viewportSize.x + 16);
}

void update()
{
handleMouseClick();
Expand All @@ -5371,8 +5411,9 @@ namespace LevelEditor
updateContextWindow();
updateWindowControls();
handleHotkeys();
updateOutput();

viewport_update((s32)UI_SCALE(480) + 16, (s32)UI_SCALE(68) + 18);
viewport_update((s32)UI_SCALE(480) + 16, (s32)UI_SCALE(68) + 18 + s_outputHeight);
viewport_render(s_view);

// Toolbar
Expand Down Expand Up @@ -6689,7 +6730,7 @@ namespace LevelEditor

DisplayInfo displayInfo;
TFE_RenderBackend::getDisplayInfo(&displayInfo);
s_editWinSize = { (s32)displayInfo.width - (s32)UI_SCALE(480), (s32)displayInfo.height - (s32)UI_SCALE(68) };
s_editWinSize = { (s32)displayInfo.width - (s32)UI_SCALE(480), (s32)displayInfo.height - (s32)UI_SCALE(68) - s_outputHeight };

ImGui::SetWindowPos("LevelEditWin", { (f32)s_editWinPos.x, (f32)s_editWinPos.z });
ImGui::SetWindowSize("LevelEditWin", { (f32)s_editWinSize.x, (f32)s_editWinSize.z });
Expand Down
8 changes: 7 additions & 1 deletion TheForceEngine/TFE_RenderShared/lineDraw2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ namespace TFE_RenderShared
defines[0].value = "1";
defineCount++;
}

#if 0
// Dashed lines.
defines[defineCount].name = "OPT_DASHED_LINE";
defines[defineCount].value = "1";
defineCount++;
#endif

if (!s_shader.load("Shaders/line2d.vert", "Shaders/line2d.frag", defineCount, defines, SHADER_VER_STD))
{
return false;
Expand Down

0 comments on commit 0f8dde0

Please sign in to comment.