Commit fe0cb9fc authored by mercury233's avatar mercury233

Merge branch 'master' of https://github.com/Fluorohydride/ygopro into server

parents afe1e497 6425dfae
Pipeline #40726 passed with stages
in 3 minutes and 9 seconds
...@@ -6,17 +6,17 @@ ...@@ -6,17 +6,17 @@
.DS_Store .DS_Store
/deck/ /deck
/expansions/ /expansions
/fonts/ /fonts
/icon /icon
/pack/ /pack
/pics/ /pics
/replay/ /replay
/single/ /single
/sound/ /sound
!/sound/files.txt !/sound/files.txt
/WindBot/ /WindBot
/cards.cdb /cards.cdb
/error.log /error.log
/bot.conf /bot.conf
...@@ -31,16 +31,16 @@ ...@@ -31,16 +31,16 @@
/.vscode/ /.vscode/
/bin/ /bin/
/build/ /build
/obj/ /obj/
/event/ /event
/freetype/ /freetype
/irrlicht/ /irrlicht
/irrklang/ /irrklang
/ikpmp3/ /ikpmp3
/lua/ /lua
/miniaudio/ /miniaudio
/sqlite3/ /sqlite3
/gframe/*.ico /gframe/*.ico
/gframe/ygopro.rc /gframe/ygopro.rc
/gframe/ygopro.aps /gframe/ygopro.aps
......
...@@ -27,13 +27,11 @@ ClientField::~ClientField() { ...@@ -27,13 +27,11 @@ ClientField::~ClientField() {
} }
hand[i].clear(); hand[i].clear();
for (auto& card : mzone[i]) { for (auto& card : mzone[i]) {
if (card) delete card;
delete card;
card = nullptr; card = nullptr;
} }
for (auto& card : szone[i]) { for (auto& card : szone[i]) {
if (card) delete card;
delete card;
card = nullptr; card = nullptr;
} }
for (auto& card : grave[i]) { for (auto& card : grave[i]) {
...@@ -44,7 +42,6 @@ ClientField::~ClientField() { ...@@ -44,7 +42,6 @@ ClientField::~ClientField() {
delete card; delete card;
} }
remove[i].clear(); remove[i].clear();
for (auto& card : extra[i]) { for (auto& card : extra[i]) {
delete card; delete card;
} }
...@@ -57,30 +54,33 @@ ClientField::~ClientField() { ...@@ -57,30 +54,33 @@ ClientField::~ClientField() {
} }
void ClientField::Clear() { void ClientField::Clear() {
for(int i = 0; i < 2; ++i) { for(int i = 0; i < 2; ++i) {
for(auto cit = deck[i].begin(); cit != deck[i].end(); ++cit) for (auto& card : deck[i]) {
delete *cit; delete card;
}
deck[i].clear(); deck[i].clear();
for(auto cit = hand[i].begin(); cit != hand[i].end(); ++cit) for (auto& card : hand[i]) {
delete *cit; delete card;
}
hand[i].clear(); hand[i].clear();
for(auto cit = mzone[i].begin(); cit != mzone[i].end(); ++cit) { for (auto& card : mzone[i]) {
if(*cit) delete card;
delete *cit; card = nullptr;
*cit = 0; }
} for (auto& card : szone[i]) {
for(auto cit = szone[i].begin(); cit != szone[i].end(); ++cit) { delete card;
if(*cit) card = nullptr;
delete *cit; }
*cit = 0; for (auto& card : grave[i]) {
} delete card;
for(auto cit = grave[i].begin(); cit != grave[i].end(); ++cit) }
delete *cit;
grave[i].clear(); grave[i].clear();
for(auto cit = remove[i].begin(); cit != remove[i].end(); ++cit) for (auto& card : remove[i]) {
delete *cit; delete card;
}
remove[i].clear(); remove[i].clear();
for(auto cit = extra[i].begin(); cit != extra[i].end(); ++cit) for (auto& card : extra[i]) {
delete *cit; delete card;
}
extra[i].clear(); extra[i].clear();
deck_act[i] = false; deck_act[i] = false;
grave_act[i] = false; grave_act[i] = false;
...@@ -88,8 +88,9 @@ void ClientField::Clear() { ...@@ -88,8 +88,9 @@ void ClientField::Clear() {
extra_act[i] = false; extra_act[i] = false;
pzone_act[i] = false; pzone_act[i] = false;
} }
for(auto sit = overlay_cards.begin(); sit != overlay_cards.end(); ++sit) for (auto& card : overlay_cards) {
delete *sit; delete card;
}
overlay_cards.clear(); overlay_cards.clear();
extra_p_count[0] = 0; extra_p_count[0] = 0;
extra_p_count[1] = 0; extra_p_count[1] = 0;
...@@ -417,7 +418,8 @@ void ClientField::ClearChainSelect() { ...@@ -417,7 +418,8 @@ void ClientField::ClearChainSelect() {
conti_act = false; conti_act = false;
} }
// needs to be synchronized with EGET_SCROLL_BAR_CHANGED // needs to be synchronized with EGET_SCROLL_BAR_CHANGED
void ClientField::ShowSelectCard(bool buttonok, bool chain) { void ClientField::ShowSelectCard(bool buttonok, bool is_continuous) {
select_continuous = is_continuous;
if(cant_check_grave) { if(cant_check_grave) {
bool has_card_in_grave = false; bool has_card_in_grave = false;
for (auto& pcard : selectable_cards) { for (auto& pcard : selectable_cards) {
...@@ -444,7 +446,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -444,7 +446,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
// image // image
if(selectable_cards[i]->code) if(selectable_cards[i]->code)
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->code));
else if(conti_selecting) else if(select_continuous)
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->chain_code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->chain_code));
else else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]); mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]);
...@@ -454,7 +456,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -454,7 +456,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
if(mainGame->dInfo.curMsg != MSG_SORT_CARD) { if(mainGame->dInfo.curMsg != MSG_SORT_CARD) {
// text // text
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
if(conti_selecting) if(select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
...@@ -470,7 +472,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -470,7 +472,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
if (selectable_cards[i]->is_selected) if (selectable_cards[i]->is_selected)
mainGame->stCardPos[i]->setBackgroundColor(0xffffff00); mainGame->stCardPos[i]->setBackgroundColor(0xffffff00);
else { else {
if(conti_selecting) if(select_continuous)
mainGame->stCardPos[i]->setBackgroundColor(0xffffffff); mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
else if(selectable_cards[i]->location == LOCATION_OVERLAY) { else if(selectable_cards[i]->location == LOCATION_OVERLAY) {
if(selectable_cards[i]->owner != selectable_cards[i]->overlayTarget->controler) if(selectable_cards[i]->owner != selectable_cards[i]->overlayTarget->controler)
......
...@@ -86,14 +86,14 @@ public: ...@@ -86,14 +86,14 @@ public:
ChainInfo current_chain; ChainInfo current_chain;
bool last_chain{ false }; bool last_chain{ false };
bool deck_reversed{ false }; bool deck_reversed{ false };
bool conti_selecting{ false }; bool select_continuous{ false };
bool cant_check_grave{ false }; bool cant_check_grave{ false };
bool tag_surrender{ false }; bool tag_surrender{ false };
bool tag_teammate_surrender{ false }; bool tag_teammate_surrender{ false };
std::mt19937 rnd; std::mt19937 rnd;
ClientField(); ClientField();
~ClientField(); ~ClientField() override;
void Clear(); void Clear();
void Initial(int player, int deckc, int extrac, int sidec = 0); void Initial(int player, int deckc, int extrac, int sidec = 0);
void ResetSequence(std::vector<ClientCard*>& list, bool reset_height); void ResetSequence(std::vector<ClientCard*>& list, bool reset_height);
...@@ -105,7 +105,7 @@ public: ...@@ -105,7 +105,7 @@ public:
void ClearCommandFlag(); void ClearCommandFlag();
void ClearSelect(); void ClearSelect();
void ClearChainSelect(); void ClearChainSelect();
void ShowSelectCard(bool buttonok = false, bool chain = false); void ShowSelectCard(bool buttonok = false, bool is_continuous = false);
void ShowChainCard(); void ShowChainCard();
void ShowLocationCard(); void ShowLocationCard();
void ShowSelectOption(int select_hint = 0); void ShowSelectOption(int select_hint = 0);
......
...@@ -324,7 +324,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const { ...@@ -324,7 +324,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const {
if (attribute & (0x1U << i)) { if (attribute & (0x1U << i)) {
if (!buffer.empty()) if (!buffer.empty())
buffer.push_back(L'|'); buffer.push_back(L'|');
buffer.append(GetSysString(1010 + i)); buffer.append(GetSysString(STRING_ID_ATTRIBUTE + i));
} }
} }
if (buffer.empty()) if (buffer.empty())
...@@ -337,7 +337,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const { ...@@ -337,7 +337,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const {
if(race & (0x1U << i)) { if(race & (0x1U << i)) {
if (!buffer.empty()) if (!buffer.empty())
buffer.push_back(L'|'); buffer.push_back(L'|');
buffer.append(GetSysString(1020 + i)); buffer.append(GetSysString(STRING_ID_RACE + i));
} }
} }
if (buffer.empty()) if (buffer.empty())
...@@ -346,12 +346,11 @@ std::wstring DataManager::FormatRace(unsigned int race) const { ...@@ -346,12 +346,11 @@ std::wstring DataManager::FormatRace(unsigned int race) const {
} }
std::wstring DataManager::FormatType(unsigned int type) const { std::wstring DataManager::FormatType(unsigned int type) const {
std::wstring buffer; std::wstring buffer;
int i = 1050; for (int i = 0; i < TYPES_COUNT; ++i) {
for (unsigned filter = TYPE_MONSTER; filter <= TYPE_LINK; filter <<= 1, ++i) { if (type & (0x1U << i)) {
if (type & filter) {
if (!buffer.empty()) if (!buffer.empty())
buffer.push_back(L'|'); buffer.push_back(L'|');
buffer.append(GetSysString(i)); buffer.append(GetSysString(STRING_ID_TYPE + i));
} }
} }
if (buffer.empty()) if (buffer.empty())
......
...@@ -110,6 +110,11 @@ public: ...@@ -110,6 +110,11 @@ public:
irr::io::IFileSystem* FileSystem{}; irr::io::IFileSystem* FileSystem{};
#endif #endif
static constexpr int STRING_ID_ATTRIBUTE = 1010;
static constexpr int STRING_ID_RACE = 1020;
static constexpr int STRING_ID_TYPE = 1050;
static constexpr int TYPES_COUNT = 27;
static unsigned char scriptBuffer[0x100000]; static unsigned char scriptBuffer[0x100000];
static uint32_t CardReader(uint32_t, card_data*); static uint32_t CardReader(uint32_t, card_data*);
static unsigned char* ScriptReaderEx(const char* script_path, int* slen); static unsigned char* ScriptReaderEx(const char* script_path, int* slen);
......
...@@ -1095,7 +1095,6 @@ void Game::HideElement(irr::gui::IGUIElement * win, bool set_action) { ...@@ -1095,7 +1095,6 @@ void Game::HideElement(irr::gui::IGUIElement * win, bool set_action) {
if(win == wCardSelect) { if(win == wCardSelect) {
for(int i = 0; i < 5; ++i) for(int i = 0; i < 5; ++i)
btnCardSelect[i]->setDrawImage(false); btnCardSelect[i]->setDrawImage(false);
dField.conti_selecting = false;
stCardListTip->setVisible(false); stCardListTip->setVisible(false);
for(auto& pcard : dField.selectable_cards) for(auto& pcard : dField.selectable_cards)
dField.SetShowMark(pcard, false); dField.SetShowMark(pcard, false);
...@@ -1307,8 +1306,9 @@ void Game::DrawDeckBd() { ...@@ -1307,8 +1306,9 @@ void Game::DrawDeckBd() {
else else
myswprintf(adBuffer, L"%d/-", ptr->second.attack); myswprintf(adBuffer, L"%d/-", ptr->second.attack);
} }
myswprintf(textBuffer, L"%ls/%ls %ls%d", dataManager.FormatAttribute(ptr->second.attribute).c_str(), dataManager.FormatRace(ptr->second.race).c_str(), const auto& attribute = dataManager.FormatAttribute(ptr->second.attribute);
form, ptr->second.level); const auto& race = dataManager.FormatRace(ptr->second.race);
myswprintf(textBuffer, L"%ls/%ls %ls%d", attribute.c_str(), race.c_str(), form, ptr->second.level);
DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0));
if(ptr->second.type & TYPE_PENDULUM) { if(ptr->second.type & TYPE_PENDULUM) {
myswprintf(scaleBuffer, L" %d/%d", ptr->second.lscale, ptr->second.rscale); myswprintf(scaleBuffer, L" %d/%d", ptr->second.lscale, ptr->second.rscale);
...@@ -1318,7 +1318,8 @@ void Game::DrawDeckBd() { ...@@ -1318,7 +1318,8 @@ void Game::DrawDeckBd() {
} else { } else {
myswprintf(textBuffer, L"%ls", dataManager.GetName(ptr->first)); myswprintf(textBuffer, L"%ls", dataManager.GetName(ptr->first));
DrawShadowText(textFont, textBuffer, Resize(860, 165 + i * 66, 955, 185 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 165 + i * 66, 955, 185 + i * 66), Resize(1, 1, 0, 0));
myswprintf(textBuffer, L"%ls", dataManager.FormatType(ptr->second.type).c_str()); const auto& type = dataManager.FormatType(ptr->second.type);
myswprintf(textBuffer, L"%ls", type.c_str());
DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0));
myswprintf(textBuffer, L"%ls", availBuffer); myswprintf(textBuffer, L"%ls", availBuffer);
DrawShadowText(textFont, textBuffer, Resize(860, 209 + i * 66, 955, 229 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 209 + i * 66, 955, 229 + i * 66), Resize(1, 1, 0, 0));
......
...@@ -762,8 +762,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) { ...@@ -762,8 +762,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
prep += sizeof new_replay.pheader; prep += sizeof new_replay.pheader;
std::memcpy(new_replay.comp_data, prep, len - sizeof new_replay.pheader - 1); std::memcpy(new_replay.comp_data, prep, len - sizeof new_replay.pheader - 1);
new_replay.comp_size = len - sizeof new_replay.pheader - 1; new_replay.comp_size = len - sizeof new_replay.pheader - 1;
if(mainGame->actionParam) if (mainGame->actionParam) {
new_replay.SaveReplay(mainGame->ebRSName->getText()); bool save_result = new_replay.SaveReplay(mainGame->ebRSName->getText());
if (!save_result)
new_replay.SaveReplay(L"_LastReplay");
}
else else
new_replay.SaveReplay(L"_LastReplay"); new_replay.SaveReplay(L"_LastReplay");
} }
...@@ -1113,7 +1116,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1113,7 +1116,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
break; break;
} }
case HINT_RACE: { case HINT_RACE: {
myswprintf(textBuffer, dataManager.GetSysString(1511), dataManager.FormatRace(data).c_str()); const auto& race = dataManager.FormatRace(data);
myswprintf(textBuffer, dataManager.GetSysString(1511), race.c_str());
mainGame->AddLog(textBuffer); mainGame->AddLog(textBuffer);
mainGame->gMutex.lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer); mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer);
...@@ -1123,7 +1127,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1123,7 +1127,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
break; break;
} }
case HINT_ATTRIB: { case HINT_ATTRIB: {
myswprintf(textBuffer, dataManager.GetSysString(1511), dataManager.FormatAttribute(data).c_str()); const auto& attribute = dataManager.FormatAttribute(data);
myswprintf(textBuffer, dataManager.GetSysString(1511), attribute.c_str());
mainGame->AddLog(textBuffer); mainGame->AddLog(textBuffer);
mainGame->gMutex.lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer); mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer);
......
...@@ -404,7 +404,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -404,7 +404,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
} else { } else {
selectable_cards.clear(); selectable_cards.clear();
conti_selecting = false; bool is_continuous = false;
switch(command_location) { switch(command_location) {
case LOCATION_DECK: { case LOCATION_DECK: {
for(size_t i = 0; i < deck[command_controler].size(); ++i) for(size_t i = 0; i < deck[command_controler].size(); ++i)
...@@ -431,15 +431,15 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -431,15 +431,15 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break; break;
} }
case POSITION_HINT: { case POSITION_HINT: {
is_continuous = true;
selectable_cards = conti_cards; selectable_cards = conti_cards;
std::sort(selectable_cards.begin(), selectable_cards.end()); std::sort(selectable_cards.begin(), selectable_cards.end());
auto eit = std::unique(selectable_cards.begin(), selectable_cards.end()); auto eit = std::unique(selectable_cards.begin(), selectable_cards.end());
selectable_cards.erase(eit, selectable_cards.end()); selectable_cards.erase(eit, selectable_cards.end());
conti_selecting = true;
break; break;
} }
} }
if(!conti_selecting) { if (!is_continuous) {
mainGame->wCardSelect->setText(dataManager.GetSysString(566)); mainGame->wCardSelect->setText(dataManager.GetSysString(566));
list_command = COMMAND_ACTIVATE; list_command = COMMAND_ACTIVATE;
} else { } else {
...@@ -447,7 +447,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -447,7 +447,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
list_command = COMMAND_OPERATION; list_command = COMMAND_OPERATION;
} }
std::sort(selectable_cards.begin(), selectable_cards.end(), ClientCard::client_card_sort); std::sort(selectable_cards.begin(), selectable_cards.end(), ClientCard::client_card_sort);
ShowSelectCard(true, true); ShowSelectCard(true, is_continuous);
} }
break; break;
} }
...@@ -892,7 +892,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -892,7 +892,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
// image // image
if(selectable_cards[i + pos]->code) if(selectable_cards[i + pos]->code)
mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->code)); mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->code));
else if(conti_selecting) else if(select_continuous)
mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->chain_code)); mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->chain_code));
else else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i + pos]->controler + 2]); mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i + pos]->controler + 2]);
...@@ -905,7 +905,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -905,7 +905,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
else else
myswprintf(formatBuffer, L""); myswprintf(formatBuffer, L"");
} else { } else {
if(conti_selecting) if(select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
...@@ -919,7 +919,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -919,7 +919,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
mainGame->stCardPos[i]->setText(formatBuffer); mainGame->stCardPos[i]->setText(formatBuffer);
// color // color
if(conti_selecting) if(select_continuous)
mainGame->stCardPos[i]->setBackgroundColor(0xffffffff); mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY) { else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY) {
if(selectable_cards[i + pos]->owner != selectable_cards[i + pos]->overlayTarget->controler) if(selectable_cards[i + pos]->owner != selectable_cards[i + pos]->overlayTarget->controler)
...@@ -1597,7 +1597,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1597,7 +1597,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"\nLINK-%d", mcard->link); myswprintf(formatBuffer, L"\nLINK-%d", mcard->link);
str.append(formatBuffer); str.append(formatBuffer);
} }
myswprintf(formatBuffer, L" %ls/%ls", dataManager.FormatRace(mcard->race).c_str(), dataManager.FormatAttribute(mcard->attribute).c_str()); const auto& race = dataManager.FormatRace(mcard->race);
const auto& attribute = dataManager.FormatAttribute(mcard->attribute);
myswprintf(formatBuffer, L" %ls/%ls", race.c_str(), attribute.c_str());
str.append(formatBuffer); str.append(formatBuffer);
if(mcard->location == LOCATION_HAND && (mcard->type & TYPE_PENDULUM)) { if(mcard->location == LOCATION_HAND && (mcard->type & TYPE_PENDULUM)) {
myswprintf(formatBuffer, L"\n%d/%d", mcard->lscale, mcard->rscale); myswprintf(formatBuffer, L"\n%d/%d", mcard->lscale, mcard->rscale);
...@@ -1622,10 +1624,14 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1622,10 +1624,14 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(211), mcard->chValue); myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(211), mcard->chValue);
else if(mcard->cHint == CHINT_CARD) else if(mcard->cHint == CHINT_CARD)
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(212), dataManager.GetName(mcard->chValue)); myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(212), dataManager.GetName(mcard->chValue));
else if(mcard->cHint == CHINT_RACE) else if(mcard->cHint == CHINT_RACE) {
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(213), dataManager.FormatRace(mcard->chValue).c_str()); const auto& race = dataManager.FormatRace(mcard->chValue);
else if(mcard->cHint == CHINT_ATTRIBUTE) myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(213), race.c_str());
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(214), dataManager.FormatAttribute(mcard->chValue).c_str()); }
else if(mcard->cHint == CHINT_ATTRIBUTE) {
const auto& attribute = dataManager.FormatAttribute(mcard->chValue);
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(214), attribute.c_str());
}
else if(mcard->cHint == CHINT_NUMBER) else if(mcard->cHint == CHINT_NUMBER)
myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(215), mcard->chValue); myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(215), mcard->chValue);
str.append(formatBuffer); str.append(formatBuffer);
......
...@@ -645,16 +645,16 @@ bool Game::Initialize() { ...@@ -645,16 +645,16 @@ bool Game::Initialize() {
wANAttribute = env->addWindow(irr::core::rect<irr::s32>(500, 200, 830, 285), false, dataManager.GetSysString(562)); wANAttribute = env->addWindow(irr::core::rect<irr::s32>(500, 200, 830, 285), false, dataManager.GetSysString(562));
wANAttribute->getCloseButton()->setVisible(false); wANAttribute->getCloseButton()->setVisible(false);
wANAttribute->setVisible(false); wANAttribute->setVisible(false);
for(int filter = 0x1, i = 0; i < 7; filter <<= 1, ++i) for (int i = 0; i < ATTRIBUTES_COUNT; ++i)
chkAttribute[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 80, 25 + (i / 4) * 25, 90 + (i % 4) * 80, 50 + (i / 4) * 25), chkAttribute[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 80, 25 + (i / 4) * 25, 90 + (i % 4) * 80, 50 + (i / 4) * 25),
wANAttribute, CHECK_ATTRIBUTE, dataManager.FormatAttribute(filter).c_str()); wANAttribute, CHECK_ATTRIBUTE, dataManager.GetSysString(DataManager::STRING_ID_ATTRIBUTE + i));
//announce race //announce race
wANRace = env->addWindow(irr::core::rect<irr::s32>(480, 200, 850, 410), false, dataManager.GetSysString(563)); wANRace = env->addWindow(irr::core::rect<irr::s32>(480, 200, 850, 410), false, dataManager.GetSysString(563));
wANRace->getCloseButton()->setVisible(false); wANRace->getCloseButton()->setVisible(false);
wANRace->setVisible(false); wANRace->setVisible(false);
for(int filter = 0x1, i = 0; i < RACES_COUNT; filter <<= 1, ++i) for (int i = 0; i < RACES_COUNT; ++i)
chkRace[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 90, 25 + (i / 4) * 25, 100 + (i % 4) * 90, 50 + (i / 4) * 25), chkRace[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 90, 25 + (i / 4) * 25, 100 + (i % 4) * 90, 50 + (i / 4) * 25),
wANRace, CHECK_RACE, dataManager.FormatRace(filter).c_str()); wANRace, CHECK_RACE, dataManager.GetSysString(DataManager::STRING_ID_RACE + i));
//selection hint //selection hint
stHintMsg = env->addStaticText(L"", irr::core::rect<irr::s32>(500, 60, 820, 90), true, false, 0, -1, false); stHintMsg = env->addStaticText(L"", irr::core::rect<irr::s32>(500, 60, 820, 90), true, false, 0, -1, false);
stHintMsg->setBackgroundColor(0xc0ffffff); stHintMsg->setBackgroundColor(0xc0ffffff);
...@@ -787,14 +787,14 @@ bool Game::Initialize() { ...@@ -787,14 +787,14 @@ bool Game::Initialize() {
cbAttribute = env->addComboBox(irr::core::rect<irr::s32>(60, 20 + 50 / 6, 195, 40 + 50 / 6), wFilter, COMBOBOX_ATTRIBUTE); cbAttribute = env->addComboBox(irr::core::rect<irr::s32>(60, 20 + 50 / 6, 195, 40 + 50 / 6), wFilter, COMBOBOX_ATTRIBUTE);
cbAttribute->setMaxSelectionRows(10); cbAttribute->setMaxSelectionRows(10);
cbAttribute->addItem(dataManager.GetSysString(1310), 0); cbAttribute->addItem(dataManager.GetSysString(1310), 0);
for (int filter = 0; filter < ATTRIBUTES_COUNT; ++filter) for (int i = 0; i < ATTRIBUTES_COUNT; ++i)
cbAttribute->addItem(dataManager.FormatAttribute(0x1U << filter).c_str(), 0x1U << filter); cbAttribute->addItem(dataManager.GetSysString(DataManager::STRING_ID_ATTRIBUTE + i), 0x1U << i);
stRace = env->addStaticText(dataManager.GetSysString(1321), irr::core::rect<irr::s32>(10, 42 + 75 / 6, 70, 62 + 75 / 6), false, false, wFilter); stRace = env->addStaticText(dataManager.GetSysString(1321), irr::core::rect<irr::s32>(10, 42 + 75 / 6, 70, 62 + 75 / 6), false, false, wFilter);
cbRace = env->addComboBox(irr::core::rect<irr::s32>(60, 40 + 75 / 6, 195, 60 + 75 / 6), wFilter, COMBOBOX_RACE); cbRace = env->addComboBox(irr::core::rect<irr::s32>(60, 40 + 75 / 6, 195, 60 + 75 / 6), wFilter, COMBOBOX_RACE);
cbRace->setMaxSelectionRows(10); cbRace->setMaxSelectionRows(10);
cbRace->addItem(dataManager.GetSysString(1310), 0); cbRace->addItem(dataManager.GetSysString(1310), 0);
for (int filter = 0; filter < RACES_COUNT; ++filter) for (int i = 0; i < RACES_COUNT; ++i)
cbRace->addItem(dataManager.FormatRace(0x1U << filter).c_str(), 0x1U << filter); cbRace->addItem(dataManager.GetSysString(DataManager::STRING_ID_RACE + i), 0x1U << i);
stAttack = env->addStaticText(dataManager.GetSysString(1322), irr::core::rect<irr::s32>(205, 22 + 50 / 6, 280, 42 + 50 / 6), false, false, wFilter); stAttack = env->addStaticText(dataManager.GetSysString(1322), irr::core::rect<irr::s32>(205, 22 + 50 / 6, 280, 42 + 50 / 6), false, false, wFilter);
ebAttack = env->addEditBox(L"", irr::core::rect<irr::s32>(260, 20 + 50 / 6, 340, 40 + 50 / 6), true, wFilter, EDITBOX_INPUTS); ebAttack = env->addEditBox(L"", irr::core::rect<irr::s32>(260, 20 + 50 / 6, 340, 40 + 50 / 6), true, wFilter, EDITBOX_INPUTS);
ebAttack->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); ebAttack->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
...@@ -1137,41 +1137,48 @@ void Game::InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, i ...@@ -1137,41 +1137,48 @@ void Game::InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, i
scrCardText->setPos(0); scrCardText->setPos(0);
} }
std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, irr::u32 pos) { std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, irr::u32 pos) {
int pbuffer = 0; size_t pbuffer = 0;
irr::u32 _width = 0, _height = 0; irr::u32 _width = 0, _height = 0;
wchar_t prev = 0; wchar_t prev = 0;
wchar_t strBuffer[4096]; wchar_t strBuffer[4096]{};
std::wstring ret; constexpr size_t buffer_len = sizeof strBuffer / sizeof strBuffer[0] - 1;
const size_t text_len = std::wcslen(text);
for(size_t i = 0; text[i] != 0 && i < std::wcslen(text); ++i) { for(size_t i = 0; i < text_len ; ++i) {
if (pbuffer >= buffer_len)
break;
wchar_t c = text[i]; wchar_t c = text[i];
irr::u32 w = font->getCharDimension(c).Width + font->getKerningWidth(c, prev); irr::u32 w = font->getCharDimension(c).Width + font->getKerningWidth(c, prev);
prev = c; prev = c;
if(text[i] == L'\r') { if (c == L'\r') {
continue; continue;
} else if(text[i] == L'\n') { }
if (c == L'\n') {
strBuffer[pbuffer++] = L'\n'; strBuffer[pbuffer++] = L'\n';
_width = 0; _width = 0;
_height++; _height++;
prev = 0; prev = 0;
if(_height == pos) if (_height == pos)
pbuffer = 0; pbuffer = 0;
continue; continue;
} else if(_width > 0 && _width + w > cWidth) { }
if (_width > 0 && _width + w > cWidth) {
strBuffer[pbuffer++] = L'\n'; strBuffer[pbuffer++] = L'\n';
_width = 0; _width = 0;
_height++; _height++;
prev = 0; prev = 0;
if(_height == pos) if (_height == pos)
pbuffer = 0; pbuffer = 0;
} }
if (pbuffer >= buffer_len)
break;
_width += w; _width += w;
strBuffer[pbuffer++] = c; strBuffer[pbuffer++] = c;
} }
strBuffer[pbuffer] = 0; strBuffer[pbuffer] = 0;
if(pControl) pControl->setText(strBuffer); if (pControl)
ret.assign(strBuffer); pControl->setText(strBuffer);
return ret; return std::wstring(strBuffer);
} }
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
void Game::LoadExpansions() { void Game::LoadExpansions() {
...@@ -1631,7 +1638,8 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1631,7 +1638,8 @@ void Game::ShowCardInfo(int code, bool resize) {
} }
if (target->second.setcode[0]) { if (target->second.setcode[0]) {
offset = 23;// *yScale; offset = 23;// *yScale;
myswprintf(formatBuffer, L"%ls%ls", dataManager.GetSysString(1329), dataManager.FormatSetName(target->second.setcode).c_str()); const auto& setname = dataManager.FormatSetName(target->second.setcode);
myswprintf(formatBuffer, L"%ls%ls", dataManager.GetSysString(1329), setname.c_str());
stSetName->setText(formatBuffer); stSetName->setText(formatBuffer);
} }
else else
...@@ -1642,7 +1650,10 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1642,7 +1650,10 @@ void Game::ShowCardInfo(int code, bool resize) {
} }
if(is_valid && cit->second.type & TYPE_MONSTER) { if(is_valid && cit->second.type & TYPE_MONSTER) {
auto& cd = cit->second; auto& cd = cit->second;
myswprintf(formatBuffer, L"[%ls] %ls/%ls", dataManager.FormatType(cd.type).c_str(), dataManager.FormatRace(cd.race).c_str(), dataManager.FormatAttribute(cd.attribute).c_str()); const auto& type = dataManager.FormatType(cd.type);
const auto& race = dataManager.FormatRace(cd.race);
const auto& attribute = dataManager.FormatAttribute(cd.attribute);
myswprintf(formatBuffer, L"[%ls] %ls/%ls", type.c_str(), race.c_str(), attribute.c_str());
stInfo->setText(formatBuffer); stInfo->setText(formatBuffer);
int offset_info = 0; int offset_info = 0;
irr::core::dimension2d<unsigned int> dtxt = guiFont->getDimension(formatBuffer); irr::core::dimension2d<unsigned int> dtxt = guiFont->getDimension(formatBuffer);
...@@ -1664,10 +1675,11 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1664,10 +1675,11 @@ void Game::ShowCardInfo(int code, bool resize) {
myswprintf(adBuffer, L"%d/%d", cd.attack, cd.defense); myswprintf(adBuffer, L"%d/%d", cd.attack, cd.defense);
} else { } else {
form = L"LINK-"; form = L"LINK-";
const auto& link_marker = dataManager.FormatLinkMarker(cd.link_marker);
if(cd.attack < 0) if(cd.attack < 0)
myswprintf(adBuffer, L"?/- %ls", dataManager.FormatLinkMarker(cd.link_marker).c_str()); myswprintf(adBuffer, L"?/- %ls", link_marker.c_str());
else else
myswprintf(adBuffer, L"%d/- %ls", cd.attack, dataManager.FormatLinkMarker(cd.link_marker).c_str()); myswprintf(adBuffer, L"%d/- %ls", cd.attack, link_marker.c_str());
} }
if(cd.type & TYPE_PENDULUM) { if(cd.type & TYPE_PENDULUM) {
myswprintf(scaleBuffer, L" %d/%d", cd.lscale, cd.rscale); myswprintf(scaleBuffer, L" %d/%d", cd.lscale, cd.rscale);
...@@ -1685,8 +1697,10 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1685,8 +1697,10 @@ void Game::ShowCardInfo(int code, bool resize) {
scrCardText->setRelativePosition(irr::core::rect<irr::s32>(287 * xScale - 20, (83 + offset_arrows) + offset, 287 * xScale, 324 * yScale)); scrCardText->setRelativePosition(irr::core::rect<irr::s32>(287 * xScale - 20, (83 + offset_arrows) + offset, 287 * xScale, 324 * yScale));
} }
else { else {
if (is_valid) if (is_valid) {
myswprintf(formatBuffer, L"[%ls]", dataManager.FormatType(cit->second.type).c_str()); const auto& type = dataManager.FormatType(cit->second.type);
myswprintf(formatBuffer, L"[%ls]", type.c_str());
}
else else
myswprintf(formatBuffer, L"[%ls]", dataManager.unknown_string); myswprintf(formatBuffer, L"[%ls]", dataManager.unknown_string);
stInfo->setText(formatBuffer); stInfo->setText(formatBuffer);
......
...@@ -98,24 +98,30 @@ void Replay::EndRecord() { ...@@ -98,24 +98,30 @@ void Replay::EndRecord() {
} }
is_recording = false; is_recording = false;
} }
void Replay::SaveReplay(const wchar_t* name) { bool Replay::SaveReplay(const wchar_t* base_name) {
if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay")) if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay"))
return; return false;
wchar_t fname[256]; wchar_t filename[256]{};
myswprintf(fname, L"./replay/%ls.yrp", name); wchar_t path[256]{};
FILE* rfp = mywfopen(fname, "wb"); BufferIO::CopyWideString(base_name, filename);
FileSystem::SafeFileName(filename);
if (myswprintf(path, L"./replay/%ls.yrp", filename) <= 0)
return false;
FILE* rfp = mywfopen(path, "wb");
if(!rfp) if(!rfp)
return; return false;
std::fwrite(&pheader, sizeof pheader, 1, rfp); std::fwrite(&pheader, sizeof pheader, 1, rfp);
std::fwrite(comp_data, comp_size, 1, rfp); std::fwrite(comp_data, comp_size, 1, rfp);
std::fclose(rfp); std::fclose(rfp);
return true;
} }
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
bool Replay::OpenReplay(const wchar_t* name) { bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = mywfopen(name, "rb"); FILE* rfp = mywfopen(name, "rb");
if(!rfp) { if(!rfp) {
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name); if (myswprintf(fname, L"./replay/%ls", name) <= 0)
return false;
rfp = mywfopen(fname, "rb"); rfp = mywfopen(fname, "rb");
} }
if(!rfp) if(!rfp)
...@@ -167,19 +173,28 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -167,19 +173,28 @@ bool Replay::OpenReplay(const wchar_t* name) {
return true; return true;
} }
bool Replay::DeleteReplay(const wchar_t* name) { bool Replay::DeleteReplay(const wchar_t* name) {
if (std::wcschr(name, L'/') || std::wcschr(name, L'\\'))
return false;
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name); if(myswprintf(fname, L"./replay/%ls", name) <= 0)
return false;
return FileSystem::RemoveFile(fname); return FileSystem::RemoveFile(fname);
} }
bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) { bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) {
wchar_t oldfname[256]; wchar_t old_path[256];
wchar_t newfname[256]; wchar_t new_path[256];
myswprintf(oldfname, L"./replay/%ls", oldname); if (std::wcschr(oldname, L'/') || std::wcschr(oldname, L'\\'))
myswprintf(newfname, L"./replay/%ls", newname); return false;
if (std::wcschr(newname, L'/') || std::wcschr(newname, L'\\'))
return false;
if (myswprintf(old_path, L"./replay/%ls", oldname) <= 0)
return false;
if (myswprintf(new_path, L"./replay/%ls", newname) <= 0)
return false;
char oldfilefn[1024]; char oldfilefn[1024];
char newfilefn[1024]; char newfilefn[1024];
BufferIO::EncodeUTF8(oldfname, oldfilefn); BufferIO::EncodeUTF8(old_path, oldfilefn);
BufferIO::EncodeUTF8(newfname, newfilefn); BufferIO::EncodeUTF8(new_path, newfilefn);
int result = std::rename(oldfilefn, newfilefn); int result = std::rename(oldfilefn, newfilefn);
return result == 0; return result == 0;
} }
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
void WriteInt32(int32_t data, bool flush = true); void WriteInt32(int32_t data, bool flush = true);
void Flush(); void Flush();
void EndRecord(); void EndRecord();
void SaveReplay(const wchar_t* name); bool SaveReplay(const wchar_t* base_name);
// play // play
static bool DeleteReplay(const wchar_t* name); static bool DeleteReplay(const wchar_t* name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment