Skip to content

Commit e44499a

Browse files
committedNov 26, 2024
Apply UI and drag and drop fixes to Content Browser
SearchIcon, ListView rename fix, DnD Other files
1 parent cbac957 commit e44499a

File tree

2 files changed

+163
-86
lines changed

2 files changed

+163
-86
lines changed
 
1.48 KB
Binary file not shown.

‎src/Editors/LevelEditor/Editor/Utils/ContentView.cpp

+163-86
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,56 @@ void CContentView::DrawHeader()
157157
DrawByPathLambda(CurrentDir);
158158
}
159159

160+
160161
int FindStartPosX = (int)ImGui::GetWindowSize().x;
161-
if (FindStartPosX > 300)
162+
163+
float w = 0;
164+
165+
if (FindStartPosX > 400)
162166
{
163167
ImGui::SameLine();
164168
int FindSizeX = FindStartPosX / 3.5f;
165169
FindStartPosX -= FindSizeX;
166170

167171
ImGui::SetCursorPosX(FindStartPosX);
168-
ImGui::SetNextItemWidth(FindSizeX - 35);
172+
173+
w = FindSizeX - 35;
169174
}
170175
else
171176
{
172-
ImGui::SetNextItemWidth(FindStartPosX - 45);
177+
w = FindStartPosX - 45;
173178
}
174179

180+
IconData* IconPtr = &GetTexture("search");
181+
ImVec2 IconSize{ 0,0 };
182+
183+
//Varian 1
184+
/*if (IconPtr->Icon)
185+
{
186+
IconSize={ 16,16 };
187+
ImGui::Image(IconPtr->Icon->pSurface, IconSize);
188+
ImGui::SameLine();
189+
}*/
190+
191+
ImGui::SetNextItemWidth(w - IconSize.x*1.5f);
192+
175193
if (ImGui::InputTextWithHint("##Search", "Search", FindStr, sizeof(FindStr)))
176194
{
177195
FindFile();
178196
}
197+
198+
//Varian 2
199+
if (IconPtr->Icon)
200+
{
201+
IconSize = { 12,12 };
202+
203+
ImGui::SameLine();
204+
ImVec2 cursorPos = ImGui::GetCursorPos();
205+
ImGui::SetCursorPos(ImVec2(cursorPos.x - IconSize.x-10.f, cursorPos.y+(IconSize.y/4)));
206+
207+
ImGui::Image(IconPtr->Icon->pSurface, IconSize);
208+
}
209+
179210
ImGui::SameLine();
180211

181212
if (ImGui::BeginPopupContextItem("MenuCBPpp"))
@@ -195,7 +226,7 @@ void CContentView::DrawHeader()
195226

196227
ImGui::EndMenu();
197228
}
198-
229+
199230
ImGui::EndPopup();
200231
}
201232

@@ -561,6 +592,8 @@ void CContentView::Init()
561592
Icons["backup"] = {EDevice->Resources->_CreateTexture("ed\\content_browser\\backup"), true};
562593
Icons["env_mod"]= {EDevice->Resources->_CreateTexture("ed\\content_browser\\env_mod"), true};
563594

595+
Icons["search"]= {EDevice->Resources->_CreateTexture("ed\\content_browser\\search"), false};
596+
564597
MenuIcon = EDevice->Resources->_CreateTexture("ed\\bar\\menu");
565598
}
566599

