From a4f701014bb72a441b29d6d39216cf1c3d299e09 Mon Sep 17 00:00:00 2001 From: FeniksFire Date: Wed, 1 Nov 2017 14:58:49 +0100 Subject: [PATCH 1/4] Quick Army Purhase in Town Screen Mouse click on castle icon (it is now clickable) - quick recruit of all available creatures. --- client/CMakeLists.txt | 6 + client/CreatureCostBox.cpp | 63 +++++++++ client/CreatureCostBox.h | 22 +++ client/windows/CCastleInterface.cpp | 11 +- client/windows/CCastleInterface.h | 4 +- client/windows/CreaturePurhaseCard.cpp | 80 +++++++++++ client/windows/CreaturePurhaseCard.h | 49 +++++++ client/windows/GUIClasses.cpp | 56 +------- client/windows/GUIClasses.h | 17 +-- client/windows/QuickRecruitmentWindow.cpp | 157 ++++++++++++++++++++++ client/windows/QuickRecruitmentWindow.h | 44 ++++++ 11 files changed, 439 insertions(+), 70 deletions(-) create mode 100644 client/CreatureCostBox.cpp create mode 100644 client/CreatureCostBox.h create mode 100644 client/windows/CreaturePurhaseCard.cpp create mode 100644 client/windows/CreaturePurhaseCard.h create mode 100644 client/windows/QuickRecruitmentWindow.cpp create mode 100644 client/windows/QuickRecruitmentWindow.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 692924f9e..213954997 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -32,6 +32,7 @@ set(client_SRCS windows/CAdvmapInterface.cpp windows/CCastleInterface.cpp windows/CCreatureWindow.cpp + windows/CreaturePurhaseCard.cpp windows/CHeroWindow.cpp windows/CKingdomInterface.cpp windows/CQuestLog.cpp @@ -40,8 +41,10 @@ set(client_SRCS windows/CWindowObject.cpp windows/GUIClasses.cpp windows/InfoWindows.cpp + windows/QuickRecruitmentWindow.cpp CBitmapHandler.cpp + CreatureCostBox.cpp CDefHandler.cpp CGameInfo.cpp Client.cpp @@ -87,6 +90,7 @@ set(client_HEADERS windows/CAdvmapInterface.h windows/CCastleInterface.h windows/CCreatureWindow.h + windows/CreaturePurhaseCard.h windows/CHeroWindow.h windows/CKingdomInterface.h windows/CQuestLog.h @@ -95,8 +99,10 @@ set(client_HEADERS windows/CWindowObject.h windows/GUIClasses.h windows/InfoWindows.h + windows/QuickRecruitmentWindow.h CBitmapHandler.h + CreatureCostBox.h CDefHandler.h CGameInfo.h Client.h diff --git a/client/CreatureCostBox.cpp b/client/CreatureCostBox.cpp new file mode 100644 index 000000000..898850c41 --- /dev/null +++ b/client/CreatureCostBox.cpp @@ -0,0 +1,63 @@ +/* + * CreatureCostBox.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" +#include "CreatureCostBox.h" +#include "windows/CAdvmapInterface.h" +#include "gui/CGuiHandler.h" + + +void CreatureCostBox::set(TResources res) +{ + for(auto & item : resources) + item.second.first->setText(boost::lexical_cast(res[item.first])); +} + +CreatureCostBox::CreatureCostBox(Rect position, std::string title) +{ + type |= REDRAW_PARENT; + pos = position + pos; + OBJ_CONSTRUCTION_CAPTURING_ALL; + new CLabel(pos.w/2, 10, FONT_SMALL, CENTER, Colors::WHITE, title); +} + +void CreatureCostBox::createItems(TResources res) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + + for(auto & curr : resources) + { + delete curr.second.first; + delete curr.second.second; + } + resources.clear(); + + TResources::nziterator iter(res); + while (iter.valid()) + { + CAnimImage * image = new CAnimImage("RESOURCE", iter->resType); + CLabel * text = new CLabel(15, 43, FONT_SMALL, CENTER, Colors::WHITE, "0"); + + resources.insert(std::make_pair(iter->resType, std::make_pair(text, image))); + iter++; + } + + if (!resources.empty()) + { + int curx = pos.w / 2 - (16 * resources.size()) - (8 * (resources.size() - 1)); + //reverse to display gold as first resource + for (auto & res : boost::adaptors::reverse(resources)) + { + res.second.first->moveBy(Point(curx, 22)); + res.second.second->moveBy(Point(curx, 22)); + curx += 48; + } + } + redraw(); +} diff --git a/client/CreatureCostBox.h b/client/CreatureCostBox.h new file mode 100644 index 000000000..064bb7026 --- /dev/null +++ b/client/CreatureCostBox.h @@ -0,0 +1,22 @@ +/* + * CreatureCostBox.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "widgets/Images.h" +#include "../lib/ResourceSet.h" + +class CreatureCostBox : public CIntObject +{ + std::map > resources; +public: + void set(TResources res); + CreatureCostBox(Rect position, std::string title); + void createItems(TResources res); +}; diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index c0e86553e..5c9070c54 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -14,6 +14,7 @@ #include "CHeroWindow.h" #include "CTradeWindow.h" #include "GUIClasses.h" +#include "QuickRecruitmentWindow.h" #include "../CBitmapHandler.h" #include "../CGameInfo.h" @@ -21,7 +22,6 @@ #include "../CMusicHandler.h" #include "../CPlayerInterface.h" #include "../Graphics.h" - #include "../gui/CGuiHandler.h" #include "../gui/SDL_Extensions.h" #include "../windows/InfoWindows.h" @@ -795,6 +795,11 @@ void CCastleBuildings::enterDwelling(int level) GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, -87)); } +void CCastleBuildings::enterToTheQuickRecruitmentWindow() +{ + GH.pushInt(new QuickRecruitmentWindow(town)); +} + void CCastleBuildings::enterFountain(BuildingID building) { std::vector comps(1, new CComponent(CComponent::building,town->subID,building)); @@ -885,6 +890,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst town(Town) { OBJ_CONSTRUCTION_CAPTURING_ALL; + LOCPLINT->castleInt = this; addUsedEvents(KEYBOARD); @@ -990,7 +996,8 @@ void CCastleInterface::recreateIcons() hall = new CTownInfo( 80, 413, town, true); fort = new CTownInfo(122, 413, town, false); - + fastArmyPurhase = std::make_shared(Point(122, 413), "itmcl.def", CButton::tooltip("quick army purhase"), [&](){builds->enterToTheQuickRecruitmentWindow();}); + fastArmyPurhase->setImageOrder(town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1); for (auto & elem : creainfo) delete elem; creainfo.clear(); diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 3146eaf83..79b2ae8b8 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -143,6 +143,7 @@ public: ~CCastleBuildings(); void enterDwelling(int level); + void enterToTheQuickRecruitmentWindow(); void buildingClicked(BuildingID building); void addBuilding(BuildingID building); @@ -180,8 +181,8 @@ class CTownInfo : public CIntObject { const CGTownInstance *town; const CBuilding *building; - CAnimImage *picture; public: + CAnimImage * picture; //if (townHall) hall-capital else fort - castle CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall); @@ -204,6 +205,7 @@ class CCastleInterface : public CWindowObject, public CWindowWithGarrison CButton *exit; CButton *split; + std::shared_ptr fastArmyPurhase; std::vector creainfo;//small icons of creatures (bottom-left corner); diff --git a/client/windows/CreaturePurhaseCard.cpp b/client/windows/CreaturePurhaseCard.cpp new file mode 100644 index 000000000..861a9b79f --- /dev/null +++ b/client/windows/CreaturePurhaseCard.cpp @@ -0,0 +1,80 @@ +/* + * CreaturePurhaseCard.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" +#include "CreaturePurhaseCard.h" +#include "CAdvmapInterface.h" +#include "CHeroWindow.h" +#include "../widgets/Buttons.h" +#include "../../CCallback.h" +#include "../CreatureCostBox.h" +#include "QuickRecruitmentWindow.h" + +void CreaturePurhaseCard::initButtons() +{ + initMaxButton(); + initMinButton(); +} + +void CreaturePurhaseCard::initMaxButton() +{ + maxButton = std::make_shared(Point(pos.x + 52, pos.y + 178), "iam014.def", CButton::tooltip(), std::bind(&CSlider::moveToMax,slider), SDLK_m); +} + +void CreaturePurhaseCard::initMinButton() +{ + minButton = std::make_shared(Point(pos.x, pos.y + 178), "iam015.def", CButton::tooltip(), std::bind(&CSlider::moveToMin,slider), SDLK_m); +} + +void CreaturePurhaseCard::initAmountInfo() +{ + availableAmount = std::make_shared(pos.x + 27, pos.y + 146, FONT_SMALL, CENTER, Colors::YELLOW); + purhaseAmount = std::make_shared(pos.x + 77, pos.y + 146, FONT_SMALL, CENTER, Colors::WHITE); + updateAmountInfo(0); +} + +void CreaturePurhaseCard::updateAmountInfo(int value) +{ + availableAmount->setText(boost::lexical_cast(maxamount-value)); + purhaseAmount->setText(boost::lexical_cast(value)); +} + +void CreaturePurhaseCard::initSlider() +{ + slider = std::make_shared(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxamount, 0); +} + +void CreaturePurhaseCard::initCostBox() +{ + cost = std::make_shared(Rect(pos.x, pos.y + 194, 97, 74), ""); + cost->createItems(creature->cost); +} + + +void CreaturePurhaseCard::sliderMoved(int to) +{ + updateAmountInfo(to); + cost->set(creature->cost * to); + parent->updateAllSliders(); +} + +CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * monster, Point p, int amount, QuickRecruitmentWindow * par) : creature(monster), parent(par), maxamount(amount) +{ + moveTo(Point(p.x, p.y)); + initView(); +} + +void CreaturePurhaseCard::initView() +{ + picture = std::make_shared(pos.x, pos.y, creature); + initAmountInfo(); + initSlider(); + initButtons(); + initCostBox(); +} diff --git a/client/windows/CreaturePurhaseCard.h b/client/windows/CreaturePurhaseCard.h new file mode 100644 index 000000000..4832c3371 --- /dev/null +++ b/client/windows/CreaturePurhaseCard.h @@ -0,0 +1,49 @@ +/* + * CreaturePurhaseCard.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "../widgets/Images.h" + +class CCreaturePic; +class CSlider; +class CButton; +class CreatureCostBox; +class QuickRecruitmentWindow; + +class CreaturePurhaseCard : public CIntObject +{ +public: + const CCreature * creature; + std::shared_ptr slider; + QuickRecruitmentWindow * parent; + int maxamount; + void sliderMoved(int to); + CreaturePurhaseCard(const CCreature * monster, Point p, int amount, QuickRecruitmentWindow * par); + +private: + void initView(); + + void initButtons(); + void initMaxButton(); + void initMinButton(); + + void initAmountInfo(); + void updateAmountInfo(int value); + + void initSlider(); + + void initCostBox(); + + std::shared_ptr maxButton, minButton; + std::shared_ptr availableAmount, purhaseAmount; + std::shared_ptr picture; + std::shared_ptr cost; + +}; diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 727e21c17..b7f080b1d 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -14,6 +14,7 @@ #include "CCastleInterface.h" #include "CCreatureWindow.h" #include "CHeroWindow.h" +#include "CreatureCostBox.h" #include "../CBitmapHandler.h" #include "../CGameInfo.h" @@ -108,57 +109,6 @@ void CRecruitmentWindow::CCreatureCard::showAll(SDL_Surface * to) drawBorder(to, pos, int3(232, 212, 120)); } -CRecruitmentWindow::CCostBox::CCostBox(Rect position, std::string title) -{ - type |= REDRAW_PARENT; - pos = position + pos; - OBJ_CONSTRUCTION_CAPTURING_ALL; - new CLabel(pos.w/2, 10, FONT_SMALL, CENTER, Colors::WHITE, title); -} - -void CRecruitmentWindow::CCostBox::set(TResources res) -{ - //just update values - for(auto & item : resources) - { - item.second.first->setText(boost::lexical_cast(res[item.first])); - } -} - -void CRecruitmentWindow::CCostBox::createItems(TResources res) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - - for(auto & curr : resources) - { - delete curr.second.first; - delete curr.second.second; - } - resources.clear(); - - TResources::nziterator iter(res); - while (iter.valid()) - { - CAnimImage * image = new CAnimImage("RESOURCE", iter->resType); - CLabel * text = new CLabel(15, 43, FONT_SMALL, CENTER, Colors::WHITE, "0"); - - resources.insert(std::make_pair(iter->resType, std::make_pair(text, image))); - iter++; - } - - if (!resources.empty()) - { - int curx = pos.w / 2 - (16 * resources.size()) - (8 * (resources.size() - 1)); - //reverse to display gold as first resource - for (auto & res : boost::adaptors::reverse(resources)) - { - res.second.first->moveBy(Point(curx, 22)); - res.second.second->moveBy(Point(curx, 22)); - curx += 48; - } - } - redraw(); -} void CRecruitmentWindow::select(CCreatureCard *card) { @@ -268,8 +218,8 @@ CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, co availableValue = new CLabel(205, 253, FONT_SMALL, CENTER, Colors::WHITE); toRecruitValue = new CLabel(279, 253, FONT_SMALL, CENTER, Colors::WHITE); - costPerTroopValue = new CCostBox(Rect(65, 222, 97, 74), CGI->generaltexth->allTexts[346]); - totalCostValue = new CCostBox(Rect(323, 222, 97, 74), CGI->generaltexth->allTexts[466]); + costPerTroopValue = new CreatureCostBox(Rect(65, 222, 97, 74), CGI->generaltexth->allTexts[346]); + totalCostValue = new CreatureCostBox(Rect(323, 222, 97, 74), CGI->generaltexth->allTexts[466]); new CLabel(205, 233, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[465]); //available t new CLabel(279, 233, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[16]); //recruit t diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index fcfe280c5..12bcf3fb8 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -18,6 +18,7 @@ #include "../windows/CWindowObject.h" class CGDwelling; +class CreatureCostBox; class IMarket; class CCreaturePic; class MoraleLuckBox; @@ -54,18 +55,6 @@ class CRecruitmentWindow : public CWindowObject CCreatureCard(CRecruitmentWindow * window, const CCreature *crea, int totalAmount); }; - /// small class to display creature costs - class CCostBox : public CIntObject - { - std::map > resources; - public: - //res - resources to show - void set(TResources res); - //res - visible resources - CCostBox(Rect position, std::string title); - void createItems(TResources res); - }; - std::function onRecruit; //void (int ID, int amount) <-- call to recruit creatures int level; @@ -80,8 +69,8 @@ class CRecruitmentWindow : public CWindowObject CLabel * title; CLabel * availableValue; CLabel * toRecruitValue; - CCostBox * costPerTroopValue; - CCostBox * totalCostValue; + CreatureCostBox * costPerTroopValue; + CreatureCostBox * totalCostValue; void select(CCreatureCard * card); void buy(); diff --git a/client/windows/QuickRecruitmentWindow.cpp b/client/windows/QuickRecruitmentWindow.cpp new file mode 100644 index 000000000..688b080f2 --- /dev/null +++ b/client/windows/QuickRecruitmentWindow.cpp @@ -0,0 +1,157 @@ +/* + * QuickRecruitmentWindow.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" +#include "QuickRecruitmentWindow.h" +#include "../../lib/mapObjects/CGTownInstance.h" +#include "../CPlayerInterface.h" +#include "../widgets/Buttons.h" +#include "../gui/CGuiHandler.h" +#include "../../CCallback.h" +#include "../CreatureCostBox.h" +#include "../lib/ResourceSet.h" +#include "CreaturePurhaseCard.h" + + +void QuickRecruitmentWindow::setButtons() +{ + setCancelButton(); + setBuyButton(); + setMaxButton(); +} + +void QuickRecruitmentWindow::setCancelButton() +{ + cancelButton = std::make_shared(Point((pos.w / 2) + 47, 417), "ICN6432.DEF", CButton::tooltip(), [&](){ close(); }, SDLK_RETURN); + cancelButton->setImageOrder(0, 1, 2, 3); +} + +void QuickRecruitmentWindow::setBuyButton() +{ + buyButton = std::make_shared(Point((pos.w/2)-33, 417), "IBY6432.DEF", CButton::tooltip(), [&](){ purhaseUnits(); }); + cancelButton->assignedKeys.insert(SDLK_ESCAPE); + buyButton->setImageOrder(0, 1, 2, 3); +} + +void QuickRecruitmentWindow::setMaxButton() +{ + maxButton = std::make_shared(Point((pos.w/2)-113, 417), "IRCBTNS.DEF", CButton::tooltip(), [&](){ maxAllCards(cards); }); + maxButton->setImageOrder(0, 1, 2, 3); +} + +void QuickRecruitmentWindow::setCreaturePurhaseCards() +{ + Point pos = Point(8,64); + for (int i=0; i < GameConstants::CREATURES_PER_TOWN; i++) + { + if(!town->town->creatures.at(i).empty() && !town->creatures.at(i).second.empty() && town->creatures[i].first) + { + CreatureID crid = town->creatures[i].second[0]; + if(town->creatures[i].second.size() > 1) + crid = town->creatures[i].second[1]; + + cards.push_back(std::make_shared(VLC->creh->creatures[crid], pos, town->creatures[i].first, this)); + pos.x += 108; + } + } + totalCost = std::make_shared(Rect((this->pos.w/2)-45, pos.y + 260, 97, 74), ""); +} + +void QuickRecruitmentWindow::initWindow() +{ + pos.x = 238; + pos.y = 45; + pos.w = 332; + pos.h = 461; + int creaturesAmount = getAvailableCreatures(); + if(creaturesAmount > 3) + { + pos.w += 108 * (creaturesAmount - 3); + pos.x -= 55 * (creaturesAmount - 3); + } + backgroundTexture = std::make_shared("DIBOXBCK.pcx", Rect(0, 0, pos.w, pos.h)); +} + +void QuickRecruitmentWindow::maxAllCards(std::vector > cards) +{ + auto allAvailableResources = LOCPLINT->cb->getResourceAmount(); + for(auto i : boost::adaptors::reverse(cards)) + { + si32 maxAmount = i->creature->maxAmount(allAvailableResources); + vstd::amin(maxAmount, i->maxamount); + + i->slider->setAmount(maxAmount); + + if(i->slider->getValue() != maxAmount) + i->slider->moveTo(maxAmount); + else + i->sliderMoved(maxAmount); + + i->slider->moveToMax(); + allAvailableResources -= (i->creature->cost * maxAmount); + } + maxButton->block(allAvailableResources == LOCPLINT->cb->getResourceAmount()); +} + + +void QuickRecruitmentWindow::purhaseUnits() +{ + for(auto selected : cards) + { + if(selected->slider->getValue()) + { + auto onRecruit = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, selected->creature->level-1); }; + CreatureID crid = selected->creature->idNumber; + SlotID dstslot = town -> getSlotFor(crid); + if(!dstslot.validSlot()) + continue; + onRecruit(crid, selected->slider->getValue()); + } + } + close(); +} + +int QuickRecruitmentWindow::getAvailableCreatures() +{ + int creaturesAmount = 0; + for (int i=0; i< GameConstants::CREATURES_PER_TOWN; i++) + if(!town->town->creatures.at(i).empty() && !town->creatures.at(i).second.empty() && town->creatures[i].first) + creaturesAmount++; + return creaturesAmount; +} + +void QuickRecruitmentWindow::updateAllSliders() +{ + auto allAvailableResources = LOCPLINT->cb->getResourceAmount(); + for(auto i : boost::adaptors::reverse(cards)) + allAvailableResources -= (i->creature->cost * i->slider->getValue()); + for(auto i : cards) + { + si32 maxAmount = i->creature->maxAmount(allAvailableResources); + vstd::amin(maxAmount, i->maxamount); + if(maxAmount < 0) + continue; + if(i->slider->getValue() + maxAmount < i->maxamount) + i->slider->setAmount(i->slider->getValue() + maxAmount); + else + i->slider->setAmount(i->maxamount); + i->slider->moveTo(i->slider->getValue()); + } + totalCost->createItems(LOCPLINT->cb->getResourceAmount() - allAvailableResources); + totalCost->set(LOCPLINT->cb->getResourceAmount() - allAvailableResources); +} + +QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd) : CWindowObject(PLAYER_COLORED | BORDERED), town(townd) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + initWindow(); + setButtons(); + setCreaturePurhaseCards(); + maxAllCards(cards); +} diff --git a/client/windows/QuickRecruitmentWindow.h b/client/windows/QuickRecruitmentWindow.h new file mode 100644 index 000000000..e5660a211 --- /dev/null +++ b/client/windows/QuickRecruitmentWindow.h @@ -0,0 +1,44 @@ +/* + * QuickRecruitmentWindow.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "../widgets/CGarrisonInt.h" + +class CButton; +class CreatureCostBox; +class CreaturePurhaseCard; +class CFilledTexture; + +class QuickRecruitmentWindow : public CWindowObject +{ +public: + int getAvailableCreatures(); + void updateAllSliders(); + QuickRecruitmentWindow(const CGTownInstance * townd); + +private: + void initWindow(); + + void setButtons(); + void setCancelButton(); + void setBuyButton(); + void setMaxButton(); + + void setCreaturePurhaseCards(); + + void maxAllCards(std::vector> cards); + void maxAllSlidersAmount(std::vector> cards); + void purhaseUnits(); + const CGTownInstance * town; + std::shared_ptr maxButton, buyButton, cancelButton; + std::shared_ptr totalCost; + std::vector> cards; + std::shared_ptr backgroundTexture; +}; From f2b7c85811be3fe6d257507c900a075d2feab3ee Mon Sep 17 00:00:00 2001 From: FeniksFire Date: Tue, 14 Nov 2017 08:50:04 +0100 Subject: [PATCH 2/4] Adding object construction macro with parameter - Adding macro "OBJECT_CONSTRUCTION_CAPTURING" that take as parameter action flag. - Fixed minor errors --- client/CreatureCostBox.h | 3 ++- client/gui/CGuiHandler.h | 1 + client/windows/CCastleInterface.cpp | 2 +- client/windows/CCastleInterface.h | 2 +- client/windows/QuickRecruitmentWindow.cpp | 3 ++- client/windows/QuickRecruitmentWindow.h | 1 + 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/CreatureCostBox.h b/client/CreatureCostBox.h index 064bb7026..872ac628f 100644 --- a/client/CreatureCostBox.h +++ b/client/CreatureCostBox.h @@ -14,9 +14,10 @@ class CreatureCostBox : public CIntObject { - std::map > resources; public: void set(TResources res); CreatureCostBox(Rect position, std::string title); void createItems(TResources res); +private: + std::map > resources; }; diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index 3dea9c8b3..10cc47621 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -140,6 +140,7 @@ struct SSetCaptureState }; #define OBJ_CONSTRUCTION SObjectConstruction obj__i(this) +#define OBJECT_CONSTRUCTION_CAPTURING(actions) defActions = actions; SSetCaptureState obj__i1(true, actions); SObjectConstruction obj__i(this) #define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this) #define BLOCK_CAPTURING SSetCaptureState obj__i(false, 0) #define BLOCK_CAPTURING_DONT_TOUCH_REC_ACTIONS SSetCaptureState obj__i(false, GH.defActionsDef) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 5c9070c54..fe361ba89 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -996,7 +996,7 @@ void CCastleInterface::recreateIcons() hall = new CTownInfo( 80, 413, town, true); fort = new CTownInfo(122, 413, town, false); - fastArmyPurhase = std::make_shared(Point(122, 413), "itmcl.def", CButton::tooltip("quick army purhase"), [&](){builds->enterToTheQuickRecruitmentWindow();}); + fastArmyPurhase = new CButton(Point(122, 413), "itmcl.def", CButton::tooltip("quick army purhase"), [&](){builds->enterToTheQuickRecruitmentWindow();}); fastArmyPurhase->setImageOrder(town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1); for (auto & elem : creainfo) delete elem; diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 79b2ae8b8..307afb345 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -205,7 +205,7 @@ class CCastleInterface : public CWindowObject, public CWindowWithGarrison CButton *exit; CButton *split; - std::shared_ptr fastArmyPurhase; + CButton * fastArmyPurhase; std::vector creainfo;//small icons of creatures (bottom-left corner); diff --git a/client/windows/QuickRecruitmentWindow.cpp b/client/windows/QuickRecruitmentWindow.cpp index 688b080f2..5091da97e 100644 --- a/client/windows/QuickRecruitmentWindow.cpp +++ b/client/windows/QuickRecruitmentWindow.cpp @@ -149,7 +149,8 @@ void QuickRecruitmentWindow::updateAllSliders() QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd) : CWindowObject(PLAYER_COLORED | BORDERED), town(townd) { - OBJ_CONSTRUCTION_CAPTURING_ALL; + OBJECT_CONSTRUCTION_CAPTURING(ACTIVATE + DEACTIVATE + UPDATE + SHOWALL); + initWindow(); setButtons(); setCreaturePurhaseCards(); diff --git a/client/windows/QuickRecruitmentWindow.h b/client/windows/QuickRecruitmentWindow.h index e5660a211..b5dc51041 100644 --- a/client/windows/QuickRecruitmentWindow.h +++ b/client/windows/QuickRecruitmentWindow.h @@ -36,6 +36,7 @@ private: void maxAllCards(std::vector> cards); void maxAllSlidersAmount(std::vector> cards); void purhaseUnits(); + const CGTownInstance * town; std::shared_ptr maxButton, buyButton, cancelButton; std::shared_ptr totalCost; From 3c3aaa7bb5339a983c4b86e7406cbf503d7d8654 Mon Sep 17 00:00:00 2001 From: FeniksFire Date: Wed, 15 Nov 2017 19:44:54 +0100 Subject: [PATCH 3/4] Improvement quick recruitment window -Position is now relative to castle interface -The highest level of creature is now presented. -Improve positioning of creature card, now it's look like in hd mod. --- client/windows/CCastleInterface.cpp | 4 +- client/windows/CreaturePurhaseCard.cpp | 14 +++---- client/windows/CreaturePurhaseCard.h | 6 +-- client/windows/QuickRecruitmentWindow.cpp | 47 +++++++++++------------ client/windows/QuickRecruitmentWindow.h | 4 +- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index fe361ba89..e969280c1 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -797,7 +797,7 @@ void CCastleBuildings::enterDwelling(int level) void CCastleBuildings::enterToTheQuickRecruitmentWindow() { - GH.pushInt(new QuickRecruitmentWindow(town)); + GH.pushInt(new QuickRecruitmentWindow(town, pos)); } void CCastleBuildings::enterFountain(BuildingID building) @@ -996,7 +996,7 @@ void CCastleInterface::recreateIcons() hall = new CTownInfo( 80, 413, town, true); fort = new CTownInfo(122, 413, town, false); - fastArmyPurhase = new CButton(Point(122, 413), "itmcl.def", CButton::tooltip("quick army purhase"), [&](){builds->enterToTheQuickRecruitmentWindow();}); + fastArmyPurhase = new CButton(Point(122, 413), "itmcl.def", CButton::tooltip(), [&](){builds->enterToTheQuickRecruitmentWindow();}); fastArmyPurhase->setImageOrder(town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1); for (auto & elem : creainfo) delete elem; diff --git a/client/windows/CreaturePurhaseCard.cpp b/client/windows/CreaturePurhaseCard.cpp index 861a9b79f..0c6373148 100644 --- a/client/windows/CreaturePurhaseCard.cpp +++ b/client/windows/CreaturePurhaseCard.cpp @@ -41,38 +41,38 @@ void CreaturePurhaseCard::initAmountInfo() void CreaturePurhaseCard::updateAmountInfo(int value) { - availableAmount->setText(boost::lexical_cast(maxamount-value)); + availableAmount->setText(boost::lexical_cast(maxAmount-value)); purhaseAmount->setText(boost::lexical_cast(value)); } void CreaturePurhaseCard::initSlider() { - slider = std::make_shared(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxamount, 0); + slider = std::make_shared(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxAmount, 0); } void CreaturePurhaseCard::initCostBox() { cost = std::make_shared(Rect(pos.x, pos.y + 194, 97, 74), ""); - cost->createItems(creature->cost); + cost->createItems(creatureOnTheCard->cost); } void CreaturePurhaseCard::sliderMoved(int to) { updateAmountInfo(to); - cost->set(creature->cost * to); + cost->set(creatureOnTheCard->cost * to); parent->updateAllSliders(); } -CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * monster, Point p, int amount, QuickRecruitmentWindow * par) : creature(monster), parent(par), maxamount(amount) +CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents) : creatureOnTheCard(creature), parent(parents), maxAmount(creaturesMaxAmount) { - moveTo(Point(p.x, p.y)); + moveTo(Point(position.x, position.y)); initView(); } void CreaturePurhaseCard::initView() { - picture = std::make_shared(pos.x, pos.y, creature); + picture = std::make_shared(pos.x, pos.y, creatureOnTheCard); initAmountInfo(); initSlider(); initButtons(); diff --git a/client/windows/CreaturePurhaseCard.h b/client/windows/CreaturePurhaseCard.h index 4832c3371..59e36a94d 100644 --- a/client/windows/CreaturePurhaseCard.h +++ b/client/windows/CreaturePurhaseCard.h @@ -20,12 +20,12 @@ class QuickRecruitmentWindow; class CreaturePurhaseCard : public CIntObject { public: - const CCreature * creature; + const CCreature * creatureOnTheCard; std::shared_ptr slider; QuickRecruitmentWindow * parent; - int maxamount; + int maxAmount; void sliderMoved(int to); - CreaturePurhaseCard(const CCreature * monster, Point p, int amount, QuickRecruitmentWindow * par); + CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents); private: void initView(); diff --git a/client/windows/QuickRecruitmentWindow.cpp b/client/windows/QuickRecruitmentWindow.cpp index 5091da97e..07c0f4d4d 100644 --- a/client/windows/QuickRecruitmentWindow.cpp +++ b/client/windows/QuickRecruitmentWindow.cpp @@ -47,26 +47,24 @@ void QuickRecruitmentWindow::setMaxButton() void QuickRecruitmentWindow::setCreaturePurhaseCards() { - Point pos = Point(8,64); - for (int i=0; i < GameConstants::CREATURES_PER_TOWN; i++) + int availableAmount = getAvailableCreatures(); + Point position = Point((pos.w - 100*availableAmount - 8*(availableAmount-1))/2,64); + for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; i++) { if(!town->town->creatures.at(i).empty() && !town->creatures.at(i).second.empty() && town->creatures[i].first) { - CreatureID crid = town->creatures[i].second[0]; - if(town->creatures[i].second.size() > 1) - crid = town->creatures[i].second[1]; - - cards.push_back(std::make_shared(VLC->creh->creatures[crid], pos, town->creatures[i].first, this)); - pos.x += 108; + CreatureID crid = town->creatures[i].second[town->creatures[i].second.size() - 1]; + cards.push_back(std::make_shared(VLC->creh->creatures[crid], position, town->creatures[i].first, this)); + position.x += 108; } } - totalCost = std::make_shared(Rect((this->pos.w/2)-45, pos.y + 260, 97, 74), ""); + totalCost = std::make_shared(Rect((this->pos.w/2)-45, position.y+260, 97, 74), ""); } -void QuickRecruitmentWindow::initWindow() +void QuickRecruitmentWindow::initWindow(Rect startupPosition) { - pos.x = 238; - pos.y = 45; + pos.x = startupPosition.x + 238; + pos.y = startupPosition.y + 45; pos.w = 332; pos.h = 461; int creaturesAmount = getAvailableCreatures(); @@ -83,8 +81,8 @@ void QuickRecruitmentWindow::maxAllCards(std::vectorcb->getResourceAmount(); for(auto i : boost::adaptors::reverse(cards)) { - si32 maxAmount = i->creature->maxAmount(allAvailableResources); - vstd::amin(maxAmount, i->maxamount); + si32 maxAmount = i->creatureOnTheCard->maxAmount(allAvailableResources); + vstd::amin(maxAmount, i->maxAmount); i->slider->setAmount(maxAmount); @@ -94,7 +92,7 @@ void QuickRecruitmentWindow::maxAllCards(std::vectorsliderMoved(maxAmount); i->slider->moveToMax(); - allAvailableResources -= (i->creature->cost * maxAmount); + allAvailableResources -= (i->creatureOnTheCard->cost * maxAmount); } maxButton->block(allAvailableResources == LOCPLINT->cb->getResourceAmount()); } @@ -106,8 +104,8 @@ void QuickRecruitmentWindow::purhaseUnits() { if(selected->slider->getValue()) { - auto onRecruit = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, selected->creature->level-1); }; - CreatureID crid = selected->creature->idNumber; + auto onRecruit = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, selected->creatureOnTheCard->level-1); }; + CreatureID crid = selected->creatureOnTheCard->idNumber; SlotID dstslot = town -> getSlotFor(crid); if(!dstslot.validSlot()) continue; @@ -130,28 +128,29 @@ void QuickRecruitmentWindow::updateAllSliders() { auto allAvailableResources = LOCPLINT->cb->getResourceAmount(); for(auto i : boost::adaptors::reverse(cards)) - allAvailableResources -= (i->creature->cost * i->slider->getValue()); + allAvailableResources -= (i->creatureOnTheCard->cost * i->slider->getValue()); for(auto i : cards) { - si32 maxAmount = i->creature->maxAmount(allAvailableResources); - vstd::amin(maxAmount, i->maxamount); + si32 maxAmount = i->creatureOnTheCard->maxAmount(allAvailableResources); + vstd::amin(maxAmount, i->maxAmount); if(maxAmount < 0) continue; - if(i->slider->getValue() + maxAmount < i->maxamount) + if(i->slider->getValue() + maxAmount < i->maxAmount) i->slider->setAmount(i->slider->getValue() + maxAmount); else - i->slider->setAmount(i->maxamount); + i->slider->setAmount(i->maxAmount); i->slider->moveTo(i->slider->getValue()); } totalCost->createItems(LOCPLINT->cb->getResourceAmount() - allAvailableResources); totalCost->set(LOCPLINT->cb->getResourceAmount() - allAvailableResources); } -QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd) : CWindowObject(PLAYER_COLORED | BORDERED), town(townd) +QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd, Rect startupPosition) + : CWindowObject(PLAYER_COLORED | BORDERED), town(townd) { OBJECT_CONSTRUCTION_CAPTURING(ACTIVATE + DEACTIVATE + UPDATE + SHOWALL); - initWindow(); + initWindow(startupPosition); setButtons(); setCreaturePurhaseCards(); maxAllCards(cards); diff --git a/client/windows/QuickRecruitmentWindow.h b/client/windows/QuickRecruitmentWindow.h index b5dc51041..33781e117 100644 --- a/client/windows/QuickRecruitmentWindow.h +++ b/client/windows/QuickRecruitmentWindow.h @@ -21,10 +21,10 @@ class QuickRecruitmentWindow : public CWindowObject public: int getAvailableCreatures(); void updateAllSliders(); - QuickRecruitmentWindow(const CGTownInstance * townd); + QuickRecruitmentWindow(const CGTownInstance * townd, Rect startupPosition); private: - void initWindow(); + void initWindow(Rect startupPosition); void setButtons(); void setCancelButton(); From 42a2aa202093ead0dc408d0c7d5c3da7baafe3bc Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Wed, 15 Nov 2017 22:31:30 +0300 Subject: [PATCH 4/4] [C::B] project update --- client/VCMI_client.cbp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/VCMI_client.cbp b/client/VCMI_client.cbp index 86c888f51..62259bb71 100644 --- a/client/VCMI_client.cbp +++ b/client/VCMI_client.cbp @@ -122,6 +122,8 @@ + + @@ -198,10 +200,14 @@ + + + +