Skip to content

Commit 1ff0270

Browse files
committed
* Do not autosave when a popup is open.
* Do not update the editor when the window is minimized. * Do not update the viewport and hotkeys while a input UI element has focus.
1 parent 1e994f6 commit 1ff0270

File tree

12 files changed

+122
-27
lines changed

12 files changed

+122
-27
lines changed

TheForceEngine/TFE_Editor/LevelEditor/browser.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ namespace LevelEditor
6868
static u32 s_textureSourceFlags = 0xffffffffu;
6969
static u32 s_nextTextureSourceFlags = 0xffffffffu;
7070

71-
void browseTextures();
72-
void browseEntities();
71+
bool browseTextures();
72+
bool browseEntities();
7373
s32 getFilteredIndex(s32 unfilteredIndex);
7474
s32 getUnfilteredIndex(s32 filteredIndex);
7575
s32 getLevelTextureIndex(s32 id);
@@ -106,19 +106,23 @@ namespace LevelEditor
106106
ImGui::End();
107107
}
108108

109-
void drawBrowser(BrowseMode mode)
109+
bool drawBrowser(BrowseMode mode)
110110
{
111+
bool uiHasFocus = false;
112+
111113
browserBegin(infoPanelGetHeight());
112114
switch (mode)
113115
{
114116
case BROWSE_TEXTURE:
115-
browseTextures();
117+
uiHasFocus = browseTextures();
116118
break;
117119
case BROWSE_ENTITY:
118-
browseEntities();
120+
uiHasFocus = browseEntities();
119121
break;
120122
}
121123
browserEnd();
124+
125+
return uiHasFocus;
122126
}
123127

124128
bool textureSourcesUI()
@@ -356,8 +360,10 @@ namespace LevelEditor
356360
}
357361
}
358362

359-
void browseTextures()
363+
bool browseTextures()
360364
{
365+
bool uiHasFocus = false;
366+
361367
ImVec4 bgColor = { 0.0f, 0.0f, 0.0f, 0.0f };
362368
ImVec4 tintColorNrml = { 1.0f, 1.0f, 1.0f, 1.0f };
363369
ImVec4 tintColorSel = { 1.5f, 1.5f, 1.5f, 1.0f };
@@ -398,6 +404,7 @@ namespace LevelEditor
398404
{
399405
filterChanged = true;
400406
}
407+
uiHasFocus |= ImGui::IsItemActive();
401408
setTooltip("Filter textures by string");
402409
ImGui::SameLine();
403410
if (ImGui::Button("X##BrowserFilterClear"))
@@ -478,6 +485,7 @@ namespace LevelEditor
478485
}
479486
}
480487
ImGui::EndChild();
488+
return uiHasFocus;
481489
}
482490

483491
void updateEntityFilter()
@@ -495,8 +503,10 @@ namespace LevelEditor
495503
}
496504
}
497505

498-
void browseEntities()
506+
bool browseEntities()
499507
{
508+
bool uiHasFocus = false;
509+
500510
// Do sort stuff later....
501511
ImGui::Text("Category: ");
502512
ImGui::SameLine(0.0f, 8.0f);
@@ -598,5 +608,6 @@ namespace LevelEditor
598608
}
599609
}
600610
ImGui::EndChild();
611+
return uiHasFocus;
601612
}
602613
}

TheForceEngine/TFE_Editor/LevelEditor/browser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace LevelEditor
1717
};
1818

1919
void browserBegin(s32 offset);
20-
void drawBrowser(BrowseMode mode = BROWSE_TEXTURE);
20+
bool drawBrowser(BrowseMode mode = BROWSE_TEXTURE);
2121
void browserEnd();
2222
void browserScrollToSelection();
2323

TheForceEngine/TFE_Editor/LevelEditor/infoPanel.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace LevelEditor
8080
static Feature s_prevObjectFeature = {};
8181
static bool s_wallShownLast = false;
8282
static s32 s_prevCategoryFlags = 0;
83+
static bool s_textInputFocused = false;
8384

8485
static s32 s_groupOpen = -1;
8586
static s32 s_scrollToBottom = SCROLL_FALSE;
@@ -476,30 +477,39 @@ namespace LevelEditor
476477
const f32 iconBtnTint[] = { 103.0f / 255.0f, 122.0f / 255.0f, 139.0f / 255.0f, 1.0f };
477478
char name[64];
478479
strcpy(name, s_level.name.c_str());
479-
480+
480481
ImGui::Text("Level Name:"); ImGui::SameLine();
482+
481483
if (ImGui::InputText("##InputLevelName", name, 64))
482484
{
483485
s_level.name = name;
484486
}
487+
s_textInputFocused |= ImGui::IsItemActive();
488+
485489
ImGui::Text("Sector Count: %u", (u32)s_level.sectors.size());
486490
ImGui::Text("Bounds: (%0.3f, %0.3f, %0.3f)\n (%0.3f, %0.3f, %0.3f)", s_level.bounds[0].x, s_level.bounds[0].y, s_level.bounds[0].z,
487491
s_level.bounds[1].x, s_level.bounds[1].y, s_level.bounds[1].z);
488492
ImGui::Text("Layer Range: [%d, %d]", s_level.layerRange[0], s_level.layerRange[1]);
489493
ImGui::LabelText("##GridLabel", "Grid Height");
490494
ImGui::SameLine(108.0f);
491495
ImGui::SetNextItemWidth(80.0f);
496+
492497
ImGui::InputFloat("##GridHeight", &s_grid.height, 0.0f, 0.0f, "%0.2f", ImGuiInputTextFlags_CharsDecimal);
498+
s_textInputFocused |= ImGui::IsItemActive();
493499

494500
ImGui::SameLine(0.0f, 16.0f);
495501
ImGui::SetNextItemWidth(86.0f);
496502
ImGui::LabelText("##DepthLabel", "View Depth");
497503
ImGui::SameLine(0.0f, 8.0f);
498504
ImGui::SetNextItemWidth(80.0f);
505+
499506
ImGui::InputFloat("##ViewDepth0", &s_viewDepth[0], 0.0f, 0.0f, "%0.2f", ImGuiInputTextFlags_CharsDecimal);
507+
s_textInputFocused |= ImGui::IsItemActive();
508+
500509
ImGui::SameLine(0.0f, 4.0f);
501510
ImGui::SetNextItemWidth(80.0f);
502511
ImGui::InputFloat("##ViewDepth1", &s_viewDepth[1], 0.0f, 0.0f, "%0.2f", ImGuiInputTextFlags_CharsDecimal);
512+
s_textInputFocused |= ImGui::IsItemActive();
503513

504514
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
505515
| ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoFocusOnAppearing;
@@ -647,6 +657,7 @@ namespace LevelEditor
647657
hadFocusX = true;
648658
}
649659
}
660+
s_textInputFocused |= ImGui::IsItemActive();
650661
bool lostFocusX = !ImGui::IsItemFocused() && !ImGui::IsItemHovered() && !ImGui::IsItemActive();
651662

652663
ImGui::SameLine();
@@ -658,6 +669,7 @@ namespace LevelEditor
658669
hadFocusZ = true;
659670
}
660671
}
672+
s_textInputFocused |= ImGui::IsItemActive();
661673
bool lostFocusZ = !ImGui::IsItemFocused() && !ImGui::IsItemHovered() && !ImGui::IsItemActive();
662674

663675
// Only update the value and add the edit when the input loses focus (clicking away or on another control) or
@@ -810,10 +822,12 @@ namespace LevelEditor
810822
char* endPtr = nullptr;
811823
*value = strtol(buf, &endPtr, 10);
812824
}
825+
s_textInputFocused |= ImGui::IsItemActive();
813826
}
814827
else
815828
{
816829
result = ImGui::InputInt(labelId, value);
830+
s_textInputFocused |= ImGui::IsItemActive();
817831
}
818832
ImGui::PopItemWidth();
819833
return result;
@@ -832,10 +846,12 @@ namespace LevelEditor
832846
char* endPtr = nullptr;
833847
*value = strtoul(buf, &endPtr, 10);
834848
}
849+
s_textInputFocused |= ImGui::IsItemActive();
835850
}
836851
else
837852
{
838853
result = ImGui::InputUInt(labelId, value);
854+
s_textInputFocused |= ImGui::IsItemActive();
839855
}
840856
ImGui::PopItemWidth();
841857
return result;
@@ -854,10 +870,12 @@ namespace LevelEditor
854870
char* endPtr = nullptr;
855871
*value = (f32)strtod(buf, &endPtr);
856872
}
873+
s_textInputFocused |= ImGui::IsItemActive();
857874
}
858875
else
859876
{
860877
result = ImGui::InputFloat(labelId, value, 0.0f, 0.0f, "%.2f");
878+
s_textInputFocused |= ImGui::IsItemActive();
861879
}
862880
ImGui::PopItemWidth();
863881
return result;
@@ -1006,6 +1024,15 @@ namespace LevelEditor
10061024
return (u32)s_sectorInfo.size();
10071025
}
10081026

