Commit 870b6b9d authored by nanahira's avatar nanahira

Merge remote-tracking branch 'fh/master' into patch-miniaudio

parents f9362163 148c7680
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_GUI_BUTTON_H_INCLUDED__
#define __C_GUI_BUTTON_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIButton.h"
#include "IGUISpriteBank.h"
#include "SColor.h"
namespace irr
{
namespace gui
{
class CGUIButton : public IGUIButton
{
public:
//! constructor
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip=false);
//! destructor
virtual ~CGUIButton();
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets the sprite bank used by the button
virtual void setSpriteBank(IGUISpriteBank* bank=0);
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color=video::SColor(255,255,255,255), bool loop=false);
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
virtual void setIsPushButton(bool isPushButton=true);
//! Checks whether the button is a push button
virtual bool isPushButton() const;
//! Sets the pressed state of the button if this is a pushbutton
virtual void setPressed(bool pressed=true);
//! Returns if the button is currently pressed
virtual bool isPressed() const;
//! Sets if the button should use the skin to draw its border
virtual void setDrawBorder(bool border=true);
//! Checks if the button face and border are being drawn
virtual bool isDrawingBorder() const;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
virtual void setUseAlphaChannel(bool useAlphaChannel=true);
//! Checks if the alpha channel should be used for drawing images on the button
virtual bool isAlphaChannelUsed() const;
//! Sets if the button should scale the button images to fit
virtual void setScaleImage(bool scaleImage=true);
//! Checks whether the button scales the used images
virtual bool isScalingImage() const;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
u32 ClickTime, HoverTime, FocusTime;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
};
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
#endif // __C_GUI_BUTTON_H_INCLUDED__
This diff is collapsed.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_GUI_IMAGE_BUTTON_H_
#define _C_GUI_IMAGE_BUTTON_H_
#include <irrlicht.h>
#include "CGUIButton.h"
#include <IrrCompileConfig.h>
#ifdef _IRR_COMPILE_WITH_GUI_
#include <IGUIButton.h>
#include <SColor.h>
namespace irr {
namespace video {
class IVideoDriver;
class ITexture;
}
namespace gui {
class IGUISpriteBank;
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff);
void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public CGUIButton {
class CGUIImageButton : public IGUIButton {
public:
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle);
static CGUIImageButton* addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
virtual void draw();
virtual void setImage(video::ITexture* image = 0);
virtual void setDrawImage(bool b);
virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s);
virtual void setImageSize(core::dimension2di s);
virtual IGUIFont* getOverrideFont(void) const;
virtual IGUIFont* getActiveFont() const;
private:
static CGUIImageButton* addImageButton(IGUIEnvironment* env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
//! constructor
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip = false);
//! destructor
~CGUIImageButton() override;
//! called if an event happened.
bool OnEvent(const SEvent& event) override;
//! draws the element and its children
void draw() override;
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
void setOverrideFont(IGUIFont* font = 0) override;
//! Gets the override font (if any)
IGUIFont* getOverrideFont() const override;
//! Get the font which is used right now for drawing
IGUIFont* getActiveFont() const override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets the sprite bank used by the button
void setSpriteBank(IGUISpriteBank* bank = 0) override;
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color = video::SColor(255, 255, 255, 255), bool loop = false) override;
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
void setIsPushButton(bool isPushButton = true) override;
//! Checks whether the button is a push button
bool isPushButton() const override;
//! Sets the pressed state of the button if this is a pushbutton
void setPressed(bool pressed = true) override;
//! Returns if the button is currently pressed
bool isPressed() const override;
//! Sets if the button should use the skin to draw its border
void setDrawBorder(bool border = true) override;
//! Checks if the button face and border are being drawn
bool isDrawingBorder() const override;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
void setUseAlphaChannel(bool useAlphaChannel = true) override;
//! Checks if the alpha channel should be used for drawing images on the button
bool isAlphaChannelUsed() const override;
//! Sets if the button should scale the button images to fit
void setScaleImage(bool scaleImage = true) override;
//! Checks whether the button scales the used images
bool isScalingImage() const override;
//! Writes attributes of the element.
void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const override;
//! Reads attributes of the element
void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) override;
// from ygopro
void setDrawImage(bool b);
void setImageRotation(f32 r);
void setImageScale(core::vector2df s);
void setImageSize(core::dimension2di s);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
// from ygopro
bool isDrawImage;
bool isFixedSize;
f32 imageRotation;
......@@ -36,4 +155,6 @@ private:
}
}
#endif // _IRR_COMPILE_WITH_GUI_
#endif //_C_GUI_IMAGE_BUTTON_H_
......@@ -43,7 +43,7 @@
#define mystrncasecmp strncasecmp
#endif
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
......@@ -56,7 +56,7 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
return std::swprintf(buf, N, fmt, args...);
}
inline FILE* myfopen(const wchar_t* filename, const char* mode) {
inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
FILE* fp{};
#ifdef _WIN32
wchar_t wmode[20]{};
......@@ -65,7 +65,7 @@ inline FILE* myfopen(const wchar_t* filename, const char* mode) {
#else
char fname[1024]{};
BufferIO::EncodeUTF8(filename, fname);
fp = fopen(fname, mode);
fp = std::fopen(fname, mode);
#endif
return fp;
}
......
#include "data_manager.h"
#include "game.h"
#include <stdio.h>
#include "spmemvfs/spmemvfs.h"
namespace ygo {
......@@ -109,14 +108,14 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
return ret;
}
bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r");
FILE* fp = std::fopen(file, "r");
if(!fp)
return false;
char linebuf[TEXT_LINE_SIZE]{};
while(fgets(linebuf, sizeof linebuf, fp)) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
ReadStringConfLine(linebuf);
}
fclose(fp);
std::fclose(fp);
return true;
}
bool DataManager::LoadStrings(irr::io::IReadFile* reader) {
......@@ -140,26 +139,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
char strbuf[TEXT_LINE_SIZE]{};
int value{};
wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1)
if (std::sscanf(linebuf, "!%63s", strbuf) != 1)
return;
if(!std::strcmp(strbuf, "system")) {
if (sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "victory")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "counter")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "setname")) {
//using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
......@@ -432,9 +431,7 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl
return scriptBuffer;
}
unsigned char* DataManager::ReadScriptFromFile(const char* script_name, int* slen) {
wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname);
FILE* fp = myfopen(fname, "rb");
FILE* fp = std::fopen(script_name, "rb");
if (!fp)
return nullptr;
size_t len = std::fread(scriptBuffer, 1, sizeof scriptBuffer, fp);
......
......@@ -46,6 +46,14 @@ static inline bool havePopupWindow() {
return mainGame->wQuery->isVisible() || mainGame->wCategories->isVisible() || mainGame->wLinkMarks->isVisible() || mainGame->wDeckManage->isVisible() || mainGame->wDMQuery->isVisible();
}
static inline void get_deck_file(wchar_t* ret) {
deckManager.GetDeckFile(ret, mainGame->cbDBCategory->getSelected(), mainGame->cbDBCategory->getText(), mainGame->cbDBDecks->getText());
}
static inline void load_current_deck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
deckManager.LoadCurrentDeck(cbCategory->getSelected(), cbCategory->getText(), cbDeck->getText());
}
void DeckBuilder::Initialize() {
mainGame->is_building = true;
mainGame->is_siding = false;
......@@ -164,7 +172,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(sel == -1)
break;
wchar_t filepath[256];
deckManager.GetDeckFile(filepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(filepath);
if(deckManager.SaveDeck(deckManager.current_deck, filepath)) {
mainGame->stACMessage->setText(dataManager.GetSysString(1335));
mainGame->PopupElement(mainGame->wACMessage, 20);
......@@ -480,7 +488,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
int decksel = mainGame->lstDecks->getSelected();
const wchar_t* catename = mainGame->lstCategories->getListItem(catesel);
wchar_t oldfilepath[256];
deckManager.GetDeckFile(oldfilepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(oldfilepath);
const wchar_t* newdeckname = mainGame->ebDMName->getText();
wchar_t newfilepath[256];
if(catesel == 2) {
......@@ -512,7 +520,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case BUTTON_DELETE_DECK_DM: {
int decksel = mainGame->lstDecks->getSelected();
wchar_t filepath[256];
deckManager.GetDeckFile(filepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(filepath);
if(deckManager.DeleteDeck(filepath)) {
mainGame->lstDecks->removeItem(decksel);
mainGame->cbDBDecks->removeItem(decksel);
......@@ -523,7 +531,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(decksel != -1) {
mainGame->lstDecks->setSelected(decksel);
mainGame->cbDBDecks->setSelected(decksel);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
}
RefreshReadonly(prev_category);
prev_deck = decksel;
......@@ -542,7 +550,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
wchar_t deckname[256];
BufferIO::CopyWideString(olddeckname, deckname);
wchar_t oldfilepath[256];
deckManager.GetDeckFile(oldfilepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(oldfilepath);
wchar_t newfilepath[256];
if(oldcatesel != 2 && newcatesel == 0) {
myswprintf(newfilepath, L"./deck/%ls.ydk", deckname);
......@@ -651,7 +659,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_SIDE_RELOAD: {
deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
load_current_deck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
break;
}
case BUTTON_BIG_CARD_ORIG_SIZE: {
......@@ -689,7 +697,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
int sel = prev_sel;
mainGame->cbDBDecks->setSelected(sel);
wchar_t filepath[256];
deckManager.GetDeckFile(filepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(filepath);
if(deckManager.DeleteDeck(filepath)) {
mainGame->cbDBDecks->removeItem(sel);
int count = mainGame->cbDBDecks->getItemCount();
......@@ -697,7 +705,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
sel = count - 1;
mainGame->cbDBDecks->setSelected(sel);
if(sel != -1)
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->stACMessage->setText(dataManager.GetSysString(1338));
mainGame->PopupElement(mainGame->wACMessage, 20);
prev_deck = sel;
......@@ -711,7 +719,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
ChangeCategory(catesel);
} else if(prev_operation == COMBOBOX_DBDECKS) {
int decksel = mainGame->cbDBDecks->getSelected();
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
prev_deck = decksel;
is_modified = false;
} else if(prev_operation == BUTTON_MANAGE_DECK) {
......@@ -828,7 +836,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
int decksel = mainGame->cbDBDecks->getSelected();
if(decksel >= 0) {
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
}
prev_deck = decksel;
is_modified = false;
......@@ -1630,7 +1638,7 @@ void DeckBuilder::ChangeCategory(int catesel) {
mainGame->RefreshDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->cbDBDecks->setSelected(0);
RefreshReadonly(catesel);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
is_modified = false;
prev_category = catesel;
prev_deck = 0;
......
#include "deck_manager.h"
#include "game.h"
#include "myfilesystem.h"
#include "network.h"
#include "game.h"
namespace ygo {
......@@ -10,30 +10,27 @@ DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
auto cur = _lfList.rend();
FILE* fp = fopen(path, "r");
FILE* fp = std::fopen(path, "r");
char linebuf[256]{};
wchar_t strBuffer[256]{};
if(fp) {
while(fgets(linebuf, 256, fp)) {
while(std::fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
int sa = BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' )
sa--;
strBuffer[sa] = 0;
auto len = std::strcspn(linebuf, "\r\n");
linebuf[len] = 0;
BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
LFList newlist;
newlist.listName = strBuffer;
newlist.hash = 0x7dfcee6a;
_lfList.push_back(newlist);
cur = _lfList.rbegin();
cur->listName = strBuffer;
cur->hash = 0x7dfcee6a;
continue;
}
if(linebuf[0] == 0)
continue;
int code = 0;
int count = -1;
if (sscanf(linebuf, "%d %d", &code, &count) != 2)
if (std::sscanf(linebuf, "%d %d", &code, &count) != 2)
continue;
if (code <= 0 || code > MAX_CARD_ID)
continue;
......@@ -45,7 +42,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
cur->content[code] = count;
cur->hash = cur->hash ^ ((hcode << 18) | (hcode >> 14)) ^ ((hcode << (27 + count)) | (hcode >> (5 - count)));
}
fclose(fp);
std::fclose(fp);
}
}
void DeckManager::LoadLFList() {
......@@ -252,12 +249,11 @@ void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text)
}
BufferIO::CopyWStr(catepath, ret, 256);
}
void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
void DeckManager::GetDeckFile(wchar_t* ret, int category_index, const wchar_t* category_name, const wchar_t* deckname) {
wchar_t filepath[256];
wchar_t catepath[256];
const wchar_t* deckname = cbDeck->getItem(cbDeck->getSelected());
if(deckname != nullptr) {
GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText());
GetCategoryPath(catepath, category_index, category_name);
myswprintf(filepath, L"%ls/%ls.ydk", catepath, deckname);
BufferIO::CopyWStr(filepath, ret, 256);
}
......@@ -266,16 +262,16 @@ void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory,
}
}
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
FILE* fp = myfopen(file, mode);
FILE* fp = mywfopen(file, mode);
return fp;
}
IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
irr::io::IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
#ifdef _WIN32
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file);
auto reader = DataManager::FileSystem->createAndOpenFile(file);
#else
char file2[256];
BufferIO::EncodeUTF8(file, file2);
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file2);
auto reader = DataManager::FileSystem->createAndOpenFile(file2);
#endif
return reader;
}
......@@ -304,10 +300,10 @@ bool DeckManager::LoadCurrentDeck(const wchar_t* file, bool is_packlist) {
LoadDeck(current_deck, deckStream, is_packlist);
return true; // the above LoadDeck has return value but we ignore it here for now
}
bool DeckManager::LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
bool DeckManager::LoadCurrentDeck(int category_index, const wchar_t* category_name, const wchar_t* deckname) {
wchar_t filepath[256];
GetDeckFile(filepath, cbCategory, cbDeck);
bool is_packlist = cbCategory->getSelected() == 0;
GetDeckFile(filepath, category_index, category_name, deckname);
bool is_packlist = (category_index == 0);
bool res = LoadCurrentDeck(filepath, is_packlist);
if (res && mainGame->is_building)
mainGame->deckBuilder.RefreshPackListScroll();
......@@ -319,16 +315,16 @@ bool DeckManager::SaveDeck(Deck& deck, const wchar_t* file) {
FILE* fp = OpenDeckFile(file, "w");
if(!fp)
return false;
fprintf(fp, "#created by ...\n#main\n");
std::fprintf(fp, "#created by ...\n#main\n");
for(size_t i = 0; i < deck.main.size(); ++i)
fprintf(fp, "%d\n", deck.main[i]->first);
fprintf(fp, "#extra\n");
std::fprintf(fp, "%d\n", deck.main[i]->first);
std::fprintf(fp, "#extra\n");
for(size_t i = 0; i < deck.extra.size(); ++i)
fprintf(fp, "%d\n", deck.extra[i]->first);
fprintf(fp, "!side\n");
std::fprintf(fp, "%d\n", deck.extra[i]->first);
std::fprintf(fp, "!side\n");
for(size_t i = 0; i < deck.side.size(); ++i)
fprintf(fp, "%d\n", deck.side[i]->first);
fclose(fp);
std::fprintf(fp, "%d\n", deck.side[i]->first);
std::fclose(fp);
return true;
}
bool DeckManager::DeleteDeck(const wchar_t* file) {
......@@ -378,26 +374,26 @@ bool DeckManager::SaveDeckBuffer(const int deckbuf[], const wchar_t* name) {
int it = 0;
const int mainc = deckbuf[it];
++it;
fprintf(fp, "#created by ...\n#main\n");
std::fprintf(fp, "#created by ...\n#main\n");
for (int i = 0; i < mainc; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
const int extrac = deckbuf[it];
++it;
fprintf(fp, "#extra\n");
std::fprintf(fp, "#extra\n");
for (int i = 0; i < extrac; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
const int sidec = deckbuf[it];
++it;
fprintf(fp, "!side\n");
std::fprintf(fp, "!side\n");
for (int i = 0; i < sidec; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
fclose(fp);
std::fclose(fp);
return true;
}
}
#ifndef DECKMANAGER_H
#define DECKMANAGER_H
#include "config.h"
#include "data_manager.h"
#include <unordered_map>
#include <vector>
#include <sstream>
#include "data_manager.h"
namespace ygo {
constexpr int DECK_MAX_SIZE = 60;
......@@ -52,11 +51,11 @@ public:
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
void GetDeckFile(wchar_t* ret, int category_index, const wchar_t* category_name, const wchar_t* deckname);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file);
irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool LoadCurrentDeck(int category_index, const wchar_t* category_name, const wchar_t* deckname);
bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file);
bool CreateCategory(const wchar_t* name);
......
This diff is collapsed.
......@@ -234,10 +234,10 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr && !mainGame->gameConf.use_image_scale) {
......@@ -261,10 +261,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
}
irr::video::ITexture* texture;
char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == nullptr) {
......@@ -290,18 +290,18 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock();
char file[256];
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
irr::video::IImage* img = imageManager.driver->createImageFromFile(file);
if(img == nullptr) {
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img != nullptr) {
......@@ -346,7 +346,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) {
if(lit->second != nullptr) {
char file[256];
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop();
tThumb[code] = texture;
......@@ -379,18 +379,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.png", code);
std::snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
tFields[code] = nullptr;
......
......@@ -176,7 +176,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case BUTTON_HP_READY: {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect->getSelected(), mainGame->cbCategorySelect->getText(), mainGame->cbDeckSelect->getText())) {
mainGame->gMutex.lock();
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1406));
......@@ -367,7 +367,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t arg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory->getSelected(), mainGame->cbBotDeckCategory->getText(), mainGame->cbBotDeck->getText());
myswprintf(arg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......@@ -386,7 +386,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t warg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory->getSelected(), mainGame->cbBotDeckCategory->getText(), mainGame->cbBotDeck->getText());
myswprintf(warg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......@@ -396,9 +396,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8];
snprintf(arg2, sizeof arg2, "%d", flag);
std::snprintf(arg2, sizeof arg2, "%d", flag);
char arg3[8];
snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
std::snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, nullptr);
exit(0);
} else {
......@@ -472,7 +472,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
open_file = false;
}
else if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory->getSelected(), mainGame->cbDBCategory->getText(), mainGame->cbDBDecks->getText());
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu);
......@@ -581,7 +581,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(sel);
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
FILE* fp = myfopen(fname, "rb");
FILE* fp = mywfopen(fname, "rb");
if(!fp) {
mainGame->stSinglePlayInfo->setText(L"");
break;
......@@ -590,7 +590,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t wlinebuf[1024];
std::wstring message = L"";
bool in_message = false;
while(fgets(linebuf, 1024, fp)) {
while(std::fgets(linebuf, 1024, fp)) {
if(!std::strncmp(linebuf, "--[[message", 11)) {
size_t len = std::strlen(linebuf);
char* msgend = std::strrchr(linebuf, ']');
......@@ -613,7 +613,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
message.append(wlinebuf);
}
}
fclose(fp);
std::fclose(fp);
mainGame->SetStaticText(mainGame->stSinglePlayInfo, 200, mainGame->guiFont, message.c_str());
break;
}
......@@ -637,7 +637,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->env->setFocus(mainGame->wHostPrepare);
if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect->getSelected(), mainGame->cbCategorySelect->getText(), mainGame->cbDeckSelect->getText())) {
mainGame->gMutex.lock();
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
soundManager.PlaySoundEffect(SOUND_INFO);
......
......@@ -94,7 +94,7 @@ public:
if(fh == INVALID_HANDLE_VALUE)
return;
do {
if(mywcsncasecmp(fdataw.cFileName, L".", 1) && mywcsncasecmp(fdataw.cFileName, L"..", 2))
if(std::wcscmp(fdataw.cFileName, L".") && std::wcscmp(fdataw.cFileName, L".."))
cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
......@@ -216,7 +216,7 @@ public:
stat(fname, &fileStat);
funit.filename = std::string(dirp->d_name);
funit.is_dir = S_ISDIR(fileStat.st_mode);
if(funit.is_dir && (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0))
if(funit.is_dir && (std::strcmp(dirp->d_name, ".") == 0 || std::strcmp(dirp->d_name, "..") == 0))
continue;
file_list.push_back(funit);
}
......
......@@ -23,8 +23,8 @@ void Replay::BeginRecord() {
return;
#else
if(is_recording)
fclose(fp);
fp = fopen("./replay/_LastReplay.yrp", "wb");
std::fclose(fp);
fp = std::fopen("./replay/_LastReplay.yrp", "wb");
if(!fp)
return;
#endif
......@@ -39,8 +39,8 @@ void Replay::WriteHeader(ReplayHeader& header) {
DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, nullptr);
#else
fwrite(&header, sizeof(header), 1, fp);
fflush(fp);
std::fwrite(&header, sizeof(header), 1, fp);
std::fflush(fp);
#endif
}
void Replay::WriteData(const void* data, size_t length, bool flush) {
......@@ -54,9 +54,9 @@ void Replay::WriteData(const void* data, size_t length, bool flush) {
DWORD size;
WriteFile(recording_fp, data, length, &size, nullptr);
#else
fwrite(data, length, 1, fp);
std::fwrite(data, length, 1, fp);
if(flush)
fflush(fp);
std::fflush(fp);
#endif
}
void Replay::WriteInt32(int32_t data, bool flush) {
......@@ -67,7 +67,7 @@ void Replay::Flush() {
return;
#ifdef _WIN32
#else
fflush(fp);
std::fflush(fp);
#endif
}
void Replay::EndRecord() {
......@@ -76,7 +76,7 @@ void Replay::EndRecord() {
#ifdef _WIN32
CloseHandle(recording_fp);
#else
fclose(fp);
std::fclose(fp);
#endif
pheader.datasize = replay_size;
pheader.flag |= REPLAY_COMPRESSED;
......@@ -94,19 +94,19 @@ void Replay::SaveReplay(const wchar_t* name) {
return;
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls.yrp", name);
FILE* rfp = myfopen(fname, "wb");
FILE* rfp = mywfopen(fname, "wb");
if(!rfp)
return;
fwrite(&pheader, sizeof pheader, 1, rfp);
fwrite(comp_data, comp_size, 1, rfp);
fclose(rfp);
std::fwrite(&pheader, sizeof pheader, 1, rfp);
std::fwrite(comp_data, comp_size, 1, rfp);
std::fclose(rfp);
}
bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = myfopen(name, "rb");
FILE* rfp = mywfopen(name, "rb");
if(!rfp) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
rfp = myfopen(fname, "rb");
rfp = mywfopen(fname, "rb");
}
if(!rfp)
return false;
......@@ -116,13 +116,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
is_replaying = false;
replay_size = 0;
comp_size = 0;
if(fread(&pheader, sizeof pheader, 1, rfp) < 1) {
fclose(rfp);
if(std::fread(&pheader, sizeof pheader, 1, rfp) < 1) {
std::fclose(rfp);
return false;
}
if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = fread(comp_data, 1, MAX_COMP_SIZE, rfp);
fclose(rfp);
comp_size = std::fread(comp_data, 1, MAX_COMP_SIZE, rfp);
std::fclose(rfp);
if (pheader.datasize > MAX_REPLAY_SIZE)
return false;
replay_size = pheader.datasize;
......@@ -133,8 +133,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false;
}
} else {
replay_size = fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
fclose(rfp);
replay_size = std::fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
std::fclose(rfp);
comp_size = 0;
}
is_replaying = true;
......@@ -143,12 +143,12 @@ bool Replay::OpenReplay(const wchar_t* name) {
bool Replay::CheckReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
FILE* rfp = myfopen(fname, "rb");
FILE* rfp = mywfopen(fname, "rb");
if(!rfp)
return false;
ReplayHeader rheader;
size_t count = fread(&rheader, sizeof rheader, 1, rfp);
fclose(rfp);
size_t count = std::fread(&rheader, sizeof rheader, 1, rfp);
std::fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
}
bool Replay::DeleteReplay(const wchar_t* name) {
......
......@@ -169,7 +169,7 @@ void SoundManager::PlaySoundEffect(int sound) {
break;
}
char soundPath[40];
snprintf(soundPath, 40, "./sound/%s.wav", soundName);
std::snprintf(soundPath, 40, "./sound/%s.wav", soundName);
#ifdef YGOPRO_USE_AUDIO
ma_engine_set_volume(&engineSound, mainGame->gameConf.sound_volume);
auto res = ma_engine_play_sound(&engineSound, soundPath, nullptr);
......
This diff is collapsed.
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