Skip to content

Commit a02a51c

Browse files
committed
Working Headless mode, now added Datafile source
1 parent 6e8b46d commit a02a51c

4 files changed

Lines changed: 856 additions & 74 deletions

File tree

extensions/olcPGEX_QuickGUI.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,32 @@ namespace olc::QuickGUI
361361
void Draw(olc::PixelGameEngine* pge) override;
362362
void DrawDecal(olc::PixelGameEngine* pge) override;
363363
};
364+
365+
366+
class ModalDialog : public olc::PGEX
367+
{
368+
public:
369+
ModalDialog();
370+
371+
public:
372+
void ShowFileOpen(const std::string& sPath);
373+
374+
protected:
375+
virtual bool OnBeforeUserUpdate(float& fElapsedTime) override;
376+
377+
private:
378+
bool m_bShowDialog = false;
379+
380+
Manager m_manFileSelect;
381+
ListBox* m_listVolumes = nullptr;
382+
ListBox* m_listDirectory = nullptr;
383+
ListBox* m_listFiles = nullptr;
384+
385+
std::vector<std::string> m_vVolumes;
386+
std::vector<std::string> m_vDirectory;
387+
std::vector<std::string> m_vFiles;
388+
std::filesystem::path m_path;
389+
};
364390
}
365391

366392

@@ -1050,6 +1076,95 @@ namespace olc::QuickGUI
10501076
#pragma endregion
10511077

10521078

1079+
1080+
#pragma region Modal
1081+
ModalDialog::ModalDialog() : olc::PGEX(true)
1082+
{
1083+
1084+
// Create File Open Dialog
1085+
olc::vi2d vScreenSize = pge->GetScreenSize();
1086+
1087+
m_listDirectory = new ListBox(m_manFileSelect, m_vDirectory, olc::vf2d(20, 20), olc::vf2d(300, 500));
1088+
m_listFiles = new ListBox(m_manFileSelect, m_vFiles, olc::vf2d(330, 20), olc::vf2d(300, 500));
1089+
1090+
m_path = "/";
1091+
for (auto const& dir_entry : std::filesystem::directory_iterator{ m_path })
1092+
{
1093+
if(dir_entry.is_directory())
1094+
m_vDirectory.push_back(dir_entry.path().filename().string());
1095+
else
1096+
m_vFiles.push_back(dir_entry.path().filename().string());
1097+
}
1098+
}
1099+
1100+
void ModalDialog::ShowFileOpen(const std::string& sPath)
1101+
{
1102+
m_bShowDialog = true;
1103+
}
1104+
1105+
bool ModalDialog::OnBeforeUserUpdate(float& fElapsedTime)
1106+
{
1107+
if(!m_bShowDialog) return false;
1108+
1109+
m_manFileSelect.Update(this->pge);
1110+
1111+
if (pge->GetKey(olc::Key::BACK).bPressed)
1112+
{
1113+
m_path = m_path.parent_path().string() + "/";
1114+
//m_listDirectory->bSelectionChanged = true;
1115+
//m_listDirectory->nSelectedItem = 0;
1116+
}
1117+
1118+
if (m_listDirectory->bSelectionChanged)
1119+
{
1120+
std::string sDirectory = m_vDirectory[m_listDirectory->nSelectedItem];
1121+
/*if (sDirectory == "..")
1122+
m_path = m_path.parent_path().string() + "/";
1123+
else
1124+
m_path += sDirectory+ "/";*/
1125+
1126+
1127+
m_path += sDirectory + "/";
1128+
// Reconstruct Lists
1129+
m_vDirectory.clear();
1130+
1131+
m_vFiles.clear();
1132+
1133+
1134+
for (auto const& dir_entry : std::filesystem::directory_iterator{ m_path })
1135+
{
1136+
if (dir_entry.is_directory() || dir_entry.is_other())
1137+
m_vDirectory.push_back(dir_entry.path().filename().string());
1138+
else
1139+
m_vFiles.push_back(dir_entry.path().filename().string());
1140+
}
1141+
1142+
//m_vDirectory.push_back("..");
1143+
1144+
//m_listFiles->nSelectedItem = 0;
1145+
//m_listDirectory->nSelectedItem = 0;
1146+
1147+
}
1148+
1149+
pge->DrawStringDecal({ 0,0 }, m_path.string());
1150+
1151+
1152+
1153+
1154+
m_manFileSelect.DrawDecal(this->pge);
1155+
1156+
1157+
1158+
if (pge->GetKey(olc::Key::ESCAPE).bPressed)
1159+
{
1160+
m_bShowDialog = false;
1161+
return false;
1162+
}
1163+
1164+
return true;
1165+
}
1166+
#pragma endregion
1167+
10531168
}
10541169
#endif // OLC_PGEX_QUICKGUI
10551170
#endif // OLC_PGEX_QUICKGUI_H

0 commit comments

Comments
 (0)