1027+
// TODO: Debug why this happens.
1028+
SelectionListId selectType = selection_getCurrent();
1029+
if (s_editMode == LEDIT_SECTOR && selectType != SEL_SECTOR ||
1030+
s_editMode == LEDIT_WALL && selectType != SEL_SURFACE)
1031+
{
1032+
assert(0);
1033+
return 0;
1034+
}
1035+
10091036
s_sectorInfo.clear();
10101037
s_sectorFlags.clear();
10111038
const u32 count = selection_getCount();
@@ -1510,13 +1537,15 @@ namespace LevelEditor
15101537
ImGui::Text("Mid Offset");
15111538
ImGui::PushItemWidth(136.0f);
15121539
changed |= ImGui::InputFloat2("##MidOffsetInput", &wall->tex[WP_MID].offset.x, "%.3f");
1540+
s_textInputFocused |= ImGui::IsItemActive();
15131541
ImGui::PopItemWidth();
15141542

15151543
ImGui::NewLine();
15161544

15171545
ImGui::Text("Sign Offset");
15181546
ImGui::PushItemWidth(136.0f);
15191547
changed |= ImGui::InputFloat2("##SignOffsetInput", &wall->tex[WP_SIGN].offset.x, "%.3f");
1548+
s_textInputFocused |= ImGui::IsItemActive();
15201549
ImGui::PopItemWidth();
15211550
}
15221551
ImGui::EndChild();
@@ -1533,13 +1562,15 @@ namespace LevelEditor
15331562
ImGui::Text("Top Offset");
15341563
ImGui::PushItemWidth(136.0f);
15351564
changed |= ImGui::InputFloat2("##TopOffsetInput", &wall->tex[WP_TOP].offset.x, "%.3f");
1565+
s_textInputFocused |= ImGui::IsItemActive();
15361566
ImGui::PopItemWidth();
15371567

15381568
ImGui::NewLine();
15391569

15401570
ImGui::Text("Bottom Offset");
15411571
ImGui::PushItemWidth(136.0f);
15421572
changed |= ImGui::InputFloat2("##BotOffsetInput", &wall->tex[WP_BOT].offset.x, "%.3f");
1573+
s_textInputFocused |= ImGui::IsItemActive();
15431574
ImGui::PopItemWidth();
15441575
}
15451576
ImGui::EndChild();
@@ -1669,6 +1700,7 @@ namespace LevelEditor
16691700
sector->name = sectorName;
16701701
changed = true;
16711702
}
1703+
s_textInputFocused |= ImGui::IsItemActive();
16721704
ImGui::PopItemWidth();
16731705
if (otherNameId >= 0) { ImGui::PopStyleColor(); }
16741706

@@ -1812,13 +1844,15 @@ namespace LevelEditor
18121844
ImGui::Text("Floor Offset");
18131845
ImGui::PushItemWidth(136.0f);
18141846
changed |= ImGui::InputFloat2("##FloorOffsetInput", &sector->floorTex.offset.x, "%.3f");
1847+
s_textInputFocused |= ImGui::IsItemActive();
18151848
ImGui::PopItemWidth();
18161849

18171850
ImGui::NewLine();
18181851

18191852
ImGui::Text("Ceil Offset");
18201853
ImGui::PushItemWidth(136.0f);
18211854
changed |= ImGui::InputFloat2("##CeilOffsetInput", &sector->ceilTex.offset.x, "%.3f");
1855+
s_textInputFocused |= ImGui::IsItemActive();
18221856
ImGui::PopItemWidth();
18231857
}
18241858
ImGui::EndChild();
@@ -2208,6 +2242,7 @@ namespace LevelEditor
22082242
{
22092243
s_objEntity.name = name;
22102244
}
2245+
s_textInputFocused |= ImGui::IsItemActive();
22112246
ImGui::SameLine(0.0f, 16.0f);
22122247
// Entity Class/Type
22132248
s32 classId = s_objEntity.type;
@@ -2238,6 +2273,7 @@ namespace LevelEditor
22382273
{
22392274
s_objEntity.assetName = assetName;
22402275
}
2276+
s_textInputFocused |= ImGui::IsItemActive();
22412277
ImGui::SameLine(0.0f, 8.0f);
22422278
if (ImGui::Button("Browse"))
22432279
{
@@ -2264,6 +2300,7 @@ namespace LevelEditor
22642300

22652301
ImGui::Text("%s", "Position"); ImGui::SameLine(0.0f, 8.0f);
22662302
ImGui::InputFloat3("##Position", &obj->pos.x);
2303+
s_textInputFocused |= ImGui::IsItemActive();
22672304

22682305
bool orientAdjusted = false;
22692306
ImGui::Text("%s", "Angle"); ImGui::SameLine(0.0f, 32.0f);
@@ -2281,6 +2318,7 @@ namespace LevelEditor
22812318
obj->angle = angle * PI / 180.0f;
22822319
orientAdjusted = true;
22832320
}
2321+
s_textInputFocused |= ImGui::IsItemActive();
22842322

