Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add HQ card image source #186

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions gframe/data_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,24 @@ void DataHandler::LoadPicUrls() {
auto type = obj["type"].get<std::string>();
if(obj["url"].get<std::string>() == "default") {
if(type == "pic") {
if (configs->toggle_hd_card_pics) {
#ifdef DEFAULT_HD_PIC_URL
imageDownloader->AddDownloadResource({ DEFAULT_HD_PIC_URL, ImageDownloader::ART });
#else
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#elseif is a thing, also, this isn't a proper approach, it should be implemented by adding a new field to the json file, then teh client will choose the sources that have that field set/unset depending on the user setting. with this, the user will be stuck with only the hardcoded hq sources and also this change will only apply oncve the game is restarted, not at runtime

Copy link
Author

@KingYamato KingYamato May 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are both details I had considered while making this.

  1. New field on JSON file: Is it really something we have to implement? Having a new field for solely the distinction of HD sources of card art (which would be specific to card art and not field or cover which doesn't make sense) a sensible thing to add?
  2. Image sources currently cannot have runtime distinction as the program always uses the first source it finds which matches the image type regardless. A new field would allow to select it at runtime but for this use case it would need to hard check if it's both 'card art' and 'hd' if there exists an hd source and prioritize that one
  3. I did some testing and it seemed like card art downloads would not 'reset' if you already downloaded a picture but then deleted it afterwards, but I'll check it again. If so, then it would be pointless to change sources at runtimd because already downloaded card images would leave the image stuck as blank

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the json itself is to be able to add new fields more easily, and the client aims into customizability, so yes, a new field is needed, because in that way you could make your custom packs and provide proper image sources as well, that's the primary goal of all this customizability.
For the runtime behaviour, it would really be a matter of just checking if the setting is toggled, and switch to the hq sources accordingly, handling previously downloaded images shouldn't be our problem.
For the "reset", do you mean when a pic is downloaded, then it won't be downloaded again if missing? That's still intended behaviour, the client shouldn't download a pic indefinitely if it's for example deleted by the antivirus, that would only waste resources, and if it weirdly disappeared, then it would be a bigger issue than the handling in the client.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior you just mentioned has been implemented in the commits below, thanks for the feedback.

#ifdef DEFAULT_PIC_URL
imageDownloader->AddDownloadResource({ DEFAULT_PIC_URL, ImageDownloader::ART });
imageDownloader->AddDownloadResource({ DEFAULT_PIC_URL, ImageDownloader::ART });
#else
continue;
continue;
#endif
#endif
}
else {
#ifdef DEFAULT_PIC_URL
imageDownloader->AddDownloadResource({ DEFAULT_PIC_URL, ImageDownloader::ART });
#else
continue;
#endif
}
} else if(type == "field") {
#ifdef DEFAULT_FIELD_URL
imageDownloader->AddDownloadResource({ DEFAULT_FIELD_URL, ImageDownloader::FIELD });
Expand Down
4 changes: 4 additions & 0 deletions gframe/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,10 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event, bool& stopPropagation)
mainGame->fpsCounter->setVisible(gGameConfig->showFPS);
return true;
}
case CHECKBOX_TOGGLE_HD_CARD_PICS: {
gGameConfig->toggle_hd_card_pics = mainGame->gSettings.chkToggleHdCardPics->isChecked();
return true;
}
case CHECKBOX_DRAW_FIELD_SPELLS: {
gGameConfig->draw_field_spell = mainGame->gSettings.chkDrawFieldSpells->isChecked();
return true;
Expand Down
24 changes: 13 additions & 11 deletions gframe/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,22 @@ bool Game::Initialize() {
defaultStrings.emplace_back(gSettings.chkHideSetname, 1354);
gSettings.chkHidePasscodeScope = env->addCheckBox(gGameConfig->hidePasscodeScope, Scale(15, 185, 320, 210), sPanel, CHECKBOX_HIDE_PASSCODE_SCOPE, gDataManager->GetSysString(2063).c_str());
defaultStrings.emplace_back(gSettings.chkHidePasscodeScope, 2063);
gSettings.chkDrawFieldSpells = env->addCheckBox(gGameConfig->draw_field_spell, Scale(15, 215, 320, 240), sPanel, CHECKBOX_DRAW_FIELD_SPELLS, gDataManager->GetSysString(2068).c_str());
gSettings.chkToggleHdCardPics = env->addCheckBox(gGameConfig->toggle_hd_card_pics, Scale(15, 215, 320, 240), sPanel, CHECKBOX_TOGGLE_HD_CARD_PICS, gDataManager->GetSysString(2081).c_str());
defaultStrings.emplace_back(gSettings.chkToggleHdCardPics, 2081);
gSettings.chkDrawFieldSpells = env->addCheckBox(gGameConfig->draw_field_spell, Scale(15, 245, 320, 270), sPanel, CHECKBOX_DRAW_FIELD_SPELLS, gDataManager->GetSysString(2068).c_str());
defaultStrings.emplace_back(gSettings.chkDrawFieldSpells, 2068);
gSettings.chkFilterBot = env->addCheckBox(gGameConfig->filterBot, Scale(15, 245, 320, 270), sPanel, CHECKBOX_FILTER_BOT, gDataManager->GetSysString(2069).c_str());
gSettings.chkFilterBot = env->addCheckBox(gGameConfig->filterBot, Scale(15, 275, 320, 300), sPanel, CHECKBOX_FILTER_BOT, gDataManager->GetSysString(2069).c_str());
defaultStrings.emplace_back(gSettings.chkFilterBot, 2069);
gSettings.stCurrentSkin = env->addStaticText(gDataManager->GetSysString(2064).c_str(), Scale(15, 275, 90, 300), false, true, sPanel);
gSettings.stCurrentSkin = env->addStaticText(gDataManager->GetSysString(2064).c_str(), Scale(15, 305, 90, 330), false, true, sPanel);
defaultStrings.emplace_back(gSettings.stCurrentSkin, 2064);
gSettings.cbCurrentSkin = ADDComboBox(Scale(95, 275, 320, 300), sPanel, COMBOBOX_CURRENT_SKIN);
gSettings.cbCurrentSkin = ADDComboBox(Scale(95, 305, 320, 330), sPanel, COMBOBOX_CURRENT_SKIN);
ReloadCBCurrentSkin();
gSettings.btnReloadSkin = env->addButton(Scale(15, 305, 320, 330), sPanel, BUTTON_RELOAD_SKIN, gDataManager->GetSysString(2066).c_str());
gSettings.btnReloadSkin = env->addButton(Scale(15, 335, 320, 360), sPanel, BUTTON_RELOAD_SKIN, gDataManager->GetSysString(2066).c_str());
defaultStrings.emplace_back(gSettings.btnReloadSkin, 2066);
gSettings.stCurrentLocale = env->addStaticText(gDataManager->GetSysString(2067).c_str(), Scale(15, 335, 90, 360), false, true, sPanel);
gSettings.stCurrentLocale = env->addStaticText(gDataManager->GetSysString(2067).c_str(), Scale(15, 365, 90, 390), false, true, sPanel);
defaultStrings.emplace_back(gSettings.stCurrentLocale, 2067);
PopulateLocales();
gSettings.cbCurrentLocale = ADDComboBox(Scale(95, 335, 320, 360), sPanel, COMBOBOX_CURRENT_LOCALE);
gSettings.cbCurrentLocale = ADDComboBox(Scale(95, 365, 320, 390), sPanel, COMBOBOX_CURRENT_LOCALE);
int selectedLocale = gSettings.cbCurrentLocale->addItem(L"English");
for(auto& _locale : locales) {
auto& locale = _locale.first;
Expand All @@ -681,12 +683,12 @@ bool Game::Initialize() {
}
}
gSettings.cbCurrentLocale->setSelected(selectedLocale);
gSettings.stDpiScale = env->addStaticText(gDataManager->GetSysString(2070).c_str(), Scale(15, 365, 90, 390), false, false, sPanel);
gSettings.stDpiScale = env->addStaticText(gDataManager->GetSysString(2070).c_str(), Scale(15, 395, 90, 420), false, false, sPanel);
defaultStrings.emplace_back(gSettings.stDpiScale, 2070);
gSettings.ebDpiScale = env->addEditBox(fmt::to_wstring<int>(gGameConfig->dpi_scale * 100).c_str(), Scale(95, 365, 150, 390), true, sPanel, EDITBOX_NUMERIC);
env->addStaticText(L"%", Scale(155, 365, 170, 390), false, false, sPanel);
gSettings.ebDpiScale = env->addEditBox(fmt::to_wstring<int>(gGameConfig->dpi_scale * 100).c_str(), Scale(95, 395, 150, 420), true, sPanel, EDITBOX_NUMERIC);
env->addStaticText(L"%", Scale(155, 395, 170, 420), false, false, sPanel);
gSettings.ebDpiScale->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
gSettings.btnRestart = env->addButton(Scale(175, 365, 320, 390), sPanel, BUTTON_APPLY_RESTART, gDataManager->GetSysString(2071).c_str());
gSettings.btnRestart = env->addButton(Scale(175, 395, 320, 420), sPanel, BUTTON_APPLY_RESTART, gDataManager->GetSysString(2071).c_str());
defaultStrings.emplace_back(gSettings.btnRestart, 2071);

gSettings.stAntiAlias = env->addStaticText(gDataManager->GetSysString(2075).c_str(), Scale(340, 5, 545, 30), false, true, sPanel);
Expand Down
2 changes: 2 additions & 0 deletions gframe/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ bool GameConfig::Load(const path_char* filename)
DESERIALIZE_BOOL(loopMusic)
DESERIALIZE_BOOL(noClientUpdates)
DESERIALIZE_BOOL(alternative_phase_layout)
DESERIALIZE_BOOL(toggle_hd_card_pics)
#ifdef WIN32
DESERIALIZE_BOOL(showConsole)
#endif
Expand Down Expand Up @@ -269,6 +270,7 @@ bool GameConfig::Save(const path_char* filename)
conf_file << "mute_spectators = " << chkIgnore2 << "\n";
conf_file << "hide_setname = " << chkHideSetname << "\n";
conf_file << "hide_hint_button = " << chkHideHintButton << "\n";
SERIALIZE(toggle_hd_card_pics);
conf_file << "draw_field_spell = " << draw_field_spell << "\n";
conf_file << "quick_animation = " << quick_animation << "\n";
SERIALIZE(alternative_phase_layout);
Expand Down
1 change: 1 addition & 0 deletions gframe/game_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct GameConfig
bool chkIgnore2 = false;
bool chkHideSetname = false;
bool chkHideHintButton = true;
bool toggle_hd_card_pics = false;
bool draw_field_spell = true;
bool quick_animation = false;
bool alternative_phase_layout = false;
Expand Down
1 change: 1 addition & 0 deletions gframe/menu_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ enum GUI {
CHECKBOX_ACCURATE_BACKGROUND_RESIZE,
CHECKBOX_HIDE_ARCHETYPES,
CHECKBOX_HIDE_PASSCODE_SCOPE,
CHECKBOX_TOGGLE_HD_CARD_PICS,
CHECKBOX_DRAW_FIELD_SPELLS,
CHECKBOX_FILTER_BOT,
CHECKBOX_VSYNC,
Expand Down
3 changes: 3 additions & 0 deletions gframe/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ local ygopro_config=function(static_core)
excludes { "lzma/**", "sound_sdlmixer.*", "sound_irrklang.*", "irrklang_dynamic_loader.*", "Android/**" }

defines "CURL_STATICLIB"
if _OPTIONS["hd-pics"] then
defines { "DEFAULT_HD_PIC_URL=" .. _OPTIONS["hd-pics"] }
end
if _OPTIONS["pics"] then
defines { "DEFAULT_PIC_URL=" .. _OPTIONS["pics"] }
end
Expand Down
1 change: 1 addition & 0 deletions gframe/settings_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct SettingsWindow {
irr::gui::IGUICheckBox* chkAccurateBackgroundResize;
irr::gui::IGUICheckBox* chkHideSetname;
irr::gui::IGUICheckBox* chkHidePasscodeScope;
irr::gui::IGUICheckBox* chkToggleHdCardPics;
irr::gui::IGUICheckBox* chkDrawFieldSpells;
irr::gui::IGUICheckBox* chkFilterBot;
irr::gui::IGUIStaticText* stCurrentSkin;
Expand Down
5 changes: 5 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ newoption {
{ "sdl-mixer", "SDL2-mixer" }
}
}
newoption {
trigger = "hd-pics",
value = "url_template",
description = "Default URL for high quality card images"
}
newoption {
trigger = "pics",
value = "url_template",
Expand Down