Skip to content

Commit

Permalink
Revert travel changes
Browse files Browse the repository at this point in the history
Fixed but preventing /tp command from working with some explorable areas
  • Loading branch information
3vcloud committed Jul 13, 2024
1 parent b73cd95 commit f0cc85c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
18 changes: 8 additions & 10 deletions GWToolboxdll/Utils/FontLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,41 +390,39 @@ namespace {
for (auto& pending : *fonts_built) {
*pending.dst_font = pending.src_font;
}
ImGui::GetIO().Fonts = font_text->ContainerAtlas;
ImGui::GetIO().Fonts = fonts_built->at(0).src_font->ContainerAtlas;
delete fonts_built;
};

auto first_pass = new std::vector<FontPending>({
{&font_text, FontLoader::FontSize::text},
{&font_header2, FontLoader::FontSize::header2},
{&font_header1, FontLoader::FontSize::header1},
{&font_widget_label, FontLoader::FontSize::widget_label},
{&font_widget_small, FontLoader::FontSize::widget_small},
{&font_widget_large, FontLoader::FontSize::widget_large},
{&font_text, FontLoader::FontSize::text}
{&font_widget_large, FontLoader::FontSize::widget_large}
});

// First pass; only build the first font.
for (auto& pending : *first_pass) {
pending.build(true);
}

Resources::EnqueueDxTask([&](IDirect3DDevice9*) {
assign_fonts(first_pass);
});
Resources::EnqueueDxTask([fonts_built = first_pass](IDirect3DDevice9*) {
Resources::EnqueueDxTask([assign_fonts, fonts = first_pass](IDirect3DDevice9*) {
assign_fonts(fonts);
printf("Fonts loaded\n");
fonts_loaded = true;
fonts_loading = false;
});
});

// First pass; build full glyph ranges
auto second_pass = new std::vector<FontPending>(*first_pass);
for (auto& pending : *second_pass) {
pending.build();
}

Resources::EnqueueDxTask([&](IDirect3DDevice9*) {
assign_fonts(second_pass);
Resources::EnqueueDxTask([assign_fonts, fonts = second_pass](IDirect3DDevice9*) {
assign_fonts(fonts);
});
}
}
Expand Down
66 changes: 40 additions & 26 deletions GWToolboxdll/Windows/TravelWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
#include <Windows/TravelWindowConstants.h>

namespace {

std::string SanitiseForSearch(const std::wstring& in) {
std::string sanitised = GuiUtils::ToLower(GuiUtils::RemovePunctuation(GuiUtils::WStringToString(in)));
// Remove "the " from front of entered string
const size_t found = sanitised.rfind("the ");
if (found == 0) {
sanitised.replace(found, 4, "");
}
return sanitised;
}

// Maps map id to a searchable char array via Name()
struct SearchableArea {
protected:
Expand Down Expand Up @@ -63,7 +74,7 @@ namespace {
if (enc_name->IsDecoding())
return nullptr;
// Sanitise for searching my removing punctuation etc
std::string sanitised = GuiUtils::ToLower(GuiUtils::RemovePunctuation(enc_name->string()));
const auto sanitised = SanitiseForSearch(enc_name->wstring());
name = new char[sanitised.length() + 1];
strcpy(name, sanitised.c_str());
delete enc_name;
Expand Down Expand Up @@ -231,7 +242,7 @@ namespace {
}

// By full outpost name (without punctuation) e.g. "/tp GrEaT TemplE oF BalthaZAR"
std::string compare = GuiUtils::ToLower(GuiUtils::RemovePunctuation(GuiUtils::WStringToString(s)));
std::string compare = SanitiseForSearch(s);

// Shortcut words e.g "/tp doa" for domain of anguish
const std::string first_word = compare.substr(0, compare.find(' '));
Expand All @@ -245,58 +256,57 @@ namespace {
return true;
}

// Remove "the " from front of entered string
const auto unstripped_compare = compare;
const size_t found = compare.rfind("the ");
if (found == 0) {
compare.replace(found, 4, "");
}

// Helper function
auto FindMatchingMap = [](std::string_view compare, const char* const* map_names, const GW::Constants::MapID* map_ids, const size_t map_count) -> GW::Constants::MapID {
if (compare.empty()) return GW::Constants::MapID::None;
auto FindMatchingMap = [](const char* compare, const char* const* map_names, const GW::Constants::MapID* map_ids, const size_t map_count) -> GW::Constants::MapID {
const char* bestMatchMapName = nullptr;
auto bestMatchMapID = GW::Constants::MapID::None;

const auto searchStringLength = compare ? strlen(compare) : 0;
if (!searchStringLength) {
return bestMatchMapID;
}
for (size_t i = 0; i < map_count; i++) {
const std::string_view map_name = map_names[i];
if (compare.length() > map_name.length()) {
const auto thisMapLength = strlen(map_names[i]);
if (searchStringLength > thisMapLength) {
continue; // String entered by user is longer than this outpost name.
}
if (!map_name.contains(compare)) {
if (strncmp(map_names[i], compare, searchStringLength) != 0) {
continue; // No match
}
if (compare.length() == map_name.length()) {
if (thisMapLength == searchStringLength) {
return map_ids[i]; // Exact match, break.
}
if (!bestMatchMapName || map_name.compare(bestMatchMapName) < 0) {
if (!bestMatchMapName || strcmp(map_names[i], bestMatchMapName) < 0) {
bestMatchMapID = map_ids[i];
bestMatchMapName = map_names[i];
}
}
return bestMatchMapID;
};
// Helper function
auto FindMatchingMapVec = [](std::string_view compare, std::vector<SearchableArea*>& maps) -> GW::Constants::MapID {
if (compare.empty()) return GW::Constants::MapID::None;
auto FindMatchingMapVec = [](const char* compare, std::vector<SearchableArea*>& maps) -> GW::Constants::MapID {
const char* bestMatchMapName = nullptr;
auto bestMatchMapID = GW::Constants::MapID::None;

for (const auto it : maps) {
const auto searchStringLength = compare ? strlen(compare) : 0;
if (!searchStringLength) {
return bestMatchMapID;
}
for (auto it : maps) {
auto& map = *it;
if (!map.Name())
continue;
const std::string_view map_name = map.Name();
if (compare.length() > map_name.length()) {
const auto thisMapLength = strlen(map.Name());
if (searchStringLength > thisMapLength) {
continue; // String entered by user is longer than this outpost name.
}
if (!map_name.contains(compare)) {
if (strncmp(map.Name(), compare, searchStringLength) != 0) {
continue; // No match
}
if (compare.length() == map_name.length()) {
if (thisMapLength == searchStringLength) {
return map.map_id; // Exact match, break.
}
if (!bestMatchMapName || map_name.compare(bestMatchMapName) < 0) {
if (!bestMatchMapName || strcmp(map.Name(), bestMatchMapName) < 0) {
bestMatchMapID = map.map_id;
bestMatchMapName = map.Name();
}
Expand All @@ -314,9 +324,9 @@ namespace {
}
if (best_match_map_id == GW::Constants::MapID::None && fetched_searchable_explorable_areas == FetchedMapNames::Ready) {
// find explorable area matching this, and then find nearest unlocked outpost.
best_match_map_id = FindMatchingMapVec(unstripped_compare, searchable_explorable_areas);
best_match_map_id = FindMatchingMapVec(compare.c_str(), searchable_explorable_areas);
if (best_match_map_id != GW::Constants::MapID::None) {
best_match_map_id = TravelWindow::GetNearestOutpost(best_match_map_id);
best_match_map_id = Instance().GetNearestOutpost(best_match_map_id);
}
}
}
Expand Down Expand Up @@ -489,6 +499,10 @@ namespace {
*out_text = GetMapName(outpost_ids[idx]);
return true;
}

void OnDecodedSearchableMapName(const wchar_t*) {

}
}

void TravelWindow::Initialize()
Expand Down

0 comments on commit f0cc85c

Please sign in to comment.