Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/gwdevhub/GWToolboxpp into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	GWToolboxdll/Windows/TargetInfoWindow.cpp
  • Loading branch information
3vcloud committed Apr 7, 2024
2 parents 07b5b20 + a776049 commit 1c3f304
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 25 deletions.
1 change: 1 addition & 0 deletions GWToolboxdll/Modules/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,7 @@ void GameSettings::DrawSettingsInternal()
if (ImGui::Checkbox("Remove 1.5 second minimum for the cast bar to show.", &remove_min_skill_warmup_duration)) {
remove_skill_warmup_duration_patch.TogglePatch(remove_min_skill_warmup_duration);
}
ImGui::Checkbox("Disable camera smoothing", &disable_camera_smoothing);

ImGui::Checkbox("Automatically skip cinematics", &auto_skip_cinematic);
ImGui::Checkbox("Automatically return to outpost on defeat", &auto_return_on_defeat);
Expand Down
61 changes: 54 additions & 7 deletions GWToolboxdll/Modules/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,43 @@ namespace {
}
}

const char* profession_icon_urls[] = {"", "8/87/Warrior-tango-icon-48", "e/e8/Ranger-tango-icon-48", "5/53/Monk-tango-icon-48", "b/b1/Necromancer-tango-icon-48", "b/b1/Mesmer-tango-icon-48", "4/47/Elementalist-tango-icon-48",
"2/2b/Assassin-tango-icon-48", "5/5b/Ritualist-tango-icon-48", "5/5e/Paragon-tango-icon-48", "3/38/Dervish-tango-icon-48"};
constexpr std::array profession_icon_urls = {
"",
"8/87/Warrior-tango-icon-48",
"e/e8/Ranger-tango-icon-48",
"5/53/Monk-tango-icon-48",
"b/b1/Necromancer-tango-icon-48",
"b/b1/Mesmer-tango-icon-48",
"4/47/Elementalist-tango-icon-48",
"2/2b/Assassin-tango-icon-48",
"5/5b/Ritualist-tango-icon-48",
"5/5e/Paragon-tango-icon-48",
"3/38/Dervish-tango-icon-48"
};
std::map<uint32_t, IDirect3DTexture9**> profession_icons;
std::map<GW::Constants::SkillID, IDirect3DTexture9**> skill_images;
std::map<std::wstring, IDirect3DTexture9**> item_images;
std::map<std::string, IDirect3DTexture9**> guild_wars_wiki_images;
std::map<uint32_t, IDirect3DTexture9**> profession_icons;
const std::map<std::string, const char*> damagetype_icon_urls = {
{"Blunt damage", "1/19/Blunt_damage.png/60px-Blunt_damage.png"},
{"Piercing damage", "1/1a/Piercing_damage.png/60px-Piercing_damage.png"},
{"Slashing damage", "3/3c/Slashing_damage.png/60px-Slashing_damage.png"},
{"Cold damage", "4/48/Cold_damage.png/60px-Cold_damage.png"},
{"Earth damage", "b/bb/Earth_damage.png/60px-Earth_damage.png"},
{"Fire damage", "6/6a/Fire_damage.png/60px-Fire_damage.png"},
{"Lightning damage", "0/06/Lightning_damage.png/60px-Lightning_damage.png"},
};

std::map<std::string, IDirect3DTexture9**> damagetype_icons;
std::map<GW::Constants::MapID, GuiUtils::EncString*> map_names;
std::unordered_map<GW::Constants::Language, std::unordered_map<uint32_t,GuiUtils::EncString*>> encoded_string_ids;
std::unordered_map<GW::Constants::Language, std::unordered_map<uint32_t, GuiUtils::EncString*>> encoded_string_ids;
std::filesystem::path current_settings_folder;
constexpr size_t MAX_WORKERS = 5;
const wchar_t* GUILD_WARS_WIKI_FILES_PATH = L"img\\gww_files";
const wchar_t* SKILL_IMAGES_PATH = L"img\\skills";
const wchar_t* ITEM_IMAGES_PATH = L"img\\items";
const wchar_t* PROF_ICONS_PATH = L"img\\professions";
const wchar_t* DMGTYPE_ICONS_PATH = L"img\\damagetypes";

std::recursive_mutex worker_mutex;
std::recursive_mutex main_mutex;
Expand Down Expand Up @@ -779,6 +802,29 @@ IDirect3DTexture9** Resources::GetProfessionIcon(GW::Constants::Profession p)
return texture;
}

