2014-07-05 12:58:42 +03:00
/*
* CArtifactHolder . 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
*
*/
2017-07-13 10:26:03 +02:00
# pragma once
# include "MiscWidgets.h"
2014-07-05 12:58:42 +03:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
struct ArtifactLocation ;
VCMI_LIB_NAMESPACE_END
2014-07-05 12:58:42 +03:00
class CArtifactsOfHero ;
class CAnimImage ;
2014-08-03 14:16:19 +03:00
class CButton ;
2014-07-05 12:58:42 +03:00
class CArtifactHolder
{
public :
CArtifactHolder ( ) ;
virtual void artifactRemoved ( const ArtifactLocation & artLoc ) = 0 ;
virtual void artifactMoved ( const ArtifactLocation & artLoc , const ArtifactLocation & destLoc ) = 0 ;
virtual void artifactDisassembled ( const ArtifactLocation & artLoc ) = 0 ;
virtual void artifactAssembled ( const ArtifactLocation & artLoc ) = 0 ;
} ;
2016-11-04 18:54:09 +02:00
class CArtPlace : public LRClickableAreaWTextComp
2014-07-05 12:58:42 +03:00
{
2016-11-04 18:54:09 +02:00
protected :
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CAnimImage > image ;
2016-11-04 18:54:09 +02:00
virtual void createImage ( ) = 0 ;
public :
const CArtifactInstance * ourArt ; // should be changed only with setArtifact()
2017-07-17 23:04:00 +02:00
CArtPlace ( Point position , const CArtifactInstance * Art = nullptr ) ;
2016-11-04 18:54:09 +02:00
void clickLeft ( tribool down , bool previousState ) override ;
void clickRight ( tribool down , bool previousState ) override ;
virtual void setArtifact ( const CArtifactInstance * art ) = 0 ;
} ;
class CCommanderArtPlace : public CArtPlace
{
protected :
2016-11-06 14:02:00 +02:00
const CGHeroInstance * commanderOwner ;
ArtifactPosition commanderSlotID ;
2016-11-04 18:54:09 +02:00
void createImage ( ) override ;
2016-11-06 14:02:00 +02:00
void returnArtToHeroCallback ( ) ;
2016-11-04 18:54:09 +02:00
public :
2017-07-17 23:04:00 +02:00
CCommanderArtPlace ( Point position , const CGHeroInstance * commanderOwner , ArtifactPosition artSlot , const CArtifactInstance * Art = nullptr ) ;
2016-11-04 18:54:09 +02:00
void clickLeft ( tribool down , bool previousState ) override ;
void clickRight ( tribool down , bool previousState ) override ;
virtual void setArtifact ( const CArtifactInstance * art ) override ;
} ;
/// Artifacts can be placed there. Gets shown at the hero window
class CHeroArtPlace : public CArtPlace
{
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CAnimImage > selection ;
2014-07-05 12:58:42 +03:00
2016-11-04 18:54:09 +02:00
void createImage ( ) override ;
2014-07-05 12:58:42 +03:00
public :
// consider these members as const - change them only with appropriate methods e.g. lockSlot()
bool locked ;
bool picked ;
bool marked ;
ArtifactPosition slotID ; //Arts::EPOS enum + backpack starting from Arts::BACKPACK_START
2016-11-25 18:17:37 +02:00
CArtifactsOfHero * ourOwner ;
2017-07-17 23:04:00 +02:00
CHeroArtPlace ( Point position , const CArtifactInstance * Art = nullptr ) ;
2016-11-25 18:17:37 +02:00
2014-07-05 12:58:42 +03:00
void lockSlot ( bool on ) ;
void pickSlot ( bool on ) ;
void selectSlot ( bool on ) ;
2015-10-12 15:47:10 +02:00
void clickLeft ( tribool down , bool previousState ) override ;
void clickRight ( tribool down , bool previousState ) override ;
2016-11-04 18:54:09 +02:00
void select ( ) ;
void deselect ( ) ;
2015-10-12 15:47:10 +02:00
void showAll ( SDL_Surface * to ) override ;
2014-07-05 12:58:42 +03:00
bool fitsHere ( const CArtifactInstance * art ) const ; //returns true if given artifact can be placed here
void setMeAsDest ( bool backpackAsVoid = true ) ;
2016-11-04 18:54:09 +02:00
void setArtifact ( const CArtifactInstance * art ) override ;
2016-01-23 14:20:51 +02:00
static bool askToAssemble ( const CArtifactInstance * art , ArtifactPosition slot ,
const CGHeroInstance * hero ) ;
2014-07-05 12:58:42 +03:00
} ;
/// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
class CArtifactsOfHero : public CIntObject
{
public :
2018-04-07 13:34:11 +02:00
using ArtPlacePtr = std : : shared_ptr < CHeroArtPlace > ;
using ArtPlaceMap = std : : map < ArtifactPosition , ArtPlacePtr > ;
2014-07-05 12:58:42 +03:00
struct SCommonPart
{
struct Artpos
{
ArtifactPosition slotID ;
const CArtifactsOfHero * AOH ;
const CArtifactInstance * art ;
Artpos ( ) ;
void clear ( ) ;
2016-11-04 18:54:09 +02:00
void setTo ( const CHeroArtPlace * place , bool dontTakeBackpack ) ;
2014-07-05 12:58:42 +03:00
bool valid ( ) ;
bool operator = = ( const ArtifactLocation & al ) const ;
} src , dst ;
std : : set < CArtifactsOfHero * > participants ; // Needed to mark slots.
void reset ( ) ;
2016-08-30 06:05:31 +02:00
} ;
std : : shared_ptr < SCommonPart > commonInfo ; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
2014-07-05 12:58:42 +03:00
bool updateState ; // Whether the commonInfo should be updated on setHero or not.
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CButton > leftArtRoll ;
std : : shared_ptr < CButton > rightArtRoll ;
2014-07-05 12:58:42 +03:00
bool allowedAssembling ;
2018-04-07 13:34:11 +02:00
2014-07-05 12:58:42 +03:00
std : : multiset < const CArtifactInstance * > artifactsOnAltar ; //artifacts id that are technically present in backpack but in GUI are moved to the altar - they'll be omitted in backpack slots
2016-11-04 18:54:09 +02:00
std : : function < void ( CHeroArtPlace * ) > highlightModeCallback ; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
2014-07-05 12:58:42 +03:00
void realizeCurrentTransaction ( ) ; //calls callback with parameters stored in commonInfo
void artifactMoved ( const ArtifactLocation & src , const ArtifactLocation & dst ) ;
void artifactRemoved ( const ArtifactLocation & al ) ;
void artifactAssembled ( const ArtifactLocation & al ) ;
void artifactDisassembled ( const ArtifactLocation & al ) ;
2018-04-07 13:34:11 +02:00
ArtPlacePtr getArtPlace ( int slot ) ; //may return null
2014-07-05 12:58:42 +03:00
void setHero ( const CGHeroInstance * hero ) ;
const CGHeroInstance * getHero ( ) const ;
void dispose ( ) ; //free resources not needed after closing windows and reset state
void scrollBackpack ( int dir ) ; //dir==-1 => to left; dir==1 => to right
void safeRedraw ( ) ;
void markPossibleSlots ( const CArtifactInstance * art ) ;
void unmarkSlots ( bool withRedraw = true ) ; //unmarks slots in all visible AOHs
void unmarkLocalSlots ( bool withRedraw = true ) ; //unmarks slots in that particular AOH
void updateWornSlots ( bool redrawParent = true ) ;
void updateSlot ( ArtifactPosition i ) ;
CArtifactsOfHero ( const Point & position , bool createCommonPart = false ) ;
//Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
2018-04-07 13:34:11 +02:00
CArtifactsOfHero ( ArtPlaceMap ArtWorn , std : : vector < ArtPlacePtr > Backpack ,
std : : shared_ptr < CButton > leftScroll , std : : shared_ptr < CButton > rightScroll , bool createCommonPart = false ) ;
2017-07-17 23:04:00 +02:00
~ CArtifactsOfHero ( ) ;
2014-07-05 12:58:42 +03:00
void updateParentWindow ( ) ;
2016-11-04 18:54:09 +02:00
friend class CHeroArtPlace ;
2018-04-07 13:34:11 +02:00
private :
const CGHeroInstance * curHero ;
ArtPlaceMap artWorn ;
std : : vector < ArtPlacePtr > backpack ; //hero's visible backpack (only 5 elements!)
int backpackPos ; //number of first art visible in backpack (in hero's vector)
void eraseSlotData ( ArtPlacePtr artPlace , ArtifactPosition slotID ) ;
void setSlotData ( ArtPlacePtr artPlace , ArtifactPosition slotID ) ;
} ;
class CWindowWithArtifacts : public CArtifactHolder
{
std : : vector < std : : weak_ptr < CArtifactsOfHero > > artSets ;
public :
void addSet ( std : : shared_ptr < CArtifactsOfHero > artSet ) ;
std : : shared_ptr < CArtifactsOfHero : : SCommonPart > getCommonPart ( ) ;
void artifactRemoved ( const ArtifactLocation & artLoc ) override ;
void artifactMoved ( const ArtifactLocation & artLoc , const ArtifactLocation & destLoc ) override ;
void artifactDisassembled ( const ArtifactLocation & artLoc ) override ;
void artifactAssembled ( const ArtifactLocation & artLoc ) override ;
2014-07-05 12:58:42 +03:00
} ;