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 @@
.DS_Store
/deck/
/expansions/
/fonts/
/deck
/expansions
/fonts
/icon
/pack/
/pics/
/replay/
/single/
/sound/
/pack
/pics
/replay
/single
/sound
!/sound/files.txt
/WindBot/
/WindBot
/cards.cdb
/error.log
/bot.conf
......@@ -31,16 +31,16 @@
/.vscode/
/bin/
/build/
/build
/obj/
/event/
/freetype/
/irrlicht/
/irrklang/
/ikpmp3/
/lua/
/miniaudio/
/sqlite3/
/event
/freetype
/irrlicht
/irrklang
/ikpmp3
/lua
/miniaudio
/sqlite3
/gframe/*.ico
/gframe/ygopro.rc
/gframe/ygopro.aps
......
......@@ -27,13 +27,11 @@ ClientField::~ClientField() {
}
hand[i].clear();
for (auto& card : mzone[i]) {
if (card)
delete card;
delete card;
card = nullptr;
}
for (auto& card : szone[i]) {
if (card)
delete card;
delete card;
card = nullptr;
}
for (auto& card : grave[i]) {
......@@ -44,7 +42,6 @@ ClientField::~ClientField() {
delete card;
}
remove[i].clear();
for (auto& card : extra[i]) {
delete card;
}
......@@ -57,30 +54,33 @@ ClientField::~ClientField() {
}
void ClientField::Clear() {
for(int i = 0; i < 2; ++i) {
for(auto cit = deck[i].begin(); cit != deck[i].end(); ++cit)
delete *cit;
for (auto& card : deck[i]) {
delete card;
}
deck[i].clear();
for(auto cit = hand[i].begin(); cit != hand[i].end(); ++cit)
delete *cit;
for (auto& card : hand[i]) {
delete card;
}
hand[i].clear();
for(auto cit = mzone[i].begin(); cit != mzone[i].end(); ++cit) {
if(*cit)
delete *cit;
*cit = 0;
}
for(auto cit = szone[i].begin(); cit != szone[i].end(); ++cit) {
if(*cit)
delete *cit;
*cit = 0;
}
for(auto cit = grave[i].begin(); cit != grave[i].end(); ++cit)
delete *cit;
for (auto& card : mzone[i]) {
delete card;
card = nullptr;
}
for (auto& card : szone[i]) {
delete card;
card = nullptr;
}
for (auto& card : grave[i]) {
delete card;
}
grave[i].clear();
for(auto cit = remove[i].begin(); cit != remove[i].end(); ++cit)
delete *cit;
for (auto& card : remove[i]) {
delete card;
}
remove[i].clear();
for(auto cit = extra[i].begin(); cit != extra[i].end(); ++cit)
delete *cit;
for (auto& card : extra[i]) {
delete card;
}
extra[i].clear();
deck_act[i] = false;
grave_act[i] = false;
......@@ -88,8 +88,9 @@ void ClientField::Clear() {
extra_act[i] = false;
pzone_act[i] = false;
}
for(auto sit = overlay_cards.begin(); sit != overlay_cards.end(); ++sit)
delete *sit;
for (auto& card : overlay_cards) {
delete card;
}
overlay_cards.clear();
extra_p_count[0] = 0;
extra_p_count[1] = 0;
......@@ -417,7 +418,8 @@ void ClientField::ClearChainSelect() {
conti_act = false;
}
// 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) {
bool has_card_in_grave = false;
for (auto& pcard : selectable_cards) {
......@@ -444,7 +446,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
// image
if(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));
else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]);
......@@ -454,7 +456,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
if(mainGame->dInfo.curMsg != MSG_SORT_CARD) {
// text
wchar_t formatBuffer[2048];
if(conti_selecting)
if(select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
......@@ -470,7 +472,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
if (selectable_cards[i]->is_selected)
mainGame->stCardPos[i]->setBackgroundColor(0xffffff00);
else {
if(conti_selecting)
if(select_continuous)
mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
else if(selectable_cards[i]->location == LOCATION_OVERLAY) {
if(selectable_cards[i]->owner != selectable_cards[i]->overlayTarget->controler)
......
......@@ -86,14 +86,14 @@ public:
ChainInfo current_chain;
bool last_chain{ false };
bool deck_reversed{ false };
bool conti_selecting{ false };
bool select_continuous{ false };
bool cant_check_grave{ false };
bool tag_surrender{ false };
bool tag_teammate_surrender{ false };
std::mt19937 rnd;
ClientField();
~ClientField();
~ClientField() override;
void Clear();
void Initial(int player, int deckc, int extrac, int sidec = 0);
void ResetSequence(std::vector<ClientCard*>& list, bool reset_height);
......@@ -105,7 +105,7 @@ public:
void ClearCommandFlag();
void ClearSelect();
void ClearChainSelect();
void ShowSelectCard(bool buttonok = false, bool chain = false);
void ShowSelectCard(bool buttonok = false, bool is_continuous = false);
void ShowChainCard();
void ShowLocationCard();
void ShowSelectOption(int select_hint = 0);
......
......@@ -324,7 +324,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const {
if (attribute & (0x1U << i)) {
if (!buffer.empty())
buffer.push_back(L'|');
buffer.append(GetSysString(1010 + i));
buffer.append(GetSysString(STRING_ID_ATTRIBUTE + i));
}
}
if (buffer.empty())
......@@ -337,7 +337,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const {
if(race & (0x1U << i)) {
if (!buffer.empty())
buffer.push_back(L'|');
buffer.append(GetSysString(1020 + i));
buffer.append(GetSysString(STRING_ID_RACE + i));
}
}
if (buffer.empty())
......@@ -346,12 +346,11 @@ std::wstring DataManager::FormatRace(unsigned int race) const {
}
std::wstring DataManager::FormatType(unsigned int type) const {
std::wstring buffer;
int i = 1050;
for (unsigned filter = TYPE_MONSTER; filter <= TYPE_LINK; filter <<= 1, ++i) {
if (type & filter) {
for (int i = 0; i < TYPES_COUNT; ++i) {
if (type & (0x1U << i)) {
if (!buffer.empty())
buffer.push_back(L'|');
buffer.append(GetSysString(i));
buffer.append(GetSysString(STRING_ID_TYPE + i));
}
}
if (buffer.empty())
......
......@@ -110,6 +110,11 @@ public:
irr::io::IFileSystem* FileSystem{};
#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 uint32_t CardReader(uint32_t, card_data*);
static unsigned char* ScriptReaderEx(const char* script_path, int* slen);
......
......@@ -1095,7 +1095,6 @@ void Game::HideElement(irr::gui::IGUIElement * win, bool set_action) {
if(win == wCardSelect) {
for(int i = 0; i < 5; ++i)
btnCardSelect[i]->setDrawImage(false);
dField.conti_selecting = false;
stCardListTip->setVisible(false);
for(auto& pcard : dField.selectable_cards)
dField.SetShowMark(pcard, false);
......@@ -1307,8 +1306,9 @@ void Game::DrawDeckBd() {
else
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(),
form, ptr->second.level);
const auto& attribute = dataManager.FormatAttribute(ptr->second.attribute);
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));
if(ptr->second.type & TYPE_PENDULUM) {
myswprintf(scaleBuffer, L" %d/%d", ptr->second.lscale, ptr->second.rscale);
......@@ -1318,7 +1318,8 @@ void Game::DrawDeckBd() {
} else {
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));
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));
myswprintf(textBuffer, L"%ls", availBuffer);
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) {
prep += sizeof new_replay.pheader;
std::memcpy(new_replay.comp_data, prep, len - sizeof new_replay.pheader - 1);
new_replay.comp_size = len - sizeof new_replay.pheader - 1;
if(mainGame->actionParam)
new_replay.SaveReplay(mainGame->ebRSName->getText());
if (mainGame->actionParam) {
bool save_result = new_replay.SaveReplay(mainGame->ebRSName->getText());
if (!save_result)
new_replay.SaveReplay(L"_LastReplay");
}
else
new_replay.SaveReplay(L"_LastReplay");
}
......@@ -1113,7 +1116,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
break;
}
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->gMutex.lock();
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer);
......@@ -1123,7 +1127,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
break;
}
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->gMutex.lock();
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer);
......
......@@ -404,7 +404,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
} else {
selectable_cards.clear();
conti_selecting = false;
bool is_continuous = false;
switch(command_location) {
case LOCATION_DECK: {
for(size_t i = 0; i < deck[command_controler].size(); ++i)
......@@ -431,15 +431,15 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case POSITION_HINT: {
is_continuous = true;
selectable_cards = conti_cards;
std::sort(selectable_cards.begin(), selectable_cards.end());
auto eit = std::unique(selectable_cards.begin(), selectable_cards.end());
selectable_cards.erase(eit, selectable_cards.end());
conti_selecting = true;
break;
}
}
if(!conti_selecting) {
if (!is_continuous) {
mainGame->wCardSelect->setText(dataManager.GetSysString(566));
list_command = COMMAND_ACTIVATE;
} else {
......@@ -447,7 +447,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
list_command = COMMAND_OPERATION;
}
std::sort(selectable_cards.begin(), selectable_cards.end(), ClientCard::client_card_sort);
ShowSelectCard(true, true);
ShowSelectCard(true, is_continuous);
}
break;
}
......@@ -892,7 +892,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
// image
if(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));
else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i + pos]->controler + 2]);
......@@ -905,7 +905,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
else
myswprintf(formatBuffer, L"");
} else {
if(conti_selecting)
if(select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
......@@ -919,7 +919,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
mainGame->stCardPos[i]->setText(formatBuffer);
// color
if(conti_selecting)
if(select_continuous)
mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY) {
if(selectable_cards[i + pos]->owner != selectable_cards[i + pos]->overlayTarget->controler)
......@@ -1597,7 +1597,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"\nLINK-%d", mcard->link);
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);
if(mcard->location == LOCATION_HAND && (mcard->type & TYPE_PENDULUM)) {
myswprintf(formatBuffer, L"\n%d/%d", mcard->lscale, mcard->rscale);
......@@ -1622,10 +1624,14 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(211), mcard->chValue);
else if(mcard->cHint == CHINT_CARD)
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(212), dataManager.GetName(mcard->chValue));
else if(mcard->cHint == CHINT_RACE)
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(213), dataManager.FormatRace(mcard->chValue).c_str());
else if(mcard->cHint == CHINT_ATTRIBUTE)
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(214), dataManager.FormatAttribute(mcard->chValue).c_str());
else if(mcard->cHint == CHINT_RACE) {
const auto& race = dataManager.FormatRace(mcard->chValue);
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(213), race.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)
myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(215), mcard->chValue);
str.append(formatBuffer);
......
......@@ -645,16 +645,16 @@ bool Game::Initialize() {
wANAttribute = env->addWindow(irr::core::rect<irr::s32>(500, 200, 830, 285), false, dataManager.GetSysString(562));
wANAttribute->getCloseButton()->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),
wANAttribute, CHECK_ATTRIBUTE, dataManager.FormatAttribute(filter).c_str());
wANAttribute, CHECK_ATTRIBUTE, dataManager.GetSysString(DataManager::STRING_ID_ATTRIBUTE + i));
//announce race
wANRace = env->addWindow(irr::core::rect<irr::s32>(480, 200, 850, 410), false, dataManager.GetSysString(563));
wANRace->getCloseButton()->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),
wANRace, CHECK_RACE, dataManager.FormatRace(filter).c_str());
wANRace, CHECK_RACE, dataManager.GetSysString(DataManager::STRING_ID_RACE + i));
//selection hint
stHintMsg = env->addStaticText(L"", irr::core::rect<irr::s32>(500, 60, 820, 90), true, false, 0, -1, false);
stHintMsg->setBackgroundColor(0xc0ffffff);
......@@ -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->setMaxSelectionRows(10);
cbAttribute->addItem(dataManager.GetSysString(1310), 0);
for (int filter = 0; filter < ATTRIBUTES_COUNT; ++filter)
cbAttribute->addItem(dataManager.FormatAttribute(0x1U << filter).c_str(), 0x1U << filter);
for (int i = 0; i < ATTRIBUTES_COUNT; ++i)
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);
cbRace = env->addComboBox(irr::core::rect<irr::s32>(60, 40 + 75 / 6, 195, 60 + 75 / 6), wFilter, COMBOBOX_RACE);
cbRace->setMaxSelectionRows(10);
cbRace->addItem(dataManager.GetSysString(1310), 0);
for (int filter = 0; filter < RACES_COUNT; ++filter)
cbRace->addItem(dataManager.FormatRace(0x1U << filter).c_str(), 0x1U << filter);
for (int i = 0; i < RACES_COUNT; ++i)
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);
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);
......@@ -1137,41 +1137,48 @@ void Game::InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, i
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) {
int pbuffer = 0;
size_t pbuffer = 0;
irr::u32 _width = 0, _height = 0;
wchar_t prev = 0;
wchar_t strBuffer[4096];
std::wstring ret;
wchar_t strBuffer[4096]{};
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];
irr::u32 w = font->getCharDimension(c).Width + font->getKerningWidth(c, prev);
prev = c;
if(text[i] == L'\r') {
if (c == L'\r') {
continue;
} else if(text[i] == L'\n') {
}
if (c == L'\n') {
strBuffer[pbuffer++] = L'\n';
_width = 0;
_height++;
prev = 0;
if(_height == pos)
if (_height == pos)
pbuffer = 0;
continue;
} else if(_width > 0 && _width + w > cWidth) {
}
if (_width > 0 && _width + w > cWidth) {
strBuffer[pbuffer++] = L'\n';
_width = 0;
_height++;
prev = 0;
if(_height == pos)
if (_height == pos)
pbuffer = 0;
}
if (pbuffer >= buffer_len)
break;
_width += w;
strBuffer[pbuffer++] = c;
}
strBuffer[pbuffer] = 0;
if(pControl) pControl->setText(strBuffer);
ret.assign(strBuffer);
return ret;
if (pControl)
pControl->setText(strBuffer);
return std::wstring(strBuffer);
}
#endif //YGOPRO_SERVER_MODE
void Game::LoadExpansions() {
......@@ -1631,7 +1638,8 @@ void Game::ShowCardInfo(int code, bool resize) {
}
if (target->second.setcode[0]) {
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);
}
else
......@@ -1642,7 +1650,10 @@ void Game::ShowCardInfo(int code, bool resize) {
}
if(is_valid && cit->second.type & TYPE_MONSTER) {
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);
int offset_info = 0;
irr::core::dimension2d<unsigned int> dtxt = guiFont->getDimension(formatBuffer);
......@@ -1664,10 +1675,11 @@ void Game::ShowCardInfo(int code, bool resize) {
myswprintf(adBuffer, L"%d/%d", cd.attack, cd.defense);
} else {
form = L"LINK-";
const auto& link_marker = dataManager.FormatLinkMarker(cd.link_marker);
if(cd.attack < 0)
myswprintf(adBuffer, L"?/- %ls", dataManager.FormatLinkMarker(cd.link_marker).c_str());
myswprintf(adBuffer, L"?/- %ls", link_marker.c_str());
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) {
myswprintf(scaleBuffer, L" %d/%d", cd.lscale, cd.rscale);
......@@ -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));
}
else {
if (is_valid)
myswprintf(formatBuffer, L"[%ls]", dataManager.FormatType(cit->second.type).c_str());
if (is_valid) {
const auto& type = dataManager.FormatType(cit->second.type);
myswprintf(formatBuffer, L"[%ls]", type.c_str());
}
else
myswprintf(formatBuffer, L"[%ls]", dataManager.unknown_string);
stInfo->setText(formatBuffer);
......
......@@ -98,24 +98,30 @@ void Replay::EndRecord() {
}
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"))
return;
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls.yrp", name);
FILE* rfp = mywfopen(fname, "wb");
return false;
wchar_t filename[256]{};
wchar_t path[256]{};
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)
return;
return false;
std::fwrite(&pheader, sizeof pheader, 1, rfp);
std::fwrite(comp_data, comp_size, 1, rfp);
std::fclose(rfp);
return true;
}
#ifndef YGOPRO_SERVER_MODE
bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = mywfopen(name, "rb");
if(!rfp) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
if (myswprintf(fname, L"./replay/%ls", name) <= 0)
return false;
rfp = mywfopen(fname, "rb");
}
if(!rfp)
......@@ -167,19 +173,28 @@ bool Replay::OpenReplay(const wchar_t* name) {
return true;
}
bool Replay::DeleteReplay(const wchar_t* name) {
if (std::wcschr(name, L'/') || std::wcschr(name, L'\\'))
return false;
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
if(myswprintf(fname, L"./replay/%ls", name) <= 0)
return false;
return FileSystem::RemoveFile(fname);
}
bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) {
wchar_t oldfname[256];
wchar_t newfname[256];
myswprintf(oldfname, L"./replay/%ls", oldname);
myswprintf(newfname, L"./replay/%ls", newname);
wchar_t old_path[256];
wchar_t new_path[256];
if (std::wcschr(oldname, L'/') || std::wcschr(oldname, L'\\'))
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 newfilefn[1024];
BufferIO::EncodeUTF8(oldfname, oldfilefn);
BufferIO::EncodeUTF8(newfname, newfilefn);
BufferIO::EncodeUTF8(old_path, oldfilefn);
BufferIO::EncodeUTF8(new_path, newfilefn);
int result = std::rename(oldfilefn, newfilefn);
return result == 0;
}
......
......@@ -71,7 +71,7 @@ public:
void WriteInt32(int32_t data, bool flush = true);
void Flush();
void EndRecord();
void SaveReplay(const wchar_t* name);
bool SaveReplay(const wchar_t* base_name);
// play
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