Skip to content

Commit

Permalink
add card big picture (#2307)
Browse files Browse the repository at this point in the history
  • Loading branch information
mercury233 authored Jul 7, 2020
1 parent d1c09cb commit 1c36764
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 2 deletions.
93 changes: 92 additions & 1 deletion gframe/deck_con.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,52 @@ static bool check_set_code(const CardDataC& data, int set_code) {
return res;
}

inline void ShowBigCard(int code, float zoom) {
mainGame->deckBuilder.bigcard_code = code;
mainGame->deckBuilder.bigcard_zoom = zoom;
ITexture* img = imageManager.GetBigPicture(code, zoom);
mainGame->imgBigCard->setImage(img);
auto size = img->getSize();
s32 left = mainGame->window_size.Width / 2 - size.Width / 2;
s32 top = mainGame->window_size.Height / 2 - size.Height / 2;
mainGame->imgBigCard->setRelativePosition(recti(0, 0, size.Width, size.Height));
mainGame->wBigCard->setRelativePosition(recti(left, top, left + size.Width, top + size.Height));
mainGame->gMutex.lock();
mainGame->btnBigCardOriginalSize->setVisible(true);
mainGame->btnBigCardZoomIn->setVisible(true);
mainGame->btnBigCardZoomOut->setVisible(true);
mainGame->btnBigCardClose->setVisible(true);
mainGame->ShowElement(mainGame->wBigCard);
mainGame->env->getRootGUIElement()->bringToFront(mainGame->wBigCard);
mainGame->gMutex.unlock();
}
inline void ZoomBigCard(s32 centerx = -1, s32 centery = -1) {
if(mainGame->deckBuilder.bigcard_zoom >= 4)
mainGame->deckBuilder.bigcard_zoom = 4;
if(mainGame->deckBuilder.bigcard_zoom <= 0.2)
mainGame->deckBuilder.bigcard_zoom = 0.2;
ITexture* img = imageManager.GetBigPicture(mainGame->deckBuilder.bigcard_code, mainGame->deckBuilder.bigcard_zoom);
mainGame->imgBigCard->setImage(img);
auto size = img->getSize();
auto pos = mainGame->wBigCard->getRelativePosition();
if(centerx == -1) {
centerx = pos.UpperLeftCorner.X + pos.getWidth() / 2;
centery = pos.UpperLeftCorner.Y + pos.getHeight() * 0.444f;
}
float posx = (float)(centerx - pos.UpperLeftCorner.X) / pos.getWidth();
float posy = (float)(centery - pos.UpperLeftCorner.Y) / pos.getHeight();
s32 left = centerx - size.Width * posx;
s32 top = centery - size.Height * posy;
mainGame->imgBigCard->setRelativePosition(recti(0, 0, size.Width, size.Height));
mainGame->wBigCard->setRelativePosition(recti(left, top, left + size.Width, top + size.Height));
}
inline void CloseBigCard() {
mainGame->HideElement(mainGame->wBigCard);
mainGame->btnBigCardOriginalSize->setVisible(false);
mainGame->btnBigCardZoomIn->setVisible(false);
mainGame->btnBigCardZoomOut->setVisible(false);
mainGame->btnBigCardClose->setVisible(false);
}
void DeckBuilder::Initialize() {
mainGame->is_building = true;
mainGame->is_siding = false;
Expand Down Expand Up @@ -99,6 +145,11 @@ void DeckBuilder::Terminate() {
mainGame->wCardImg->setVisible(false);
mainGame->wInfos->setVisible(false);
mainGame->btnLeaveGame->setVisible(false);
mainGame->wBigCard->setVisible(false);
mainGame->btnBigCardOriginalSize->setVisible(false);
mainGame->btnBigCardZoomIn->setVisible(false);
mainGame->btnBigCardZoomOut->setVisible(false);
mainGame->btnBigCardClose->setVisible(false);
mainGame->PopupElement(mainGame->wMainMenu);
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->wACMessage->setVisible(false);
Expand Down Expand Up @@ -254,6 +305,24 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
deckManager.LoadDeck(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()));
break;
}
case BUTTON_BIG_CARD_ORIG_SIZE: {
ShowBigCard(bigcard_code, 1);
break;
}
case BUTTON_BIG_CARD_ZOOM_IN: {
bigcard_zoom += 0.2;
ZoomBigCard();
break;
}
case BUTTON_BIG_CARD_ZOOM_OUT: {
bigcard_zoom -= 0.2;
ZoomBigCard();
break;
}
case BUTTON_BIG_CARD_CLOSE: {
CloseBigCard();
break;
}
case BUTTON_MSG_OK: {
mainGame->HideElement(mainGame->wMessage);
mainGame->actionSignal.Set();
Expand Down Expand Up @@ -531,6 +600,11 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
case irr::EMIE_LMOUSE_LEFT_UP: {
is_starting_dragging = false;
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(!is_draging && !mainGame->is_siding && root->getElementFromPoint(mouse_pos) == mainGame->imgCard) {
ShowBigCard(mainGame->showingcode, 1);
break;
}
if(!is_draging)
break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
Expand All @@ -554,6 +628,14 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
is_draging = false;
break;
}
case irr::EMIE_LMOUSE_DOUBLE_CLICK: {
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(!is_draging && !mainGame->is_siding && root->getElementFromPoint(mouse_pos) == root && hovered_code) {
ShowBigCard(hovered_code, 1);
break;
}
break;
}
case irr::EMIE_RMOUSE_LEFT_UP: {
if(mainGame->is_siding) {
if(is_draging)
Expand All @@ -576,6 +658,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
break;
}
if(mainGame->wBigCard->isVisible()) {
CloseBigCard();
break;
}
if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible())
break;
if(!is_draging) {
Expand Down Expand Up @@ -658,11 +744,16 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
case irr::EMIE_MOUSE_WHEEL: {
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(root->getElementFromPoint(mouse_pos) == mainGame->imgBigCard) {
bigcard_zoom += 0.1f * event.MouseInput.Wheel;
ZoomBigCard(mouse_pos.X, mouse_pos.Y);
break;
}
if(!mainGame->scrFilter->isVisible())
break;
if(mainGame->env->hasFocus(mainGame->scrFilter))
break;
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(root->getElementFromPoint(mouse_pos) != root)
break;
if(event.MouseInput.Wheel < 0) {
Expand Down
2 changes: 2 additions & 0 deletions gframe/deck_con.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class DeckBuilder: public irr::IEventReceiver {
bool is_starting_dragging;
int dragx;
int dragy;
int bigcard_code;
float bigcard_zoom;
size_t pre_mainc;
size_t pre_extrac;
size_t pre_sidec;
Expand Down
6 changes: 5 additions & 1 deletion gframe/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,14 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
mainGame->SetCursor(event.GUIEvent.Caller->isEnabled() ? ECI_IBEAM : ECI_NORMAL);
return true;
}
if(event.GUIEvent.Caller == mainGame->imgCard && mainGame->is_building && !mainGame->is_siding) {
mainGame->SetCursor(ECI_HAND);
return true;
}
break;
}
case irr::gui::EGET_ELEMENT_LEFT: {
if(event.GUIEvent.Caller->getType() == EGUIET_EDIT_BOX) {
if(event.GUIEvent.Caller->getType() == EGUIET_EDIT_BOX || event.GUIEvent.Caller == mainGame->imgCard) {
mainGame->SetCursor(ECI_NORMAL);
return true;
}
Expand Down
22 changes: 22 additions & 0 deletions gframe/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,23 @@ bool Game::Initialize() {
//cancel or finish
btnCancelOrFinish = env->addButton(rect<s32>(205, 230, 295, 265), 0, BUTTON_CANCEL_OR_FINISH, dataManager.GetSysString(1295));
btnCancelOrFinish->setVisible(false);
//big picture
wBigCard = env->addWindow(rect<s32>(0, 0, 0, 0), false, L"");
wBigCard->getCloseButton()->setVisible(false);
wBigCard->setDrawTitlebar(false);
wBigCard->setDrawBackground(false);
wBigCard->setVisible(false);
imgBigCard = env->addImage(rect<s32>(0, 0, 0, 0), wBigCard);
imgBigCard->setScaleImage(false);
imgBigCard->setUseAlphaChannel(true);
btnBigCardOriginalSize = env->addButton(rect<s32>(205, 100, 295, 135), 0, BUTTON_BIG_CARD_ORIG_SIZE, dataManager.GetSysString(1443));
btnBigCardZoomIn = env->addButton(rect<s32>(205, 140, 295, 175), 0, BUTTON_BIG_CARD_ZOOM_IN, dataManager.GetSysString(1441));
btnBigCardZoomOut = env->addButton(rect<s32>(205, 180, 295, 215), 0, BUTTON_BIG_CARD_ZOOM_OUT, dataManager.GetSysString(1442));
btnBigCardClose = env->addButton(rect<s32>(205, 230, 295, 265), 0, BUTTON_BIG_CARD_CLOSE, dataManager.GetSysString(1440));
btnBigCardOriginalSize->setVisible(false);
btnBigCardZoomIn->setVisible(false);
btnBigCardZoomOut->setVisible(false);
btnBigCardClose->setVisible(false);
//leave/surrender/exit
btnLeaveGame = env->addButton(rect<s32>(205, 5, 295, 80), 0, BUTTON_LEAVE_GAME, L"");
btnLeaveGame->setVisible(false);
Expand Down Expand Up @@ -1723,6 +1740,11 @@ void Game::OnResize() {
btnChainWhenAvail->setRelativePosition(Resize(205, 180, 295, 215));
btnShuffle->setRelativePosition(Resize(205, 230, 295, 265));
btnCancelOrFinish->setRelativePosition(Resize(205, 230, 295, 265));

btnBigCardOriginalSize->setRelativePosition(Resize(205, 100, 295, 135));
btnBigCardZoomIn->setRelativePosition(Resize(205, 140, 295, 175));
btnBigCardZoomOut->setRelativePosition(Resize(205, 180, 295, 215));
btnBigCardClose->setRelativePosition(Resize(205, 230, 295, 265));
}
recti Game::Resize(s32 x, s32 y, s32 x2, s32 y2) {
x = x * xScale;
Expand Down
11 changes: 11 additions & 0 deletions gframe/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ class Game {
irr::gui::IGUIButton* btnChainWhenAvail;
//cancel or finish
irr::gui::IGUIButton* btnCancelOrFinish;
//big picture
irr::gui::IGUIWindow* wBigCard;
irr::gui::IGUIImage* imgBigCard;
irr::gui::IGUIButton* btnBigCardOriginalSize;
irr::gui::IGUIButton* btnBigCardZoomIn;
irr::gui::IGUIButton* btnBigCardZoomOut;
irr::gui::IGUIButton* btnBigCardClose;
};

extern Game* mainGame;
Expand Down Expand Up @@ -728,6 +735,10 @@ extern Game* mainGame;
#define CHECKBOX_MULTI_KEYWORDS 372
#define CHECKBOX_PREFER_EXPANSION 373
#define CHECKBOX_DRAW_SINGLE_CHAIN 374
#define BUTTON_BIG_CARD_CLOSE 380
#define BUTTON_BIG_CARD_ZOOM_IN 381
#define BUTTON_BIG_CARD_ZOOM_OUT 382
#define BUTTON_BIG_CARD_ORIG_SIZE 383

#define DEFAULT_DUEL_RULE 5

Expand Down
36 changes: 36 additions & 0 deletions gframe/image_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool ImageManager::Initial() {
tUnknown = NULL;
tUnknownFit = NULL;
tUnknownThumb = NULL;
tBigPicture = NULL;
tLoading = NULL;
tThumbLoadingThreadRunning = false;
tAct = driver->getTexture("textures/act.png");
Expand Down Expand Up @@ -60,6 +61,10 @@ void ImageManager::ClearTexture() {
if(tit->second && tit->second != tLoading)
driver->removeTexture(tit->second);
}
if(tBigPicture != NULL) {
driver->removeTexture(tBigPicture);
tBigPicture = NULL;
}
tMap[0].clear();
tMap[1].clear();
tThumb.clear();
Expand Down Expand Up @@ -246,6 +251,37 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
else
return mainGame->gameConf.use_image_scale ? (fit ? tUnknownFit : tUnknown) : GetTextureThumb(code);
}
irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
if(code == 0)
return tUnknown;
if(tBigPicture != NULL) {
driver->removeTexture(tBigPicture);
tBigPicture = NULL;
}
irr::video::ITexture* texture;
char file[256];
sprintf(file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == NULL) {
sprintf(file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == NULL) {
return tUnknown;
}
if(zoom == 1) {
texture = driver->addTexture(file, srcimg);
} else {
auto origsize = srcimg->getDimension();
video::IImage* destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<u32>(origsize.Width * zoom, origsize.Height * zoom));
imageScaleNNAA(srcimg, destimg);
texture = driver->addTexture(file, destimg);
destimg->drop();
}
srcimg->drop();
tBigPicture = texture;
return texture;
}
int ImageManager::LoadThumbThread() {
while(true) {
imageManager.tThumbLoadingMutex.lock();
Expand Down
2 changes: 2 additions & 0 deletions gframe/image_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ImageManager {
void ResizeTexture();
irr::video::ITexture* GetTextureFromFile(const char* file, s32 width, s32 height);
irr::video::ITexture* GetTexture(int code, bool fit = false);
irr::video::ITexture* GetBigPicture(int code, float zoom);
irr::video::ITexture* GetTextureThumb(int code);
irr::video::ITexture* GetTextureField(int code);
static int LoadThumbThread();
Expand All @@ -34,6 +35,7 @@ class ImageManager {
irr::video::ITexture* tUnknown;
irr::video::ITexture* tUnknownFit;
irr::video::ITexture* tUnknownThumb;
irr::video::ITexture* tBigPicture;
irr::video::ITexture* tLoading;
irr::video::ITexture* tAct;
irr::video::ITexture* tAttack;
Expand Down
4 changes: 4 additions & 0 deletions strings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@
!system 1429 选择的位置不符合条件。
!system 1430 选择的表示形式不符合条件。
!system 1431 选择的指示物不符合条件。
!system 1440 关闭大图
!system 1441 放大
!system 1442 缩小
!system 1443 原始尺寸
!system 1500 决斗结束。
!system 1501 录像结束。
!system 1502 连接已断开。
Expand Down

0 comments on commit 1c36764

Please sign in to comment.