IDirect3DTexture9** Resources::GetDamagetypeImage(std::string dmg_type)
{
if (damagetype_icons.contains(dmg_type)) {
return damagetype_icons.at(dmg_type);
}
const auto texture = new IDirect3DTexture9*;
*texture = nullptr;
damagetype_icons[dmg_type] = texture;
if (damagetype_icon_urls.contains(dmg_type)) {
const auto path = GetPath(DMGTYPE_ICONS_PATH);
EnsureFolderExists(path);
const auto local_path = path / GuiUtils::SanitiseFilename(dmg_type + ".png");
const auto remote_path = std::format("https://wiki.guildwars.com/images/thumb/{}", damagetype_icon_urls.at(dmg_type));
LoadTexture(texture, local_path, remote_path, [dmg_type](const bool success, const std::wstring& error) {
if (!success) {
const auto dmg_type_wstr = GuiUtils::StringToWString(dmg_type);
Log::ErrorW(L"Failed to load icon for %d\n%s", dmg_type_wstr.c_str(), error.c_str());
}
});
}
return texture;
}

IDirect3DTexture9** Resources::GetGuildWarsWikiImage(const char* filename, size_t width)
{
ASSERT(filename && filename[0]);
Expand Down Expand Up @@ -864,8 +910,8 @@ IDirect3DTexture9** Resources::GetSkillImage(GW::Constants::SkillID skill_id)
const auto skill = GW::SkillbarMgr::GetSkillConstantData(skill_id);
ASSERT(skill && skill->icon_file_id);
return GwDatTextureModule::LoadTextureFromFileId(skill->icon_file_id);

}

