Skip to content

Commit

Permalink
filtering and performance enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
BttrDrgn committed May 4, 2022
1 parent 3c78735 commit b35a40b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 38 deletions.
15 changes: 15 additions & 0 deletions src/app/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,23 @@ void api::get_station(const std::string& id)
}).detach();
}

void api::filter_place(const std::string& key)
{
api::filtered_place.clear();

for (auto place : api::place)
{
//Look for city, country, or id with this string
if (place.city.find(key) != std::string::npos || place.country.find(key) != std::string::npos || place.id.find(key) != std::string::npos)
{
api::filtered_place.emplace_back(place);
}
}
}

nl::json api::places;
std::vector<place_t> api::place;
std::vector<place_t> api::filtered_place;
bool api::places_done = true;

nl::json api::details;
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class api
{
public:
static void get_places();
static void filter_place(const std::string& key);
static void get_details(const std::string& id);
static void get_station(const std::string& id);

static nl::json places;
static std::vector<place_t> place;
static std::vector<place_t> filtered_place;
static bool places_done;

static nl::json details;
Expand Down
104 changes: 67 additions & 37 deletions src/app/menus/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,56 +109,77 @@ void menus::places()
{
if (ImGui::BeginMenu("Places"))
{

if (ImGui::BeginCombo("Country", &menus::current_country[0]))
if (std::strlen(menus::search_buffer) == 0)
{
if (api::places_done)
{
if (ImGui::Button("Reset"))
{
menus::current_country = "N/A";
ImGui::CloseCurrentPopup();
}

ImGui::NewLine();
menus::filtering = false;
}

for (auto c : api::all_countries)
{
if (ImGui::Button(&c[0]))
{
menus::current_country = c;
ImGui::CloseCurrentPopup();
}
}
}
ImGui::EndCombo();
if (ImGui::Button("Reset Filter"))
{
menus::filtering = false;
memset(menus::search_buffer, 0, sizeof(menus::search_buffer));
}

if (ImGui::InputText("Search", menus::search_buffer, sizeof(search_buffer)))
{
menus::filtering = true;
api::filter_place(std::string(menus::search_buffer));
}

if (ImGui::BeginMenu("Locations"))
{
if (api::places_done)
{
for (auto place : api::place)
if (!menus::filtering)
{
std::string country = place.country;
if (std::strcmp(&menus::current_country[0], "N/A"))
if (api::place.empty())
{
ImGui::Text("Places are empty!\nYou might need to refresh\n\nPlease click Actions -> Refresh Places.");
}
else
{
if (!std::strcmp(&place.country[0], &menus::current_country[0]))
if (!menus::show_all_stations)
{
if (ImGui::Button(&logger::va("%s", &place.city[0])[0]))
ImGui::Text("There are %i places, hidden by default for performance.\nClick the button to show all stations", api::place.size());
if (ImGui::Button("Show All"))
{
api::get_details(place.id);
ImGui::CloseCurrentPopup();
menus::show_all_stations = true;
}
}
else if (menus::show_all_stations)
{
if (ImGui::Button("Hide All"))
{
menus::show_all_stations = false;
}

ImGui::NewLine();

for (auto place : api::place)
{
if (ImGui::Button(&logger::va("[%s] %s", &place.country[0], &place.city[0])[0]))
{
api::get_details(place.id);
ImGui::CloseCurrentPopup();
}
}
}
}
else
}
else if (menus::filtering)
{
if (api::filtered_place.empty())
{
ImGui::Text("Places are empty!\nYou might need to refresh\n\nPlease click Actions -> Refresh Places.");
}
{
if (ImGui::Button(&logger::va("[%s] %s", &country[0], &place.city[0])[0]))
for (auto place : api::filtered_place)
{
api::get_details(place.id);
ImGui::CloseCurrentPopup();
if (ImGui::Button(&logger::va("[%s] %s", &place.country[0], &place.city[0])[0]))
{
api::get_details(place.id);
ImGui::CloseCurrentPopup();
}
}
}
}
Expand All @@ -173,11 +194,18 @@ void menus::stations()
{
if (ImGui::BeginMenu("Stations"))
{
for (station_t station : api::station)
if (api::station.empty())
{
if (ImGui::Button(&logger::va("%s", &station.title[0])[0]))
ImGui::Text("Stations are empty!\nYou might need to select a place.");
}
else
{
for (station_t station : api::station)
{
audio::play(station.id);
if (ImGui::Button(&logger::va("%s", &station.title[0])[0]))
{
audio::play(station.id);
}
}
}
ImGui::EndMenu();
Expand Down Expand Up @@ -218,7 +246,9 @@ void menus::enumerate_snow()
}
}

std::string menus::current_country = "N/A";
std::vector<snow_t> menus::snow;
std::int32_t menus::max_points = 255;
bool menus::show_snow = false;
bool menus::show_all_stations = false;
bool menus::show_snow = false;
bool menus::filtering = false;
char menus::search_buffer[64];
4 changes: 3 additions & 1 deletion src/app/menus/menus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ class menus
static void init();
static void update();

static std::string current_country;
static std::vector<snow_t> snow;
static std::int32_t max_points;

static bool show_all_stations;
static bool show_snow;
static char search_buffer[64];

private:
static void main_menu_bar();
static void actions();
static void places();
static void stations();
static bool filtering;

static void render_snow();
static void enumerate_snow();
Expand Down

0 comments on commit b35a40b

Please sign in to comment.