@@ -598,6 +631,9 @@ bool CContentView::DrawItemByList(const FileOptData& InitFileName, size_t& HorBt
598631
if (!IconPtr->Icon)
599632
return false;
600633

634+
if (FilePath == CopyObjectPath && IsCutting)
635+
IconColor.w = 0.3;
636+
601637
OutValue = ImGui::ImageButton
602638
(
603639
FileName.c_str(),
@@ -607,7 +643,12 @@ bool CContentView::DrawItemByList(const FileOptData& InitFileName, size_t& HorBt
607643
);
608644
}
609645

610-
DrawItemHelper(FilePath, FileName, InitFileName, IconPtr);
646+
ImVec4 TextColor = ImVec4(1, 1, 1, 1);
647+
648+
bool RenameThisItem = RenameObject.Active && RenameObject.Path == FilePath;
649+
650+
if (!RenameThisItem && DrawItemHelper(FilePath, FileName, InitFileName, IconPtr))
651+
TextColor.w = 0.3;
611652

612653
ImVec2 NextCursorPos = ImGui::GetCursorPos();
613654
ImGui::SameLine();
@@ -617,83 +658,122 @@ bool CContentView::DrawItemByList(const FileOptData& InitFileName, size_t& HorBt
617658
StartCursorPos.y -= (TextHeight + 2) ;
618659
ImGui::SetCursorPos(StartCursorPos);
619660

620-
ImGui::Text(Platform::ANSI_TO_UTF8(FileName).c_str());
661+
if (RenameObject.Path == FilePath)
662+
{
663+
if (RenameObject.Active)
664+
{
665+
if (RenameObject.SetText)
666+
{
667+
RenameObject.SetText = false;
668+
RenameObject.RenameBuf = Platform::ANSI_TO_UTF8(FileName).c_str();
669+
ImGui::SetKeyboardFocusHere();
670+
}
671+
672+
ImGuiIO& io = ImGui::GetIO();
673+
674+
if (ImGui::InputText("##ren", RenameObject.RenameBuf.data(), 255, ImGuiInputTextFlags_EnterReturnsTrue))
675+
RenameObject.Active = false;
676+
677+
if (io.KeysDown[ImGuiKey_Escape])
678+
RenameActionEnd();
679+
680+
RenameObject.Focus = ImGui::IsItemHovered();
681+
}
682+
else
683+
{
684+
if (strcmp(Platform::ANSI_TO_UTF8(FileName).c_str(), RenameObject.RenameBuf.c_str()))
685+
RenameAction(FilePath, RenameObject.RenameBuf.c_str());
686+
687+
RenameActionEnd();
688+
}
689+
}
690+
else
691+
{
692+
ImGui::TextColored(TextColor, Platform::ANSI_TO_UTF8(FileName).c_str());
693+
694+
if (ImGui::IsMouseDoubleClicked(0) && ImGui::IsItemHovered())
695+
{
696+
if (FilePath.xstring() != ".." && !FilePath.parent_path().empty() && !IsSpawnElement)
697+
RenameActionActivate(FilePath);
698+
}
699+
}
621700

622701
StartCursorPos.y += TextHeight + 2.f;
623702
ImGui::SetCursorPos(StartCursorPos);
624703

625704
ImVec4 TooltipTextColor = ImGui::GetStyle().Colors[ImGuiCol_Text];
626705
TooltipTextColor.w *= 0.5f;
627706

628-
if (InitFileName.IsDir)
629-
{
630-
ImGui::TextColored(TooltipTextColor, "Directory");
631-
}
632-
else if (FileName.ends_with(".dds"))
633-
{
634-
ImGui::TextColored(TooltipTextColor, "Texture Asset");
635-
}
636-
else if (FileName.ends_with(".tga"))
637-
{
638-
ImGui::TextColored(TooltipTextColor, "Raw Texture Asset");
639-
}
640-
else if (FileName.ends_with(".png"))
641-
{
642-
ImGui::TextColored(TooltipTextColor, "Image");
643-
}
644-
else if (FileName.ends_with(".object"))
645-
{
646-
ImGui::TextColored(TooltipTextColor, "Object Asset");
647-
}
648-
else if (FileName.ends_with(".group"))
649-
{
650-
ImGui::TextColored(TooltipTextColor, "Group object Asset");
651-
}
652-
else if (FileName.ends_with(".ogf"))
653-
{
654-
ImGui::TextColored(TooltipTextColor, "Object");
655-
}
656-
else if (FileName.ends_with(".wav"))
657-
{
658-
ImGui::TextColored(TooltipTextColor, "Raw Sound");
659-
}
660-
else if (FileName.ends_with(".ogg"))
661-
{
662-
ImGui::TextColored(TooltipTextColor, "Sound Asset");
663-
}
664-
else if (FileName.ends_with(".ise"))
665-
{
666-
ImGui::TextColored(TooltipTextColor, "Spawn Component");
667-
}
668-
else if (FileName.ends_with(".skl"))
669-
{
670-
ImGui::TextColored(TooltipTextColor, "Raw Single Animation Asset");
671-
}
672-
else if (FileName.ends_with(".skls"))
673-
{
674-
ImGui::TextColored(TooltipTextColor, "Raw Animations Asset");
675-
}
676-
else if (FileName.ends_with(".omf"))
677-
{
678-
ImGui::TextColored(TooltipTextColor, "Animations Asset");
679-
}
680-
else if (FileName.ends_with(".ltx"))
681707
{
682-
xr_string PathName = FilePath;
683-
if (PathName.Contains("scripts\\"))
708+
if (InitFileName.IsDir)
684709
{
685-
ImGui::TextColored(TooltipTextColor, "Logic Preference");
710+
ImGui::TextColored(TooltipTextColor, "Directory");
686711
}
687-
else
712+
else if (FileName.ends_with(".dds"))
688713
{
689-
ImGui::TextColored(TooltipTextColor, "Config");
714+
ImGui::TextColored(TooltipTextColor, "Texture Asset");
715+
}
716+
else if (FileName.ends_with(".tga"))
717+
{
718+
ImGui::TextColored(TooltipTextColor, "Raw Texture Asset");
719+
}
720+
else if (FileName.ends_with(".png"))
721+
{
722+
ImGui::TextColored(TooltipTextColor, "Image");
723+
}
724+
else if (FileName.ends_with(".object"))
725+
{
726+
ImGui::TextColored(TooltipTextColor, "Object Asset");
727+
}
728+
else if (FileName.ends_with(".group"))
729+
{
730+
ImGui::TextColored(TooltipTextColor, "Group object Asset");
731+
}
732+
else if (FileName.ends_with(".ogf"))
733+
{
734+
ImGui::TextColored(TooltipTextColor, "Object");
735+
}
736+
else if (FileName.ends_with(".wav"))
737+
{
738+
ImGui::TextColored(TooltipTextColor, "Raw Sound");
739+
}
740+
else if (FileName.ends_with(".ogg"))
741+
{
742+
ImGui::TextColored(TooltipTextColor, "Sound Asset");
743+
}
744+
else if (FileName.ends_with(".ise"))
745+
{
746+
ImGui::TextColored(TooltipTextColor, "Spawn Component");
747+
}
748+
else if (FileName.ends_with(".skl"))
749+
{
750+
ImGui::TextColored(TooltipTextColor, "Raw Single Animation Asset");
751+
}
752+
else if (FileName.ends_with(".skls"))
753+
{
754+
ImGui::TextColored(TooltipTextColor, "Raw Animations Asset");
755+
}
756+
else if (FileName.ends_with(".omf"))
757+
{
758+
ImGui::TextColored(TooltipTextColor, "Animations Asset");
759+
}
760+
else if (FileName.ends_with(".ltx"))
761+
{
762+
xr_string PathName = FilePath;
763+
if (PathName.Contains("scripts\\"))
764+
{
765+
ImGui::TextColored(TooltipTextColor, "Logic Preference");
766+
}
767+
else
768+
{
769+
ImGui::TextColored(TooltipTextColor, "Config");
770+
}
771+
}
772+
else if (FileName.ends_with(".script"))
773+
{
774+
ImGui::TextColored(TooltipTextColor, "Lua Script");
690775
}
691776
}
692-
else if (FileName.ends_with(".script"))
693-
{
694-
ImGui::TextColored(TooltipTextColor, "Lua Script");
695-
}
696-
697777
ImGui::SetCursorPos(NextCursorPos);
698778
ImGui::Separator();
699779

@@ -713,6 +793,9 @@ void CContentView::AcceptDragDropAction(xr_path& FilePath)
713793
if (ImData == nullptr)
714794
ImData = ImGui::AcceptDragDropPayload("FLDR");
715795

796+
if (ImData == nullptr)
797+
ImData = ImGui::AcceptDragDropPayload("OTHR");
798+
716799
if (ImData != nullptr)
717800
{
718801
if (ImData != nullptr)
@@ -752,13 +835,13 @@ bool CContentView::BeginDragDropAction(xr_path& FilePath, xr_string& FileName, c
752835
xr_string Extension = FilePath.extension().string().c_str();
753836
WeCanDrag = Extension == ".object" || Extension == ".group" || Extension == ".ise";
754837

755-
if (WeCanDrag)
838+
if (!ImGui::BeginDragDropSource())
756839
{
757-
if (!ImGui::BeginDragDropSource())
758-
{
759-
return false;
760-
}
840+
return false;
841+
}
761842

843+
if (WeCanDrag)
844+
{
762845
if (IsSpawnElement || FilePath.xstring().ends_with(".ise"))
763846
{
764847
if (InitFileName.ISESect.size() > 0)
@@ -775,8 +858,8 @@ bool CContentView::BeginDragDropAction(xr_path& FilePath, xr_string& FileName, c
775858
}
776859
else
777860
{
778-
//ImGui::SetDragDropPayload("OTHR", &Data, sizeof(DragDropData));
779-
return false;
861+
Data.FileName = FilePath;
862+
ImGui::SetDragDropPayload("OTHR", &Data, sizeof(DragDropData));
780863
}
781864
}
782865
else
@@ -909,7 +992,7 @@ bool CContentView::DrawItemByTile(const FileOptData& InitFileName, size_t& HorBt
909992
if (RenameObject.SetText)
910993
{
911994
RenameObject.SetText = false;
912-
RenameObject.RenameBuf = LabelText;
995+
RenameObject.RenameBuf = Platform::ANSI_TO_UTF8(LabelText);
913996
ImGui::SetKeyboardFocusHere();
914997
}
915998

@@ -918,21 +1001,16 @@ bool CContentView::DrawItemByTile(const FileOptData& InitFileName, size_t& HorBt
9181001
ImGui::SetCursorPosX(CursorPos.x);
9191002
ImGui::SetNextItemWidth(BtnSize.x + 10);
9201003
if (ImGui::InputText("##ren", RenameObject.RenameBuf.data(), 255,ImGuiInputTextFlags_EnterReturnsTrue))
921-
{
9221004
RenameObject.Active = false;
923-
}
9241005

925-
if (io.KeysDown[ImGuiKey_Escape]) {
1006+
if (io.KeysDown[ImGuiKey_Escape])
9261007
RenameActionEnd();
927-
}
9281008

9291009
RenameObject.Focus = ImGui::IsItemHovered();
9301010
}
9311011
else
9321012
{
933-
934-
bool c = strcmp(LabelText.c_str(), RenameObject.RenameBuf.c_str());
935-
if (c)
1013+
if (strcmp(Platform::ANSI_TO_UTF8(LabelText).c_str(), RenameObject.RenameBuf.c_str()))
9361014
RenameAction(FilePath, RenameObject.RenameBuf.c_str());
9371015

9381016
RenameActionEnd();
@@ -957,7 +1035,6 @@ bool CContentView::DrawItemByTile(const FileOptData& InitFileName, size_t& HorBt
9571035
RenameActionActivate(FilePath);
9581036
}
9591037
}
960-
//}
9611038

9621039
InvalidateLambda();
9631040
return OutValue;
@@ -1038,7 +1115,7 @@ bool CContentView::DrawContext(const xr_path& Path)
10381115
ImGui::Separator();
10391116
}
10401117

1041-
if (!ShowOpen) //Actions are temporarily unavailable for levels. The logic is not worked out
1118+
//if (!ShowOpen) //Actions are temporarily unavailable for levels. The logic is not worked out
10421119
{
10431120
if (ImGui::MenuItem("Cut"))
10441121
{

0 commit comments

Comments
 (0)
Please sign in to comment.