IDirect3DTexture9** Resources::GetSkillImageFromGWW(GW::Constants::SkillID skill_id)
{
if (skill_images.contains(skill_id)) {
Expand Down Expand Up @@ -987,7 +1033,8 @@ GuiUtils::EncString* Resources::DecodeStringId(const uint32_t enc_str_id, GW::Co
return enc_string;
}

IDirect3DTexture9** Resources::GetItemImage(GW::Item* item) {
IDirect3DTexture9** Resources::GetItemImage(GW::Item* item)
{
if (!(item && item->model_file_id))
return nullptr;
uint32_t model_id_to_load = 0;
Expand All @@ -998,7 +1045,7 @@ IDirect3DTexture9** Resources::GetItemImage(GW::Item* item) {
if (is_composite_item) {
// Armor/runes
const auto model_file_info = GW::Items::GetCompositeModelInfo(item->model_file_id);
if(!model_id_to_load)
if (!model_id_to_load)
model_id_to_load = model_file_info->file_ids[0xa];
if (!model_id_to_load)
model_id_to_load = is_female ? model_file_info->file_ids[5] : model_file_info->file_ids[0];
Expand Down
2 changes: 2 additions & 0 deletions GWToolboxdll/Modules/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Resources : public ToolboxModule {

// Guaranteed to return a pointer, but reference will be null until the texture has been loaded
static IDirect3DTexture9** GetProfessionIcon(GW::Constants::Profession p);
// Guaranteed to return a pointer, but reference will be null until the texture has been loaded
static IDirect3DTexture9** GetDamagetypeImage(std::string dmg_type);
// Fetches skill image from gw dat via file_id
static IDirect3DTexture9** GetSkillImage(GW::Constants::SkillID skill_id);
// Fetches skill page from GWW, parses out the image for the skill then downloads that to disk
Expand Down
35 changes: 19 additions & 16 deletions GWToolboxdll/Widgets/SkillMonitorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ void SkillMonitorWidget::Draw(IDirect3DDevice9*)
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0.0f, 0.0f));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImColor(background).Value);

if (snap_to_party_window && party_window_position) {
const float uiscale_multiply = GuiUtils::GetGWScaleMultiplier();
const float uiscale_multiply = GuiUtils::GetGWScaleMultiplier();
const auto calculate_window_position = [uiscale_multiply]() -> auto {
// NB: Use case to define GW::Vec4f ?
GW::Vec2f x = party_window_position->xAxis();
GW::Vec2f y = party_window_position->yAxis();
Expand All @@ -334,13 +334,16 @@ void SkillMonitorWidget::Draw(IDirect3DDevice9*)
// GW Clamps windows to viewport; we need to do the same.
GuiUtils::ClampRect(rect, viewport);
// Left placement
GW::Vec2f internal_offset(
7.f, GW::Map::GetInstanceType() == GW::Constants::InstanceType::Explorable ? 31.f : 34.f);
return rect;
};

if (snap_to_party_window && party_window_position) {
GW::Vec2f internal_offset(7.f, GW::Map::GetInstanceType() == GW::Constants::InstanceType::Explorable ? 31.f : 34.f);
internal_offset *= uiscale_multiply;
const auto user_offset_x = abs(user_offset);
float offset_width = width;
auto calculated_pos =
ImVec2(rect.x + internal_offset.x - user_offset_x - offset_width, rect.y + internal_offset.y);
const auto rect = calculate_window_position();
auto calculated_pos = ImVec2(rect.x + internal_offset.x - user_offset_x - offset_width, rect.y + internal_offset.y);
if (calculated_pos.x < 0 || user_offset < 0) {
// Right placement
internal_offset.x = 4.f * uiscale_multiply;
Expand Down Expand Up @@ -398,26 +401,26 @@ void SkillMonitorWidget::Draw(IDirect3DDevice9*)
if (skill_activation.status == CASTING && skill_activation.cast_time * 1000 >= cast_indicator_threshold) {
const auto remainingCast = TIMER_DIFF(skill_activation.cast_start);
const auto percentageCast = std::min(remainingCast / (skill_activation.cast_time * 1000), 1.0f);
const auto uiscale_multiply = GuiUtils::GetGWScaleMultiplier();
GW::Vec2f xPartyWindow = party_window_position->xAxis() * uiscale_multiply;
const auto calculated_pos = calculate_window_position();
GW::Vec2f xPartyWindow = { calculated_pos.x, calculated_pos.z };
xPartyWindow.x += PARTY_OFFSET_LEFT_BASE * uiscale_multiply;
xPartyWindow.y -= PARTY_OFFSET_RIGHT_BASE * uiscale_multiply;
GW::Vec2f yPartyWindow = party_window_position->yAxis() * uiscale_multiply;
GW::Vec2f yPartyWindow = {calculated_pos.y, calculated_pos.w};
yPartyWindow.x += PARTY_OFFSET_TOP_BASE * uiscale_multiply;

ImVec2 member_tl(xPartyWindow.x, yPartyWindow.x + y * GuiUtils::GetPartyHealthbarHeight());
ImVec2 member_topleft(xPartyWindow.x, yPartyWindow.x + y * GuiUtils::GetPartyHealthbarHeight());

if (party_map_indent[agent_id]) {
member_tl.x += PARTY_HERO_INDENT_BASE * uiscale_multiply;
member_topleft.x += PARTY_HERO_INDENT_BASE * uiscale_multiply;
}

ImVec2 member_br(xPartyWindow.y,
member_tl.y + GuiUtils::GetPartyHealthbarHeight() - PARTY_MEMBER_PADDING_FIXED);
ImVec2 member_bottomright(xPartyWindow.y,
member_topleft.y + GuiUtils::GetPartyHealthbarHeight() - PARTY_MEMBER_PADDING_FIXED);

ImGui::PushClipRect(member_tl, member_br, false);
ImGui::PushClipRect(member_topleft, member_bottomright, false);
ImGui::GetWindowDrawList()->AddRectFilled(
ImVec2(member_tl.x, member_br.y - cast_indicator_height),
ImVec2(member_tl.x + (member_br.x - member_tl.x) * percentageCast, member_br.y),
ImVec2(member_topleft.x, member_bottomright.y - cast_indicator_height),
ImVec2(member_topleft.x + (member_bottomright.x - member_topleft.x) * percentageCast, member_bottomright.y),
cast_indicator_color);
ImGui::PopClipRect();
}
Expand Down
4 changes: 2 additions & 2 deletions GWToolboxdll/Windows/ArmoryWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,10 @@ void ArmoryWindow::Draw(IDirect3DDevice9*)
pending_reset_equipment = true;
}

if (ImGui::MyCombo("##filter", "All", (int*)&current_campaign, armor_filter_array_getter, nullptr, 6)) {
if (ImGui::MyCombo("##filter", "All", reinterpret_cast<int*>(&current_campaign), armor_filter_array_getter, nullptr, 6)) {
UpdateArmorsFilter();
}
const auto order = {Headpiece, Chestpiece, Leggings, Boots, CostumeHead, CostumeBody};
const auto order = {Headpiece, Chestpiece, Gloves, Leggings, Boots, CostumeHead, CostumeBody, LeftHand, RightHand};
for (const auto slot : order) {
if (!IsEquipmentSlotSupportedByArmory(slot))
continue;
Expand Down

0 comments on commit 1c3f304

Please sign in to comment.