22852323
// Show pitch and roll.
22862324
if (s_objEntity.type == ETYPE_3D)
@@ -2295,6 +2333,7 @@ namespace LevelEditor
22952333
obj->pitch = pitch * PI / 180.0f;
22962334
orientAdjusted = true;
22972335
}
2336+
s_textInputFocused |= ImGui::IsItemActive();
22982337
ImGui::SameLine(0.0f, 32.0f);
22992338
ImGui::Text("%s", "Roll"); ImGui::SameLine(0.0f, 8.0f);
23002339
ImGui::SetNextItemWidth(128.0f);
@@ -2303,6 +2342,7 @@ namespace LevelEditor
23032342
obj->roll = roll * PI / 180.0f;
23042343
orientAdjusted = true;
23052344
}
2345+
s_textInputFocused |= ImGui::IsItemActive();
23062346

23072347
if (orientAdjusted)
23082348
{
@@ -2443,11 +2483,13 @@ namespace LevelEditor
24432483
{
24442484
sprintf(name, "##VarFloat%d", i);
24452485
ImGui::InputFloat(name, &list[i].value.fValue);
2486+
s_textInputFocused |= ImGui::IsItemActive();
24462487
} break;
24472488
case EVARTYPE_INT:
24482489
{
24492490
sprintf(name, "##VarInt%d", i);
24502491
ImGui::InputInt(name, &list[i].value.iValue);
2492+
s_textInputFocused |= ImGui::IsItemActive();
24512493
} break;
24522494
case EVARTYPE_FLAGS:
24532495
{
@@ -2486,12 +2528,14 @@ namespace LevelEditor
24862528
{
24872529
list[i].value.sValue = pair1;
24882530
}
2531+
s_textInputFocused |= ImGui::IsItemActive();
24892532
ImGui::SameLine(0.0f, 8.0f);
24902533
ImGui::SetNextItemWidth(128.0f);
24912534
if (ImGui::InputText("###Pair2", pair2, 256))
24922535
{
24932536
list[i].value.sValue1 = pair2;
24942537
}
2538+
s_textInputFocused |= ImGui::IsItemActive();
24952539
} break;
24962540
}
24972541
}
@@ -2614,7 +2658,9 @@ namespace LevelEditor
26142658
ImGui::SetNextItemWidth(textWidth);
26152659
ImGui::LabelText("##Label", "%s", label); ImGui::SameLine();
26162660
if (width) { ImGui::SetNextItemWidth((f32)width); }
2617-
return ImGui::InputFloat(editor_getUniqueLabel(""), value, step, 10.0f * step, prec);
2661+
bool changed = ImGui::InputFloat(editor_getUniqueLabel(""), value, step, 10.0f * step, prec);
2662+
s_textInputFocused |= ImGui::IsItemActive();
2663+
return changed;
26182664
}
26192665

26202666
static s32 s_selectedOffset = -1;
@@ -2723,10 +2769,12 @@ namespace LevelEditor
27232769
ImGui::LabelText("##Label", "Start Fade (3D)"); ImGui::SameLine();
27242770
ImGui::SetNextItemWidth(128.0f);
27252771
ImGui::InputFloat("##StartFade", &note->fade.x, 1.0f, 10.0f, "%.1f");
2772+
s_textInputFocused |= ImGui::IsItemActive();
27262773
ImGui::SetNextItemWidth(128.0f);
27272774
ImGui::LabelText("##Label", "End Fade (3D)"); ImGui::SameLine();
27282775
ImGui::SetNextItemWidth(128.0f);
27292776
ImGui::InputFloat("##EndFade", &note->fade.z, 1.0f, 10.0f, "%.1f");
2777+
s_textInputFocused |= ImGui::IsItemActive();
27302778
ImGui::Separator();
27312779
ImGui::SetNextItemWidth(128.0f);
27322780
ImGui::LabelText("##Label", "Icon Color"); ImGui::SameLine();
@@ -2753,11 +2801,13 @@ namespace LevelEditor
27532801
{
27542802
note->note = tmpBuffer;
27552803
}
2804+
s_textInputFocused |= ImGui::IsItemActive();
27562805
}
27572806

2758-
void drawInfoPanel(EditorView view)
2807+
bool drawInfoPanel(EditorView view)
27592808
{
27602809
bool show = getSelectMode() == SELECTMODE_NONE;
2810+
s_textInputFocused = false;
27612811

27622812
// Draw the info bars.
27632813
s_infoHeight = 486 + 44;
@@ -2820,6 +2870,7 @@ namespace LevelEditor
28202870
}
28212871
}
28222872
infoToolEnd();
2873+
return s_textInputFocused;
28232874
}
28242875

28252876
void infoToolEnd()

0 commit comments

Comments
 (0)