Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoadMenu Class Reference

#include <LoadMenu.hxx>

+ Inheritance diagram for LoadMenu:
+ Collaboration diagram for LoadMenu:

Public Types

enum  Result { e_none, e_close, e_load_file, e_delete_file }
 
- Public Types inherited from GameMenu
using Ptr = std::shared_ptr< GameMenu >
 

Public Member Functions

 LoadMenu ()
 
 ~LoadMenu ()
 
void draw () const override
 
const std::stringfilename () const
 
Result result () const
 
- Public Member Functions inherited from GameMenu
virtual ~GameMenu ()=default
 
virtual bool isMouseHovered () const
 
virtual void closeSubmenus ()
 

Private Attributes

std::string m_filename
 
Result m_result
 

Detailed Description

Definition at line 6 of file LoadMenu.hxx.

Member Enumeration Documentation

◆ Result

Enumerator
e_none 
e_close 
e_load_file 
e_delete_file 

Definition at line 9 of file LoadMenu.hxx.

10  {
11  e_none,
12  e_close,
15  };

Constructor & Destructor Documentation

◆ LoadMenu()

LoadMenu::LoadMenu ( )

Definition at line 20 of file LoadMenu.cxx.

21 {
22  // still do nothing
23 }

◆ ~LoadMenu()

LoadMenu::~LoadMenu ( )

Definition at line 107 of file LoadMenu.cxx.

108 {
109  // still do nothing
110 }

Member Function Documentation

◆ draw()

void LoadMenu::draw ( ) const
overridevirtual

Reimplemented from GameMenu.

Definition at line 25 of file LoadMenu.cxx.

26 {
27  m_result = e_none;
28  m_filename.clear();
29 
30  ImVec2 windowSize(500, 500);
31  ImVec2 screenSize = ui::GetIO().DisplaySize;
32 
33  auto &uiManager = UIManager::instance();
34 
35  const auto &layout = uiManager.getLayouts()["LoadDialogButtons"];
36  ui::SetNextWindowPos(ImVec2((screenSize.x - windowSize.x) / 2, (screenSize.y - windowSize.y) / 2));
37  ui::SetNextWindowSize(windowSize);
38 
39  constexpr float btnSide = 40;
40  const ImVec2 buttonSize(windowSize.x - btnSide * 3, btnSide);
41  const ImVec2 buttonOffset((windowSize.x - buttonSize.x) / 2, buttonSize.y / 2);
42  const ImVec2 widgetSize((windowSize.x / 2) - 8, 20);
43 
44  ui::PushFont(layout.font);
45  ui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
46  ui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
47  ui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, buttonOffset.y));
48 
49  bool open = true;
50  ui::BeginCt("LoadDialog", &open,
51  ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar |
52  ImGuiWindowFlags_NoScrollWithMouse);
53 
54  // empty header
55  ui::PushItemWidth(widgetSize.x);
56 
57  // header label
58  auto textWidth = ImGui::CalcTextSize("Load city").x;
59  ImGui::SetCursorPosX((windowSize.x - textWidth) * 0.5f);
60  ui::LabelText("##loadcitylbl", "Load city");
61 
62  ImGui::BeginChild("##loadbuttons", {0.f, windowSize.y * 0.6f}, false, ImGuiWindowFlags_NoTitleBar);
63 
64  std::string path = CYTOPIA_DATA_DIR + "/saves";
65  for (const auto &entry : fs::directory_iterator(path))
66  {
67  if (!fs::is_regular_file(entry) || entry.path().extension() != ".cts")
68  continue;
69 
70  ui::Dummy({btnSide / 2.f, 0.f});
71  ui::SameLine();
72  if (ui::ButtonCt(entry.path().filename().string().c_str(), buttonSize))
73  {
74  m_filename = entry.path().filename().string();
76  }
77 
78  ui::SameLine();
79  ui::Dummy({btnSide / 2.f, 0.f});
80  ui::SameLine();
81  if (ui::ButtonCt("X", {btnSide, btnSide}))
82  {
83  m_filename = entry.path().filename().string();
85  }
86  }
87 
88  ui::EndChild();
89  ui::PopItemWidth();
90 
91  ImVec2 btnSize(windowSize.x / 4, btnSide);
92 
93  ui::SetCursorPosY(windowSize.y - btnSize.y * 2);
94  ui::Dummy({(windowSize.x - btnSize.x) / 2.f, 0.f});
95  ui::SameLine();
96  if (ui::ButtonCt("OK", btnSize))
97  {
98  m_result = e_close;
99  }
100 
101  ui::PopFont();
102  ui::PopStyleVar(3);
103 
104  ui::End();
105 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filename()

const std::string& LoadMenu::filename ( ) const
inline

Definition at line 21 of file LoadMenu.hxx.

21 { return m_filename; }
+ Here is the caller graph for this function:

◆ result()

Result LoadMenu::result ( ) const
inline

Definition at line 22 of file LoadMenu.hxx.

22 { return m_result; }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_filename

std::string LoadMenu::m_filename
mutableprivate

Definition at line 25 of file LoadMenu.hxx.

◆ m_result

Result LoadMenu::m_result
mutableprivate

Definition at line 26 of file LoadMenu.hxx.


The documentation for this class was generated from the following files:
LoadMenu::e_load_file
@ e_load_file
Definition: LoadMenu.hxx:13
LoadMenu::m_filename
std::string m_filename
Definition: LoadMenu.hxx:25
LoadMenu::e_close
@ e_close
Definition: LoadMenu.hxx:12
LoadMenu::m_result
Result m_result
Definition: LoadMenu.hxx:26
CYTOPIA_DATA_DIR
const std::string CYTOPIA_DATA_DIR
Definition: Constants.hxx:17
Singleton< UIManager >::instance
static UIManager & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
LoadMenu::e_none
@ e_none
Definition: LoadMenu.hxx:11
string
std::string string
Definition: AudioConfig.hxx:14
LoadMenu::e_delete_file
@ e_delete_file
Definition: LoadMenu.hxx:14