mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Merge branch 'SplittingShortcuts' into develop
This commit is contained in:
commit
39194a0629
@ -32,6 +32,7 @@ set(client_SRCS
|
|||||||
windows/CAdvmapInterface.cpp
|
windows/CAdvmapInterface.cpp
|
||||||
windows/CCastleInterface.cpp
|
windows/CCastleInterface.cpp
|
||||||
windows/CCreatureWindow.cpp
|
windows/CCreatureWindow.cpp
|
||||||
|
windows/CreaturePurhaseCard.cpp
|
||||||
windows/CHeroWindow.cpp
|
windows/CHeroWindow.cpp
|
||||||
windows/CKingdomInterface.cpp
|
windows/CKingdomInterface.cpp
|
||||||
windows/CQuestLog.cpp
|
windows/CQuestLog.cpp
|
||||||
@ -40,8 +41,10 @@ set(client_SRCS
|
|||||||
windows/CWindowObject.cpp
|
windows/CWindowObject.cpp
|
||||||
windows/GUIClasses.cpp
|
windows/GUIClasses.cpp
|
||||||
windows/InfoWindows.cpp
|
windows/InfoWindows.cpp
|
||||||
|
windows/QuickRecruitmentWindow.cpp
|
||||||
|
|
||||||
CBitmapHandler.cpp
|
CBitmapHandler.cpp
|
||||||
|
CreatureCostBox.cpp
|
||||||
CDefHandler.cpp
|
CDefHandler.cpp
|
||||||
CGameInfo.cpp
|
CGameInfo.cpp
|
||||||
Client.cpp
|
Client.cpp
|
||||||
@ -87,6 +90,7 @@ set(client_HEADERS
|
|||||||
windows/CAdvmapInterface.h
|
windows/CAdvmapInterface.h
|
||||||
windows/CCastleInterface.h
|
windows/CCastleInterface.h
|
||||||
windows/CCreatureWindow.h
|
windows/CCreatureWindow.h
|
||||||
|
windows/CreaturePurhaseCard.h
|
||||||
windows/CHeroWindow.h
|
windows/CHeroWindow.h
|
||||||
windows/CKingdomInterface.h
|
windows/CKingdomInterface.h
|
||||||
windows/CQuestLog.h
|
windows/CQuestLog.h
|
||||||
@ -95,8 +99,10 @@ set(client_HEADERS
|
|||||||
windows/CWindowObject.h
|
windows/CWindowObject.h
|
||||||
windows/GUIClasses.h
|
windows/GUIClasses.h
|
||||||
windows/InfoWindows.h
|
windows/InfoWindows.h
|
||||||
|
windows/QuickRecruitmentWindow.h
|
||||||
|
|
||||||
CBitmapHandler.h
|
CBitmapHandler.h
|
||||||
|
CreatureCostBox.h
|
||||||
CDefHandler.h
|
CDefHandler.h
|
||||||
CGameInfo.h
|
CGameInfo.h
|
||||||
Client.h
|
Client.h
|
||||||
|
63
client/CreatureCostBox.cpp
Normal file
63
client/CreatureCostBox.cpp
Normal file
@ -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<std::string>(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();
|
||||||
|
}
|
23
client/CreatureCostBox.h
Normal file
23
client/CreatureCostBox.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void set(TResources res);
|
||||||
|
CreatureCostBox(Rect position, std::string title);
|
||||||
|
void createItems(TResources res);
|
||||||
|
private:
|
||||||
|
std::map<int, std::pair<CLabel *, CAnimImage * > > resources;
|
||||||
|
};
|
@ -122,6 +122,8 @@
|
|||||||
<Unit filename="CVideoHandler.h" />
|
<Unit filename="CVideoHandler.h" />
|
||||||
<Unit filename="Client.cpp" />
|
<Unit filename="Client.cpp" />
|
||||||
<Unit filename="Client.h" />
|
<Unit filename="Client.h" />
|
||||||
|
<Unit filename="CreatureCostBox.cpp" />
|
||||||
|
<Unit filename="CreatureCostBox.h" />
|
||||||
<Unit filename="Graphics.cpp" />
|
<Unit filename="Graphics.cpp" />
|
||||||
<Unit filename="Graphics.h" />
|
<Unit filename="Graphics.h" />
|
||||||
<Unit filename="NetPacksClient.cpp" />
|
<Unit filename="NetPacksClient.cpp" />
|
||||||
@ -198,10 +200,14 @@
|
|||||||
<Unit filename="windows/CTradeWindow.h" />
|
<Unit filename="windows/CTradeWindow.h" />
|
||||||
<Unit filename="windows/CWindowObject.cpp" />
|
<Unit filename="windows/CWindowObject.cpp" />
|
||||||
<Unit filename="windows/CWindowObject.h" />
|
<Unit filename="windows/CWindowObject.h" />
|
||||||
|
<Unit filename="windows/CreaturePurhaseCard.cpp" />
|
||||||
|
<Unit filename="windows/CreaturePurhaseCard.h" />
|
||||||
<Unit filename="windows/GUIClasses.cpp" />
|
<Unit filename="windows/GUIClasses.cpp" />
|
||||||
<Unit filename="windows/GUIClasses.h" />
|
<Unit filename="windows/GUIClasses.h" />
|
||||||
<Unit filename="windows/InfoWindows.cpp" />
|
<Unit filename="windows/InfoWindows.cpp" />
|
||||||
<Unit filename="windows/InfoWindows.h" />
|
<Unit filename="windows/InfoWindows.h" />
|
||||||
|
<Unit filename="windows/QuickRecruitmentWindow.cpp" />
|
||||||
|
<Unit filename="windows/QuickRecruitmentWindow.h" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<code_completion />
|
<code_completion />
|
||||||
<envvars />
|
<envvars />
|
||||||
|
@ -140,6 +140,7 @@ struct SSetCaptureState
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define OBJ_CONSTRUCTION SObjectConstruction obj__i(this)
|
#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 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 SSetCaptureState obj__i(false, 0)
|
||||||
#define BLOCK_CAPTURING_DONT_TOUCH_REC_ACTIONS SSetCaptureState obj__i(false, GH.defActionsDef)
|
#define BLOCK_CAPTURING_DONT_TOUCH_REC_ACTIONS SSetCaptureState obj__i(false, GH.defActionsDef)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "CHeroWindow.h"
|
#include "CHeroWindow.h"
|
||||||
#include "CTradeWindow.h"
|
#include "CTradeWindow.h"
|
||||||
#include "GUIClasses.h"
|
#include "GUIClasses.h"
|
||||||
|
#include "QuickRecruitmentWindow.h"
|
||||||
|
|
||||||
#include "../CBitmapHandler.h"
|
#include "../CBitmapHandler.h"
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
@ -21,7 +22,6 @@
|
|||||||
#include "../CMusicHandler.h"
|
#include "../CMusicHandler.h"
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../Graphics.h"
|
#include "../Graphics.h"
|
||||||
|
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/SDL_Extensions.h"
|
#include "../gui/SDL_Extensions.h"
|
||||||
#include "../windows/InfoWindows.h"
|
#include "../windows/InfoWindows.h"
|
||||||
@ -795,6 +795,11 @@ void CCastleBuildings::enterDwelling(int level)
|
|||||||
GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, -87));
|
GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, -87));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCastleBuildings::enterToTheQuickRecruitmentWindow()
|
||||||
|
{
|
||||||
|
GH.pushInt(new QuickRecruitmentWindow(town, pos));
|
||||||
|
}
|
||||||
|
|
||||||
void CCastleBuildings::enterFountain(BuildingID building)
|
void CCastleBuildings::enterFountain(BuildingID building)
|
||||||
{
|
{
|
||||||
std::vector<CComponent*> comps(1, new CComponent(CComponent::building,town->subID,building));
|
std::vector<CComponent*> comps(1, new CComponent(CComponent::building,town->subID,building));
|
||||||
@ -885,6 +890,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
|
|||||||
town(Town)
|
town(Town)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||||
|
|
||||||
LOCPLINT->castleInt = this;
|
LOCPLINT->castleInt = this;
|
||||||
addUsedEvents(KEYBOARD);
|
addUsedEvents(KEYBOARD);
|
||||||
|
|
||||||
@ -990,7 +996,8 @@ void CCastleInterface::recreateIcons()
|
|||||||
|
|
||||||
hall = new CTownInfo( 80, 413, town, true);
|
hall = new CTownInfo( 80, 413, town, true);
|
||||||
fort = new CTownInfo(122, 413, town, false);
|
fort = new CTownInfo(122, 413, town, false);
|
||||||
|
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)
|
for (auto & elem : creainfo)
|
||||||
delete elem;
|
delete elem;
|
||||||
creainfo.clear();
|
creainfo.clear();
|
||||||
|
@ -143,6 +143,7 @@ public:
|
|||||||
~CCastleBuildings();
|
~CCastleBuildings();
|
||||||
|
|
||||||
void enterDwelling(int level);
|
void enterDwelling(int level);
|
||||||
|
void enterToTheQuickRecruitmentWindow();
|
||||||
|
|
||||||
void buildingClicked(BuildingID building);
|
void buildingClicked(BuildingID building);
|
||||||
void addBuilding(BuildingID building);
|
void addBuilding(BuildingID building);
|
||||||
@ -180,8 +181,8 @@ class CTownInfo : public CIntObject
|
|||||||
{
|
{
|
||||||
const CGTownInstance *town;
|
const CGTownInstance *town;
|
||||||
const CBuilding *building;
|
const CBuilding *building;
|
||||||
CAnimImage *picture;
|
|
||||||
public:
|
public:
|
||||||
|
CAnimImage * picture;
|
||||||
//if (townHall) hall-capital else fort - castle
|
//if (townHall) hall-capital else fort - castle
|
||||||
CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
|
CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
|
||||||
|
|
||||||
@ -204,6 +205,7 @@ class CCastleInterface : public CWindowObject, public CWindowWithGarrison
|
|||||||
|
|
||||||
CButton *exit;
|
CButton *exit;
|
||||||
CButton *split;
|
CButton *split;
|
||||||
|
CButton * fastArmyPurhase;
|
||||||
|
|
||||||
std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
|
std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
|
||||||
|
|
||||||
|
80
client/windows/CreaturePurhaseCard.cpp
Normal file
80
client/windows/CreaturePurhaseCard.cpp
Normal file
@ -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<CButton>(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<CButton>(Point(pos.x, pos.y + 178), "iam015.def", CButton::tooltip(), std::bind(&CSlider::moveToMin,slider), SDLK_m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreaturePurhaseCard::initAmountInfo()
|
||||||
|
{
|
||||||
|
availableAmount = std::make_shared<CLabel>(pos.x + 27, pos.y + 146, FONT_SMALL, CENTER, Colors::YELLOW);
|
||||||
|
purhaseAmount = std::make_shared<CLabel>(pos.x + 77, pos.y + 146, FONT_SMALL, CENTER, Colors::WHITE);
|
||||||
|
updateAmountInfo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreaturePurhaseCard::updateAmountInfo(int value)
|
||||||
|
{
|
||||||
|
availableAmount->setText(boost::lexical_cast<std::string>(maxAmount-value));
|
||||||
|
purhaseAmount->setText(boost::lexical_cast<std::string>(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreaturePurhaseCard::initSlider()
|
||||||
|
{
|
||||||
|
slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxAmount, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreaturePurhaseCard::initCostBox()
|
||||||
|
{
|
||||||
|
cost = std::make_shared<CreatureCostBox>(Rect(pos.x, pos.y + 194, 97, 74), "");
|
||||||
|
cost->createItems(creatureOnTheCard->cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CreaturePurhaseCard::sliderMoved(int to)
|
||||||
|
{
|
||||||
|
updateAmountInfo(to);
|
||||||
|
cost->set(creatureOnTheCard->cost * to);
|
||||||
|
parent->updateAllSliders();
|
||||||
|
}
|
||||||
|
|
||||||
|
CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents) : creatureOnTheCard(creature), parent(parents), maxAmount(creaturesMaxAmount)
|
||||||
|
{
|
||||||
|
moveTo(Point(position.x, position.y));
|
||||||
|
initView();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreaturePurhaseCard::initView()
|
||||||
|
{
|
||||||
|
picture = std::make_shared<CCreaturePic>(pos.x, pos.y, creatureOnTheCard);
|
||||||
|
initAmountInfo();
|
||||||
|
initSlider();
|
||||||
|
initButtons();
|
||||||
|
initCostBox();
|
||||||
|
}
|
49
client/windows/CreaturePurhaseCard.h
Normal file
49
client/windows/CreaturePurhaseCard.h
Normal file
@ -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 * creatureOnTheCard;
|
||||||
|
std::shared_ptr<CSlider> slider;
|
||||||
|
QuickRecruitmentWindow * parent;
|
||||||
|
int maxAmount;
|
||||||
|
void sliderMoved(int to);
|
||||||
|
CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initView();
|
||||||
|
|
||||||
|
void initButtons();
|
||||||
|
void initMaxButton();
|
||||||
|
void initMinButton();
|
||||||
|
|
||||||
|
void initAmountInfo();
|
||||||
|
void updateAmountInfo(int value);
|
||||||
|
|
||||||
|
void initSlider();
|
||||||
|
|
||||||
|
void initCostBox();
|
||||||
|
|
||||||
|
std::shared_ptr<CButton> maxButton, minButton;
|
||||||
|
std::shared_ptr<CLabel> availableAmount, purhaseAmount;
|
||||||
|
std::shared_ptr<CCreaturePic> picture;
|
||||||
|
std::shared_ptr<CreatureCostBox> cost;
|
||||||
|
|
||||||
|
};
|
@ -14,6 +14,7 @@
|
|||||||
#include "CCastleInterface.h"
|
#include "CCastleInterface.h"
|
||||||
#include "CCreatureWindow.h"
|
#include "CCreatureWindow.h"
|
||||||
#include "CHeroWindow.h"
|
#include "CHeroWindow.h"
|
||||||
|
#include "CreatureCostBox.h"
|
||||||
|
|
||||||
#include "../CBitmapHandler.h"
|
#include "../CBitmapHandler.h"
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
@ -108,57 +109,6 @@ void CRecruitmentWindow::CCreatureCard::showAll(SDL_Surface * to)
|
|||||||
drawBorder(to, pos, int3(232, 212, 120));
|
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<std::string>(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)
|
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);
|
availableValue = new CLabel(205, 253, FONT_SMALL, CENTER, Colors::WHITE);
|
||||||
toRecruitValue = new CLabel(279, 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]);
|
costPerTroopValue = new CreatureCostBox(Rect(65, 222, 97, 74), CGI->generaltexth->allTexts[346]);
|
||||||
totalCostValue = new CCostBox(Rect(323, 222, 97, 74), CGI->generaltexth->allTexts[466]);
|
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(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
|
new CLabel(279, 233, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[16]); //recruit t
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "../windows/CWindowObject.h"
|
#include "../windows/CWindowObject.h"
|
||||||
|
|
||||||
class CGDwelling;
|
class CGDwelling;
|
||||||
|
class CreatureCostBox;
|
||||||
class IMarket;
|
class IMarket;
|
||||||
class CCreaturePic;
|
class CCreaturePic;
|
||||||
class MoraleLuckBox;
|
class MoraleLuckBox;
|
||||||
@ -54,18 +55,6 @@ class CRecruitmentWindow : public CWindowObject
|
|||||||
CCreatureCard(CRecruitmentWindow * window, const CCreature *crea, int totalAmount);
|
CCreatureCard(CRecruitmentWindow * window, const CCreature *crea, int totalAmount);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// small class to display creature costs
|
|
||||||
class CCostBox : public CIntObject
|
|
||||||
{
|
|
||||||
std::map<int, std::pair<CLabel *, CAnimImage * > > 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<void(CreatureID,int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
|
std::function<void(CreatureID,int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
|
||||||
|
|
||||||
int level;
|
int level;
|
||||||
@ -80,8 +69,8 @@ class CRecruitmentWindow : public CWindowObject
|
|||||||
CLabel * title;
|
CLabel * title;
|
||||||
CLabel * availableValue;
|
CLabel * availableValue;
|
||||||
CLabel * toRecruitValue;
|
CLabel * toRecruitValue;
|
||||||
CCostBox * costPerTroopValue;
|
CreatureCostBox * costPerTroopValue;
|
||||||
CCostBox * totalCostValue;
|
CreatureCostBox * totalCostValue;
|
||||||
|
|
||||||
void select(CCreatureCard * card);
|
void select(CCreatureCard * card);
|
||||||
void buy();
|
void buy();
|
||||||
|
157
client/windows/QuickRecruitmentWindow.cpp
Normal file
157
client/windows/QuickRecruitmentWindow.cpp
Normal file
@ -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<CButton>(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<CButton>(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<CButton>(Point((pos.w/2)-113, 417), "IRCBTNS.DEF", CButton::tooltip(), [&](){ maxAllCards(cards); });
|
||||||
|
maxButton->setImageOrder(0, 1, 2, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuickRecruitmentWindow::setCreaturePurhaseCards()
|
||||||
|
{
|
||||||
|
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[town->creatures[i].second.size() - 1];
|
||||||
|
cards.push_back(std::make_shared<CreaturePurhaseCard>(VLC->creh->creatures[crid], position, town->creatures[i].first, this));
|
||||||
|
position.x += 108;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalCost = std::make_shared<CreatureCostBox>(Rect((this->pos.w/2)-45, position.y+260, 97, 74), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuickRecruitmentWindow::initWindow(Rect startupPosition)
|
||||||
|
{
|
||||||
|
pos.x = startupPosition.x + 238;
|
||||||
|
pos.y = startupPosition.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<CFilledTexture>("DIBOXBCK.pcx", Rect(0, 0, pos.w, pos.h));
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuickRecruitmentWindow::maxAllCards(std::vector<std::shared_ptr<CreaturePurhaseCard> > cards)
|
||||||
|
{
|
||||||
|
auto allAvailableResources = LOCPLINT->cb->getResourceAmount();
|
||||||
|
for(auto i : boost::adaptors::reverse(cards))
|
||||||
|
{
|
||||||
|
si32 maxAmount = i->creatureOnTheCard->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->creatureOnTheCard->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->creatureOnTheCard->level-1); };
|
||||||
|
CreatureID crid = selected->creatureOnTheCard->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->creatureOnTheCard->cost * i->slider->getValue());
|
||||||
|
for(auto i : cards)
|
||||||
|
{
|
||||||
|
si32 maxAmount = i->creatureOnTheCard->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, Rect startupPosition)
|
||||||
|
: CWindowObject(PLAYER_COLORED | BORDERED), town(townd)
|
||||||
|
{
|
||||||
|
OBJECT_CONSTRUCTION_CAPTURING(ACTIVATE + DEACTIVATE + UPDATE + SHOWALL);
|
||||||
|
|
||||||
|
initWindow(startupPosition);
|
||||||
|
setButtons();
|
||||||
|
setCreaturePurhaseCards();
|
||||||
|
maxAllCards(cards);
|
||||||
|
}
|
45
client/windows/QuickRecruitmentWindow.h
Normal file
45
client/windows/QuickRecruitmentWindow.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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, Rect startupPosition);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initWindow(Rect startupPosition);
|
||||||
|
|
||||||
|
void setButtons();
|
||||||
|
void setCancelButton();
|
||||||
|
void setBuyButton();
|
||||||
|
void setMaxButton();
|
||||||
|
|
||||||
|
void setCreaturePurhaseCards();
|
||||||
|
|
||||||
|
void maxAllCards(std::vector<std::shared_ptr<CreaturePurhaseCard>> cards);
|
||||||
|
void maxAllSlidersAmount(std::vector<std::shared_ptr<CreaturePurhaseCard>> cards);
|
||||||
|
void purhaseUnits();
|
||||||
|
|
||||||
|
const CGTownInstance * town;
|
||||||
|
std::shared_ptr<CButton> maxButton, buyButton, cancelButton;
|
||||||
|
std::shared_ptr<CreatureCostBox> totalCost;
|
||||||
|
std::vector<std::shared_ptr<CreaturePurhaseCard>> cards;
|
||||||
|
std::shared_ptr<CFilledTexture> backgroundTexture;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user