Commit ee31f8da authored by mercury233's avatar mercury233

Merge branch 'resize' into test

parents ddf273c6 8c7dd9d7
......@@ -671,8 +671,9 @@ void DeckBuilder::GetHoveredCard() {
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(root->getElementFromPoint(mouse_pos) != root)
return;
int x = mouse_pos.X;
int y = mouse_pos.Y;
position2di pos = mainGame->ResizeReverse(mouse_pos.X, mouse_pos.Y);
int x = pos.X;
int y = pos.Y;
int pre_code = hovered_code;
hovered_pos = 0;
hovered_code = 0;
......@@ -741,8 +742,8 @@ void DeckBuilder::GetHoveredCard() {
}
}
if(is_draging) {
dragx = x;
dragy = y;
dragx = mouse_pos.X;
dragy = mouse_pos.Y;
}
if(!is_draging && pre_code != hovered_code) {
if(hovered_code)
......
This diff is collapsed.
......@@ -1002,10 +1002,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case irr::EMIE_LMOUSE_LEFT_UP: {
if(!mainGame->dInfo.isStarted)
break;
s32 x = event.MouseInput.X;
s32 y = event.MouseInput.Y;
hovered_location = 0;
irr::core::position2di pos(x, y);
position2di pos = mainGame->ResizeReverse(event.MouseInput.X, event.MouseInput.Y);
position2di mousepos(event.MouseInput.X, event.MouseInput.Y);
s32 x = pos.X;
s32 y = pos.Y;
if(x < 300)
break;
if(mainGame->gameConf.control_mode == 1) {
......@@ -1014,7 +1015,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
mainGame->chain_when_avail = false;
UpdateChainButtons();
}
if(mainGame->wCmdMenu->isVisible() && !mainGame->wCmdMenu->getRelativePosition().isPointInside(pos))
if(mainGame->wCmdMenu->isVisible() && !mainGame->wCmdMenu->getRelativePosition().isPointInside(mousepos))
mainGame->wCmdMenu->setVisible(false);
if(panel && panel->isVisible())
break;
......@@ -1388,7 +1389,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(root->getElementFromPoint(pos) == mainGame->btnCancelOrFinish)
mainGame->chkHideHintButton->setChecked(true);
if(mainGame->gameConf.control_mode == 1 && event.MouseInput.X > 300) {
if(mainGame->gameConf.control_mode == 1 && x > 300 * mainGame->xScale) {
mainGame->ignore_chain = event.MouseInput.isRightPressed();
mainGame->always_chain = false;
mainGame->chain_when_avail = false;
......@@ -1404,9 +1405,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(!mainGame->dInfo.isStarted)
break;
bool should_show_tip = false;
s32 x = event.MouseInput.X;
s32 y = event.MouseInput.Y;
irr::core::position2di pos(x, y);
position2di pos = mainGame->ResizeReverse(event.MouseInput.X, event.MouseInput.Y);
position2di mousepos = position2di(event.MouseInput.X, event.MouseInput.Y);
s32 x = pos.X;
s32 y = pos.Y;
wchar_t formatBuffer[2048];
if(x < 300) {
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
......@@ -1416,7 +1418,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, dataManager.GetSysString(1700), mainGame->btnCancelOrFinish->getText());
mainGame->stTip->setText(formatBuffer);
irr::core::dimension2d<unsigned int> dtip = mainGame->textFont->getDimension(formatBuffer) + irr::core::dimension2d<unsigned int>(10, 10);
mainGame->stTip->setRelativePosition(recti(x - 10 - dtip.Width, y - 10 - dtip.Height, x - 10, y - 10));
mainGame->stTip->setRelativePosition(mainGame->Resize(x - 10 - dtip.Width, y - 10 - dtip.Height, x - 10, y - 10));
}
mainGame->stTip->setVisible(should_show_tip);
break;
......@@ -1424,7 +1426,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
hovered_location = 0;
ClientCard* mcard = 0;
int mplayer = -1;
if(!panel || !panel->isVisible() || !panel->getRelativePosition().isPointInside(pos)) {
if(!panel || !panel->isVisible() || !panel->getRelativePosition().isPointInside(mousepos)) {
GetHoverField(x, y);
if(hovered_location & 0xe)
mcard = GetCard(hovered_controler, hovered_location, hovered_sequence);
......@@ -1441,9 +1443,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(deck[hovered_controler].size())
mcard = deck[hovered_controler].back();
} else {
if(irr::core::recti(327, 8, 630, 51).isPointInside(pos))
if(mainGame->Resize(327, 8, 630, 51).isPointInside(mousepos))
mplayer = 0;
else if(irr::core::recti(689, 8, 991, 51).isPointInside(pos))
else if(mainGame->Resize(689, 8, 991, 51).isPointInside(mousepos))
mplayer = 1;
}
}
......@@ -1455,7 +1457,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(mainGame->stTip->isVisible()) {
should_show_tip = true;
irr::core::recti tpos = mainGame->stTip->getRelativePosition();
mainGame->stTip->setRelativePosition(irr::core::position2di(x - tpos.getWidth() - 10, mcard ? y - tpos.getHeight() - 10 : y + 10));
mainGame->stTip->setRelativePosition(irr::core::position2di(mousepos.X - tpos.getWidth() - 10, mcard ? mousepos.Y - tpos.getHeight() - 10 : y + 10));
}
}
if(mcard != hovered_card) {
......@@ -1540,7 +1542,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
should_show_tip = true;
irr::core::dimension2d<unsigned int> dtip = mainGame->textFont->getDimension(str.c_str()) + irr::core::dimension2d<unsigned int>(10, 10);
mainGame->stTip->setRelativePosition(recti(x - 10 - dtip.Width, y - 10 - dtip.Height, x - 10, y - 10));
mainGame->stTip->setRelativePosition(recti(mousepos.X - 10 - dtip.Width, mousepos.Y - 10 - dtip.Height, mousepos.X - 10, mousepos.Y - 10));
mainGame->stTip->setText(str.c_str());
}
} else {
......@@ -1578,7 +1580,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
should_show_tip = true;
irr::core::dimension2d<unsigned int> dtip = mainGame->textFont->getDimension(str.c_str()) + irr::core::dimension2d<unsigned int>(10, 10);
mainGame->stTip->setRelativePosition(recti(x - 10 - dtip.Width, y + 10, x - 10, y + 10 + dtip.Height));
mainGame->stTip->setRelativePosition(recti(mousepos.X - 10 - dtip.Width, mousepos.Y + 10, mousepos.X - 10, mousepos.Y + 10 + dtip.Height));
mainGame->stTip->setText(str.c_str());
}
hovered_player = mplayer;
......@@ -1592,7 +1594,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case irr::EMIE_LMOUSE_PRESSED_DOWN: {
if(!mainGame->dInfo.isStarted)
break;
if(mainGame->gameConf.control_mode == 1 && event.MouseInput.X > 300) {
if(mainGame->gameConf.control_mode == 1 && event.MouseInput.X > 300 * mainGame->xScale) {
mainGame->always_chain = event.MouseInput.isLeftPressed();
mainGame->ignore_chain = false;
mainGame->chain_when_avail = false;
......@@ -1603,7 +1605,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case irr::EMIE_RMOUSE_PRESSED_DOWN: {
if(!mainGame->dInfo.isStarted)
break;
if(mainGame->gameConf.control_mode == 1 && event.MouseInput.X > 300) {
if(mainGame->gameConf.control_mode == 1 && event.MouseInput.X > 300 * mainGame->xScale) {
mainGame->ignore_chain = event.MouseInput.isRightPressed();
mainGame->always_chain = false;
mainGame->chain_when_avail = false;
......@@ -2105,6 +2107,9 @@ void ClientField::ShowMenu(int flag, int x, int y) {
} else mainGame->btnReset->setVisible(false);
panel = mainGame->wCmdMenu;
mainGame->wCmdMenu->setVisible(true);
position2di mouse = mainGame->Resize(x, y);
x = mouse.X;
y = mouse.Y;
mainGame->wCmdMenu->setRelativePosition(irr::core::recti(x - 20 , y - 20 - height, x + 80, y - 20));
}
void ClientField::UpdateChainButtons() {
......
This diff is collapsed.
......@@ -124,7 +124,7 @@ public:
void HideElement(irr::gui::IGUIElement* element, bool set_action = false);
void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0);
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 LoadConfig();
void SaveConfig();
......@@ -142,6 +142,14 @@ public:
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 FlashWindow();
void SetCursor(ECURSOR_ICON icon);
......@@ -192,6 +200,10 @@ public:
bool is_building;
bool is_siding;
irr::core::dimension2d<irr::u32> window_size;
float xScale;
float yScale;
ClientField dField;
DeckBuilder deckBuilder;
MenuHandler menuHandler;
......@@ -413,6 +425,17 @@ public:
irr::gui::IGUIButton* btnSideSort;
irr::gui::IGUIButton* btnSideReload;
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
irr::gui::IGUIStaticText* wFilter;
irr::gui::IGUIScrollBar* scrFilter;
......
......@@ -45,7 +45,11 @@ void ImageManager::SetDevice(irr::IrrlichtDevice* dev) {
driver = dev->getVideoDriver();
}
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)
driver->removeTexture(tit->second);
}
......@@ -53,20 +57,26 @@ void ImageManager::ClearTexture() {
if(tit->second)
driver->removeTexture(tit->second);
}
tMap.clear();
tMap[0].clear();
tMap[1].clear();
tThumb.clear();
}
void ImageManager::RemoveTexture(int code) {
auto tit = tMap.find(code);
if(tit != tMap.end()) {
auto tit = tMap[0].find(code);
if(tit != tMap[0].end()) {
if(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
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;
u32 dy, dx;
irr::video::SColor pxl;
......@@ -158,23 +168,29 @@ irr::video::ITexture* ImageManager::GetTextureFromFile(char* file, s32 width, s3
return driver->getTexture(file);
}
}
irr::video::ITexture* ImageManager::GetTexture(int code) {
irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
if(code == 0)
return tUnknown;
auto tit = tMap.find(code);
if(tit == tMap.end()) {
int width = CARD_IMG_WIDTH;
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];
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) {
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) {
tMap[code] = NULL;
tMap[fit ? 1 : 0][code] = NULL;
return GetTextureThumb(code);
}
tMap[code] = img;
tMap[fit ? 1 : 0][code] = img;
return (img == NULL) ? tUnknown : img;
}
if(tit->second)
......@@ -186,20 +202,22 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(code == 0)
return tUnknown;
auto tit = tThumb.find(code);
int width = CARD_THUMB_WIDTH * mainGame->xScale;
int height = CARD_THUMB_HEIGHT * mainGame->yScale;
if(tit == tThumb.end()) {
char file[256];
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) {
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) {
sprintf(file, "expansions/pics/%d.jpg", code);
img = GetTextureFromFile(file, CARD_THUMB_WIDTH, CARD_THUMB_HEIGHT);
img = GetTextureFromFile(file, width, height);
if(img == NULL) {
sprintf(file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, CARD_THUMB_WIDTH, CARD_THUMB_HEIGHT);
img = GetTextureFromFile(file, width, height);
}
}
tThumb[code] = img;
......@@ -217,18 +235,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
if(tit == tFields.end()) {
char file[256];
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) {
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) {
sprintf(file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512, 512);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == NULL) {
sprintf(file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512, 512);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) {
tFields[code] = NULL;
return NULL;
......
......@@ -14,11 +14,11 @@ public:
void ClearTexture();
void RemoveTexture(int code);
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* 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*> tFields;
irr::IrrlichtDevice* device;
......
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