Commit f435bd8a authored by nanahira's avatar nanahira

merge server

parents 5e93c448 6be4895b
# data files # data files
/beta /beta
/expansions /expansions
/specials /specials
# build files # build files
/bin /bin
/build /build
/obj /obj
# dependencies # dependencies
/event /event
/freetype /freetype
/sqlite3 /sqlite3
/ikpmp3 /ikpmp3
/irrklang /irrklang
/irrlicht /irrlicht
/lua /lua
# gframe additionals # gframe additionals
/gframe/ygopro.ico /gframe/ygopro.ico
/gframe/ygopro.rc /gframe/ygopro.rc
/gframe/ygopro.aps /gframe/ygopro.aps
/gframe/ygopro.icns /gframe/ygopro.icns
/gframe/dirent.h /gframe/dirent.h
# git repos # git repos
/CustomTools /CustomTools
/DataEditorX /DataEditorX
/Magic* /Magic*
/pics /pics
/Printer /Printer
/script /script
/ygopro-* /ygopro-*
/*-Cards /*-Cards
# libs # libs
/*.dll /*.dll
/*.so /*.so
/*.dylib /*.dylib
# windbot related files # windbot related files
/[Bb]ot /[Bb]ot
/[Bb]ot.conf /[Bb]ot.conf
/[Bb]ot.exe /[Bb]ot.exe
/[Bb]ot.sh /[Bb]ot.sh
/[Ww]ind[Bb]ot /[Ww]ind[Bb]ot
# ygopro config file # ygopro config file
/system_user.conf /system_user.conf
# ygopro folders # ygopro folders
/deck /deck
/fonts /fonts
/replay /replay
/single /single
/sound/*.wav /sound/*.wav
/sound/custom /sound/custom
/sound/BGM /sound/BGM
/update /update
/update* /update*
# ygopro main program # ygopro main program
/ygopro /ygopro
/ygopro_* /ygopro_*
/ygopro.exe /ygopro.exe
/ygopro_*.exe /ygopro_*.exe
/ygopro.app /ygopro.app
/ygopro_*.app /ygopro_*.app
/premake4 /premake4
/premake4.exe /premake4.exe
/premake5 /premake5
/premake5.exe /premake5.exe
# others # others
*.log *.log
/.vscode /.vscode
/bak/ /bak/
/temp /temp
/PrinterData.txt /PrinterData.txt
/ygopro_*.bat /ygopro_*.bat
/ygopro_*.sh /ygopro_*.sh
...@@ -60,6 +60,9 @@ void ClientField::Clear() { ...@@ -60,6 +60,9 @@ void ClientField::Clear() {
delete *cit; delete *cit;
extra[i].clear(); extra[i].clear();
} }
for(auto cit = limbo_temp.begin(); cit != limbo_temp.end(); ++cit)
delete *cit;
limbo_temp.clear();
for(auto sit = overlay_cards.begin(); sit != overlay_cards.end(); ++sit) for(auto sit = overlay_cards.begin(); sit != overlay_cards.end(); ++sit)
delete *sit; delete *sit;
overlay_cards.clear(); overlay_cards.clear();
...@@ -415,6 +418,8 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -415,6 +418,8 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
myswprintf(formatBuffer, L"%ls[%d](%d)", myswprintf(formatBuffer, L"%ls[%d](%d)",
dataManager.FormatLocation(selectable_cards[i]->overlayTarget->location, selectable_cards[i]->overlayTarget->sequence), dataManager.FormatLocation(selectable_cards[i]->overlayTarget->location, selectable_cards[i]->overlayTarget->sequence),
selectable_cards[i]->overlayTarget->sequence + 1, selectable_cards[i]->sequence + 1); selectable_cards[i]->overlayTarget->sequence + 1, selectable_cards[i]->sequence + 1);
else if (selectable_cards[i]->location == 0)
myswprintf(formatBuffer, L"");
else else
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence), myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence),
selectable_cards[i]->sequence + 1); selectable_cards[i]->sequence + 1);
...@@ -652,6 +657,7 @@ void ClientField::ReplaySwap() { ...@@ -652,6 +657,7 @@ void ClientField::ReplaySwap() {
mainGame->dInfo.isReplaySwapped = !mainGame->dInfo.isReplaySwapped; mainGame->dInfo.isReplaySwapped = !mainGame->dInfo.isReplaySwapped;
std::swap(mainGame->dInfo.lp[0], mainGame->dInfo.lp[1]); std::swap(mainGame->dInfo.lp[0], mainGame->dInfo.lp[1]);
std::swap(mainGame->dInfo.strLP[0], mainGame->dInfo.strLP[1]); std::swap(mainGame->dInfo.strLP[0], mainGame->dInfo.strLP[1]);
std::swap(mainGame->dInfo.start_lp[0], mainGame->dInfo.start_lp[1]);
std::swap(mainGame->dInfo.hostname, mainGame->dInfo.clientname); std::swap(mainGame->dInfo.hostname, mainGame->dInfo.clientname);
std::swap(mainGame->dInfo.hostname_tag, mainGame->dInfo.clientname_tag); std::swap(mainGame->dInfo.hostname_tag, mainGame->dInfo.clientname_tag);
for(auto chit = chains.begin(); chit != chains.end(); ++chit) { for(auto chit = chains.begin(); chit != chains.end(); ++chit) {
...@@ -953,24 +959,44 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -953,24 +959,44 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
break; break;
} }
case LOCATION_OVERLAY: { case LOCATION_OVERLAY: {
if (pcard->overlayTarget->location != 0x4) { if (!(pcard->overlayTarget->location & LOCATION_ONFIELD)) {
return; return;
} }
int oseq = pcard->overlayTarget->sequence; int oseq = pcard->overlayTarget->sequence;
if (pcard->overlayTarget->controler == 0) { if (pcard->overlayTarget->location == LOCATION_MZONE) {
t->X = (matManager.vFieldMzone[0][oseq][0].Pos.X + matManager.vFieldMzone[0][oseq][1].Pos.X) / 2 - 0.12f + 0.06f * sequence; if (pcard->overlayTarget->controler == 0) {
t->Y = (matManager.vFieldMzone[0][oseq][0].Pos.Y + matManager.vFieldMzone[0][oseq][2].Pos.Y) / 2 + 0.05f; t->X = (matManager.vFieldMzone[0][oseq][0].Pos.X + matManager.vFieldMzone[0][oseq][1].Pos.X) / 2 - 0.12f + 0.06f * sequence;
t->Z = 0.005f + pcard->sequence * 0.0001f; t->Y = (matManager.vFieldMzone[0][oseq][0].Pos.Y + matManager.vFieldMzone[0][oseq][2].Pos.Y) / 2 + 0.05f;
r->X = 0.0f; t->Z = 0.005f + pcard->sequence * 0.0001f;
r->Y = 0.0f; r->X = 0.0f;
r->Z = 0.0f; r->Y = 0.0f;
r->Z = 0.0f;
}
else {
t->X = (matManager.vFieldMzone[1][oseq][0].Pos.X + matManager.vFieldMzone[1][oseq][1].Pos.X) / 2 + 0.12f - 0.06f * sequence;
t->Y = (matManager.vFieldMzone[1][oseq][0].Pos.Y + matManager.vFieldMzone[1][oseq][2].Pos.Y) / 2 - 0.05f;
t->Z = 0.005f + pcard->sequence * 0.0001f;
r->X = 0.0f;
r->Y = 0.0f;
r->Z = 3.1415926f;
}
} else { } else {
t->X = (matManager.vFieldMzone[1][oseq][0].Pos.X + matManager.vFieldMzone[1][oseq][1].Pos.X) / 2 + 0.12f - 0.06f * sequence; if (pcard->overlayTarget->controler == 0) {
t->Y = (matManager.vFieldMzone[1][oseq][0].Pos.Y + matManager.vFieldMzone[1][oseq][2].Pos.Y) / 2 - 0.05f; t->X = (matManager.vFieldSzone[0][oseq][rule][0].Pos.X + matManager.vFieldSzone[0][oseq][rule][1].Pos.X) / 2 - 0.12f + 0.06f * sequence;
t->Z = 0.005f + pcard->sequence * 0.0001f; t->Y = (matManager.vFieldSzone[0][oseq][rule][0].Pos.Y + matManager.vFieldSzone[0][oseq][rule][2].Pos.Y) / 2 + 0.05f;
r->X = 0.0f; t->Z = 0.005f + pcard->sequence * 0.0001f;
r->Y = 0.0f; r->X = 0.0f;
r->Z = 3.1415926f; r->Y = 0.0f;
r->Z = 0.0f;
}
else {
t->X = (matManager.vFieldSzone[1][oseq][rule][0].Pos.X + matManager.vFieldSzone[1][oseq][rule][1].Pos.X) / 2 + 0.12f - 0.06f * sequence;
t->Y = (matManager.vFieldSzone[1][oseq][rule][0].Pos.Y + matManager.vFieldSzone[1][oseq][rule][2].Pos.Y) / 2 - 0.05f;
t->Z = 0.005f + pcard->sequence * 0.0001f;
r->X = 0.0f;
r->Y = 0.0f;
r->Z = 3.1415926f;
}
} }
break; break;
} }
......
...@@ -30,6 +30,7 @@ public: ...@@ -30,6 +30,7 @@ public:
std::vector<ClientCard*> grave[2]; std::vector<ClientCard*> grave[2];
std::vector<ClientCard*> remove[2]; std::vector<ClientCard*> remove[2];
std::vector<ClientCard*> extra[2]; std::vector<ClientCard*> extra[2];
std::vector<ClientCard*> limbo_temp;
std::set<ClientCard*> overlay_cards; std::set<ClientCard*> overlay_cards;
std::vector<ClientCard*> summonable_cards; std::vector<ClientCard*> summonable_cards;
std::vector<ClientCard*> spsummonable_cards; std::vector<ClientCard*> spsummonable_cards;
......
...@@ -55,8 +55,13 @@ inline int _wtoi(const wchar_t * s) { ...@@ -55,8 +55,13 @@ inline int _wtoi(const wchar_t * s) {
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
#include <irrlicht.h> #include <irrlicht.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#endif
#include "CGUITTFont.h" #include "CGUITTFont.h"
#include "CGUIImageButton.h" #include "CGUIImageButton.h"
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
...@@ -81,7 +86,7 @@ using namespace io; ...@@ -81,7 +86,7 @@ using namespace io;
using namespace gui; using namespace gui;
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
extern const unsigned short PRO_VERSION; extern unsigned short PRO_VERSION;
extern int enable_log; extern int enable_log;
extern bool exit_on_return; extern bool exit_on_return;
extern bool open_file; extern bool open_file;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -33,6 +33,12 @@ private: ...@@ -33,6 +33,12 @@ private:
static wchar_t event_string[256]; static wchar_t event_string[256];
static mtrandom rnd; static mtrandom rnd;
public: public:
//modded
static unsigned int temp_ip;
static unsigned short temp_port;
static unsigned short temp_ver;
static bool try_needed;
static bool StartClient(unsigned int ip, unsigned short port, bool create_game = true); static bool StartClient(unsigned int ip, unsigned short port, bool create_game = true);
static void ConnectTimeout(evutil_socket_t fd, short events, void* arg); static void ConnectTimeout(evutil_socket_t fd, short events, void* arg);
static void StopClient(bool is_exiting = false); static void StopClient(bool is_exiting = false);
......
This diff is collapsed.
This diff is collapsed.
...@@ -47,6 +47,10 @@ struct Config { ...@@ -47,6 +47,10 @@ struct Config {
int chkIgnoreDeckChanges; int chkIgnoreDeckChanges;
int defaultOT; int defaultOT;
int enable_bot_mode; int enable_bot_mode;
bool window_maximized;
int window_width;
int window_height;
bool resize_popup_menu;
bool enable_sound; bool enable_sound;
bool enable_music; bool enable_music;
double sound_volume; double sound_volume;
...@@ -63,8 +67,11 @@ struct DuelInfo { ...@@ -63,8 +67,11 @@ struct DuelInfo {
bool isTag; bool isTag;
bool isSingleMode; bool isSingleMode;
bool is_shuffling; bool is_shuffling;
//modded - to check swapped
bool is_swapped;
bool tag_player[2]; bool tag_player[2];
int lp[2]; int lp[2];
int start_lp[2];
int duel_rule; int duel_rule;
int turn; int turn;
short curMsg; short curMsg;
...@@ -78,6 +85,9 @@ struct DuelInfo { ...@@ -78,6 +85,9 @@ struct DuelInfo {
unsigned char time_player; unsigned char time_player;
unsigned short time_limit; unsigned short time_limit;
unsigned short time_left[2]; unsigned short time_left[2];
wchar_t str_time_limit[16];
wchar_t str_time_left[2][16];
video::SColor time_color[2];
bool isReplaySwapped; bool isReplaySwapped;
}; };
...@@ -113,6 +123,7 @@ public: ...@@ -113,6 +123,7 @@ public:
void AddDebugMsg(char* msgbuf); void AddDebugMsg(char* msgbuf);
#else #else
void MainLoop(); void MainLoop();
void RefreshTimeDisplay();
void BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar); void BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar);
void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text); void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text);
void SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0); void SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0);
...@@ -128,6 +139,7 @@ public: ...@@ -128,6 +139,7 @@ public:
void CheckMutual(ClientCard* pcard, int mark); void CheckMutual(ClientCard* pcard, int mark);
void DrawCards(); void DrawCards();
void DrawCard(ClientCard* pcard); void DrawCard(ClientCard* pcard);
void DrawShadowText(irr::gui::CGUITTFont* font, const core::stringw& text, const core::rect<s32>& position, const core::rect<s32>& padding, video::SColor color = 0xffffffff, video::SColor shadowcolor = 0xff000000, bool hcenter = false, bool vcenter = false, const core::rect<s32>* clip = 0);
void DrawMisc(); void DrawMisc();
void DrawStatus(ClientCard* pcard, int x1, int y1, int x2, int y2); void DrawStatus(ClientCard* pcard, int x1, int y1, int x2, int y2);
void DrawGUI(); void DrawGUI();
...@@ -137,11 +149,11 @@ public: ...@@ -137,11 +149,11 @@ public:
void HideElement(irr::gui::IGUIElement* element, bool set_action = false); void HideElement(irr::gui::IGUIElement* element, bool set_action = false);
void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0); void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0);
void WaitFrameSignal(int frame); void WaitFrameSignal(int frame);
void DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist); void DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist, bool drag = false);
void DrawDeckBd(); void DrawDeckBd();
void LoadConfig(); void LoadConfig();
void SaveConfig(); void SaveConfig();
void ShowCardInfo(int code); void ShowCardInfo(int code, bool resize = false);
void AddChatMsg(wchar_t* msg, int player); void AddChatMsg(wchar_t* msg, int player);
void AddDebugMsg(char* msgbuf); void AddDebugMsg(char* msgbuf);
void ClearTextures(); void ClearTextures();
...@@ -155,6 +167,14 @@ public: ...@@ -155,6 +167,14 @@ public:
return focus && focus->hasType(type); return focus && focus->hasType(type);
} }
void OnResize();
recti Resize(s32 x, s32 y, s32 x2, s32 y2);
recti Resize(s32 x, s32 y, s32 x2, s32 y2, s32 dx, s32 dy, s32 dx2, s32 dy2);
position2di Resize(s32 x, s32 y);
position2di ResizeReverse(s32 x, s32 y);
recti ResizeElem(s32 x, s32 y, s32 x2, s32 y2);
recti ResizeWin(s32 x, s32 y, s32 x2, s32 y2, bool chat = false);
void SetWindowsIcon(); void SetWindowsIcon();
void FlashWindow(); void FlashWindow();
void SetCursor(ECURSOR_ICON icon); void SetCursor(ECURSOR_ICON icon);
...@@ -184,6 +204,7 @@ public: ...@@ -184,6 +204,7 @@ public:
int waitFrame; int waitFrame;
int signalFrame; int signalFrame;
int actionParam; int actionParam;
int showingcode;
const wchar_t* showingtext; const wchar_t* showingtext;
int showcard; int showcard;
int showcardcode; int showcardcode;
...@@ -206,6 +227,10 @@ public: ...@@ -206,6 +227,10 @@ public:
bool is_building; bool is_building;
bool is_siding; bool is_siding;
irr::core::dimension2d<irr::u32> window_size;
float xScale;
float yScale;
ClientField dField; ClientField dField;
DeckBuilder deckBuilder; DeckBuilder deckBuilder;
MenuHandler menuHandler; MenuHandler menuHandler;
...@@ -427,6 +452,17 @@ public: ...@@ -427,6 +452,17 @@ public:
irr::gui::IGUIButton* btnSideSort; irr::gui::IGUIButton* btnSideSort;
irr::gui::IGUIButton* btnSideReload; irr::gui::IGUIButton* btnSideReload;
irr::gui::IGUIEditBox* ebDeckname; irr::gui::IGUIEditBox* ebDeckname;
irr::gui::IGUIStaticText* stBanlist;
irr::gui::IGUIStaticText* stDeck;
irr::gui::IGUIStaticText* stCategory;
irr::gui::IGUIStaticText* stLimit;
irr::gui::IGUIStaticText* stAttribute;
irr::gui::IGUIStaticText* stRace;
irr::gui::IGUIStaticText* stAttack;
irr::gui::IGUIStaticText* stDefense;
irr::gui::IGUIStaticText* stStar;
irr::gui::IGUIStaticText* stSearch;
irr::gui::IGUIStaticText* stScale;
//filter //filter
irr::gui::IGUIStaticText* wFilter; irr::gui::IGUIStaticText* wFilter;
irr::gui::IGUIScrollBar* scrFilter; irr::gui::IGUIScrollBar* scrFilter;
...@@ -638,5 +674,16 @@ extern HostInfo game_info; ...@@ -638,5 +674,16 @@ extern HostInfo game_info;
#define BUTTON_MARKS_FILTER 380 #define BUTTON_MARKS_FILTER 380
#define BUTTON_MARKERS_OK 381 #define BUTTON_MARKERS_OK 381
#define TEXTURE_DUEL 0
#define TEXTURE_DECK 1
#define TEXTURE_MENU 2
#define TEXTURE_COVER_S 3
#define TEXTURE_COVER_O 4
#define TEXTURE_ATTACK 5
#define TEXTURE_ACTIVATE 6
#define DEFAULT_DUEL_RULE 4 #define DEFAULT_DUEL_RULE 4
#endif // GAME_H #endif // GAME_H
#include "image_manager.h" #include "image_manager.h"
#include "game.h" #include "game.h"
#ifndef _WIN32
#include <dirent.h>
#endif
namespace ygo { namespace ygo {
ImageManager imageManager; ImageManager imageManager;
bool ImageManager::Initial() { bool ImageManager::Initial() {
tCover[0] = driver->getTexture("textures/cover.jpg"); RefreshRandomImageList();
tCover[1] = driver->getTexture("textures/cover2.jpg");
tCover[0] = GetRandomImage(TEXTURE_COVER_S);
if(!tCover[0])
tCover[0] = driver->getTexture("textures/cover.jpg");
tCover[1] = GetRandomImage(TEXTURE_COVER_O);
if(!tCover[1])
tCover[1] = driver->getTexture("textures/cover2.jpg");
if(!tCover[1])
tCover[1] = GetRandomImage(TEXTURE_COVER_S);
if(!tCover[1]) if(!tCover[1])
tCover[1] = tCover[0]; tCover[1] = tCover[0];
tUnknown = driver->getTexture("textures/unknown.jpg"); tUnknown = driver->getTexture("textures/unknown.jpg");
tAct = driver->getTexture("textures/act.png"); tAct = GetRandomImage(TEXTURE_ACTIVATE);
tAttack = driver->getTexture("textures/attack.png"); tAttack = GetRandomImage(TEXTURE_ATTACK);
if(!tAct)
tAct = driver->getTexture("textures/act.png");
if(!tAttack)
tAttack = driver->getTexture("textures/attack.png");
tChain = driver->getTexture("textures/chain.png"); tChain = driver->getTexture("textures/chain.png");
tNegated = driver->getTexture("textures/negated.png"); tNegated = driver->getTexture("textures/negated.png");
tNumber = driver->getTexture("textures/number.png"); tNumber = driver->getTexture("textures/number.png");
...@@ -27,25 +42,99 @@ bool ImageManager::Initial() { ...@@ -27,25 +42,99 @@ bool ImageManager::Initial() {
tHand[0] = driver->getTexture("textures/f1.jpg"); tHand[0] = driver->getTexture("textures/f1.jpg");
tHand[1] = driver->getTexture("textures/f2.jpg"); tHand[1] = driver->getTexture("textures/f2.jpg");
tHand[2] = driver->getTexture("textures/f3.jpg"); tHand[2] = driver->getTexture("textures/f3.jpg");
tBackGround = driver->getTexture("textures/bg.jpg"); tBackGround = GetRandomImage(TEXTURE_DUEL);
tBackGround_menu = driver->getTexture("textures/bg_menu.jpg"); if(!tBackGround)
tBackGround = driver->getTexture("textures/bg.jpg");
if(!tBackGround)
tBackGround = driver->getTexture("textures/bg_duel.jpg");
tBackGround_menu = GetRandomImage(TEXTURE_MENU);
if(!tBackGround_menu)
tBackGround_menu = driver->getTexture("textures/bg_menu.jpg");
if(!tBackGround_menu)
tBackGround_menu = GetRandomImage(TEXTURE_DUEL);
if(!tBackGround_menu) if(!tBackGround_menu)
tBackGround_menu = tBackGround; tBackGround_menu = tBackGround;
tBackGround_deck = driver->getTexture("textures/bg_deck.jpg"); tBackGround_deck = GetRandomImage(TEXTURE_DECK);
if(!tBackGround_deck) if(!tBackGround_deck)
tBackGround_deck = tBackGround; tBackGround_deck = driver->getTexture("textures/bg_deck.jpg");
if(!tBackGround_deck)
tBackGround_deck = GetRandomImage(TEXTURE_DUEL);
if(!tBackGround_deck)
tBackGround_deck = tBackGround;
tField[0] = driver->getTexture("textures/field2.png"); tField[0] = driver->getTexture("textures/field2.png");
tFieldTransparent[0] = driver->getTexture("textures/field-transparent2.png"); tFieldTransparent[0] = driver->getTexture("textures/field-transparent2.png");
tField[1] = driver->getTexture("textures/field3.png"); tField[1] = driver->getTexture("textures/field3.png");
tFieldTransparent[1] = driver->getTexture("textures/field-transparent3.png"); tFieldTransparent[1] = driver->getTexture("textures/field-transparent3.png");
return true; return true;
} }
irr::video::ITexture* ImageManager::GetRandomImage(int image_type) {
int count = ImageList[image_type].size();
if(count <= 0)
return 0;
char ImageName[1024];
wchar_t fname[1024];
int image_id = rand() % count;
auto name = ImageList[image_type][image_id].c_str();
myswprintf(fname, L"./textures/%ls", name);
BufferIO::EncodeUTF8(fname, ImageName);
return driver->getTexture(ImageName);
}
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);
}
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
}
void ImageManager::SetDevice(irr::IrrlichtDevice* dev) { void ImageManager::SetDevice(irr::IrrlichtDevice* dev) {
device = dev; device = dev;
driver = dev->getVideoDriver(); driver = dev->getVideoDriver();
} }
void ImageManager::ClearTexture() { void ImageManager::ClearTexture() {
for(auto tit = tMap.begin(); tit != tMap.end(); ++tit) { for(auto tit = tMap[0].begin(); tit != tMap[0].end(); ++tit) {
if(tit->second)
driver->removeTexture(tit->second);
}
for(auto tit = tMap[1].begin(); tit != tMap[1].end(); ++tit) {
if(tit->second) if(tit->second)
driver->removeTexture(tit->second); driver->removeTexture(tit->second);
} }
...@@ -53,20 +142,26 @@ void ImageManager::ClearTexture() { ...@@ -53,20 +142,26 @@ void ImageManager::ClearTexture() {
if(tit->second) if(tit->second)
driver->removeTexture(tit->second); driver->removeTexture(tit->second);
} }
tMap.clear(); tMap[0].clear();
tMap[1].clear();
tThumb.clear(); tThumb.clear();
} }
void ImageManager::RemoveTexture(int code) { void ImageManager::RemoveTexture(int code) {
auto tit = tMap.find(code); auto tit = tMap[0].find(code);
if(tit != tMap.end()) { if(tit != tMap[0].end()) {
if(tit->second) if(tit->second)
driver->removeTexture(tit->second); driver->removeTexture(tit->second);
tMap.erase(tit); tMap[0].erase(tit);
}
tit = tMap[1].find(code);
if(tit != tMap[1].end()) {
if(tit->second)
driver->removeTexture(tit->second);
tMap[1].erase(tit);
} }
} }
// function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified // function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified
void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
{
double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa; double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa;
u32 dy, dx; u32 dy, dx;
irr::video::SColor pxl; irr::video::SColor pxl;
...@@ -158,23 +253,29 @@ irr::video::ITexture* ImageManager::GetTextureFromFile(char* file, s32 width, s3 ...@@ -158,23 +253,29 @@ irr::video::ITexture* ImageManager::GetTextureFromFile(char* file, s32 width, s3
return driver->getTexture(file); return driver->getTexture(file);
} }
} }
irr::video::ITexture* ImageManager::GetTexture(int code) { irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
if(code == 0) if(code == 0)
return tUnknown; return tUnknown;
auto tit = tMap.find(code); int width = CARD_IMG_WIDTH;
if(tit == tMap.end()) { int height = CARD_IMG_HEIGHT;
if(fit) {
width = width * mainGame->xScale;
height = height * mainGame->yScale;
}
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/%d.jpg", code); sprintf(file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = GetTextureFromFile(file, CARD_IMG_WIDTH, CARD_IMG_HEIGHT); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/%d.jpg", code); sprintf(file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, CARD_IMG_WIDTH, CARD_IMG_HEIGHT); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL && !mainGame->gameConf.use_image_scale) { if(img == NULL && !mainGame->gameConf.use_image_scale) {
tMap[code] = NULL; tMap[fit ? 1 : 0][code] = NULL;
return GetTextureThumb(code); return GetTextureThumb(code);
} }
tMap[code] = img; tMap[fit ? 1 : 0][code] = img;
return (img == NULL) ? tUnknown : img; return (img == NULL) ? tUnknown : img;
} }
if(tit->second) if(tit->second)
...@@ -186,20 +287,22 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -186,20 +287,22 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(code == 0) if(code == 0)
return tUnknown; return tUnknown;
auto tit = tThumb.find(code); auto tit = tThumb.find(code);
int width = CARD_THUMB_WIDTH * mainGame->xScale;
int height = CARD_THUMB_HEIGHT * mainGame->yScale;
if(tit == tThumb.end()) { if(tit == tThumb.end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/thumbnail/%d.jpg", code); sprintf(file, "expansions/pics/thumbnail/%d.jpg", code);
irr::video::ITexture* img = GetTextureFromFile(file, CARD_THUMB_WIDTH, CARD_THUMB_HEIGHT); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/thumbnail/%d.jpg", code); sprintf(file, "pics/thumbnail/%d.jpg", code);
img = GetTextureFromFile(file, CARD_THUMB_WIDTH, CARD_THUMB_HEIGHT); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL && mainGame->gameConf.use_image_scale) { if(img == NULL && mainGame->gameConf.use_image_scale) {
sprintf(file, "expansions/pics/%d.jpg", code); sprintf(file, "expansions/pics/%d.jpg", code);
img = GetTextureFromFile(file, CARD_THUMB_WIDTH, CARD_THUMB_HEIGHT); img = GetTextureFromFile(file, width, height);
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/%d.jpg", code); sprintf(file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, CARD_THUMB_WIDTH, CARD_THUMB_HEIGHT); img = GetTextureFromFile(file, width, height);
} }
} }
tThumb[code] = img; tThumb[code] = img;
...@@ -217,18 +320,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) { ...@@ -217,18 +320,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
if(tit == tFields.end()) { if(tit == tFields.end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/field/%d.png", code); sprintf(file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512, 512); irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) { if(img == NULL) {
sprintf(file, "expansions/pics/field/%d.jpg", code); sprintf(file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512, 512); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/field/%d.png", code); sprintf(file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512, 512); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/field/%d.jpg", code); sprintf(file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512, 512); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) { if(img == NULL) {
tFields[code] = NULL; tFields[code] = NULL;
return NULL; return NULL;
......
...@@ -9,16 +9,21 @@ namespace ygo { ...@@ -9,16 +9,21 @@ namespace ygo {
class ImageManager { class ImageManager {
public: public:
std::vector<std::wstring> ImageList[7];
bool Initial(); bool Initial();
//random image
irr::video::ITexture* GetRandomImage(int image_type);
void RefreshRandomImageList();
void RefreshImageDir(std::wstring path, int image_type);
void SetDevice(irr::IrrlichtDevice* dev); void SetDevice(irr::IrrlichtDevice* dev);
void ClearTexture(); void ClearTexture();
void RemoveTexture(int code); void RemoveTexture(int code);
irr::video::ITexture* GetTextureFromFile(char* file, s32 width, s32 height); irr::video::ITexture* GetTextureFromFile(char* file, s32 width, s32 height);
irr::video::ITexture* GetTexture(int code); irr::video::ITexture* GetTexture(int code, bool fit = false);
irr::video::ITexture* GetTextureThumb(int code); irr::video::ITexture* GetTextureThumb(int code);
irr::video::ITexture* GetTextureField(int code); irr::video::ITexture* GetTextureField(int code);
std::unordered_map<int, irr::video::ITexture*> tMap; std::unordered_map<int, irr::video::ITexture*> tMap[2];
std::unordered_map<int, irr::video::ITexture*> tThumb; std::unordered_map<int, irr::video::ITexture*> tThumb;
std::unordered_map<int, irr::video::ITexture*> tFields; std::unordered_map<int, irr::video::ITexture*> tFields;
irr::IrrlichtDevice* device; irr::IrrlichtDevice* device;
......
...@@ -231,6 +231,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -231,6 +231,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
mainGame->imgCard->setImage(imageManager.tCover[0]); mainGame->imgCard->setImage(imageManager.tCover[0]);
mainGame->showingcode = 0;
mainGame->wCardImg->setVisible(true); mainGame->wCardImg->setVisible(true);
mainGame->wInfos->setVisible(true); mainGame->wInfos->setVisible(true);
mainGame->wReplay->setVisible(true); mainGame->wReplay->setVisible(true);
......
...@@ -166,6 +166,8 @@ bool ReplayMode::StartDuel() { ...@@ -166,6 +166,8 @@ bool ReplayMode::StartDuel() {
set_player_info(pduel, 1, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count);
mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[0] = start_lp;
mainGame->dInfo.lp[1] = start_lp; mainGame->dInfo.lp[1] = start_lp;
mainGame->dInfo.start_lp[0] = start_lp;
mainGame->dInfo.start_lp[1] = start_lp;
myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]);
myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]);
mainGame->dInfo.turn = 0; mainGame->dInfo.turn = 0;
......
...@@ -47,6 +47,8 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -47,6 +47,8 @@ int SingleMode::SinglePlayThread(void* param) {
set_player_info(pduel, 1, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count);
mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[0] = start_lp;
mainGame->dInfo.lp[1] = start_lp; mainGame->dInfo.lp[1] = start_lp;
mainGame->dInfo.start_lp[0] = start_lp;
mainGame->dInfo.start_lp[1] = start_lp;
myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]);
myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]);
BufferIO::CopyWStr(mainGame->ebNickName->getText(), mainGame->dInfo.hostname, 20); BufferIO::CopyWStr(mainGame->ebNickName->getText(), mainGame->dInfo.hostname, 20);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#ifndef _WIN32 #ifndef _WIN32
#include <dirent.h> #include <dirent.h>
#endif #endif
#ifdef IRRKLANG_STATIC #ifdef YGOPRO_USE_IRRKLANG
#include "../ikpmp3/ikpMP3.h" #include "../ikpmp3/ikpMP3.h"
#endif #endif
...@@ -13,15 +13,15 @@ SoundManager soundManager; ...@@ -13,15 +13,15 @@ SoundManager soundManager;
bool SoundManager::Init() { bool SoundManager::Init() {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
bgm_scene = -1; bgm_scene = -1;
previous_bgm_scene = -1;
RefreshBGMList(); RefreshBGMList();
bgm_process = false;
engineSound = irrklang::createIrrKlangDevice(); engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice(); engineMusic = irrklang::createIrrKlangDevice();
if(!engineSound || !engineMusic) { if(!engineSound || !engineMusic) {
return false; return false;
} else { } else {
#ifdef IRRKLANG_STATIC
irrklang::ikpMP3Init(engineMusic); irrklang::ikpMP3Init(engineMusic);
#endif
return true; return true;
} }
#endif // YGOPRO_USE_IRRKLANG #endif // YGOPRO_USE_IRRKLANG
...@@ -29,6 +29,7 @@ bool SoundManager::Init() { ...@@ -29,6 +29,7 @@ bool SoundManager::Init() {
return false; return false;
} }
void SoundManager::RefreshBGMList() { void SoundManager::RefreshBGMList() {
#ifdef YGOPRO_USE_IRRKLANG
RefershBGMDir(L"", BGM_DUEL); RefershBGMDir(L"", BGM_DUEL);
RefershBGMDir(L"duel/", BGM_DUEL); RefershBGMDir(L"duel/", BGM_DUEL);
RefershBGMDir(L"menu/", BGM_MENU); RefershBGMDir(L"menu/", BGM_MENU);
...@@ -37,8 +38,11 @@ void SoundManager::RefreshBGMList() { ...@@ -37,8 +38,11 @@ void SoundManager::RefreshBGMList() {
RefershBGMDir(L"disadvantage/", BGM_DISADVANTAGE); RefershBGMDir(L"disadvantage/", BGM_DISADVANTAGE);
RefershBGMDir(L"win/", BGM_WIN); RefershBGMDir(L"win/", BGM_WIN);
RefershBGMDir(L"lose/", BGM_LOSE); RefershBGMDir(L"lose/", BGM_LOSE);
RefershBGMDir(L"custom/", BGM_CUSTOM);
#endif
} }
void SoundManager::RefershBGMDir(std::wstring path, int scene) { void SoundManager::RefershBGMDir(std::wstring path, int scene) {
#ifdef YGOPRO_USE_IRRKLANG
#ifdef _WIN32 #ifdef _WIN32
WIN32_FIND_DATAW fdataw; WIN32_FIND_DATAW fdataw;
std::wstring search = L"./sound/BGM/" + path + L"*.*"; std::wstring search = L"./sound/BGM/" + path + L"*.*";
...@@ -75,6 +79,7 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) { ...@@ -75,6 +79,7 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) {
} }
closedir(dir); closedir(dir);
#endif #endif
#endif
} }
void SoundManager::PlaySoundEffect(int sound) { void SoundManager::PlaySoundEffect(int sound) {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
...@@ -239,12 +244,12 @@ void SoundManager::PlayMusic(char* song, bool loop) { ...@@ -239,12 +244,12 @@ void SoundManager::PlayMusic(char* song, bool loop) {
} }
void SoundManager::PlayBGM(int scene) { void SoundManager::PlayBGM(int scene) {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
if(!mainGame->chkEnableMusic->isChecked()) if(!mainGame->chkEnableMusic->isChecked() || bgm_process)
return; return;
if(!mainGame->chkMusicMode->isChecked()) if(!mainGame->chkMusicMode->isChecked())
scene = BGM_ALL; scene = BGM_ALL;
char BGMName[1024]; char BGMName[1024];
if(scene != bgm_scene || (soundBGM && soundBGM->isFinished())) { if (((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM)) || ((scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM)) || (soundBGM && soundBGM->isFinished())) {
int count = BGMList[scene].size(); int count = BGMList[scene].size();
if(count <= 0) if(count <= 0)
return; return;
...@@ -258,11 +263,39 @@ void SoundManager::PlayBGM(int scene) { ...@@ -258,11 +263,39 @@ void SoundManager::PlayBGM(int scene) {
} }
#endif #endif
} }
void SoundManager::PlayCustomBGM(char* BGMName) {
#ifdef YGOPRO_USE_IRRKLANG
if(!mainGame->chkEnableMusic->isChecked() || !mainGame->chkMusicMode->isChecked() || bgm_process)
return;
if(engineMusic->isCurrentlyPlaying(BGMName))
return;
bgm_process = true;
int pscene = bgm_scene;
if (pscene != BGM_CUSTOM)
previous_bgm_scene = pscene;
bgm_scene = BGM_CUSTOM;
PlayMusic(BGMName, false);
bgm_process = false;
#endif
}
void SoundManager::PlayCustomSound(char* SoundName) {
#ifdef YGOPRO_USE_IRRKLANG
if(!mainGame->chkEnableSound->isChecked())
return;
engineSound->play2D(SoundName);
engineSound->setSoundVolume(mainGame->gameConf.sound_volume);
#endif
}
void SoundManager::StopBGM() { void SoundManager::StopBGM() {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
engineMusic->stopAllSounds(); engineMusic->stopAllSounds();
#endif #endif
} }
void SoundManager::StopSound() {
#ifdef YGOPRO_USE_IRRKLANG
engineSound->stopAllSounds();
#endif
}
void SoundManager::SetSoundVolume(double volume) { void SoundManager::SetSoundVolume(double volume) {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
engineSound->setSoundVolume(volume); engineSound->setSoundVolume(volume);
......
...@@ -10,8 +10,10 @@ namespace ygo { ...@@ -10,8 +10,10 @@ namespace ygo {
class SoundManager { class SoundManager {
private: private:
std::vector<std::wstring> BGMList[8]; std::vector<std::wstring> BGMList[9];
int bgm_scene; int bgm_scene;
int previous_bgm_scene;
bool bgm_process;
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound; irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic; irrklang::ISoundEngine* engineMusic;
...@@ -26,7 +28,10 @@ public: ...@@ -26,7 +28,10 @@ public:
void PlayDialogSound(irr::gui::IGUIElement * element); void PlayDialogSound(irr::gui::IGUIElement * element);
void PlayMusic(char* song, bool loop); void PlayMusic(char* song, bool loop);
void PlayBGM(int scene); void PlayBGM(int scene);
void PlayCustomBGM(char* BGMName);
void PlayCustomSound(char* SoundName);
void StopBGM(); void StopBGM();
void StopSound();
void SetSoundVolume(double volume); void SetSoundVolume(double volume);
void SetMusicVolume(double volume); void SetMusicVolume(double volume);
}; };
...@@ -74,6 +79,8 @@ extern SoundManager soundManager; ...@@ -74,6 +79,8 @@ extern SoundManager soundManager;
#define BGM_DISADVANTAGE 5 #define BGM_DISADVANTAGE 5
#define BGM_WIN 6 #define BGM_WIN 6
#define BGM_LOSE 7 #define BGM_LOSE 7
//modded
#define BGM_CUSTOM 8
} }
......
...@@ -685,6 +685,16 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) { ...@@ -685,6 +685,16 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) {
#endif #endif
break; break;
} }
//modded
case 11:
case 12:
case 13: {
for(int i = 0; i < 4; ++i)
NetServer::SendBufferToPlayer(players[i], STOC_GAME_MSG, offset, pbuf - offset);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
break;
}
} }
break; break;
} }
......
diff --git a/source/Irrlicht/CGUIEditBox.cpp b/source/Irrlicht/CGUIEditBox.cpp
index 395fb69..323c9a2 100644
--- a/source/Irrlicht/CGUIEditBox.cpp
+++ b/source/Irrlicht/CGUIEditBox.cpp
@@ -287,9 +287,11 @@ bool CGUIEditBox::processKey(const SEvent& event)
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
- core::stringc s;
- s = Text.subString(realmbgn, realmend - realmbgn).c_str();
- Operator->copyToClipboard(s.c_str());
+ const int max_char_size = sizeof(wchar_t) * 3 / 2;
+ int max_size = (realmend - realmbgn)*max_char_size + 1;
+ c8 *s = new char[max_size];
+ wcstombs(s, Text.subString(realmbgn, realmend-realmbgn).c_str(), max_size);
+ Operator->copyToClipboard(s);
}
break;
case KEY_KEY_X:
@@ -300,9 +302,11 @@ bool CGUIEditBox::processKey(const SEvent& event)
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
// copy
- core::stringc sc;
- sc = Text.subString(realmbgn, realmend - realmbgn).c_str();
- Operator->copyToClipboard(sc.c_str());
+ const int max_char_size = sizeof(wchar_t) * 3 / 2;
+ int max_size = (realmend - realmbgn)*max_char_size + 1;
+ c8 *s = new char[max_size];
+ wcstombs(s, Text.subString(realmbgn, realmend-realmbgn).c_str(), max_size);
+ Operator->copyToClipboard(s);
if (isEnabled())
{
diff --git a/source/Irrlicht/MacOSX/AppDelegate.h b/source/Irrlicht/MacOSX/AppDelegate.h
index ccb116d..29705f2 100644
--- a/source/Irrlicht/MacOSX/AppDelegate.h
+++ b/source/Irrlicht/MacOSX/AppDelegate.h
@@ -10,7 +10,7 @@
#import <Cocoa/Cocoa.h>
#import "CIrrDeviceMacOSX.h"
-@interface AppDelegate : NSObject
+@interface AppDelegate : NSTextView <NSApplicationDelegate>
{
BOOL _quit;
irr::CIrrDeviceMacOSX *_device;
diff --git a/source/Irrlicht/MacOSX/AppDelegate.mm b/source/Irrlicht/MacOSX/AppDelegate.mm
index 14a7f86..0ab0c43 100644
--- a/source/Irrlicht/MacOSX/AppDelegate.mm
+++ b/source/Irrlicht/MacOSX/AppDelegate.mm
@@ -74,6 +74,30 @@
return (_quit);
}
+
+- (void)keyDown:(NSEvent *)event
+{
+ [self interpretKeyEvents:@[event]];
+}
+
+- (void)insertText:(id)string
+{
+ [self setString: @""];
+ if ([string isKindOfClass:[NSAttributedString class]])
+ {
+ _device->handleInputEvent([[string string] UTF8String]);
+ }
+ else
+ {
+ _device->handleInputEvent([string UTF8String]);
+ }
+}
+
+- (void)doCommandBySelector:(SEL)selector
+{
+ _device->processKeyEvent();
+}
+
@end
#endif // _IRR_COMPILE_WITH_OSX_DEVICE_
diff --git a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h
index f629588..d2fefae 100644
--- a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h
+++ b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h
@@ -95,6 +95,8 @@ namespace irr
void setMouseLocation(int x, int y);
void setResize(int width, int height);
void setCursorVisible(bool visible);
+ void handleInputEvent(const char *str);
+ void processKeyEvent();
private:
diff --git a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
index ad493fc..8692d0c 100644
--- a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
+++ b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
@@ -496,7 +496,7 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
{
[[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
- [NSApp setDelegate:(id<NSFileManagerDelegate>)[[[AppDelegate alloc] initWithDevice:this] autorelease]];
+ [NSApp setDelegate:[[[[AppDelegate alloc] initWithDevice:this] initWithFrame:NSZeroRect] autorelease]];
[NSBundle loadNibNamed:@"MainMenu" owner:[NSApp delegate]];
[NSApp finishLaunching];
}
@@ -592,6 +592,38 @@ void CIrrDeviceMacOSX::closeDevice()
CGLContext = NULL;
}
+void CIrrDeviceMacOSX::processKeyEvent()
+{
+ irr::SEvent ievent;
+ NSEvent *event = [[NSApplication sharedApplication] currentEvent];
+ postKeyEvent(event, ievent, true);
+}
+
+void CIrrDeviceMacOSX::handleInputEvent(const char *cStr)
+{
+ SEvent ievent;
+
+ // TODO: we should have such a function in core::string
+ size_t lenOld = strlen(cStr);
+ wchar_t *ws = new wchar_t[lenOld + 1];
+ size_t len = mbstowcs(ws,cStr,lenOld);
+ ws[len] = 0;
+ irr::core::stringw widep(ws);
+ delete[] ws;
+
+ ievent.EventType = irr::EET_KEY_INPUT_EVENT;
+ ievent.KeyInput.Key = (irr::EKEY_CODE)0;
+ ievent.KeyInput.PressedDown = true;
+ ievent.KeyInput.Shift = false;
+ ievent.KeyInput.Control = false;
+
+ for (int i = 0; i < widep.size(); ++i)
+ {
+ ievent.KeyInput.Char = widep[i];
+ postEventFromUser(ievent);
+ }
+}
+
bool CIrrDeviceMacOSX::createWindow()
{
CGDisplayErr error;
@@ -881,6 +913,8 @@ bool CIrrDeviceMacOSX::createWindow()
newSwapInterval = (CreationParams.Vsync) ? 1 : 0;
CGLSetParameter(CGLContext,kCGLCPSwapInterval,&newSwapInterval);
}
+
+ [[Window contentView] addSubview:(AppDelegate*)[NSApp delegate]];
}
return (result);
@@ -971,6 +1005,33 @@ bool CIrrDeviceMacOSX::run()
os::Timer::tick();
storeMouseLocation();
+ auto focusElement = getGUIEnvironment()->getFocus();
+ bool editing = focusElement && focusElement->getType() == irr::gui::EGUIET_EDIT_BOX;
+
+ if (!editing)
+ {
+ [Window makeFirstResponder:nil];
+ }
+ else
+ {
+ auto textView = (NSTextView*)[NSApp delegate];
+ auto crect = focusElement->getAbsolutePosition();
+
+ // ensure font height enough to fill the rect, otherwize ime window will overlaps the edit box
+ [textView setFont:[NSFont userFontOfSize:crect.getHeight()]];
+
+ // change origin from top left to bottom right
+ NSRect rect = {
+ crect.UpperLeftCorner.X,
+ [[textView superview] frame].size.height - crect.LowerRightCorner.Y,
+ crect.getWidth(), crect.getHeight(),
+ };
+ [textView setFrame:rect];
+
+ // start to receive input events
+ [Window makeFirstResponder:textView];
+ }
+
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (event != nil)
{
@@ -979,6 +1040,13 @@ bool CIrrDeviceMacOSX::run()
switch([(NSEvent *)event type])
{
case NSKeyDown:
+ if (editing)
+ {
+ // delegate to text edit control to handle text input
+ [NSApp sendEvent:event];
+ break;
+ }
+
postKeyEvent(event,ievent,true);
break;
@@ -1199,22 +1267,22 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
}
else
{
- cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];
+ cStr = (unsigned char *)[str UTF8String];
if (cStr != NULL && strlen((char*)cStr) > 0)
{
mchar = cStr[0];
mkey = toupper(mchar);
- if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask)
- {
- if (mkey == 'C' || mkey == 'V' || mkey == 'X')
- {
- mchar = 0;
- skipCommand = true;
- }
- }
}
}
}
+ if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask)
+ {
+ if (mkey == 'C' || mkey == 'V' || mkey == 'X')
+ {
+ mchar = 0;
+ skipCommand = true;
+ }
+ }
ievent.EventType = irr::EET_KEY_INPUT_EVENT;
ievent.KeyInput.Key = (irr::EKEY_CODE)mkey;
diff --git a/source/Irrlicht/MacOSX/OSXClipboard.mm b/source/Irrlicht/MacOSX/OSXClipboard.mm
index d549911..1925e80 100644
--- a/source/Irrlicht/MacOSX/OSXClipboard.mm
+++ b/source/Irrlicht/MacOSX/OSXClipboard.mm
@@ -13,7 +13,7 @@ void OSXCopyToClipboard(const char *text)
if ((text != NULL) && (strlen(text) > 0))
{
- str = [NSString stringWithCString:text encoding:NSWindowsCP1252StringEncoding];
+ str = [NSString stringWithUTF8String:text];
board = [NSPasteboard generalPasteboard];
[board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp];
[board setString:str forType:NSStringPboardType];
@@ -30,7 +30,7 @@ char* OSXCopyFromClipboard()
board = [NSPasteboard generalPasteboard];
str = [board stringForType:NSStringPboardType];
if (str != nil)
- result = (char*)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];
+ result = (char*)[str UTF8String];
return (result);
}
This diff is collapsed.
summon.wav
specialsummon.wav
activate.wav
set.wav
flip.wav
reveal.wav
equip.wav
destroyed.wav
banished.wav
token.wav
attack.wav
directattack.wav
draw.wav
shuffle.wav
damage.wav
gainlp.wav
addcounter.wav
removecounter.wav
coinflip.wav
diceroll.wav
nextturn.wav
phase.wav
menu.wav
button.wav
info.wav
question.wav
cardpick.wav
carddrop.wav
playerenter.wav
chatmessage.wav
BGM/*.mp3
BGM/duel/*.mp3
BGM/menu/*.mp3
BGM/deck/*.mp3
BGM/advantage/*.mp3
BGM/disadvantage/*.mp3
BGM/win/*.mp3
BGM/lose/*.mp3
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