Skip to content

Commit 2a17cad

Browse files
committed
adding control config menu, incomplete
1 parent 7a32762 commit 2a17cad

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/MenuState.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void MenuState :: enter()
246246
m_MenuContext.push(&m_ControlsMenu);
247247
});
248248
m_OptionsMenu.options().emplace_back(
249-
"Back",
249+
"Back",
250250
[this]{
251251
m_pQor->save_settings();
252252
m_MenuContext.pop();
@@ -256,6 +256,8 @@ void MenuState :: enter()
256256
Menu::Option::BACK
257257
);
258258

259+
init_controls_menu();
260+
259261
m_MenuContext.clear(&m_MainMenu);
260262
m_pRoot->add(m_pMenuGUI);
261263

@@ -304,6 +306,52 @@ MenuState :: ~MenuState()
304306
m_pPipeline->partitioner()->clear();
305307
}
306308

309+
void MenuState :: init_controls_menu()
310+
{
311+
shared_ptr<Meta> binds;
312+
TRY(binds = m_pQor->session()->profile(0)->config()->
313+
meta("input")->meta("binds")
314+
);
315+
316+
317+
if(binds)
318+
{
319+
for(auto&& bind: *binds)
320+
{
321+
try{
322+
// individual action -> key
323+
m_Binds[bind.as<string>()].push_back(bind.key);
324+
}catch(const boost::bad_any_cast&){
325+
// many actions -> one key
326+
auto bind_list = bind.as<shared_ptr<Meta>>();
327+
for(auto&& key: *bind_list)
328+
m_Binds[key.as<string>()].push_back(bind.key);
329+
}
330+
}
331+
332+
// TODO: add empty binds for buttons not found
333+
334+
for(auto&& bind: m_Binds)
335+
m_ControlsMenu.options().emplace_back(
336+
bind.first + ": " + boost::algorithm::join(bind.second, ", "),
337+
[this]{
338+
339+
}
340+
);
341+
}
342+
343+
m_ControlsMenu.options().emplace_back(
344+
"Back",
345+
[this]{
346+
m_pQor->save_settings();
347+
m_MenuContext.pop();
348+
},
349+
std::function<bool(int)>(), // no adjust
350+
string(), // no desc
351+
Menu::Option::BACK
352+
);
353+
}
354+
307355
void MenuState :: logic(Freq::Time t)
308356
{
309357
Actuation::logic(t);

src/MenuState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class MenuState:
6262
m_pCamera = std::dynamic_pointer_cast<Camera>(camera);
6363
}
6464

65+
void init_controls_menu();
66+
6567
private:
6668

6769
Qor* m_pQor = nullptr;
@@ -97,6 +99,8 @@ class MenuState:
9799
std::shared_ptr<std::string> m_pVolumeText;
98100
std::shared_ptr<std::string> m_pSoundText;
99101
std::shared_ptr<std::string> m_pMusicText;
102+
103+
std::map<std::string, std::vector<std::string>> m_Binds;
100104
};
101105

102106
#endif

0 commit comments

Comments
 (0)