Commit 2a46e39f authored by mercury233's avatar mercury233

Merge branch 'resize' into test

parents 4e315886 0586e8ab
...@@ -745,11 +745,13 @@ void Game::DrawGUI() { ...@@ -745,11 +745,13 @@ void Game::DrawGUI() {
env->drawAll(); env->drawAll();
} }
void Game::DrawSpec() { void Game::DrawSpec() {
s32 midx = 574 + (CARD_IMG_WIDTH * 0.5);
s32 midy = 150 + (CARD_IMG_HEIGHT * 0.5);
if(showcard) { if(showcard) {
switch(showcard) { switch(showcard) {
case 1: { case 1: {
driver->draw2DImage(imageManager.GetTexture(showcardcode, true), Resize(574, 150)); driver->draw2DImage(imageManager.GetTexture(showcardcode, true), ResizeCardHint(574, 150));
driver->draw2DImage(imageManager.tMask, Resize(574, 150, 574 + (showcarddif > CARD_IMG_WIDTH ? CARD_IMG_WIDTH : showcarddif), 150 + CARD_IMG_HEIGHT), driver->draw2DImage(imageManager.tMask, ResizeCardMid(574, 150, 574 + (showcarddif > CARD_IMG_WIDTH ? CARD_IMG_WIDTH : showcarddif), 150 + CARD_IMG_HEIGHT, midx, midy),
recti(CARD_IMG_HEIGHT - showcarddif, 0, CARD_IMG_HEIGHT - (showcarddif > CARD_IMG_WIDTH ? showcarddif - CARD_IMG_WIDTH : 0), CARD_IMG_HEIGHT), 0, 0, true); recti(CARD_IMG_HEIGHT - showcarddif, 0, CARD_IMG_HEIGHT - (showcarddif > CARD_IMG_WIDTH ? showcarddif - CARD_IMG_WIDTH : 0), CARD_IMG_HEIGHT), 0, 0, true);
showcarddif += 15; showcarddif += 15;
if(showcarddif >= CARD_IMG_HEIGHT) { if(showcarddif >= CARD_IMG_HEIGHT) {
...@@ -759,8 +761,8 @@ void Game::DrawSpec() { ...@@ -759,8 +761,8 @@ void Game::DrawSpec() {
break; break;
} }
case 2: { case 2: {
driver->draw2DImage(imageManager.GetTexture(showcardcode, true), Resize(574, 150)); driver->draw2DImage(imageManager.GetTexture(showcardcode, true), ResizeCardHint(574, 150));
driver->draw2DImage(imageManager.tMask, Resize(574 + showcarddif, 150, 574 + CARD_IMG_WIDTH, 150 + CARD_IMG_HEIGHT), driver->draw2DImage(imageManager.tMask, ResizeCardMid(574 + showcarddif, 150, 574 + CARD_IMG_WIDTH, 150 + CARD_IMG_HEIGHT, midx, midy),
recti(0, 0, CARD_IMG_WIDTH - showcarddif, CARD_IMG_HEIGHT), 0, 0, true); recti(0, 0, CARD_IMG_WIDTH - showcarddif, CARD_IMG_HEIGHT), 0, 0, true);
showcarddif += 15; showcarddif += 15;
if(showcarddif >= CARD_IMG_WIDTH) { if(showcarddif >= CARD_IMG_WIDTH) {
...@@ -769,8 +771,8 @@ void Game::DrawSpec() { ...@@ -769,8 +771,8 @@ void Game::DrawSpec() {
break; break;
} }
case 3: { case 3: {
driver->draw2DImage(imageManager.GetTexture(showcardcode, true), Resize(574, 150)); driver->draw2DImage(imageManager.GetTexture(showcardcode, true), ResizeCardHint(574, 150));
driver->draw2DImage(imageManager.tNegated, Resize(536 + showcarddif, 141 + showcarddif, 792 - showcarddif, 397 - showcarddif), recti(0, 0, 128, 128), 0, 0, true); driver->draw2DImage(imageManager.tNegated, ResizeCardMid(536 + showcarddif, 141 + showcarddif, 792 - showcarddif, 397 - showcarddif, midx, midy), recti(0, 0, 128, 128), 0, 0, true);
if(showcarddif < 64) if(showcarddif < 64)
showcarddif += 4; showcarddif += 4;
break; break;
...@@ -780,8 +782,8 @@ void Game::DrawSpec() { ...@@ -780,8 +782,8 @@ void Game::DrawSpec() {
matManager.c2d[1] = (showcarddif << 24) | 0xffffff; matManager.c2d[1] = (showcarddif << 24) | 0xffffff;
matManager.c2d[2] = (showcarddif << 24) | 0xffffff; matManager.c2d[2] = (showcarddif << 24) | 0xffffff;
matManager.c2d[3] = (showcarddif << 24) | 0xffffff; matManager.c2d[3] = (showcarddif << 24) | 0xffffff;
driver->draw2DImage(imageManager.GetTexture(showcardcode, true), Resize(574, 150, 574 + CARD_IMG_WIDTH, 150 + CARD_IMG_HEIGHT), driver->draw2DImage(imageManager.GetTexture(showcardcode, true), ResizeCardHint(574, 150, 574 + CARD_IMG_WIDTH, 150 + CARD_IMG_HEIGHT),
Resize(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), 0, matManager.c2d, true); ResizeFit(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), 0, matManager.c2d, true);
if(showcarddif < 255) if(showcarddif < 255)
showcarddif += 17; showcarddif += 17;
break; break;
...@@ -791,28 +793,34 @@ void Game::DrawSpec() { ...@@ -791,28 +793,34 @@ void Game::DrawSpec() {
matManager.c2d[1] = (showcarddif << 25) | 0xffffff; matManager.c2d[1] = (showcarddif << 25) | 0xffffff;
matManager.c2d[2] = (showcarddif << 25) | 0xffffff; matManager.c2d[2] = (showcarddif << 25) | 0xffffff;
matManager.c2d[3] = (showcarddif << 25) | 0xffffff; matManager.c2d[3] = (showcarddif << 25) | 0xffffff;
driver->draw2DImage(imageManager.GetTexture(showcardcode, true), Resize(662 - showcarddif * 0.69685f, 277 - showcarddif, 662 + showcarddif * 0.69685f, 277 + showcarddif), driver->draw2DImage(imageManager.GetTexture(showcardcode, true), ResizeCardMid(662 - showcarddif * 0.69685f, 277 - showcarddif, 662 + showcarddif * 0.69685f, 277 + showcarddif, midx, midy),
Resize(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), 0, matManager.c2d, true); ResizeFit(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), 0, matManager.c2d, true);
if(showcarddif < 127) if(showcarddif < 127)
showcarddif += 9; showcarddif += 9;
break; break;
} }
case 6: { case 6: {
driver->draw2DImage(imageManager.GetTexture(showcardcode, true), Resize(574, 150)); driver->draw2DImage(imageManager.GetTexture(showcardcode, true), ResizeCardHint(574, 150));
driver->draw2DImage(imageManager.tNumber, Resize(536 + showcarddif, 141 + showcarddif, 792 - showcarddif, 397 - showcarddif), driver->draw2DImage(imageManager.tNumber, ResizeCardMid(536 + showcarddif, 141 + showcarddif, 792 - showcarddif, 397 - showcarddif, midx, midy),
recti((showcardp % 5) * 64, (showcardp / 5) * 64, (showcardp % 5 + 1) * 64, (showcardp / 5 + 1) * 64), 0, 0, true); recti((showcardp % 5) * 64, (showcardp / 5) * 64, (showcardp % 5 + 1) * 64, (showcardp / 5 + 1) * 64), 0, 0, true);
if(showcarddif < 64) if(showcarddif < 64)
showcarddif += 4; showcarddif += 4;
break; break;
} }
case 7: { case 7: {
float mul = xScale;
if(xScale > yScale)
mul = yScale;
core::position2d<s32> corner[4]; core::position2d<s32> corner[4];
float y = sin(showcarddif * 3.1415926f / 180.0f) * CARD_IMG_HEIGHT * yScale; float y = sin(showcarddif * 3.1415926f / 180.0f) * CARD_IMG_HEIGHT * mul;
corner[0] = core::position2d<s32>(574 * xScale - (CARD_IMG_HEIGHT * yScale - y) * 0.3f, 404 * yScale - y); s32 winx = midx * xScale + (574 - midx) * mul;
corner[1] = core::position2d<s32>(751 * xScale + (CARD_IMG_HEIGHT * yScale - y) * 0.3f, 404 * yScale - y); s32 winx2 = midx * xScale + (751 - midx) * mul;
corner[2] = core::position2d<s32>(574 * xScale, 404 * yScale); s32 winy = midy * yScale + (404 - midy) * mul;
corner[3] = core::position2d<s32>(751 * xScale, 404 * yScale); corner[0] = core::position2d<s32>(winx - (CARD_IMG_HEIGHT * mul - y) * 0.3f, winy - y);
irr::gui::Draw2DImageQuad(driver, imageManager.GetTexture(showcardcode, true), Resize(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), corner); corner[1] = core::position2d<s32>(winx2 + (CARD_IMG_HEIGHT * mul - y) * 0.3f, winy - y);
corner[2] = core::position2d<s32>(winx, winy);
corner[3] = core::position2d<s32>(winx2, winy);
irr::gui::Draw2DImageQuad(driver, imageManager.GetTexture(showcardcode, true), ResizeFit(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), corner);
showcardp++; showcardp++;
showcarddif += 9; showcarddif += 9;
if(showcarddif >= 90) if(showcarddif >= 90)
......
...@@ -12,7 +12,12 @@ ...@@ -12,7 +12,12 @@
#ifndef _WIN32 #ifndef _WIN32
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h>
#else
#include <direct.h>
#include <io.h>
#endif #endif
const unsigned short PRO_VERSION = 0x1343; const unsigned short PRO_VERSION = 0x1343;
...@@ -23,6 +28,7 @@ Game* mainGame; ...@@ -23,6 +28,7 @@ Game* mainGame;
bool Game::Initialize() { bool Game::Initialize() {
srand(time(0)); srand(time(0));
initUtils();
LoadConfig(); LoadConfig();
irr::SIrrlichtCreationParameters params = irr::SIrrlichtCreationParameters(); irr::SIrrlichtCreationParameters params = irr::SIrrlichtCreationParameters();
params.AntiAlias = gameConf.antialias; params.AntiAlias = gameConf.antialias;
...@@ -1394,6 +1400,52 @@ void Game::AddDebugMsg(char* msg) ...@@ -1394,6 +1400,52 @@ void Game::AddDebugMsg(char* msg)
fclose(fp); fclose(fp);
} }
} }
bool Game::MakeDirectory(const std::string folder) {
std::string folder_builder;
std::string sub;
sub.reserve(folder.size());
for(auto it = folder.begin(); it != folder.end(); ++it) {
const char c = *it;
sub.push_back(c);
if(c == '/' || it == folder.end() - 1) {
folder_builder.append(sub);
if(access(folder_builder.c_str(), 0) != 0)
#ifdef _WIN32
if(mkdir(folder_builder.c_str()) != 0)
#else
if(mkdir(folder_builder.c_str(), 0777) != 0)
#endif
return false;
sub.clear();
}
}
return true;
}
void Game::initUtils() {
//user files
MakeDirectory("replay");
//cards from extra pack
MakeDirectory("expansions");
//files in ygopro-starter-pack
MakeDirectory("deck");
MakeDirectory("single");
//original files
MakeDirectory("script");
MakeDirectory("textures");
//sound
MakeDirectory("sound");
MakeDirectory("sound/BGM");
MakeDirectory("sound/BGM/advantage");
MakeDirectory("sound/BGM/deck");
MakeDirectory("sound/BGM/disadvantage");
MakeDirectory("sound/BGM/duel");
MakeDirectory("sound/BGM/lose");
MakeDirectory("sound/BGM/menu");
MakeDirectory("sound/BGM/win");
//pics
MakeDirectory("pics");
MakeDirectory("pics/field");
}
void Game::ClearTextures() { void Game::ClearTextures() {
matManager.mCard.setTexture(0, 0); matManager.mCard.setTexture(0, 0);
imgCard->setImage(imageManager.tCover[0]); imgCard->setImage(imageManager.tCover[0]);
...@@ -1571,8 +1623,8 @@ void Game::OnResize() { ...@@ -1571,8 +1623,8 @@ void Game::OnResize() {
btnReset->setRelativePosition(recti(1, 1, width, height)); btnReset->setRelativePosition(recti(1, 1, width, height));
} }
wCardImg->setRelativePosition(Resize(1, 1, 1 + CARD_IMG_WIDTH + 20, 1 + CARD_IMG_HEIGHT + 18)); wCardImg->setRelativePosition(ResizeCard(1, 1, 20, 18));
imgCard->setRelativePosition(Resize(10, 9, 10 + CARD_IMG_WIDTH, 9 + CARD_IMG_HEIGHT)); imgCard->setRelativePosition(ResizeCard(10, 9, 0, 0));
wInfos->setRelativePosition(Resize(1, 275, 301, 639)); wInfos->setRelativePosition(Resize(1, 275, 301, 639));
stName->setRelativePosition(recti(10, 10, 287 * xScale, 32)); stName->setRelativePosition(recti(10, 10, 287 * xScale, 32));
lstLog->setRelativePosition(Resize(10, 10, 290, 290)); lstLog->setRelativePosition(Resize(10, 10, 290, 290));
...@@ -1656,6 +1708,56 @@ recti Game::ResizeElem(s32 x, s32 y, s32 x2, s32 y2) { ...@@ -1656,6 +1708,56 @@ recti Game::ResizeElem(s32 x, s32 y, s32 x2, s32 y2) {
y2 = sy + y; y2 = sy + y;
return recti(x, y, x2, y2); return recti(x, y, x2, y2);
} }
recti Game::ResizeCard(s32 x, s32 y, s32 x2, s32 y2) {
float mul = xScale;
if(xScale > yScale)
mul = yScale;
s32 sx = CARD_IMG_WIDTH * mul + x2 * xScale;
s32 sy = CARD_IMG_HEIGHT * mul + y2 * yScale;
x = x * xScale;
y = y * yScale;
x2 = sx + x;
y2 = sy + y;
return recti(x, y, x2, y2);
}
recti Game::ResizeCardHint(s32 x, s32 y, s32 x2, s32 y2) {
return ResizeCardMid(x, y, x2, y2, (x + x2) * 0.5, (y + y2) * 0.5);
}
position2di Game::ResizeCardHint(s32 x, s32 y) {
return ResizeCardMid(x, y, x + CARD_IMG_WIDTH * 0.5, y + CARD_IMG_HEIGHT * 0.5);
}
recti Game::ResizeCardMid(s32 x, s32 y, s32 x2, s32 y2, s32 midx, s32 midy) {
float mul = xScale;
if(xScale > yScale)
mul = yScale;
s32 cx = midx * xScale;
s32 cy = midy * yScale;
x = cx + (x - midx) * mul;
y = cy + (y - midy) * mul;
x2 = cx + (x2 - midx) * mul;
y2 = cy + (y2 - midy) * mul;
return recti(x, y, x2, y2);
}
position2di Game::ResizeCardMid(s32 x, s32 y, s32 midx, s32 midy) {
float mul = xScale;
if(xScale > yScale)
mul = yScale;
s32 cx = midx * xScale;
s32 cy = midy * yScale;
x = cx + (x - midx) * mul;
y = cy + (y - midy) * mul;
return position2di(x, y);
}
recti Game::ResizeFit(s32 x, s32 y, s32 x2, s32 y2) {
float mul = xScale;
if(xScale > yScale)
mul = yScale;
x = x * mul;
y = y * mul;
x2 = x2 * mul;
y2 = y2 * mul;
return recti(x, y, x2, y2);
}
void Game::SetWindowsIcon() { void Game::SetWindowsIcon() {
#ifdef _WIN32 #ifdef _WIN32
HINSTANCE hInstance = (HINSTANCE)GetModuleHandleW(NULL); HINSTANCE hInstance = (HINSTANCE)GetModuleHandleW(NULL);
......
...@@ -138,6 +138,8 @@ public: ...@@ -138,6 +138,8 @@ public:
void AddChatMsg(wchar_t* msg, int player); void AddChatMsg(wchar_t* msg, int player);
void ClearChatMsg(); void ClearChatMsg();
void AddDebugMsg(char* msgbuf); void AddDebugMsg(char* msgbuf);
bool MakeDirectory(const std::string folder);
void initUtils();
void ClearTextures(); void ClearTextures();
void CloseDuelWindow(); void CloseDuelWindow();
...@@ -156,6 +158,12 @@ public: ...@@ -156,6 +158,12 @@ public:
position2di ResizeReverse(s32 x, s32 y); position2di ResizeReverse(s32 x, s32 y);
recti ResizeElem(s32 x, s32 y, s32 x2, s32 y2); recti ResizeElem(s32 x, s32 y, s32 x2, s32 y2);
recti ResizeWin(s32 x, s32 y, s32 x2, s32 y2, bool chat = false); recti ResizeWin(s32 x, s32 y, s32 x2, s32 y2, bool chat = false);
recti ResizeCard(s32 x, s32 y, s32 x2, s32 y2);
recti ResizeCardHint(s32 x, s32 y, s32 x2, s32 y2);
position2di ResizeCardHint(s32 x, s32 y);
recti ResizeCardMid(s32 x, s32 y, s32 x2, s32 y2, s32 midx, s32 midy);
position2di ResizeCardMid(s32 x, s32 y, s32 midx, s32 midy);
recti ResizeFit(s32 x, s32 y, s32 x2, s32 y2);
void SetWindowsIcon(); void SetWindowsIcon();
void FlashWindow(); void FlashWindow();
......
...@@ -174,8 +174,11 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) { ...@@ -174,8 +174,11 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
int width = CARD_IMG_WIDTH; int width = CARD_IMG_WIDTH;
int height = CARD_IMG_HEIGHT; int height = CARD_IMG_HEIGHT;
if(fit) { if(fit) {
width = width * mainGame->xScale; float mul = mainGame->xScale;
height = height * mainGame->yScale; if(mainGame->xScale > mainGame->yScale)
mul = mainGame->yScale;
width = width * mul;
height = height * mul;
} }
auto tit = tMap[fit ? 1 : 0].find(code); auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) { if(tit == tMap[fit ? 1 : 0].end()) {
......
Subproject commit c500b7763a78c6b5ad3dc71a719e232a7e9ef413 Subproject commit 36152ff19b37d8f411c1f301cc9ed9b0a7e93285
Subproject commit 45fa3f0610504b48bcf1cd299ecd88d7d2393d9b Subproject commit 11a3cf932ef0ba3e2dccaa4442db5d98ecc89163
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