11#include " menu.h"
22#include < iostream>
3+ #include < thread>
4+
35
46// constructor
57Menu::Menu ()
@@ -32,8 +34,23 @@ void Menu::displayAllies()
3234 std::cout << fflogs_->arch_ ->getFilteredAllies ().size () << " \n " ;
3335
3436
35- // for(int i = 0; i < fflogs_->partyMembers_; i++)
36- for (int i = 0 ; i < fflogs_->arch_ ->getFilteredAllies ().size (); i++)
37+ /*
38+ * if the size of filteredAllies_ is less than party members,
39+ * display number of elements in filteredAllies_ instead of
40+ * party members, or cause vector overflow
41+ */
42+ int numOfPartyMembers;
43+
44+ if (fflogs_->arch_ ->getFilteredAllies ().size () < fflogs_->partyMembers_ )
45+ {
46+ numOfPartyMembers = fflogs_->arch_ ->getFilteredAllies ().size ();
47+ }
48+ else
49+ {
50+ numOfPartyMembers = fflogs_->partyMembers_ ;
51+ }
52+
53+ for (int i = 0 ; i < numOfPartyMembers; i++)
3754 {
3855 SetConsoleTextAttribute (hConsole_, 7 );
3956 if (i == currentMenuSelection_)
@@ -61,21 +78,53 @@ void Menu::alliesMenu(DWORD &mode, INPUT_RECORD &event, HANDLE &hstdin)
6178 displayAllies ();
6279 prevPartySize_ = fflogs_->partyMembers_ ;
6380
81+
6482
6583 while (true )
6684 {
6785 DWORD count;
6886
69- fflogs_->arch_ ->updateNames (fflogs_->ffxiv_ , fflogs_->partyMembers_ );
87+ // fflogs_->arch_->updateNames(fflogs_->ffxiv_, fflogs_->partyMembers_);
7088
7189 if (prevPartySize_ != fflogs_->partyMembers_ )
7290 {
7391 prevPartySize_ = fflogs_->partyMembers_ ;
7492 redraw ();
7593 }
94+ bool isConsoleWindowFocussed = (GetConsoleWindow () == GetForegroundWindow ());
95+
96+ if (GetAsyncKeyState (VK_ESCAPE ) & 0x1 && isConsoleWindowFocussed)
97+ {
98+ exit (0 );
99+ }
76100
101+ if (GetAsyncKeyState (VK_UP ) & 0x1 && isConsoleWindowFocussed)
102+ {
103+ if (currentMenuSelection_ > 0 )
104+ {
105+ currentMenuSelection_--;
106+ redraw ();
107+ }
108+ }
109+
110+ if (GetAsyncKeyState (VK_DOWN ) & 0x1 && isConsoleWindowFocussed)
111+ {
112+ if (currentMenuSelection_ < fflogs_->arch_ ->getFilteredAllies ().size () - 1 )
113+ {
114+ currentMenuSelection_++;
115+ redraw ();
116+ }
117+ }
77118
78- if (WaitForSingleObject (hstdin, 0 ) == WAIT_OBJECT_0 )
119+ if (GetAsyncKeyState (VK_RETURN ) & 0x1 && isConsoleWindowFocussed)
120+ {
121+ fflogs_->arch_ ->getFilteredAllies ()[currentMenuSelection_]->openBrowser ();
122+ }
123+
124+ Sleep (1 );
125+
126+ /*
127+ else if(WaitForSingleObject(hstdin, 0) == WAIT_OBJECT_0)
79128 {
80129 ReadConsoleInput(hstdin, &event, 1, &count);
81130 // on keydown
@@ -108,6 +157,7 @@ void Menu::alliesMenu(DWORD &mode, INPUT_RECORD &event, HANDLE &hstdin)
108157 }
109158 }
110159 }
160+ */
111161 }
112162}
113163
@@ -121,6 +171,18 @@ void Menu::start()
121171 GetConsoleMode (hstdin, &mode);
122172 SetConsoleMode (hstdin, 0 );
123173
124- alliesMenu (mode, event, hstdin);
125174
126- }
175+ std::thread t1 ([=, &mode, &event, &hstdin] { alliesMenu (mode, event, hstdin); });
176+
177+ std::thread t2 ([=] {
178+ while (true )
179+ {
180+ fflogs_->arch_ ->updateNames (fflogs_->ffxiv_ , fflogs_->partyMembers_ );
181+ Sleep (2 );
182+ }
183+ });
184+
185+ t1.join ();
186+ t2.join ();
187+ // alliesMenu(mode, event, hstdin);
188+ }
0 commit comments