1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge branch 'feature/creatureWindow' into refactoring/guiClasses

This commit is contained in:
Ivan Savenko 2014-07-14 17:23:24 +03:00
commit 92d22bae63
41 changed files with 964 additions and 990 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,8 @@
{
"basepath" : "stackWindow/",
"images" :
[
{ "frame" : 0, "file" : "cancel-normal.png"},
{ "frame" : 1, "file" : "cancel-pressed.png"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,17 @@
{
"basepath" : "stackWindow/",
"images" :
[
{ "frame" : 0, "file" : "level-0.png"},
{ "frame" : 1, "file" : "level-1.png"},
{ "frame" : 2, "file" : "level-2.png"},
{ "frame" : 3, "file" : "level-3.png"},
{ "frame" : 4, "file" : "level-4.png"},
{ "frame" : 5, "file" : "level-5.png"},
{ "frame" : 6, "file" : "level-6.png"},
{ "frame" : 7, "file" : "level-7.png"},
{ "frame" : 8, "file" : "level-8.png"},
{ "frame" : 9, "file" : "level-9.png"},
{ "frame" : 10,"file" : "level-10.png"}
]
}

View File

@ -0,0 +1,7 @@
{
"images" :
[
{ "frame" : 0, "file" : "SECSK32:69"},
{ "frame" : 1, "file" : "SECSK32:28"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,8 @@
{
"basepath" : "stackWindow/",
"images" :
[
{ "frame" : 0, "file" : "upgrade-normal.png"},
{ "frame" : 1, "file" : "upgrade-pressed.png"}
]
}

View File

@ -15,6 +15,7 @@ For building from source see project wiki at http://wiki.vcmi.eu/
## Copyright and license
VCMI Project is released under GPL version 2 or later
VCMI Project source code is licensed under GPL version 2 or later.
VCMI Project assets are licensed under CC-BY-SA 4.0. Assets sources and information about contributors are available under following link: [https://github.com/vcmi/vcmi-assets]
Copyright (C) 2007-2014 VCMI Team (check AUTHORS file for the contributors list)

View File

@ -497,10 +497,12 @@ void CPlayerInterface::commanderGotLevel (const CCommanderInstance * commander,
waitWhileDialog();
CCS->soundh->playSound(soundBase::heroNewLevel);
CCreatureWindow * cw = new CCreatureWindow(skills, commander,
[=](ui32 selection){ cb->selectionMade(selection, queryID); });
GH.pushInt(cw);
GH.pushInt(new CStackWindow(commander, skills, [=](ui32 selection)
{
cb->selectionMade(selection, queryID);
}));
}
void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
{
EVENT_HANDLER_CALLED_BY_CLIENT;

View File

@ -671,7 +671,9 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
if(multiPlayer == CMenuScreen::MULTI_NETWORK_GUEST)
{
SDL_Color orange = {232, 184, 32, 0};
select->text->color = opts->text->color = randomBtn->text->color = orange;
dynamic_cast<CLabel*>(select->overlay)->color = orange;
dynamic_cast<CLabel*>(opts->overlay)->color = orange;
dynamic_cast<CLabel*>(randomBtn->overlay)->color = orange;
select->block(true);
opts->block(true);
randomBtn->block(true);

View File

@ -2430,7 +2430,7 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
{
cursorFrame = ECursor::COMBAT_QUERY;
consoleMsg = (boost::format(CGI->generaltexth->allTexts[297]) % shere->getName()).str();
realizeAction = [=]{ GH.pushInt(createCreWindow(shere, true)); };
realizeAction = [=]{ GH.pushInt(new CStackWindow(shere, false)); };
break;
}
}

View File

@ -608,7 +608,7 @@ void CClickableHex::clickRight(tribool down, bool previousState)
if(!myst->alive()) return;
if(down)
{
GH.pushInt(createCreWindow(myst));
GH.pushInt(new CStackWindow(myst, true));
}
}
}

View File

@ -141,15 +141,16 @@ typename boost::enable_if_c<boost::is_unsigned<T>::type, T>::type abs(T arg)
}
template<typename IntType>
std::string makeNumberShort(IntType number) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k)
std::string makeNumberShort(IntType number, IntType maxLength = 3) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k)
{
if (abs(number) < 1000)
IntType max = pow(10, maxLength);
if (abs(number) < max)
return boost::lexical_cast<std::string>(number);
std::string symbols = "kMGTPE";
std::string symbols = " kMGTPE";
auto iter = symbols.begin();
while (number >= 1000)
while (number >= max)
{
number /= 1000;
iter++;

View File

@ -210,7 +210,7 @@ CButtonBase::CButtonBase()
bitmapOffset = 0;
state=NORMAL;
image = nullptr;
text = nullptr;
overlay = nullptr;
}
CButtonBase::~CButtonBase()
@ -220,12 +220,12 @@ CButtonBase::~CButtonBase()
void CButtonBase::update()
{
if (text)
if (overlay)
{
if (state == PRESSED)
text->moveTo(Point(pos.x+pos.w/2+1, pos.y+pos.h/2+1));
overlay->moveTo(overlay->pos.centerIn(pos).topLeft() + Point(1,1));
else
text->moveTo(Point(pos.x+pos.w/2, pos.y+pos.h/2));
overlay->moveTo(overlay->pos.centerIn(pos).topLeft());
}
int newPos = (int)state + bitmapOffset;
@ -251,8 +251,16 @@ void CButtonBase::update()
void CButtonBase::addTextOverlay( const std::string &Text, EFonts font, SDL_Color color)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
delete text;
text = new CLabel(pos.w/2, pos.h/2, font, CENTER, color, Text);
addOverlay(new CLabel(pos.w/2, pos.h/2, font, CENTER, color, Text));
update();
}
void CButtonBase::addOverlay(CIntObject *newOverlay)
{
delete overlay;
overlay = newOverlay;
addChild(newOverlay);
overlay->moveTo(overlay->pos.centerIn(pos).topLeft());
update();
}
@ -1154,14 +1162,15 @@ CHoverableArea::~CHoverableArea()
void LRClickableAreaWText::clickLeft(tribool down, bool previousState)
{
if(!down && previousState)
if(!down && previousState && !text.empty())
{
LOCPLINT->showInfoDialog(text);
}
}
void LRClickableAreaWText::clickRight(tribool down, bool previousState)
{
adventureInt->handleRightClick(text, down);
if (!text.empty())
adventureInt->handleRightClick(text, down);
}
LRClickableAreaWText::LRClickableAreaWText()

View File

@ -100,7 +100,9 @@ public:
bool swappedImages,//fix for some buttons: normal and pressed image are swapped
keepFrame; // don't change visual representation
void addOverlay(CIntObject * newOverlay);
void addTextOverlay(const std::string &Text, EFonts font, SDL_Color color = Colors::WHITE);
void update();//to refresh button after image or text change
void setOffset(int newOffset);
@ -113,7 +115,7 @@ public:
bool isHighlighted();
CAnimImage * image; //image for this button
CLabel * text;//text overlay
CIntObject * overlay;//object-overlay
CButtonBase(); //c-tor
virtual ~CButtonBase(); //d-tor

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,6 @@
#include "../../lib/HeroBonus.h"
#include "../gui/CIntObject.h"
#include "../widgets/CArtifactHolder.h"
/*
* CCreatureWindow.h, part of VCMI engine
@ -14,150 +13,106 @@
*
*/
struct Bonus;
class CCreature;
class CStackInstance;
class StackWindowInfo;
class CCommanderInstance;
class CStackInstance;
class CStack;
struct ArtifactLocation;
class CCreatureArtifactInstance;
class CAdventureMapButton;
class CBonusItem;
class CGHeroInstance;
class CComponent;
class LRClickableAreaWText;
class MoraleLuckBox;
class CAdventureMapButton;
struct UpgradeInfo;
class CPicture;
class CCreaturePic;
class LRClickableAreaWTextComp;
class CSlider;
class CLabel;
class CAnimImage;
class CSelectableSkill;
// New creature window
class CCreatureWindow : public CWindowObject, public CArtifactHolder
class CClickableObject : public LRClickableAreaWText
{
CIntObject * object; // passive object that will be used to determine clickable area
public:
enum CreWinType {OTHER = 0, BATTLE = 1, ARMY = 2, HERO = 3, COMMANDER = 4, COMMANDER_LEVEL_UP = 5, COMMANDER_BATTLE = 6}; // > 3 are opened permanently
//bool active; //TODO: comment me
CreWinType type;
int bonusRows; //height of skill window
ArtifactPosition displayedArtifact;
CClickableObject(CIntObject * object, std::function<void()> callback);
std::string count; //creature count in text format
const CCreature *c; //related creature
const CStackInstance *stack;
const CBonusSystemNode *stackNode;
const CCommanderInstance * commander;
const CGHeroInstance *heroOwner;
const CArtifactInstance *creatureArtifact; //currently worn artifact
std::vector<CComponent*> upgResCost; //cost of upgrade (if not possible then empty)
std::vector<CBonusItem*> bonusItems;
std::vector<LRClickableAreaWText*> spellEffects;
CCreaturePic *anim; //related creature's animation
MoraleLuckBox *luck, *morale;
LRClickableAreaWTextComp * expArea; //displays exp details
CSlider * slider; //Abilities
CAdventureMapButton *dismiss, *upgrade, *ok;
CAdventureMapButton * leftArtRoll, * rightArtRoll; //artifact selection
CAdventureMapButton * passArtToHero;
CAnimImage * artifactImage;
CAnimation * spellEffectsPics; //bitmaps representing spells affecting a stack in battle
//commander level-up
int selectedOption; //index for upgradeOptions
std::vector<ui32> upgradeOptions; //value 0-5 - secondary skills, 100+ - special skills
std::vector<CSelectableSkill *> selectableSkills, selectableBonuses;
std::vector<CPicture *> skillPictures; //secondary skills
std::string skillToFile(int skill); //return bitmap for secondary skill depending on selection / avaliability
void selectSkill (ui32 which);
void setArt(const CArtifactInstance *creatureArtifact);
void artifactRemoved (const ArtifactLocation &artLoc);
void artifactMoved (const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
void artifactDisassembled (const ArtifactLocation &artLoc) {return;};
void artifactAssembled (const ArtifactLocation &artLoc) {return;};
std::function<void()> dsm; //dismiss button callback
std::function<void()> Upg; //upgrade button callback
std::function<void(ui32)> levelUp; //choose commander skill to level up
CCreatureWindow(const CStack & stack, CreWinType type); //battle c-tor
CCreatureWindow (const CStackInstance &stack, CreWinType Type); //pop-up c-tor
CCreatureWindow(const CStackInstance &st, CreWinType Type, std::function<void()> Upg, std::function<void()> Dsm, UpgradeInfo *ui); //full garrison window
CCreatureWindow(const CCommanderInstance * commander, const CStack * stack = nullptr); //commander window
CCreatureWindow(std::vector<ui32> &skills, const CCommanderInstance * commander, std::function<void(ui32)> callback);
CCreatureWindow(CreatureID Cid, CreWinType Type, int creatureCount); //c-tor
void init(const CStackInstance *stack, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner);
void showAll(SDL_Surface * to);
void show(SDL_Surface * to);
void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
void sliderMoved(int newpos);
void close();
~CCreatureWindow(); //d-tor
void recreateSkillList(int pos);
void scrollArt(int dir);
void passArtifactToHero();
};
class CBonusItem : public LRClickableAreaWTextComp //responsible for displaying creature skill, active or not
{
public:
std::string name, description;
CPicture * bonusGraphics;
bool visible;
CBonusItem();
CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName);
~CBonusItem();
void showAll (SDL_Surface * to);
};
class CSelectableSkill : public LRClickableAreaWText
{
public:
std::function<void()> callback; //TODO: create more generic clickable class than AdvMapButton?
virtual void clickLeft(tribool down, bool previousState);
virtual void clickRight(tribool down, bool previousState){};
void clickLeft(tribool down, bool previousState) override;
//void clickRight(tribool down, bool previousState){};
void setObject(CIntObject * object);
};
/// original creature info window
class CCreInfoWindow : public CWindowObject
class CStackWindow : public CWindowObject
{
struct BonusInfo
{
std::string name;
std::string description;
std::string imagePath;
};
class CWindowSection : public CIntObject
{
CStackWindow * parent;
CPicture * background;
void createBackground(std::string path);
void createBonusItem(size_t index, Point position);
void printStatString(int index, std::string name, std::string value);
void printStatRange(int index, std::string name, int min, int max);
void printStatBase(int index, std::string name, int base, int current);
void printStat(int index, std::string name, int value);
public:
void createStackInfo(bool showExp, bool showArt);
void createActiveSpells();
void createCommanderSection();
void createCommander();
void createCommanderAbilities();
void createBonuses(boost::optional<size_t> size = boost::optional<size_t>());
void createBonusEntry(size_t index);
void createButtonPanel();
CWindowSection(CStackWindow * parent);
};
CAnimImage * stackArtifactIcon;
LRClickableAreaWTextComp * stackArtifactHelp;
CAdventureMapButton * stackArtifactButton;
std::unique_ptr<StackWindowInfo> info;
std::vector<BonusInfo> activeBonuses;
size_t activeTab;
CTabbedInt * commanderTab;
std::map<int, CAdventureMapButton *> switchButtons;
void setSelection(si32 newSkill, CClickableObject * newIcon);
CClickableObject * selectedIcon;
si32 selectedSkill;
CIntObject * createBonusEntry(size_t index);
CIntObject * switchTab(size_t index);
void removeStackArtifact(ArtifactPosition pos);
void setStackArtifact(const CArtifactInstance * art, Point artPos);
void initSections();
void initBonusesList();
void init();
std::string generateStackExpDescription();
CIntObject * createSkillEntry(int index);
public:
CLabel * creatureCount;
CLabel * creatureName;
CLabel * abilityText;
// for battles
CStackWindow(const CStack * stack, bool popup);
CCreaturePic * animation;
std::vector<CComponent *> upgResCost; //cost of upgrade (if not possible then empty)
std::vector<CAnimImage *> effects;
std::map<size_t, std::pair<CLabel *, CLabel * > > infoTexts;
// for non-existing stacks, e.g. recruit screen
CStackWindow(const CCreature * creature, bool popup);
MoraleLuckBox * luck, * morale;
// for normal stacks in armies
CStackWindow(const CStackInstance * stack, bool popup);
CStackWindow(const CStackInstance * stack, std::function<void()> dismiss, const UpgradeInfo & info, std::function<void(CreatureID)> callback);
CAdventureMapButton * dismiss, * upgrade, * ok;
// for commanders & commander level-up dialog
CStackWindow(const CCommanderInstance * commander, bool popup);
CStackWindow(const CCommanderInstance * commander, std::vector<ui32> &skills, std::function<void(ui32)> callback);
CCreInfoWindow(const CStackInstance & st, bool LClicked, std::function<void()> Upg = nullptr, std::function<void()> Dsm = nullptr, UpgradeInfo * ui = nullptr);
CCreInfoWindow(const CStack & st, bool LClicked = 0);
CCreInfoWindow(int Cid, bool LClicked, int creatureCount);
~CCreInfoWindow();
void init(const CCreature * cre, const CBonusSystemNode * stackNode, const CGHeroInstance * heroOwner, int creatureCount, bool LClicked);
void printLine(int nr, const std::string & text, int baseVal, int val = -1, bool range = false);
void show(SDL_Surface * to);
~CStackWindow();
};
CIntObject *createCreWindow(const CStack *s, bool lclick = false);
CIntObject *createCreWindow(CreatureID Cid, CCreatureWindow::CreWinType Type, int creatureCount);
CIntObject *createCreWindow(const CStackInstance *s, CCreatureWindow::CreWinType type, std::function<void()> Upg = nullptr, std::function<void()> Dsm = nullptr, UpgradeInfo *ui = nullptr);

View File

@ -329,7 +329,7 @@ void CHeroWindow::commanderWindow()
}
}
else
GH.pushInt(new CCreatureWindow (curHero->commander));
GH.pushInt(new CStackWindow(curHero->commander, false));
}

View File

@ -54,5 +54,23 @@
"anyOf" : "Any of the following:",
"allOf" : "All of the following:",
"noneOf" : "None of the following:"
},
"creatureWindow" :
{
"showBonuses" :
{
"label" : "Switch to bonuses view",
"help" : "Displays all active bonuses of the commander"
},
"showSkills" :
{
"label" : "Switch to skills view",
"help" : "Displays all learned skills of the commander"
},
"returnArtifact" :
{
"label" : "Give back artifact",
"help" : "Use this button to return stack artifact back into hero backpack"
}
}
}

View File

@ -459,7 +459,18 @@ CGeneralTextHandler::CGeneralTextHandler()
{
CLegacyConfigParser parser("DATA/ZCREXP.TXT");
parser.endLine();//header
do
for (size_t iter=0; iter<325; iter++)
{
parser.readString(); //ignore 1st column with description
zcrexp.push_back(parser.readString());
parser.endLine();
}
// line 325 - some weird formatting here
zcrexp.push_back(parser.readString());
parser.readString();
parser.endLine();
do // rest of file can be read normally
{
parser.readString(); //ignore 1st column with description
zcrexp.push_back(parser.readString());