mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Gui cleanup3 - UI refactoring to use smart pointers (#440)
* Changed most gui classes to use shared pointers * Store and use IImage as shared_ptr * CSpellWindow redesign * AdventureMapClasses cleanup * CLabel: store background as smart pointer * Store CObjectList items as smart pointers * Removed destroy function of list item * Store toggle buttons as smart pointers * Use CComponent as smart pointer * Attempt to fix artifact merchant drawing
This commit is contained in:
committed by
ArseniyShestakov
parent
db60983b5a
commit
5c09f751b3
@@ -48,18 +48,16 @@
|
||||
#include "../../lib/NetPacksBase.h"
|
||||
#include "../../lib/StringConstants.h"
|
||||
|
||||
CList::CListItem::CListItem(CList * Parent):
|
||||
CIntObject(LCLICK | RCLICK | HOVER),
|
||||
CList::CListItem::CListItem(CList * Parent)
|
||||
: CIntObject(LCLICK | RCLICK | HOVER),
|
||||
parent(Parent),
|
||||
selection(nullptr)
|
||||
selection()
|
||||
{
|
||||
defActions = 255-DISPOSE;
|
||||
}
|
||||
|
||||
CList::CListItem::~CListItem()
|
||||
{
|
||||
// select() method in this was already destroyed so we can't safely call method in parent
|
||||
if (parent->selected == this)
|
||||
parent->selected = nullptr;
|
||||
}
|
||||
|
||||
void CList::CListItem::clickRight(tribool down, bool previousState)
|
||||
@@ -70,15 +68,17 @@ void CList::CListItem::clickRight(tribool down, bool previousState)
|
||||
|
||||
void CList::CListItem::clickLeft(tribool down, bool previousState)
|
||||
{
|
||||
if (down == true)
|
||||
if(down == true)
|
||||
{
|
||||
//second click on already selected item
|
||||
if (parent->selected == this)
|
||||
if(parent->selected == this->shared_from_this())
|
||||
{
|
||||
open();
|
||||
}
|
||||
else
|
||||
{
|
||||
//first click - switch selection
|
||||
parent->select(this);
|
||||
parent->select(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,53 +93,54 @@ void CList::CListItem::hover(bool on)
|
||||
|
||||
void CList::CListItem::onSelect(bool on)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
vstd::clear_pointer(selection);
|
||||
if (on)
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
selection.reset();
|
||||
if(on)
|
||||
selection = genSelection();
|
||||
select(on);
|
||||
GH.totalRedraw();
|
||||
}
|
||||
|
||||
CList::CList(int Size, Point position, std::string btnUp, std::string btnDown, size_t listAmount,
|
||||
int helpUp, int helpDown, CListBox::CreateFunc create, CListBox::DestroyFunc destroy):
|
||||
CIntObject(0, position),
|
||||
CList::CList(int Size, Point position, std::string btnUp, std::string btnDown, size_t listAmount, int helpUp, int helpDown, CListBox::CreateFunc create)
|
||||
: CIntObject(0, position),
|
||||
size(Size),
|
||||
selected(nullptr)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
scrollUp = new CButton(Point(0, 0), btnUp, CGI->generaltexth->zelp[helpUp]);
|
||||
list = new CListBox(create, destroy, Point(1,scrollUp->pos.h), Point(0, 32), size, listAmount);
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
scrollUp = std::make_shared<CButton>(Point(0, 0), btnUp, CGI->generaltexth->zelp[helpUp]);
|
||||
scrollDown = std::make_shared<CButton>(Point(0, scrollUp->pos.h + 32*size), btnDown, CGI->generaltexth->zelp[helpDown]);
|
||||
|
||||
listBox = std::make_shared<CListBox>(create, Point(1,scrollUp->pos.h), Point(0, 32), size, listAmount);
|
||||
|
||||
//assign callback only after list was created
|
||||
scrollUp->addCallback(std::bind(&CListBox::moveToPrev, list));
|
||||
scrollDown = new CButton(Point(0, scrollUp->pos.h + 32*size), btnDown, CGI->generaltexth->zelp[helpDown], std::bind(&CListBox::moveToNext, list));
|
||||
scrollUp->addCallback(std::bind(&CListBox::moveToPrev, listBox));
|
||||
scrollDown->addCallback(std::bind(&CListBox::moveToNext, listBox));
|
||||
|
||||
scrollDown->addCallback(std::bind(&CList::update, this));
|
||||
scrollUp->addCallback(std::bind(&CList::update, this));
|
||||
scrollDown->addCallback(std::bind(&CList::update, this));
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void CList::update()
|
||||
{
|
||||
bool onTop = list->getPos() == 0;
|
||||
bool onBottom = list->getPos() + size >= list->size();
|
||||
bool onTop = listBox->getPos() == 0;
|
||||
bool onBottom = listBox->getPos() + size >= listBox->size();
|
||||
|
||||
scrollUp->block(onTop);
|
||||
scrollDown->block(onBottom);
|
||||
}
|
||||
|
||||
void CList::select(CListItem *which)
|
||||
void CList::select(std::shared_ptr<CListItem> which)
|
||||
{
|
||||
if (selected == which)
|
||||
if(selected == which)
|
||||
return;
|
||||
|
||||
if (selected)
|
||||
if(selected)
|
||||
selected->onSelect(false);
|
||||
|
||||
selected = which;
|
||||
if (which)
|
||||
if(which)
|
||||
{
|
||||
which->onSelect(true);
|
||||
onSelect();
|
||||
@@ -148,28 +149,28 @@ void CList::select(CListItem *which)
|
||||
|
||||
int CList::getSelectedIndex()
|
||||
{
|
||||
return list->getIndexOf(selected);
|
||||
return listBox->getIndexOf(selected);
|
||||
}
|
||||
|
||||
void CList::selectIndex(int which)
|
||||
{
|
||||
if (which < 0)
|
||||
if(which < 0)
|
||||
{
|
||||
if (selected)
|
||||
if(selected)
|
||||
select(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
list->scrollTo(which);
|
||||
listBox->scrollTo(which);
|
||||
update();
|
||||
select(dynamic_cast<CListItem*>(list->getItem(which)));
|
||||
select(std::dynamic_pointer_cast<CListItem>(listBox->getItem(which)));
|
||||
}
|
||||
}
|
||||
|
||||
void CList::selectNext()
|
||||
{
|
||||
int index = getSelectedIndex() + 1;
|
||||
if (index >= list->size())
|
||||
if(index >= listBox->size())
|
||||
index = 0;
|
||||
selectIndex(index);
|
||||
}
|
||||
@@ -177,7 +178,7 @@ void CList::selectNext()
|
||||
void CList::selectPrev()
|
||||
{
|
||||
int index = getSelectedIndex();
|
||||
if (index <= 0)
|
||||
if(index <= 0)
|
||||
selectIndex(0);
|
||||
else
|
||||
selectIndex(index-1);
|
||||
@@ -185,23 +186,23 @@ void CList::selectPrev()
|
||||
|
||||
CHeroList::CEmptyHeroItem::CEmptyHeroItem()
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
auto move = new CAnimImage("IMOBIL", 0, 0, 0, 1);
|
||||
auto img = new CPicture("HPSXXX", move->pos.w + 1);
|
||||
auto mana = new CAnimImage("IMANA", 0, 0, move->pos.w + img->pos.w + 2, 1 );
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
movement = std::make_shared<CAnimImage>("IMOBIL", 0, 0, 0, 1);
|
||||
portrait = std::make_shared<CPicture>("HPSXXX", movement->pos.w + 1);
|
||||
mana = std::make_shared<CAnimImage>("IMANA", 0, 0, movement->pos.w + portrait->pos.w + 2, 1 );
|
||||
|
||||
pos.w = mana->pos.w + mana->pos.x - pos.x;
|
||||
pos.h = std::max(std::max<SDLX_Size>(move->pos.h + 1, mana->pos.h + 1), img->pos.h);
|
||||
pos.h = std::max(std::max<SDLX_Size>(movement->pos.h + 1, mana->pos.h + 1), portrait->pos.h);
|
||||
}
|
||||
|
||||
CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero):
|
||||
CListItem(parent),
|
||||
CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero)
|
||||
: CListItem(parent),
|
||||
hero(Hero)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
movement = new CAnimImage("IMOBIL", 0, 0, 0, 1);
|
||||
portrait = new CAnimImage("PortraitsSmall", hero->portrait, 0, movement->pos.w + 1);
|
||||
mana = new CAnimImage("IMANA", 0, 0, movement->pos.w + portrait->pos.w + 2, 1 );
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
movement = std::make_shared<CAnimImage>("IMOBIL", 0, 0, 0, 1);
|
||||
portrait = std::make_shared<CAnimImage>("PortraitsSmall", hero->portrait, 0, movement->pos.w + 1);
|
||||
mana = std::make_shared<CAnimImage>("IMANA", 0, 0, movement->pos.w + portrait->pos.w + 2, 1);
|
||||
|
||||
pos.w = mana->pos.w + mana->pos.x - pos.x;
|
||||
pos.h = std::max(std::max<SDLX_Size>(movement->pos.h + 1, mana->pos.h + 1), portrait->pos.h);
|
||||
@@ -216,15 +217,15 @@ void CHeroList::CHeroItem::update()
|
||||
redraw();
|
||||
}
|
||||
|
||||
CIntObject * CHeroList::CHeroItem::genSelection()
|
||||
std::shared_ptr<CIntObject> CHeroList::CHeroItem::genSelection()
|
||||
{
|
||||
return new CPicture("HPSYYY", movement->pos.w + 1);
|
||||
return std::make_shared<CPicture>("HPSYYY", movement->pos.w + 1);
|
||||
}
|
||||
|
||||
void CHeroList::CHeroItem::select(bool on)
|
||||
{
|
||||
if (on && adventureInt->selection != hero)
|
||||
adventureInt->select(hero);
|
||||
if(on && adventureInt->selection != hero)
|
||||
adventureInt->select(hero);
|
||||
}
|
||||
|
||||
void CHeroList::CHeroItem::open()
|
||||
@@ -242,11 +243,11 @@ std::string CHeroList::CHeroItem::getHoverText()
|
||||
return boost::str(boost::format(CGI->generaltexth->allTexts[15]) % hero->name % hero->type->heroClass->name);
|
||||
}
|
||||
|
||||
CIntObject * CHeroList::createHeroItem(size_t index)
|
||||
std::shared_ptr<CIntObject> CHeroList::createHeroItem(size_t index)
|
||||
{
|
||||
if (LOCPLINT->wanderingHeroes.size() > index)
|
||||
return new CHeroItem(this, LOCPLINT->wanderingHeroes[index]);
|
||||
return new CEmptyHeroItem();
|
||||
return std::make_shared<CHeroItem>(this, LOCPLINT->wanderingHeroes[index]);
|
||||
return std::make_shared<CEmptyHeroItem>();
|
||||
}
|
||||
|
||||
CHeroList::CHeroList(int size, Point position, std::string btnUp, std::string btnDown):
|
||||
@@ -262,10 +263,10 @@ void CHeroList::select(const CGHeroInstance * hero)
|
||||
void CHeroList::update(const CGHeroInstance * hero)
|
||||
{
|
||||
//this hero is already present, update its status
|
||||
for (auto & elem : list->getItems())
|
||||
for(auto & elem : listBox->getItems())
|
||||
{
|
||||
auto item = dynamic_cast<CHeroItem*>(elem);
|
||||
if (item && item->hero == hero && vstd::contains(LOCPLINT->wanderingHeroes, hero))
|
||||
auto item = std::dynamic_pointer_cast<CHeroItem>(elem);
|
||||
if(item && item->hero == hero && vstd::contains(LOCPLINT->wanderingHeroes, hero))
|
||||
{
|
||||
item->update();
|
||||
return;
|
||||
@@ -273,7 +274,7 @@ void CHeroList::update(const CGHeroInstance * hero)
|
||||
}
|
||||
//simplest solution for now: reset list and restore selection
|
||||
|
||||
list->resize(LOCPLINT->wanderingHeroes.size());
|
||||
listBox->resize(LOCPLINT->wanderingHeroes.size());
|
||||
if (adventureInt->selection)
|
||||
{
|
||||
auto hero = dynamic_cast<const CGHeroInstance *>(adventureInt->selection);
|
||||
@@ -283,26 +284,26 @@ void CHeroList::update(const CGHeroInstance * hero)
|
||||
CList::update();
|
||||
}
|
||||
|
||||
CIntObject * CTownList::createTownItem(size_t index)
|
||||
std::shared_ptr<CIntObject> CTownList::createTownItem(size_t index)
|
||||
{
|
||||
if (LOCPLINT->towns.size() > index)
|
||||
return new CTownItem(this, LOCPLINT->towns[index]);
|
||||
return new CAnimImage("ITPA", 0);
|
||||
return std::make_shared<CTownItem>(this, LOCPLINT->towns[index]);
|
||||
return std::make_shared<CAnimImage>("ITPA", 0);
|
||||
}
|
||||
|
||||
CTownList::CTownItem::CTownItem(CTownList *parent, const CGTownInstance *Town):
|
||||
CListItem(parent),
|
||||
town(Town)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
picture = new CAnimImage("ITPA", 0);
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
picture = std::make_shared<CAnimImage>("ITPA", 0);
|
||||
pos = picture->pos;
|
||||
update();
|
||||
}
|
||||
|
||||
CIntObject * CTownList::CTownItem::genSelection()
|
||||
std::shared_ptr<CIntObject> CTownList::CTownItem::genSelection()
|
||||
{
|
||||
return new CAnimImage("ITPA", 1);
|
||||
return std::make_shared<CAnimImage>("ITPA", 1);
|
||||
}
|
||||
|
||||
void CTownList::CTownItem::update()
|
||||
@@ -348,7 +349,7 @@ void CTownList::update(const CGTownInstance *)
|
||||
{
|
||||
//simplest solution for now: reset list and restore selection
|
||||
|
||||
list->resize(LOCPLINT->towns.size());
|
||||
listBox->resize(LOCPLINT->towns.size());
|
||||
if (adventureInt->selection)
|
||||
{
|
||||
auto town = dynamic_cast<const CGTownInstance *>(adventureInt->selection);
|
||||
@@ -475,7 +476,7 @@ CMinimapInstance::~CMinimapInstance()
|
||||
SDL_FreeSurface(minimap);
|
||||
}
|
||||
|
||||
void CMinimapInstance::showAll(SDL_Surface *to)
|
||||
void CMinimapInstance::showAll(SDL_Surface * to)
|
||||
{
|
||||
blitAtLoc(minimap, 0, 0, to);
|
||||
|
||||
@@ -484,7 +485,7 @@ void CMinimapInstance::showAll(SDL_Surface *to)
|
||||
for(auto & hero : heroes)
|
||||
{
|
||||
int3 position = hero->getPosition(false);
|
||||
if (position.z == level)
|
||||
if(position.z == level)
|
||||
{
|
||||
const SDL_Color & color = graphics->playerColors[hero->getOwner().getNum()];
|
||||
blitTileWithColor(color, position, to, pos.x, pos.y);
|
||||
@@ -531,15 +532,17 @@ std::map<int, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors(std::string
|
||||
return ret;
|
||||
}
|
||||
|
||||
CMinimap::CMinimap(const Rect &position):
|
||||
CIntObject(LCLICK | RCLICK | HOVER | MOVE, position.topLeft()),
|
||||
aiShield(nullptr),
|
||||
minimap(nullptr),
|
||||
CMinimap::CMinimap(const Rect & position)
|
||||
: CIntObject(LCLICK | RCLICK | HOVER | MOVE, position.topLeft()),
|
||||
level(0),
|
||||
colors(loadColors("config/terrains.json"))
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
pos.w = position.w;
|
||||
pos.h = position.h;
|
||||
|
||||
aiShield = std::make_shared<CPicture>("AIShield");
|
||||
aiShield->disable();
|
||||
}
|
||||
|
||||
int3 CMinimap::translateMousePosition()
|
||||
@@ -567,7 +570,7 @@ void CMinimap::moveAdvMapSelection()
|
||||
|
||||
void CMinimap::clickLeft(tribool down, bool previousState)
|
||||
{
|
||||
if (down)
|
||||
if(down)
|
||||
moveAdvMapSelection();
|
||||
}
|
||||
|
||||
@@ -578,7 +581,7 @@ void CMinimap::clickRight(tribool down, bool previousState)
|
||||
|
||||
void CMinimap::hover(bool on)
|
||||
{
|
||||
if (on)
|
||||
if(on)
|
||||
GH.statusbar->setText(CGI->generaltexth->zelp[291].first);
|
||||
else
|
||||
GH.statusbar->clear();
|
||||
@@ -593,7 +596,7 @@ void CMinimap::mouseMoved(const SDL_MouseMotionEvent & sEvent)
|
||||
void CMinimap::showAll(SDL_Surface * to)
|
||||
{
|
||||
CIntObject::showAll(to);
|
||||
if (minimap)
|
||||
if(minimap)
|
||||
{
|
||||
int3 mapSizes = LOCPLINT->cb->getMapSize();
|
||||
int3 tileCountOnScreen = adventureInt->terrain.tileCountOnScreen();
|
||||
@@ -608,13 +611,13 @@ void CMinimap::showAll(SDL_Surface * to)
|
||||
ui16(tileCountOnScreen.y * pos.h / mapSizes.y)
|
||||
};
|
||||
|
||||
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
||||
if(adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
||||
{
|
||||
// adjusts radar so that it doesn't go out of map in world view mode (since there's no frame)
|
||||
radar.x = std::min<int>(std::max(pos.x, radar.x), pos.x + pos.w - radar.w);
|
||||
radar.y = std::min<int>(std::max(pos.y, radar.y), pos.y + pos.h - radar.h);
|
||||
|
||||
if (radar.x < pos.x && radar.y < pos.y)
|
||||
if(radar.x < pos.x && radar.y < pos.y)
|
||||
return; // whole map is visible at once, no point in redrawing border
|
||||
}
|
||||
|
||||
@@ -627,12 +630,11 @@ void CMinimap::showAll(SDL_Surface * to)
|
||||
|
||||
void CMinimap::update()
|
||||
{
|
||||
if (aiShield) //AI turn is going on. There is no need to update minimap
|
||||
if(aiShield->recActions & UPDATE) //AI turn is going on. There is no need to update minimap
|
||||
return;
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
vstd::clear_pointer(minimap);
|
||||
minimap = new CMinimapInstance(this, level);
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
minimap = std::make_shared<CMinimapInstance>(this, level);
|
||||
redraw();
|
||||
}
|
||||
|
||||
@@ -644,16 +646,14 @@ void CMinimap::setLevel(int newLevel)
|
||||
|
||||
void CMinimap::setAIRadar(bool on)
|
||||
{
|
||||
if (on)
|
||||
if(on)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
vstd::clear_pointer(minimap);
|
||||
if (!aiShield)
|
||||
aiShield = new CPicture("AIShield");
|
||||
aiShield->enable();
|
||||
minimap.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
vstd::clear_pointer(aiShield);
|
||||
aiShield->disable();
|
||||
update();
|
||||
}
|
||||
// this my happen during AI turn when this interface is inactive
|
||||
@@ -663,123 +663,98 @@ void CMinimap::setAIRadar(bool on)
|
||||
|
||||
void CMinimap::hideTile(const int3 &pos)
|
||||
{
|
||||
if (minimap)
|
||||
if(minimap)
|
||||
minimap->refreshTile(pos);
|
||||
}
|
||||
|
||||
void CMinimap::showTile(const int3 &pos)
|
||||
{
|
||||
if (minimap)
|
||||
if(minimap)
|
||||
minimap->refreshTile(pos);
|
||||
}
|
||||
|
||||
CInfoBar::CVisibleInfo::CVisibleInfo(Point position):
|
||||
CIntObject(0, position),
|
||||
aiProgress(nullptr)
|
||||
CInfoBar::CVisibleInfo::CVisibleInfo()
|
||||
: CIntObject(0, Point(8, 12))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::show(SDL_Surface *to)
|
||||
void CInfoBar::CVisibleInfo::show(SDL_Surface * to)
|
||||
{
|
||||
CIntObject::show(to);
|
||||
for(auto object : forceRefresh)
|
||||
object->showAll(to);
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::loadHero(const CGHeroInstance * hero)
|
||||
CInfoBar::EmptyVisibleInfo::EmptyVisibleInfo()
|
||||
{
|
||||
assert(children.empty()); // visible info should be re-created to change type
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
new CPicture("ADSTATHR");
|
||||
new CHeroTooltip(Point(0,0), hero);
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::loadTown(const CGTownInstance *town)
|
||||
CInfoBar::VisibleHeroInfo::VisibleHeroInfo(const CGHeroInstance * hero)
|
||||
{
|
||||
assert(children.empty()); // visible info should be re-created to change type
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
new CPicture("ADSTATCS");
|
||||
new CTownTooltip(Point(0,0), town);
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
background = std::make_shared<CPicture>("ADSTATHR");
|
||||
heroTooltip = std::make_shared<CHeroTooltip>(Point(0,0), hero);
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::playNewDaySound()
|
||||
CInfoBar::VisibleTownInfo::VisibleTownInfo(const CGTownInstance * town)
|
||||
{
|
||||
if (LOCPLINT->cb->getDate(Date::DAY_OF_WEEK) != 1) // not first day of the week
|
||||
CCS->soundh->playSound(soundBase::newDay);
|
||||
else
|
||||
if (LOCPLINT->cb->getDate(Date::WEEK) != 1) // not first week in month
|
||||
CCS->soundh->playSound(soundBase::newWeek);
|
||||
else
|
||||
if (LOCPLINT->cb->getDate(Date::MONTH) != 1) // not first month
|
||||
CCS->soundh->playSound(soundBase::newMonth);
|
||||
else
|
||||
CCS->soundh->playSound(soundBase::newDay);
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
background = std::make_shared<CPicture>("ADSTATCS");
|
||||
townTooltip = std::make_shared<CTownTooltip>(Point(0,0), town);
|
||||
}
|
||||
|
||||
std::string CInfoBar::CVisibleInfo::getNewDayName()
|
||||
CInfoBar::VisibleDateInfo::VisibleDateInfo()
|
||||
{
|
||||
if (LOCPLINT->cb->getDate(Date::DAY) == 1)
|
||||
return "NEWDAY";
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
|
||||
if (LOCPLINT->cb->getDate(Date::DAY) != 1)
|
||||
return "NEWDAY";
|
||||
|
||||
switch(LOCPLINT->cb->getDate(Date::WEEK))
|
||||
{
|
||||
case 1: return "NEWWEEK1";
|
||||
case 2: return "NEWWEEK2";
|
||||
case 3: return "NEWWEEK3";
|
||||
case 4: return "NEWWEEK4";
|
||||
default: assert(0); return "";
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::loadDay()
|
||||
{
|
||||
assert(children.empty()); // visible info should be re-created first to change type
|
||||
|
||||
playNewDaySound();
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
new CShowableAnim(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE);
|
||||
animation = std::make_shared<CShowableAnim>(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE);
|
||||
|
||||
std::string labelText;
|
||||
if (LOCPLINT->cb->getDate(Date::DAY_OF_WEEK) == 1 && LOCPLINT->cb->getDate(Date::DAY) != 1) // monday of any week but first - show new week info
|
||||
if(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK) == 1 && LOCPLINT->cb->getDate(Date::DAY) != 1) // monday of any week but first - show new week info
|
||||
labelText = CGI->generaltexth->allTexts[63] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK));
|
||||
else
|
||||
labelText = CGI->generaltexth->allTexts[64] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK));
|
||||
|
||||
forceRefresh.push_back(new CLabel(95, 31, FONT_MEDIUM, CENTER, Colors::WHITE, labelText));
|
||||
label = std::make_shared<CLabel>(95, 31, FONT_MEDIUM, CENTER, Colors::WHITE, labelText);
|
||||
|
||||
forceRefresh.push_back(label);
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::loadEnemyTurn(PlayerColor player)
|
||||
std::string CInfoBar::VisibleDateInfo::getNewDayName()
|
||||
{
|
||||
assert(children.empty()); // visible info should be re-created to change type
|
||||
if(LOCPLINT->cb->getDate(Date::DAY) == 1)
|
||||
return "NEWDAY";
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
new CPicture("ADSTATNX");
|
||||
new CAnimImage("CREST58", player.getNum(), 0, 20, 51);
|
||||
new CShowableAnim(99, 51, "HOURSAND");
|
||||
if(LOCPLINT->cb->getDate(Date::DAY) != 1)
|
||||
return "NEWDAY";
|
||||
|
||||
// FIXME: currently there is no way to get progress from VCAI
|
||||
// if this will change at some point switch this ifdef to enable correct code
|
||||
#if 0
|
||||
//prepare hourglass for updating AI turn
|
||||
aiProgress = new CAnimImage("HOURGLAS", 0, 0, 99, 51);
|
||||
forceRefresh.push_back(aiProgress);
|
||||
#else
|
||||
//create hourglass that will be always animated ignoring AI status
|
||||
new CShowableAnim(99, 51, "HOURGLAS", CShowableAnim::PLAY_ONCE, 40);
|
||||
#endif
|
||||
switch(LOCPLINT->cb->getDate(Date::WEEK))
|
||||
{
|
||||
case 1:
|
||||
return "NEWWEEK1";
|
||||
case 2:
|
||||
return "NEWWEEK2";
|
||||
case 3:
|
||||
return "NEWWEEK3";
|
||||
case 4:
|
||||
return "NEWWEEK4";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::loadGameStatus()
|
||||
CInfoBar::VisibleEnemyTurnInfo::VisibleEnemyTurnInfo(PlayerColor player)
|
||||
{
|
||||
assert(children.empty()); // visible info should be re-created to change type
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
background = std::make_shared<CPicture>("ADSTATNX");
|
||||
banner = std::make_shared<CAnimImage>("CREST58", player.getNum(), 0, 20, 51);
|
||||
sand = std::make_shared<CShowableAnim>(99, 51, "HOURSAND");
|
||||
glass = std::make_shared<CShowableAnim>(99, 51, "HOURGLAS", CShowableAnim::PLAY_ONCE, 40);
|
||||
}
|
||||
|
||||
CInfoBar::VisibleGameStatusInfo::VisibleGameStatusInfo()
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
//get amount of halls of each level
|
||||
std::vector<int> halls(4, 0);
|
||||
for(auto town : LOCPLINT->towns)
|
||||
@@ -797,83 +772,84 @@ void CInfoBar::CVisibleInfo::loadGameStatus()
|
||||
{
|
||||
if(LOCPLINT->cb->getPlayerStatus(PlayerColor(i), false) == EPlayerStatus::INGAME)
|
||||
{
|
||||
if (LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, PlayerColor(i)) != PlayerRelations::ENEMIES)
|
||||
if(LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, PlayerColor(i)) != PlayerRelations::ENEMIES)
|
||||
allies.push_back(PlayerColor(i));
|
||||
else
|
||||
enemies.push_back(PlayerColor(i));
|
||||
}
|
||||
}
|
||||
|
||||
//generate component
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
new CPicture("ADSTATIN");
|
||||
auto allyLabel = new CLabel(10, 106, FONT_SMALL, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[390] + ":");
|
||||
auto enemyLabel = new CLabel(10, 136, FONT_SMALL, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[391] + ":");
|
||||
//generate widgets
|
||||
background = std::make_shared<CPicture>("ADSTATIN");
|
||||
allyLabel = std::make_shared<CLabel>(10, 106, FONT_SMALL, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[390] + ":");
|
||||
enemyLabel = std::make_shared<CLabel>(10, 136, FONT_SMALL, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[391] + ":");
|
||||
|
||||
int posx = allyLabel->pos.w + allyLabel->pos.x - pos.x + 4;
|
||||
for(PlayerColor & player : allies)
|
||||
{
|
||||
auto image = new CAnimImage("ITGFLAGS", player.getNum(), 0, posx, 102);
|
||||
auto image = std::make_shared<CAnimImage>("ITGFLAGS", player.getNum(), 0, posx, 102);
|
||||
posx += image->pos.w;
|
||||
flags.push_back(image);
|
||||
}
|
||||
|
||||
posx = enemyLabel->pos.w + enemyLabel->pos.x - pos.x + 4;
|
||||
for(PlayerColor & player : enemies)
|
||||
{
|
||||
auto image = new CAnimImage("ITGFLAGS", player.getNum(), 0, posx, 132);
|
||||
auto image = std::make_shared<CAnimImage>("ITGFLAGS", player.getNum(), 0, posx, 132);
|
||||
posx += image->pos.w;
|
||||
flags.push_back(image);
|
||||
}
|
||||
|
||||
for (size_t i=0; i<halls.size(); i++)
|
||||
for(size_t i=0; i<halls.size(); i++)
|
||||
{
|
||||
new CAnimImage("itmtl", i, 0, 6 + 42 * i , 11);
|
||||
if (halls[i])
|
||||
new CLabel( 26 + 42 * i, 64, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(halls[i]));
|
||||
hallIcons.push_back(std::make_shared<CAnimImage>("itmtl", i, 0, 6 + 42 * i , 11));
|
||||
if(halls[i])
|
||||
hallLabels.push_back(std::make_shared<CLabel>( 26 + 42 * i, 64, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(halls[i])));
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::loadComponent(const Component & compToDisplay, std::string message)
|
||||
CInfoBar::VisibleComponentInfo::VisibleComponentInfo(const Component & compToDisplay, std::string message)
|
||||
{
|
||||
assert(children.empty()); // visible info should be re-created to change type
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
background = std::make_shared<CPicture>("ADSTATOT", 1);
|
||||
|
||||
new CPicture("ADSTATOT", 1);
|
||||
|
||||
auto comp = new CComponent(compToDisplay);
|
||||
comp = std::make_shared<CComponent>(compToDisplay);
|
||||
comp->moveTo(Point(pos.x+47, pos.y+50));
|
||||
|
||||
new CTextBox(message, Rect(10, 4, 160, 50), 0, FONT_SMALL, CENTER, Colors::WHITE);
|
||||
text = std::make_shared<CTextBox>(message, Rect(10, 4, 160, 50), 0, FONT_SMALL, CENTER, Colors::WHITE);
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::updateEnemyTurn(double progress)
|
||||
void CInfoBar::playNewDaySound()
|
||||
{
|
||||
if (aiProgress)
|
||||
aiProgress->setFrame((aiProgress->size() - 1) * progress);
|
||||
if(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK) != 1) // not first day of the week
|
||||
CCS->soundh->playSound(soundBase::newDay);
|
||||
else if(LOCPLINT->cb->getDate(Date::WEEK) != 1) // not first week in month
|
||||
CCS->soundh->playSound(soundBase::newWeek);
|
||||
else if(LOCPLINT->cb->getDate(Date::MONTH) != 1) // not first month
|
||||
CCS->soundh->playSound(soundBase::newMonth);
|
||||
else
|
||||
CCS->soundh->playSound(soundBase::newDay);
|
||||
}
|
||||
|
||||
void CInfoBar::reset(EState newState = EMPTY)
|
||||
void CInfoBar::reset()
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
|
||||
vstd::clear_pointer(visibleInfo);
|
||||
currentObject = nullptr;
|
||||
state = newState;
|
||||
visibleInfo = new CVisibleInfo(Point(8, 12));
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
state = EMPTY;
|
||||
visibleInfo = std::make_shared<EmptyVisibleInfo>();
|
||||
}
|
||||
|
||||
void CInfoBar::showSelection()
|
||||
{
|
||||
if (adventureInt->selection)
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
if(adventureInt->selection)
|
||||
{
|
||||
auto hero = dynamic_cast<const CGHeroInstance *>(adventureInt->selection);
|
||||
if (hero)
|
||||
if(auto hero = dynamic_cast<const CGHeroInstance *>(adventureInt->selection))
|
||||
{
|
||||
showHeroSelection(hero);
|
||||
return;
|
||||
}
|
||||
auto town = dynamic_cast<const CGTownInstance *>(adventureInt->selection);
|
||||
if (town)
|
||||
else if(auto town = dynamic_cast<const CGTownInstance *>(adventureInt->selection))
|
||||
{
|
||||
showTownSelection(town);
|
||||
return;
|
||||
@@ -891,11 +867,11 @@ void CInfoBar::tick()
|
||||
|
||||
void CInfoBar::clickLeft(tribool down, bool previousState)
|
||||
{
|
||||
if (down)
|
||||
if(down)
|
||||
{
|
||||
if (state == HERO || state == TOWN)
|
||||
if(state == HERO || state == TOWN)
|
||||
showGameStatus();
|
||||
else if (state == GAME)
|
||||
else if(state == GAME)
|
||||
showDate();
|
||||
else
|
||||
showSelection();
|
||||
@@ -909,83 +885,96 @@ void CInfoBar::clickRight(tribool down, bool previousState)
|
||||
|
||||
void CInfoBar::hover(bool on)
|
||||
{
|
||||
if (on)
|
||||
if(on)
|
||||
GH.statusbar->setText(CGI->generaltexth->zelp[292].first);
|
||||
else
|
||||
GH.statusbar->clear();
|
||||
}
|
||||
|
||||
CInfoBar::CInfoBar(const Rect &position):
|
||||
CIntObject(LCLICK | RCLICK | HOVER, position.topLeft()),
|
||||
visibleInfo(nullptr),
|
||||
state(EMPTY),
|
||||
currentObject(nullptr)
|
||||
CInfoBar::CInfoBar(const Rect & position)
|
||||
: CIntObject(LCLICK | RCLICK | HOVER, position.topLeft()),
|
||||
state(EMPTY)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
pos.w = position.w;
|
||||
pos.h = position.h;
|
||||
//FIXME: enable some mode? Should be done by advMap::select() when game starts but just in case?
|
||||
reset();
|
||||
}
|
||||
|
||||
void CInfoBar::showDate()
|
||||
{
|
||||
reset(DATE);
|
||||
visibleInfo->loadDay();
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
playNewDaySound();
|
||||
state = DATE;
|
||||
visibleInfo = std::make_shared<VisibleDateInfo>();
|
||||
setTimer(3000);
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CInfoBar::showComponent(const Component & comp, std::string message)
|
||||
{
|
||||
reset(COMPONENT);
|
||||
visibleInfo->loadComponent(comp, message);
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
state = COMPONENT;
|
||||
visibleInfo = std::make_shared<VisibleComponentInfo>(comp, message);
|
||||
setTimer(3000);
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CInfoBar::startEnemyTurn(PlayerColor color)
|
||||
{
|
||||
reset(AITURN);
|
||||
visibleInfo->loadEnemyTurn(color);
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CInfoBar::updateEnemyTurn(double progress)
|
||||
{
|
||||
assert(state == AITURN);
|
||||
visibleInfo->updateEnemyTurn(progress);
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
state = AITURN;
|
||||
visibleInfo = std::make_shared<VisibleEnemyTurnInfo>(color);
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CInfoBar::showHeroSelection(const CGHeroInstance * hero)
|
||||
{
|
||||
if (!hero)
|
||||
return;
|
||||
|
||||
reset(HERO);
|
||||
currentObject = hero;
|
||||
visibleInfo->loadHero(hero);
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
if(!hero)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
state = HERO;
|
||||
visibleInfo = std::make_shared<VisibleHeroInfo>(hero);
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CInfoBar::showTownSelection(const CGTownInstance * town)
|
||||
{
|
||||
if (!town)
|
||||
return;
|
||||
|
||||
reset(TOWN);
|
||||
currentObject = town;
|
||||
visibleInfo->loadTown(town);
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
if(!town)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
state = TOWN;
|
||||
visibleInfo = std::make_shared<VisibleTownInfo>(town);
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CInfoBar::showGameStatus()
|
||||
{
|
||||
reset(GAME);
|
||||
visibleInfo->loadGameStatus();
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
state = GAME;
|
||||
visibleInfo = std::make_shared<VisibleGameStatusInfo>();
|
||||
setTimer(3000);
|
||||
redraw();
|
||||
}
|
||||
|
||||
CInGameConsole::CInGameConsole()
|
||||
: CIntObject(KEYBOARD | TEXTINPUT),
|
||||
prevEntDisp(-1),
|
||||
defaultTimeout(10000),
|
||||
maxDisplayedTexts(10)
|
||||
{
|
||||
}
|
||||
|
||||
void CInGameConsole::show(SDL_Surface * to)
|
||||
{
|
||||
int number = 0;
|
||||
@@ -1207,11 +1196,6 @@ void CInGameConsole::refreshEnteredText()
|
||||
}
|
||||
}
|
||||
|
||||
CInGameConsole::CInGameConsole() : prevEntDisp(-1), defaultTimeout(10000), maxDisplayedTexts(10)
|
||||
{
|
||||
addUsedEvents(KEYBOARD | TEXTINPUT);
|
||||
}
|
||||
|
||||
CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position)
|
||||
: CIntObject(),
|
||||
background(bg)
|
||||
@@ -1233,32 +1217,34 @@ CAdvMapPanel::~CAdvMapPanel()
|
||||
SDL_FreeSurface(background);
|
||||
}
|
||||
|
||||
void CAdvMapPanel::addChildColorableButton(CButton * btn)
|
||||
void CAdvMapPanel::addChildColorableButton(std::shared_ptr<CButton> button)
|
||||
{
|
||||
buttons.push_back(btn);
|
||||
addChildToPanel(btn, ACTIVATE | DEACTIVATE);
|
||||
colorableButtons.push_back(button);
|
||||
addChildToPanel(button, ACTIVATE | DEACTIVATE);
|
||||
}
|
||||
|
||||
void CAdvMapPanel::setPlayerColor(const PlayerColor & clr)
|
||||
{
|
||||
for (auto &btn : buttons)
|
||||
for(auto & button : colorableButtons)
|
||||
{
|
||||
btn->setPlayerColor(clr);
|
||||
button->setPlayerColor(clr);
|
||||
}
|
||||
}
|
||||
|
||||
void CAdvMapPanel::showAll(SDL_Surface * to)
|
||||
{
|
||||
if (background)
|
||||
if(background)
|
||||
blitAt(background, pos.x, pos.y, to);
|
||||
|
||||
CIntObject::showAll(to);
|
||||
}
|
||||
|
||||
void CAdvMapPanel::addChildToPanel(CIntObject * obj, ui8 actions)
|
||||
void CAdvMapPanel::addChildToPanel(std::shared_ptr<CIntObject> obj, ui8 actions)
|
||||
{
|
||||
otherObjects.push_back(obj);
|
||||
obj->recActions |= actions | SHOWALL;
|
||||
addChild(obj, false);
|
||||
obj->recActions &= ~DISPOSE;
|
||||
addChild(obj.get(), false);
|
||||
}
|
||||
|
||||
CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color)
|
||||
@@ -1280,7 +1266,7 @@ CAdvMapWorldViewPanel::~CAdvMapWorldViewPanel()
|
||||
SDL_FreeSurface(tmpBackgroundFiller);
|
||||
}
|
||||
|
||||
void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, int indexOffset)
|
||||
void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor & color, int indexOffset)
|
||||
{
|
||||
assert(iconsData.size() == currentIcons.size());
|
||||
|
||||
@@ -1290,9 +1276,9 @@ void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, int indexOffs
|
||||
currentIcons[idx]->setFrame(data.first + indexOffset);
|
||||
}
|
||||
|
||||
if (fillerHeight > 0)
|
||||
if(fillerHeight > 0)
|
||||
{
|
||||
if (tmpBackgroundFiller)
|
||||
if(tmpBackgroundFiller)
|
||||
SDL_FreeSurface(tmpBackgroundFiller);
|
||||
tmpBackgroundFiller = CMessage::drawDialogBox(pos.w, fillerHeight, color);
|
||||
}
|
||||
@@ -1300,9 +1286,9 @@ void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, int indexOffs
|
||||
|
||||
void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, int indexOffset)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
iconsData.push_back(data);
|
||||
currentIcons.push_back(new CAnimImage(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
|
||||
currentIcons.push_back(std::make_shared<CAnimImage>(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
|
||||
}
|
||||
|
||||
void CAdvMapWorldViewPanel::showAll(SDL_Surface * to)
|
||||
|
||||
Reference in New Issue
Block a user