Commit cb8fa2e7 authored by nanahira's avatar nanahira

merge

parents b0743676 f5152094
......@@ -73,6 +73,7 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
#include <memory.h>
#include <time.h>
#include "bufferio.h"
#include "myfilesystem.h"
#include "mymutex.h"
#include "mysignal.h"
#include "mythread.h"
......
......@@ -251,6 +251,8 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
return true;
}
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
if(!FileSystem::IsDirExists(L"./deck") && !FileSystem::MakeDir(L"./deck"))
return false;
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
FILE* fp = OpenDeckFile(file, "w");
......
......@@ -728,7 +728,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->actionParam = 1;
wchar_t msgbuf[256];
myswprintf(msgbuf, dataManager.GetSysString(1376), timetext);
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->textFont, msgbuf);
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, msgbuf);
mainGame->PopupElement(mainGame->wACMessage, 20);
mainGame->gMutex.Unlock();
mainGame->WaitFrameSignal(30);
......
This diff is collapsed.
......@@ -168,11 +168,10 @@ public:
void SaveConfig();
void ShowCardInfo(int code, bool resize = false);
void ClearCardInfo(int player = 0);
void AddChatMsg(wchar_t* msg, int player);
void AddChatMsg(const wchar_t* msg, int player);
void ClearChatMsg();
void AddDebugMsg(char* msgbuf);
void ErrorLog(char* msgbuf);
bool MakeDirectory(const std::string folder);
void AddDebugMsg(const char* msgbuf);
void ErrorLog(const char* msgbuf);
void initUtils();
void ClearTextures();
void CloseDuelWindow();
......
#include "image_manager.h"
#include "game.h"
#ifndef _WIN32
#include <dirent.h>
#endif
namespace ygo {
......@@ -95,54 +92,27 @@ irr::video::ITexture* ImageManager::GetRandomImage(int image_type, s32 width, s3
return GetTextureFromFile(ImageName, width, height);
}
void ImageManager::RefreshRandomImageList() {
RefreshImageDir(L"bg/", TEXTURE_DUEL);
RefreshImageDir(L"bg_duel/", TEXTURE_DUEL);
RefreshImageDir(L"bg_deck/", TEXTURE_DECK);
RefreshImageDir(L"bg_menu/", TEXTURE_MENU);
RefreshImageDir(L"cover/", TEXTURE_COVER_S);
RefreshImageDir(L"cover2/", TEXTURE_COVER_O);
RefreshImageDir(L"attack/", TEXTURE_ATTACK);
RefreshImageDir(L"act/", TEXTURE_ACTIVATE);
RefreshImageDir(L"bg", TEXTURE_DUEL);
RefreshImageDir(L"bg_duel", TEXTURE_DUEL);
RefreshImageDir(L"bg_deck", TEXTURE_DECK);
RefreshImageDir(L"bg_menu", TEXTURE_MENU);
RefreshImageDir(L"cover", TEXTURE_COVER_S);
RefreshImageDir(L"cover2", TEXTURE_COVER_O);
RefreshImageDir(L"attack", TEXTURE_ATTACK);
RefreshImageDir(L"act", TEXTURE_ACTIVATE);
for(int i = 0; i < 7; ++ i) {
saved_image_id[i] = -1;
}
}
void ImageManager::RefreshImageDir(std::wstring path, int image_type) {
#ifdef _WIN32
WIN32_FIND_DATAW fdataw;
std::wstring search = L"./textures/" + path + L"*.*";
HANDLE fh = FindFirstFileW(search.c_str(), &fdataw);
if(fh == INVALID_HANDLE_VALUE)
return;
do {
size_t len = wcslen(fdataw.cFileName);
if((fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || len < 5
|| !(_wcsicmp(fdataw.cFileName + len - 4, L".jpg") == 0 || _wcsicmp(fdataw.cFileName + len - 4, L".png") == 0))
continue;
std::wstring filename = path + (std::wstring)fdataw.cFileName;
ImageList[image_type].push_back(filename);
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
#else
DIR * dir;
struct dirent * dirp;
std::wstring wsearchpath = L"./textures/" + path;
char searchpath[256];
BufferIO::EncodeUTF8(wsearchpath.c_str(), searchpath);
if((dir = opendir(searchpath)) == NULL)
return;
while((dirp = readdir(dir)) != NULL) {
size_t len = strlen(dirp->d_name);
if(len < 5 || !(strcasecmp(dirp->d_name + len - 4, ".jpg") == 0 || strcasecmp(dirp->d_name + len - 4, ".png")))
continue;
wchar_t wname[256];
BufferIO::DecodeUTF8(dirp->d_name, wname);
std::wstring filename = path + (std::wstring)wname;
ImageList[image_type].push_back(filename);
}
closedir(dir);
#endif
std::wstring search = L"./textures/" + path;
FileSystem::TraversalDir(search.c_str(), [this, &path, image_type](const wchar_t* name, bool isdir) {
if(!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".jpg", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".png", 4))) {
std::wstring filename = path + L"/" + name;
ImageList[image_type].push_back(filename);
}
});
}
void ImageManager::SetDevice(irr::IrrlichtDevice* dev) {
device = dev;
......
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include <string.h>
#include <functional>
#include "bufferio.h"
#ifdef _WIN32
#include <direct.h>
#include <sys/stat.h>
#else
#include <dirent.h>
#include <sys/stat.h>
#endif
#ifdef _WIN32
#include <Windows.h>
class FileSystem {
public:
static bool IsFileExists(const wchar_t* wfile) {
struct _stat fileStat;
return (_wstat(wfile, &fileStat) == 0) && !(fileStat.st_mode & _S_IFDIR);
}
static bool IsFileExists(const char* file) {
wchar_t wfile[1024];
BufferIO::DecodeUTF8(file, wfile);
return IsFileExists(wfile);
}
static bool IsDirExists(const wchar_t* wdir) {
struct _stat fileStat;
return (_wstat(wdir, &fileStat) == 0) && (fileStat.st_mode & _S_IFDIR);
}
static bool IsDirExists(const char* dir) {
wchar_t wdir[1024];
BufferIO::DecodeUTF8(dir, wdir);
return IsDirExists(wdir);
}
static bool MakeDir(const wchar_t* wdir) {
return _wmkdir(wdir) == 0;
}
static bool MakeDir(const char* dir) {
wchar_t wdir[1024];
BufferIO::DecodeUTF8(dir, wdir);
return MakeDir(wdir);
}
static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) {
wchar_t findstr[1024];
wcscpy(findstr, wpath);
wcscat(findstr, L"/*");
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(findstr, &fdataw);
if(fh == INVALID_HANDLE_VALUE)
return;
do {
cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
}
static void TraversalDir(const char* path, const std::function<void(const char*, bool)>& cb) {
wchar_t wpath[1024];
BufferIO::DecodeUTF8(path, wpath);
TraversalDir(wpath, [&cb](const wchar_t* wname, bool isdir) {
char name[1024];
BufferIO::EncodeUTF8(wname, name);
cb(name, isdir);
});
}
};
#else
class FileSystem {
public:
static bool IsFileExists(const char* file) {
struct stat fileStat;
return (stat(file, &fileStat) == 0) && !S_ISDIR(fileStat.st_mode);
}
static bool IsFileExists(const wchar_t* wfile) {
char file[1024];
BufferIO::EncodeUTF8(wfile, file);
return IsFileExists(file);
}
static bool IsDirExists(const char* dir) {
struct stat fileStat;
return (stat(dir, &fileStat) == 0) && S_ISDIR(fileStat.st_mode);
}
static bool IsDirExists(const wchar_t* wdir) {
char dir[1024];
BufferIO::EncodeUTF8(wdir, dir);
return IsDirExists(dir);
}
static bool MakeDir(const char* dir) {
return mkdir(dir, 0775) == 0;
}
static bool MakeDir(const wchar_t* wdir) {
char dir[1024];
BufferIO::EncodeUTF8(wdir, dir);
return MakeDir(dir);
}
static void TraversalDir(const char* path, const std::function<void(const char*, bool)>& cb) {
DIR* dir = nullptr;
struct dirent* dirp = nullptr;
if((dir = opendir(path)) == nullptr)
return;
struct stat fileStat;
while((dirp = readdir(dir)) != nullptr) {
char fname[1024];
strcpy(fname, path);
strcat(fname, "/");
strcat(fname, dirp->d_name);
stat(fname, &fileStat);
cb(dirp->d_name, S_ISDIR(fileStat.st_mode));
}
closedir(dir);
}
static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) {
char path[1024];
BufferIO::EncodeUTF8(wpath, path);
TraversalDir(path, [&cb](const char* name, bool isdir) {
wchar_t wname[1024];
BufferIO::DecodeUTF8(name, wname);
cb(wname, isdir);
});
}
};
#endif // _WIN32
#endif //FILESYSTEM_H
......@@ -24,6 +24,8 @@ void Replay::BeginRecord() {
#ifdef YGOPRO_SERVER_MODE
if(replay_mode > 0) {
#endif
if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay"))
return;
#ifdef _WIN32
if(is_recording)
CloseHandle(recording_fp);
......@@ -177,6 +179,8 @@ void Replay::EndRecord() {
is_recording = false;
}
void Replay::SaveReplay(const wchar_t* name) {
if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay"))
return;
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls.yrp", name);
#ifdef WIN32
......
......@@ -149,7 +149,7 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->actionParam = 1;
wchar_t msgbuf[256];
myswprintf(msgbuf, dataManager.GetSysString(1376), timetext);
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->textFont, msgbuf);
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, msgbuf);
mainGame->PopupElement(mainGame->wACMessage, 20);
mainGame->gMutex.Unlock();
mainGame->WaitFrameSignal(30);
......
#include "sound_manager.h"
#ifndef _WIN32
#include <dirent.h>
#endif
#ifdef YGOPRO_USE_IRRKLANG
#include "../ikpmp3/ikpMP3.h"
#endif
......@@ -31,55 +28,25 @@ bool SoundManager::Init() {
void SoundManager::RefreshBGMList() {
#ifdef YGOPRO_USE_IRRKLANG
RefershBGMDir(L"", BGM_DUEL);
RefershBGMDir(L"duel/", BGM_DUEL);
RefershBGMDir(L"menu/", BGM_MENU);
RefershBGMDir(L"deck/", BGM_DECK);
RefershBGMDir(L"advantage/", BGM_ADVANTAGE);
RefershBGMDir(L"disadvantage/", BGM_DISADVANTAGE);
RefershBGMDir(L"win/", BGM_WIN);
RefershBGMDir(L"lose/", BGM_LOSE);
RefershBGMDir(L"custom/", BGM_CUSTOM);
RefershBGMDir(L"duel", BGM_DUEL);
RefershBGMDir(L"menu", BGM_MENU);
RefershBGMDir(L"deck", BGM_DECK);
RefershBGMDir(L"advantage", BGM_ADVANTAGE);
RefershBGMDir(L"disadvantage", BGM_DISADVANTAGE);
RefershBGMDir(L"win", BGM_WIN);
RefershBGMDir(L"lose", BGM_LOSE);
RefershBGMDir(L"custom", BGM_CUSTOM);
#endif
}
void SoundManager::RefershBGMDir(std::wstring path, int scene) {
#ifdef YGOPRO_USE_IRRKLANG
#ifdef _WIN32
WIN32_FIND_DATAW fdataw;
std::wstring search = L"./sound/BGM/" + path + L"*.*";
HANDLE fh = FindFirstFileW(search.c_str(), &fdataw);
if(fh == INVALID_HANDLE_VALUE)
return;
do {
size_t len = wcslen(fdataw.cFileName);
if((fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || len < 5
|| !(_wcsicmp(fdataw.cFileName + len - 4, L".mp3") == 0 || _wcsicmp(fdataw.cFileName + len - 4, L".ogg") == 0))
continue;
std::wstring filename = path + (std::wstring)fdataw.cFileName;
BGMList[BGM_ALL].push_back(filename);
BGMList[scene].push_back(filename);
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
#else
DIR * dir;
struct dirent * dirp;
std::wstring wsearchpath = L"./sound/BGM/" + path;
char searchpath[256];
BufferIO::EncodeUTF8(wsearchpath.c_str(), searchpath);
if((dir = opendir(searchpath)) == NULL)
return;
while((dirp = readdir(dir)) != NULL) {
size_t len = strlen(dirp->d_name);
if(len < 5 || !(strcasecmp(dirp->d_name + len - 4, ".mp3") == 0 || strcasecmp(dirp->d_name + len - 4, ".ogg")))
continue;
wchar_t wname[256];
BufferIO::DecodeUTF8(dirp->d_name, wname);
std::wstring filename = path + (std::wstring)wname;
BGMList[BGM_ALL].push_back(filename);
BGMList[scene].push_back(filename);
}
closedir(dir);
#endif
#endif
std::wstring search = L"./sound/BGM/" + path;
FileSystem::TraversalDir(search.c_str(), [this, &path, scene](const wchar_t* name, bool isdir) {
if(!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".mp3", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".ogg", 4))) {
std::wstring filename = path + L"/" + name;
BGMList[BGM_ALL].push_back(filename);
BGMList[scene].push_back(filename);
}
});
}
void SoundManager::PlaySoundEffect(int sound) {
#ifdef YGOPRO_USE_IRRKLANG
......
......@@ -37,7 +37,7 @@ solution "ygo"
optimize "Speed"
flags { "LinkTimeOptimization" }
staticruntime "On"
disablewarnings { "4244", "4267", "4838", "4577", "4819", "4018", "4996", "4477", "4091", "4305", "4828" }
disablewarnings { "4244", "4267", "4838", "4577", "4819", "4018", "4996", "4477", "4091", "4305", "4828", "4800" }
configuration { "Release", "not vs*" }
symbols "On"
......
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