1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Merge branch 'feature/worldView' into develop

This commit is contained in:
AlexVinS
2015-02-01 20:49:14 +03:00
15 changed files with 1658 additions and 662 deletions

View File

@@ -96,7 +96,7 @@ static bool objectBlitOrderSorter(const std::pair<const CGObjectInstance*,SDL_Re
CPlayerInterface::CPlayerInterface(PlayerColor Player)
{
logGlobal->traceStream() << "\tHuman player interface for player " << Player << " being constructed";
logGlobal->traceStream() << "\tHuman player interface for player " << Player << " being constructed";
observerInDuelMode = false;
howManyPeople++;
GH.defActionsDef = 0;
@@ -115,7 +115,7 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player)
firstCall = 1; //if loading will be overwritten in serialize
autosaveCount = 0;
isAutoFightOn = false;
duringMovement = false;
ignoreEvents = false;
locked = false;
@@ -143,6 +143,8 @@ void CPlayerInterface::init(shared_ptr<CCallback> CB)
if(!adventureInt)
adventureInt = new CAdvMapInt();
else
adventureInt->restoreState();
}
void CPlayerInterface::yourTurn()
{
@@ -768,7 +770,7 @@ void CPlayerInterface::actionFinished(const BattleAction &action)
BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when it's turn of that stack
{
THREAD_CREATED_BY_CLIENT;
logGlobal->traceStream() << "Awaiting command for " << stack->nodeName();
logGlobal->traceStream() << "Awaiting command for " << stack->nodeName();
if(autofightingAI)
{
@@ -813,7 +815,7 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i
b->givenCommand->data = nullptr;
//return command
logGlobal->traceStream() << "Giving command for " << stack->nodeName();
logGlobal->traceStream() << "Giving command for " << stack->nodeName();
return ret;
}
@@ -876,7 +878,7 @@ void CPlayerInterface::battleStacksAttacked(const std::vector<BattleStackAttacke
{
EVENT_HANDLER_CALLED_BY_CLIENT;
BATTLE_EVENT_POSSIBLE_RETURN;
std::vector<StackAttackedInfo> arg;
for(auto & elem : bsa)
{
@@ -890,7 +892,7 @@ void CPlayerInterface::battleStacksAttacked(const std::vector<BattleStackAttacke
if(elem.isSpell())
{
if (defender)
battleInt->displaySpellEffect(elem.spellID, defender->position);
battleInt->displaySpellEffect(elem.spellID, defender->position);
}
//FIXME: why action is deleted during enchanter cast?
bool remoteAttack = false;
@@ -973,14 +975,14 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba)
const CStack * attacked = cb->battleGetStackByID(ba->bsa.begin()->stackAttacked);
battleInt->stackAttacking( attacker, ba->counter() ? curAction->destinationTile + shift : curAction->additionalInfo, attacked, false);
}
//battleInt->waitForAnims(); //FIXME: freeze
if(ba->spellLike())
{
//display hit animation
SpellID spellID = ba->spellID;
battleInt->displaySpellHit(spellID,curAction->destinationTile);
//display hit animation
SpellID spellID = ba->spellID;
battleInt->displaySpellHit(spellID,curAction->destinationTile);
}
}
void CPlayerInterface::battleObstaclePlaced(const CObstacleInstance &obstacle)
@@ -1264,15 +1266,15 @@ template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, c
{
h & pathsMap;
if(cb)
for(auto &p : pathsMap)
{
CGPath path;
cb->getPathsInfo(p.first)->getPath(p.second, path);
paths[p.first] = path;
logGlobal->traceStream() << boost::format("Restored path for hero %s leading to %s with %d nodes")
% p.first->nodeName() % p.second % path.nodes.size();
}
if(cb)
for(auto &p : pathsMap)
{
CGPath path;
cb->getPathsInfo(p.first)->getPath(p.second, path);
paths[p.first] = path;
logGlobal->traceStream() << boost::format("Restored path for hero %s leading to %s with %d nodes")
% p.first->nodeName() % p.second % path.nodes.size();
}
}
h & spellbookSettings;
@@ -1293,7 +1295,7 @@ void CPlayerInterface::loadGame( CISer & h, const int version )
void CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
{
logGlobal->traceStream() << __FUNCTION__;
logGlobal->traceStream() << __FUNCTION__;
if(!LOCPLINT->makingTurn)
return;
if (!h)
@@ -1304,7 +1306,7 @@ void CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
return;
duringMovement = true;
if (adventureInt && adventureInt->isHeroSleeping(h))
{
adventureInt->sleepWake->clickLeft(true, false);
@@ -1313,10 +1315,10 @@ void CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
//adventureInt->fsleepWake();
//but no authentic button click/sound ;-)
}
boost::thread moveHeroTask(std::bind(&CPlayerInterface::doMoveHero,this,h,path));
}
bool CPlayerInterface::shiftPressed() const
@@ -1480,7 +1482,7 @@ void CPlayerInterface::waitWhileDialog(bool unlockPim /*= true*/)
{
if(GH.amIGuiThread())
{
logGlobal->warnStream() << "Cannot wait for dialogs in gui thread (deadlock risk)!";
logGlobal->warnStream() << "Cannot wait for dialogs in gui thread (deadlock risk)!";
return;
}
@@ -1539,7 +1541,7 @@ void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )
EVENT_HANDLER_CALLED_BY_CLIENT;
if (LOCPLINT->cb->getCurrentPlayer() == playerID) {
std::string handlerName = VLC->objtypeh->getObjectHandlerName(obj->ID);
if ((handlerName == "pickable") || (handlerName == "scholar") || (handlerName== "artifact") || (handlerName == "pandora")) {
if ((handlerName == "pickable") || (handlerName == "scholar") || (handlerName== "artifact") || (handlerName == "pandora")) {
waitWhileDialog();
CCS->soundh->playSoundFromSet(CCS->soundh->pickupSounds);
} else if ((handlerName == "monster") || (handlerName == "hero")) {
@@ -1626,11 +1628,11 @@ void CPlayerInterface::runLocked(std::function<void(IUpdateable * )> functor)
// While mutexes were locked away we may be have stopped being the active interface
if(LOCPLINT != this)
return;
// Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
locked = true;
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
locked = true;
functor(this);
locked = false;
}
@@ -2171,6 +2173,11 @@ void CPlayerInterface::showPuzzleMap()
GH.pushInt(new CPuzzleWindow(grailPos, ratio));
}
void CPlayerInterface::viewWorldMap()
{
adventureInt->changeMode(EAdvMapMode::WORLD_VIEW);
}
void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellID)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
@@ -2179,7 +2186,7 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellI
eraseCurrentPathOf(caster, false);
}
const CSpell * spell = CGI->spellh->objects[spellID];
auto castSoundPath = spell->getCastSound();
if (!castSoundPath.empty())
CCS->soundh->playSound(castSoundPath);
@@ -2216,7 +2223,7 @@ CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h)
CGPath &path = paths[h];
if(!path.nodes.size())
{
logGlobal->warnStream() << "Warning: empty path found...";
logGlobal->warnStream() << "Warning: empty path found...";
paths.erase(h);
}
else
@@ -2601,7 +2608,7 @@ bool CPlayerInterface::capturedAllEvents()
//just inform that we are capturing events. they will be processed by heroMoved() in client thread.
return true;
}
if(ignoreEvents)
{
boost::unique_lock<boost::mutex> un(eventsM);
@@ -2611,7 +2618,7 @@ bool CPlayerInterface::capturedAllEvents()
}
return true;
}
return false;
}
@@ -2690,7 +2697,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance* h, CGPath path)
// (i == 0) means hero went through all the path
adventureInt->updateMoveHero(h, (i != 0));
adventureInt->updateNextHero(h);
}
}
duringMovement = false;
}

View File

@@ -170,6 +170,7 @@ public:
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, QueryID askID, int soundID, bool selection, bool cancel) override; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID) override;
void showPuzzleMap() override;
void viewWorldMap() override;
void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor) override;
void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor) override;
void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor) override;
@@ -267,15 +268,15 @@ public:
~CPlayerInterface();//d-tor
static CondSh<bool> terminate_cond; // confirm termination
private:
template <typename Handler> void serializeTempl(Handler &h, const int version);
private:
private:
struct IgnoreEvents
{
CPlayerInterface & owner;
@@ -287,16 +288,16 @@ private:
{
owner.ignoreEvents = false;
};
};
bool duringMovement;
bool ignoreEvents;
bool locked;
void doMoveHero(const CGHeroInstance *h, CGPath path);
};

View File

@@ -12,7 +12,7 @@ IShowActivatable::IShowActivatable()
void ILockedUpdatable::runLocked(std::function<void(IUpdateable*)> cb)
{
boost::unique_lock<boost::recursive_mutex> lock(updateGuard);
boost::unique_lock<boost::recursive_mutex> lock(updateGuard);
cb(this);
}
@@ -82,7 +82,7 @@ void CIntObject::activate()
return;
else
{
logGlobal->warnStream() << "Warning: IntObject re-activated with mismatching used and active";
logGlobal->warnStream() << "Warning: IntObject re-activated with mismatching used and active";
deactivate(); //FIXME: better to avoid such possibility at all
}
}
@@ -145,6 +145,11 @@ void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font
graphics->fonts[font]->renderTextLeft(dst, text, kolor, Point(pos.x + x, pos.y + y));
}
void CIntObject::printAtRightLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
{
graphics->fonts[font]->renderTextRight(dst, text, kolor, Point(pos.x + x, pos.y + y));
}
void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
{
printAtMiddleLoc(text, Point(x,y), font, kolor, dst);
@@ -312,8 +317,8 @@ const Rect & CIntObject::center( bool propagate )
const Rect & CIntObject::center(const Point &p, bool propagate /*= true*/)
{
moveBy(Point(p.x - pos.w/2 - pos.x,
p.y - pos.h/2 - pos.y),
moveBy(Point(p.x - pos.w/2 - pos.x,
p.y - pos.h/2 - pos.y),
propagate);
return pos;
}
@@ -333,7 +338,7 @@ CKeyShortcut::CKeyShortcut(int key)
}
CKeyShortcut::CKeyShortcut(std::set<int> Keys)
:assignedKeys(Keys)
:assignedKeys(Keys)
{}
void CKeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
@@ -342,12 +347,12 @@ void CKeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
|| vstd::contains(assignedKeys, CGuiHandler::numToDigit(key.keysym.sym)))
{
bool prev = pressedL;
if(key.state == SDL_PRESSED)
if(key.state == SDL_PRESSED)
{
pressedL = true;
clickLeft(true, prev);
}
else
}
else
{
pressedL = false;
clickLeft(false, prev);

View File

@@ -7,7 +7,7 @@
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include <SDL_events.h>
@@ -42,8 +42,8 @@ class ILockedUpdatable: public IUpdateable
{
boost::recursive_mutex updateGuard;
public:
virtual void runLocked(std::function<void(IUpdateable * )> cb);
virtual ~ILockedUpdatable(){}; //d-tor
virtual void runLocked(std::function<void(IUpdateable * )> cb);
virtual ~ILockedUpdatable(){}; //d-tor
};
// Defines a show method
@@ -97,7 +97,7 @@ public:
* Don't use them unless you really know what they are for
*/
std::vector<CIntObject *> children;
//FIXME: workaround
void deactivateKeyboard()
{
@@ -133,7 +133,7 @@ public:
bool captureAllKeys; //if true, only this object should get info about pressed keys
virtual void keyPressed(const SDL_KeyboardEvent & key){}
virtual bool captureThisEvent(const SDL_KeyboardEvent & key); //allows refining captureAllKeys against specific events (eg. don't capture ENTER)
#ifndef VCMI_SDL1
virtual void textInputed(const SDL_TextInputEvent & event){};
virtual void textEdited(const SDL_TextEditingEvent & event){};
@@ -201,6 +201,7 @@ public:
//functions for printing text. Use CLabel where possible instead
void printAtLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
void printToLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
void printAtRightLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
void printAtMiddleLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
void printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color color, SDL_Surface * dst);
void printAtMiddleWBLoc(const std::string & text, int x, int y, EFonts font, int charsPerLine, SDL_Color color, SDL_Surface * dst);

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
#include "../lib/int3.h"
#include "gui/Geometries.h"
#include "SDL.h"
/*
@@ -22,9 +23,33 @@ class CGObjectInstance;
class CDefHandler;
struct TerrainTile;
struct SDL_Surface;
//struct SDL_Rect;
struct SDL_Rect;
class CDefEssential;
enum class EWorldViewIcon
{
TOWN = 0,
HERO,
ARTIFACT,
TELEPORT,
GATE,
MINE_WOOD,
MINE_MERCURY,
MINE_STONE,
MINE_SULFUR,
MINE_CRYSTAL,
MINE_GEM,
MINE_GOLD,
RES_WOOD,
RES_MERCURY,
RES_STONE,
RES_SULFUR,
RES_CRYSTAL,
RES_GEM,
RES_GOLD,
};
struct TerrainTile2
{
SDL_Surface * terbitmap; //bitmap of terrain
@@ -33,6 +58,43 @@ struct TerrainTile2
TerrainTile2();
};
struct MapDrawingInfo
{
bool scaled;
int3 &topTile; // top-left tile in viewport [in tiles]
const std::vector< std::vector< std::vector<ui8> > > * visibilityMap;
SDL_Rect * drawBounds; // map rect drawing bounds on screen
CDefHandler * iconsDef; // holds overlay icons for world view mode
float scale; // map scale for world view mode (only if scaled == true)
bool otherheroAnim;
ui8 anim;
ui8 heroAnim;
int3 movement; // used for smooth map movement
bool puzzleMode;
int3 grailPos; // location of grail for puzzle mode [in tiles]
MapDrawingInfo(int3 &topTile_, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap_, SDL_Rect * drawBounds_, CDefHandler * iconsDef_ = nullptr)
: scaled(false),
topTile(topTile_),
visibilityMap(visibilityMap_),
drawBounds(drawBounds_),
iconsDef(iconsDef_),
scale(1.0f),
otherheroAnim(false),
anim(0u),
heroAnim(0u),
movement(int3()),
puzzleMode(false),
grailPos(int3())
{}
ui8 getHeroAnim() const { return otherheroAnim ? anim : heroAnim; }
};
template <typename T> class PseudoV
{
public:
@@ -69,9 +131,160 @@ private:
int offset;
std::vector<T> inver;
};
class CMapHandler
{
enum class EMapCacheType
{
TERRAIN, TERRAIN_CUSTOM, OBJECTS, ROADS, RIVERS, FOW, HEROES, HERO_FLAGS, FRAME
};
/// temporarily caches rescaled sdl surfaces for map world view redrawing
class CMapCache
{
std::map<EMapCacheType, std::map<intptr_t, SDL_Surface *>> data;
float worldViewCachedScale;
public:
/// destroys all cached data (frees surfaces)
void discardWorldViewCache();
/// updates scale and determines if currently cached data is still valid
void updateWorldViewScale(float scale);
void removeFromWorldViewCache(EMapCacheType type, intptr_t key);
/// asks for cached data; @returns cached surface or nullptr if data is not in cache
SDL_Surface * requestWorldViewCache(EMapCacheType type, intptr_t key);
/// asks for cached data; @returns cached data if found, new scaled surface otherwise
SDL_Surface * requestWorldViewCacheOrCreate(EMapCacheType type, intptr_t key, SDL_Surface * fullSurface, float scale);
SDL_Surface * cacheWorldViewEntry(EMapCacheType type, intptr_t key, SDL_Surface * entry);
intptr_t genKey(intptr_t realPtr, ui8 mod);
};
class CMapBlitter
{
protected:
CMapHandler * parent; // ptr to enclosing map handler; generally for legacy reasons, probably could/should be refactored out of here
int tileSize; // size of a tile drawn on map [in pixels]
int halfTileSizeCeil; // half of the tile size, rounded up
int3 tileCount; // number of tiles in current viewport
int3 topTile; // top-left tile of the viewport
int3 initPos; // starting drawing position [in pixels]
int3 pos; // current position [in tiles]
int3 realPos; // current position [in pixels]
Rect realTileRect; // default rect based on current pos: [realPos.x, realPos.y, tileSize, tileSize]
Rect defaultTileRect; // default rect based on 0: [0, 0, tileSize, tileSize]
const MapDrawingInfo * info; // data for drawing passed from outside
/// general drawing method, called internally by more specialized ones
virtual void drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect,
SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit = false, ui8 rotationInfo = 0u) const = 0;
// first drawing pass
/// draws terrain bitmap (or custom bitmap if applicable) on current tile
virtual void drawTileTerrain(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile2 & tile) const;
/// draws a river segment on current tile
virtual void drawRiver(SDL_Surface * targetSurf, const TerrainTile & tinfo) const;
/// draws a road segment on current tile
virtual void drawRoad(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const;
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
virtual void drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const;
/// current tile: draws non-hero object with given image/position
virtual void drawNormalObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect) const;
virtual void drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;
virtual void drawHero(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const;
// second drawing pass
/// current tile: draws overlay over the map, used to draw world view icons
virtual void drawTileOverlay(SDL_Surface * targetSurf, const TerrainTile2 & tile) const = 0;
/// draws fog of war on current tile
virtual void drawFow(SDL_Surface * targetSurf) const;
/// draws map border frame on current position
virtual void drawFrame(SDL_Surface * targetSurf) const;
// third drawing pass
/// custom post-processing, if needed (used by puzzle view)
virtual void postProcessing(SDL_Surface * targetSurf) const {}
// misc methods
/// initializes frame-drawing (called at the start of every redraw)
virtual void init(const MapDrawingInfo * drawingInfo) = 0;
/// calculates clip region for map viewport
virtual SDL_Rect clip(SDL_Surface * targetSurf) const = 0;
virtual ui8 getHeroFrameNum(ui8 dir, bool isMoving) const;
///returns appropriate bitmap and info if alpha blitting is necessary
virtual std::pair<SDL_Surface *, bool> getVisBitmap() const;
virtual ui8 getPhaseShift(const CGObjectInstance *object) const;
virtual bool canDrawObject(const CGObjectInstance * obj) const;
virtual bool canDrawCurrentTile() const;
public:
CMapBlitter(CMapHandler * p) : parent(p) {}
virtual ~CMapBlitter(){}
void blit(SDL_Surface * targetSurf, const MapDrawingInfo * info);
};
class CMapNormalBlitter : public CMapBlitter
{
protected:
void drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect,
SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit = false, ui8 rotationInfo = 0u) const override;
void drawTileOverlay(SDL_Surface * targetSurf,const TerrainTile2 & tile) const override {}
void init(const MapDrawingInfo * info) override;
SDL_Rect clip(SDL_Surface * targetSurf) const override;
public:
CMapNormalBlitter(CMapHandler * parent);
virtual ~CMapNormalBlitter(){}
};
class CMapWorldViewBlitter : public CMapBlitter
{
protected:
void drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect,
SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit = false, ui8 rotationInfo = 0u) const override;
void drawTileOverlay(SDL_Surface * targetSurf, const TerrainTile2 & tile) const override;
void drawNormalObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect) const override;
void drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const override;
void drawHero(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const;
void drawFrame(SDL_Surface * targetSurf) const override {}
void init(const MapDrawingInfo * info) override;
SDL_Rect clip(SDL_Surface * targetSurf) const override;
ui8 getHeroFrameNum(ui8 dir, bool isMoving) const override { return 0u; }
ui8 getPhaseShift(const CGObjectInstance *object) const override { return 0u; }
void drawScaledRotatedElement(EMapCacheType type, SDL_Surface * baseSurf, SDL_Surface * targetSurf, ui8 rotation,
float scale, SDL_Rect * dstRect, SDL_Rect * srcRect = nullptr) const;
void calculateWorldViewCameraPos();
public:
CMapWorldViewBlitter(CMapHandler * parent);
virtual ~CMapWorldViewBlitter(){}
};
class CMapPuzzleViewBlitter : public CMapNormalBlitter
{
std::vector<int> unblittableObjects;
void drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const override;
void drawFow(SDL_Surface * targetSurf) const override {} // skipping FoW in puzzle view
void postProcessing(SDL_Surface * targetSurf) const override;
bool canDrawObject(const CGObjectInstance * obj) const override;
bool canDrawCurrentTile() const override { return true; }
public:
CMapPuzzleViewBlitter(CMapHandler * parent);
};
CMapCache cache;
CMapBlitter * normalBlitter;
CMapBlitter * worldViewBlitter;
CMapBlitter * puzzleViewBlitter;
CMapBlitter * resolveBlitter(const MapDrawingInfo * info) const;
public:
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; //informations about map tiles
int3 sizes; //map size (x = width, y = height, z = number of levels)
@@ -105,9 +318,6 @@ public:
CMapHandler(); //c-tor
~CMapHandler(); //d-tor
std::pair<SDL_Surface *, bool> getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector<ui8> > > & visibilityMap) const; //returns appropriate bitmap and info if alpha blitting is necessary
ui8 getPhaseShift(const CGObjectInstance *object) const;
void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
@@ -120,12 +330,12 @@ public:
void roadsRiverTerrainInit();
void prepareFOWDefs();
void terrainRect(int3 top_tile, ui8 anim, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, bool otherHeroAnim, ui8 heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel) const;
void drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info);
void updateWater();
ui8 getHeroFrameNum(ui8 dir, bool isMoving) const; //terrainRect helper function
void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
static ui8 getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
void discardWorldViewCache();
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
};

View File

@@ -8,9 +8,11 @@
#include "../CGameInfo.h"
#include "../CMusicHandler.h"
#include "../CDefHandler.h"
#include "../CPlayerInterface.h"
#include "../CPreGame.h"
#include "../Graphics.h"
#include "../CMessage.h"
#include "../gui/CGuiHandler.h"
#include "../gui/SDL_Pixels.h"
@@ -47,9 +49,9 @@
*/
CList::CListItem::CListItem(CList * Parent):
CIntObject(LCLICK | RCLICK | HOVER),
parent(Parent),
selection(nullptr)
CIntObject(LCLICK | RCLICK | HOVER),
parent(Parent),
selection(nullptr)
{
}
@@ -100,10 +102,10 @@ void CList::CListItem::onSelect(bool on)
}
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),
size(Size),
selected(nullptr)
int helpUp, int helpDown, CListBox::CreateFunc create, CListBox::DestroyFunc destroy):
CIntObject(0, position),
size(Size),
selected(nullptr)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
scrollUp = new CButton(Point(0, 0), btnUp, CGI->generaltexth->zelp[helpUp]);
@@ -194,8 +196,8 @@ CHeroList::CEmptyHeroItem::CEmptyHeroItem()
}
CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero):
CListItem(parent),
hero(Hero)
CListItem(parent),
hero(Hero)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
movement = new CAnimImage("IMOBIL", 0, 0, 0, 1);
@@ -249,7 +251,7 @@ CIntObject * CHeroList::createHeroItem(size_t index)
}
CHeroList::CHeroList(int size, Point position, std::string btnUp, std::string btnDown):
CList(size, position, btnUp, btnDown, LOCPLINT->wanderingHeroes.size(), 303, 304, std::bind(&CHeroList::createHeroItem, this, _1))
CList(size, position, btnUp, btnDown, LOCPLINT->wanderingHeroes.size(), 303, 304, std::bind(&CHeroList::createHeroItem, this, _1))
{
}
@@ -290,8 +292,8 @@ CIntObject * CTownList::createTownItem(size_t index)
}
CTownList::CTownItem::CTownItem(CTownList *parent, const CGTownInstance *Town):
CListItem(parent),
town(Town)
CListItem(parent),
town(Town)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
picture = new CAnimImage("ITPA", 0);
@@ -334,7 +336,7 @@ std::string CTownList::CTownItem::getHoverText()
}
CTownList::CTownList(int size, Point position, std::string btnUp, std::string btnDown):
CList(size, position, btnUp, btnDown, LOCPLINT->towns.size(), 306, 307, std::bind(&CTownList::createTownItem, this, _1))
CList(size, position, btnUp, btnDown, LOCPLINT->towns.size(), 306, 307, std::bind(&CTownList::createTownItem, this, _1))
{
}
@@ -460,9 +462,9 @@ void CMinimapInstance::drawScaled(int level)
}
CMinimapInstance::CMinimapInstance(CMinimap *Parent, int Level):
parent(Parent),
minimap(CSDL_Ext::createSurfaceWithBpp<4>(parent->pos.w, parent->pos.h)),
level(Level)
parent(Parent),
minimap(CSDL_Ext::createSurfaceWithBpp<4>(parent->pos.w, parent->pos.h)),
level(Level)
{
pos.w = parent->pos.w;
pos.h = parent->pos.h;
@@ -479,7 +481,7 @@ void CMinimapInstance::showAll(SDL_Surface *to)
blitAtLoc(minimap, 0, 0, to);
//draw heroes
std::vector <const CGHeroInstance *> heroes = LOCPLINT->cb->getHeroesInfo(false); //TODO: do we really need separate function for drawing heroes?
std::vector <const CGHeroInstance *> heroes = LOCPLINT->cb->getHeroesInfo(false); //TODO: do we really need separate function for drawing heroes?
for(auto & hero : heroes)
{
int3 position = hero->getPosition(false);
@@ -502,7 +504,7 @@ std::map<int, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors(std::string
auto index = boost::find(GameConstants::TERRAIN_NAMES, m.first);
if (index == std::end(GameConstants::TERRAIN_NAMES))
{
logGlobal->errorStream() << "Error: unknown terrain in terrains.json: " << m.first;
logGlobal->errorStream() << "Error: unknown terrain in terrains.json: " << m.first;
continue;
}
int terrainID = index - std::begin(GameConstants::TERRAIN_NAMES);
@@ -531,11 +533,11 @@ std::map<int, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors(std::string
}
CMinimap::CMinimap(const Rect &position):
CIntObject(LCLICK | RCLICK | HOVER | MOVE, position.topLeft()),
aiShield(nullptr),
minimap(nullptr),
level(0),
colors(loadColors("config/terrains.json"))
CIntObject(LCLICK | RCLICK | HOVER | MOVE, position.topLeft()),
aiShield(nullptr),
minimap(nullptr),
level(0),
colors(loadColors("config/terrains.json"))
{
pos.w = position.w;
pos.h = position.h;
@@ -595,6 +597,7 @@ void CMinimap::showAll(SDL_Surface * to)
if (minimap)
{
int3 mapSizes = LOCPLINT->cb->getMapSize();
int3 tileCountOnScreen = adventureInt->terrain.tileCountOnScreen();
//draw radar
SDL_Rect oldClip;
@@ -602,10 +605,20 @@ void CMinimap::showAll(SDL_Surface * to)
{
si16(adventureInt->position.x * pos.w / mapSizes.x + pos.x),
si16(adventureInt->position.y * pos.h / mapSizes.y + pos.y),
ui16(adventureInt->terrain.tilesw * pos.w / mapSizes.x),
ui16(adventureInt->terrain.tilesh * pos.h / mapSizes.y)
ui16(tileCountOnScreen.x * pos.w / mapSizes.x),
ui16(tileCountOnScreen.y * pos.h / mapSizes.y)
};
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(std::max(pos.x, radar.x), pos.x + pos.w - radar.w);
radar.y = std::min(std::max(pos.y, radar.y), pos.y + pos.h - radar.h);
if (radar.x < pos.x && radar.y < pos.y)
return; // whole map is visible at once, no point in redrawing border
}
SDL_GetClipRect(to, &oldClip);
SDL_SetClipRect(to, &pos);
CSDL_Ext::drawDashedBorder(to, radar, int3(255,75,125));
@@ -662,8 +675,8 @@ void CMinimap::showTile(const int3 &pos)
}
CInfoBar::CVisibleInfo::CVisibleInfo(Point position):
CIntObject(0, position),
aiProgress(nullptr)
CIntObject(0, position),
aiProgress(nullptr)
{
}
@@ -898,10 +911,10 @@ void CInfoBar::hover(bool on)
}
CInfoBar::CInfoBar(const Rect &position):
CIntObject(LCLICK | RCLICK | HOVER, position.topLeft()),
visibleInfo(nullptr),
state(EMPTY),
currentObject(nullptr)
CIntObject(LCLICK | RCLICK | HOVER, position.topLeft()),
visibleInfo(nullptr),
state(EMPTY),
currentObject(nullptr)
{
pos.w = position.w;
pos.h = position.h;
@@ -1212,3 +1225,115 @@ CInGameConsole::CInGameConsole() : prevEntDisp(-1), defaultTimeout(10000), maxDi
addUsedEvents(KEYBOARD | TEXTINPUT);
#endif
}
CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position)
: CIntObject(),
background(bg)
{
defActions = 255;
recActions = 255;
pos.x += position.x;
pos.y += position.y;
if (bg)
{
pos.w = bg->w;
pos.h = bg->h;
}
}
CAdvMapPanel::~CAdvMapPanel()
{
if (background)
SDL_FreeSurface(background);
}
void CAdvMapPanel::addChildColorableButton(CButton * btn)
{
buttons.push_back(btn);
addChildToPanel(btn, ACTIVATE | DEACTIVATE);
}
void CAdvMapPanel::setPlayerColor(const PlayerColor & clr)
{
for (auto &btn : buttons)
{
btn->setPlayerColor(clr);
}
}
void CAdvMapPanel::showAll(SDL_Surface * to)
{
if (background)
blitAt(background, pos.x, pos.y, to);
CIntObject::showAll(to);
}
void CAdvMapPanel::addChildToPanel(CIntObject * obj, ui8 actions /* = 0 */)
{
obj->recActions |= actions | SHOWALL;
addChild(obj, false);
}
CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color)
: CAdvMapPanel(bg, position)
{
fillerHeight = bg ? spaceBottom - pos.y - pos.h : 0;
if (fillerHeight > 0)
{
tmpBackgroundFiller = CMessage::drawDialogBox(pos.w, fillerHeight, color);
}
else
tmpBackgroundFiller = nullptr;
}
CAdvMapWorldViewPanel::~CAdvMapWorldViewPanel()
{
if (tmpBackgroundFiller)
SDL_FreeSurface(tmpBackgroundFiller);
}
void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, const CDefHandler *def, int indexOffset)
{
for (auto &pic : currentIcons)
{
removeChild(pic);
delete pic;
}
currentIcons.clear();
for (auto &data : iconsData)
{
auto pic = new CPicture(def->ourImages[data.first + indexOffset].bitmap, data.second.x, data.second.y, false);
pic->recActions |= SHOWALL;
currentIcons.push_back(pic);
addChildToPanel(pic);
}
if (fillerHeight > 0)
{
if (tmpBackgroundFiller)
SDL_FreeSurface(tmpBackgroundFiller);
tmpBackgroundFiller = CMessage::drawDialogBox(pos.w, fillerHeight, color);
}
}
void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, const CDefHandler *def, int indexOffset)
{
iconsData.push_back(data);
auto pic = new CPicture(def->ourImages[data.first + indexOffset].bitmap, data.second.x, data.second.y, false);
currentIcons.push_back(pic);
addChildToPanel(pic);
}
void CAdvMapWorldViewPanel::showAll(SDL_Surface * to)
{
if (tmpBackgroundFiller)
{
blitAt(tmpBackgroundFiller, pos.x, pos.y + pos.h, to);
}
CAdvMapPanel::showAll(to);
}

View File

@@ -71,7 +71,7 @@ protected:
* @param destroy - function for deleting items in listbox
*/
CList(int size, Point position, std::string btnUp, std::string btnDown, size_t listAmount, int helpUp, int helpDown,
CListBox::CreateFunc create, CListBox::DestroyFunc destroy = CListBox::DestroyFunc());
CListBox::CreateFunc create, CListBox::DestroyFunc destroy = CListBox::DestroyFunc());
//for selection\deselection
CListItem *selected;
@@ -315,6 +315,45 @@ public:
void showGameStatus();
};
/// simple panel that contains other displayable elements; used to separate groups of controls
class CAdvMapPanel : public CIntObject
{
/// ptrs to child-buttons that can be recolored with setPlayerColor()
std::vector<CButton *> buttons;
/// the surface passed to this obj will be freed in dtor
SDL_Surface * background;
public:
CAdvMapPanel(SDL_Surface * bg, Point position);
virtual ~CAdvMapPanel();
void addChildToPanel(CIntObject * obj, ui8 actions = 0);
void addChildColorableButton(CButton * btn);
/// recolors all buttons to given player color
void setPlayerColor(const PlayerColor & clr);
void showAll(SDL_Surface * to);
};
/// specialized version of CAdvMapPanel that handles recolorable def-based pictures for world view info panel
class CAdvMapWorldViewPanel : public CAdvMapPanel
{
/// data that allows reconstruction of panel info icons
std::vector<std::pair<int, Point>> iconsData;
/// ptrs to child-pictures constructed from iconsData
std::vector<CPicture *> currentIcons;
/// temporary surface drawn below world view panel on higher resolutions (won't be needed when world view panel is configured for extraResolutions mod)
SDL_Surface * tmpBackgroundFiller;
int fillerHeight;
public:
CAdvMapWorldViewPanel(SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color);
virtual ~CAdvMapWorldViewPanel();
void addChildIcon(std::pair<int, Point> data, const CDefHandler *def, int indexOffset);
/// recreates all pictures from given def to recolor them according to current player color
void recolorIcons(const PlayerColor &color, const CDefHandler *def, int indexOffset);
void showAll(SDL_Surface * to);
};
class CInGameConsole : public CIntObject
{
private:

View File

@@ -61,7 +61,7 @@ CAdvMapInt *adventureInt;
CTerrainRect::CTerrainRect()
:curHoveredTile(-1,-1,-1), currentPath(nullptr)
: curHoveredTile(-1,-1,-1), currentPath(nullptr)
{
tilesw=(ADVOPT.advmapW+31)/32;
tilesh=(ADVOPT.advmapH+31)/32;
@@ -81,6 +81,8 @@ void CTerrainRect::deactivate()
void CTerrainRect::clickLeft(tribool down, bool previousState)
{
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
return;
if ((down==false) || indeterminate(down))
return;
@@ -93,6 +95,8 @@ void CTerrainRect::clickLeft(tribool down, bool previousState)
void CTerrainRect::clickRight(tribool down, bool previousState)
{
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
return;
int3 mp = whichTileIsIt();
if (CGI->mh->map->isInTheMap(mp) && down)
@@ -260,22 +264,37 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
void CTerrainRect::show(SDL_Surface * to)
{
if(ADVOPT.smoothMove)
CGI->mh->terrainRect
(adventureInt->position, adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
to, &pos, moveX, moveY, false, int3());
else
CGI->mh->terrainRect
(adventureInt->position, adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
to, &pos, 0, 0, false, int3());
if (adventureInt->mode == EAdvMapMode::NORMAL)
{
MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos);
info.otherheroAnim = true;
info.anim = adventureInt->anim;
info.heroAnim = adventureInt->heroAnim;
if (ADVOPT.smoothMove)
info.movement = int3(moveX, moveY, 0);
CGI->mh->drawTerrainRectNew(to, &info);
if (currentPath/* && adventureInt->position.z==currentPath->startPos().z*/) //drawing path
{
showPath(&pos, to);
}
}
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
//SDL_FreeSurface(teren);
if (currentPath/* && adventureInt->position.z==currentPath->startPos().z*/) //drawing path
}
void CTerrainRect::showAll(SDL_Surface * to)
{
// world view map is static and doesn't need redraw every frame
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
{
showPath(&pos, to);
MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos, adventureInt->worldViewIconsDef);
info.scaled = true;
info.scale = adventureInt->worldViewScale;
CGI->mh->drawTerrainRectNew(to, &info);
}
}
@@ -293,6 +312,20 @@ int3 CTerrainRect::whichTileIsIt()
return whichTileIsIt(GH.current->motion.x,GH.current->motion.y);
}
int3 CTerrainRect::tileCountOnScreen()
{
switch (adventureInt->mode)
{
default:
logGlobal->errorStream() << "Unhandled map mode " << (int)adventureInt->mode;
return int3();
case EAdvMapMode::NORMAL:
return int3(tilesw, tilesh, 1);
case EAdvMapMode::WORLD_VIEW:
return int3(tilesw / adventureInt->worldViewScale, tilesh / adventureInt->worldViewScale, 1);
}
}
void CResDataBar::clickRight(tribool down, bool previousState)
{
}
@@ -300,7 +333,7 @@ void CResDataBar::clickRight(tribool down, bool previousState)
CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
{
bg = BitmapHandler::loadBitmap(defname);
CSDL_Ext::setDefaultColorKey(bg);
CSDL_Ext::setDefaultColorKey(bg);
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
pos = genRect(bg->h, bg->w, pos.x+x, pos.y+y);
@@ -319,7 +352,7 @@ CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int
CResDataBar::CResDataBar()
{
bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
CSDL_Ext::setDefaultColorKey(bg);
CSDL_Ext::setDefaultColorKey(bg);
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
@@ -367,11 +400,13 @@ void CResDataBar::showAll(SDL_Surface * to)
}
CAdvMapInt::CAdvMapInt():
minimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH)),
statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
heroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD),
townList(ADVOPT.tlistSize, Point(ADVOPT.tlistX, ADVOPT.tlistY), ADVOPT.tlistAU, ADVOPT.tlistAD),
infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
mode(EAdvMapMode::NORMAL),
minimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH)),
statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
heroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD),
townList(ADVOPT.tlistSize, Point(ADVOPT.tlistX, ADVOPT.tlistY), ADVOPT.tlistAU, ADVOPT.tlistAD),
infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) ),
activeMapPanel(nullptr)
{
duringAITurn = false;
state = NA;
@@ -384,6 +419,7 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
townList.onSelect = std::bind(&CAdvMapInt::selectionChanged,this);
adventureInt=this;
bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
bgWorldView = BitmapHandler::loadBitmap(ADVOPT.worldViewGraphic);
scrollingDir = 0;
updateScreen = false;
anim=0;
@@ -391,6 +427,13 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
heroAnim=0;
heroAnimValHitCount=0; // hero animation frame
if (!bgWorldView)
{
logGlobal->warn("bgWorldView not defined in resolution config; fallback to VWorld.bmp");
bgWorldView = BitmapHandler::loadBitmap("VWorld.bmp");
}
worldViewIconsDef = CDefHandler::giveDef("VwSymbol.def");
for (int g=0; g<ADVOPT.gemG.size(); ++g)
{
gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[g]));
@@ -399,7 +442,6 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
auto makeButton = [&] (int textID, std::function<void()> callback, config::ButtonInfo info, int key) -> CButton *
{
auto button = new CButton(Point(info.x, info.y), info.defName, CGI->generaltexth->zelp[textID], callback, key, info.playerColoured);
for (auto image : info.additionalDefs)
button->addImage(image);
return button;
@@ -416,41 +458,172 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
nextHero = makeButton(301, std::bind(&CAdvMapInt::fnextHero,this), ADVOPT.nextHero, SDLK_h);
endTurn = makeButton(302, std::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e);
int panelSpaceBottom = screen->h - resdatabar.pos.h - 4;
panelMain = new CAdvMapPanel(nullptr, Point(0, 0));
// TODO correct drawing position
panelWorldView = new CAdvMapWorldViewPanel(bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID);
panelMain->addChildColorableButton(kingOverview);
panelMain->addChildColorableButton(underground);
panelMain->addChildColorableButton(questlog);
panelMain->addChildColorableButton(sleepWake);
panelMain->addChildColorableButton(moveHero);
panelMain->addChildColorableButton(spellbook);
panelMain->addChildColorableButton(advOptions);
panelMain->addChildColorableButton(sysOptions);
panelMain->addChildColorableButton(nextHero);
panelMain->addChildColorableButton(endTurn);
// TODO move configs to resolutions.json, similarly to previous buttons
config::ButtonInfo worldViewBackConfig = config::ButtonInfo();
worldViewBackConfig.defName = "IOK6432.DEF";
worldViewBackConfig.x = screen->w - 73;
worldViewBackConfig.y = 343 + 195;
worldViewBackConfig.playerColoured = false;
panelWorldView->addChildToPanel(
makeButton(288, std::bind(&CAdvMapInt::fworldViewBack,this), worldViewBackConfig, SDLK_ESCAPE), ACTIVATE | DEACTIVATE);
config::ButtonInfo worldViewPuzzleConfig = config::ButtonInfo();
worldViewPuzzleConfig.defName = "VWPUZ.DEF";
worldViewPuzzleConfig.x = screen->w - 188;
worldViewPuzzleConfig.y = 343 + 195;
worldViewPuzzleConfig.playerColoured = false;
panelWorldView->addChildToPanel( // no help text for this one
new CButton(Point(worldViewPuzzleConfig.x, worldViewPuzzleConfig.y), worldViewPuzzleConfig.defName, std::pair<std::string, std::string>(),
std::bind(&CPlayerInterface::showPuzzleMap,LOCPLINT), SDLK_p, worldViewPuzzleConfig.playerColoured), ACTIVATE | DEACTIVATE);
config::ButtonInfo worldViewScale1xConfig = config::ButtonInfo();
worldViewScale1xConfig.defName = "VWMAG1.DEF";
worldViewScale1xConfig.x = screen->w - 191;
worldViewScale1xConfig.y = 23 + 195;
worldViewScale1xConfig.playerColoured = false;
panelWorldView->addChildToPanel( // help text is wrong for this button
makeButton(291, std::bind(&CAdvMapInt::fworldViewScale1x,this), worldViewScale1xConfig, SDLK_1), ACTIVATE | DEACTIVATE);
config::ButtonInfo worldViewScale2xConfig = config::ButtonInfo();
worldViewScale2xConfig.defName = "VWMAG2.DEF";
worldViewScale2xConfig.x = screen->w - 191 + 63;
worldViewScale2xConfig.y = 23 + 195;
worldViewScale2xConfig.playerColoured = false;
panelWorldView->addChildToPanel( // help text is wrong for this button
makeButton(291, std::bind(&CAdvMapInt::fworldViewScale2x,this), worldViewScale2xConfig, SDLK_2), ACTIVATE | DEACTIVATE);
config::ButtonInfo worldViewScale4xConfig = config::ButtonInfo();
worldViewScale4xConfig.defName = "VWMAG4.DEF";
worldViewScale4xConfig.x = screen->w - 191 + 126;
worldViewScale4xConfig.y = 23 + 195;
worldViewScale4xConfig.playerColoured = false;
panelWorldView->addChildToPanel( // help text is wrong for this button
makeButton(291, std::bind(&CAdvMapInt::fworldViewScale4x,this), worldViewScale4xConfig, SDLK_4), ACTIVATE | DEACTIVATE);
config::ButtonInfo worldViewUndergroundConfig = config::ButtonInfo();
worldViewUndergroundConfig.defName = "IAM010.DEF";
worldViewUndergroundConfig.additionalDefs.push_back("IAM003.DEF");
worldViewUndergroundConfig.x = screen->w - 115;
worldViewUndergroundConfig.y = 343 + 195;
worldViewUndergroundConfig.playerColoured = true;
worldViewUnderground = makeButton(294, std::bind(&CAdvMapInt::fswitchLevel,this), worldViewUndergroundConfig, SDLK_u);
panelWorldView->addChildColorableButton(worldViewUnderground);
setPlayer(LOCPLINT->playerID);
underground->block(!CGI->mh->map->twoLevel);
int iconColorMultiplier = player.getNum() * 19;
int wvLeft = heroList.pos.x - 2; // TODO correct drawing position
for (int i = 0; i < 5; ++i)
{
panelWorldView->addChildIcon(std::pair<int, Point>(i, Point(wvLeft + 5, 253 + i * 20)), worldViewIconsDef, iconColorMultiplier);
panelWorldView->addChildToPanel(new CLabel(wvLeft + 45, 263 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
Colors::WHITE, CGI->generaltexth->allTexts[612 + i]));
}
for (int i = 0; i < 7; ++i)
{
panelWorldView->addChildIcon(std::pair<int, Point>(i + 5, Point(wvLeft + 5, 377 + i * 20)), worldViewIconsDef, iconColorMultiplier);
panelWorldView->addChildIcon(std::pair<int, Point>(i + 12, Point(wvLeft + 160, 377 + i * 20)), worldViewIconsDef, iconColorMultiplier);
panelWorldView->addChildToPanel(new CLabel(wvLeft + 45, 387 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
Colors::WHITE, CGI->generaltexth->allTexts[619 + i]));
}
panelWorldView->addChildToPanel(new CLabel(wvLeft + 5, 367, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
Colors::WHITE, CGI->generaltexth->allTexts[617]));
panelWorldView->addChildToPanel(new CLabel(wvLeft + 185, 387, EFonts::FONT_SMALL, EAlignment::BOTTOMRIGHT,
Colors::WHITE, CGI->generaltexth->allTexts[618]));
activeMapPanel = panelMain;
restoreState();
addUsedEvents(MOVE);
}
void CAdvMapInt::restoreState()
{
changeMode(EAdvMapMode::NORMAL);
underground->block(!CGI->mh->map->twoLevel);
worldViewUnderground->block(!CGI->mh->map->twoLevel);
}
CAdvMapInt::~CAdvMapInt()
{
SDL_FreeSurface(bg);
for(int i=0; i<gems.size(); i++)
delete gems[i];
delete worldViewIconsDef;
}
void CAdvMapInt::fshowOverview()
{
GH.pushInt(new CKingdomInterface);
}
void CAdvMapInt::fworldViewBack()
{
changeMode(EAdvMapMode::NORMAL);
CGI->mh->discardWorldViewCache();
auto hero = curHero();
if (hero)
centerOn(hero);
}
void CAdvMapInt::fworldViewScale1x()
{
// TODO set corresponding scale button to "selected" mode
changeMode(EAdvMapMode::WORLD_VIEW, 0.22f);
}
void CAdvMapInt::fworldViewScale2x()
{
changeMode(EAdvMapMode::WORLD_VIEW, 0.36f);
}
void CAdvMapInt::fworldViewScale4x()
{
changeMode(EAdvMapMode::WORLD_VIEW, 0.5f);
}
void CAdvMapInt::fswitchLevel()
{
if(!CGI->mh->map->twoLevel)
// with support for future multi-level maps :)
int maxLevels = CGI->mh->map->twoLevel ? 2 : 1;
if (maxLevels < 2)
return;
if (position.z)
{
position.z--;
underground->setIndex(0,true);
underground->showAll(screenBuf);
}
else
{
underground->setIndex(1,true);
position.z++;
underground->showAll(screenBuf);
}
position.z = (position.z + 1) % maxLevels;
underground->setIndex(position.z, true);
underground->redraw();
worldViewUnderground->setIndex(position.z, true);
worldViewUnderground->redraw();
updateScreen = true;
minimap.setLevel(position.z);
if (mode == EAdvMapMode::WORLD_VIEW)
terrain.redraw();
}
void CAdvMapInt::fshowQuestlog()
{
@@ -599,27 +772,21 @@ void CAdvMapInt::activate()
GH.statusbar = &statusbar;
if(!duringAITurn)
{
kingOverview->activate();
underground->activate();
questlog->activate();
sleepWake->activate();
moveHero->activate();
spellbook->activate();
sysOptions->activate();
advOptions->activate();
nextHero->activate();
endTurn->activate();
activeMapPanel->activate();
if (mode == EAdvMapMode::NORMAL)
{
heroList.activate();
townList.activate();
infoBar.activate();
}
minimap.activate();
heroList.activate();
townList.activate();
terrain.activate();
infoBar.activate();
LOCPLINT->cingconsole->activate();
GH.fakeMouseMove(); //to restore the cursor
}
}
void CAdvMapInt::deactivate()
{
CIntObject::deactivate();
@@ -629,25 +796,20 @@ void CAdvMapInt::deactivate()
scrollingDir = 0;
CCS->curh->changeGraphic(ECursor::ADVENTURE,0);
kingOverview->deactivate();
underground->deactivate();
questlog->deactivate();
sleepWake->deactivate();
moveHero->deactivate();
spellbook->deactivate();
advOptions->deactivate();
sysOptions->deactivate();
nextHero->deactivate();
endTurn->deactivate();
activeMapPanel->deactivate();
if (mode == EAdvMapMode::NORMAL)
{
heroList.deactivate();
townList.deactivate();
infoBar.deactivate();
}
minimap.deactivate();
heroList.deactivate();
townList.deactivate();
terrain.deactivate();
infoBar.deactivate();
if(LOCPLINT)
LOCPLINT->cingconsole->deactivate();
}
}
void CAdvMapInt::showAll(SDL_Surface * to)
{
blitAt(bg,0,0,to);
@@ -655,28 +817,30 @@ void CAdvMapInt::showAll(SDL_Surface * to)
if(state != INGAME)
return;
kingOverview->showAll(to);
underground->showAll(to);
questlog->showAll(to);
sleepWake->showAll(to);
moveHero->showAll(to);
spellbook->showAll(to);
advOptions->showAll(to);
sysOptions->showAll(to);
nextHero->showAll(to);
endTurn->showAll(to);
switch (mode)
{
case EAdvMapMode::NORMAL:
heroList.showAll(to);
townList.showAll(to);
infoBar.showAll(to);
break;
case EAdvMapMode::WORLD_VIEW:
terrain.showAll(to);
break;
}
activeMapPanel->showAll(to);
minimap.showAll(to);
heroList.showAll(to);
townList.showAll(to);
updateScreen = true;
minimap.showAll(to);
show(to);
resdatabar.draw(to);
statusbar.show(to);
infoBar.showAll(to);
LOCPLINT->cingconsole->showAll(to);
}
@@ -737,6 +901,8 @@ void CAdvMapInt::show(SDL_Surface * to)
{
updateScreen = true;
minimap.redraw();
if (mode == EAdvMapMode::WORLD_VIEW)
terrain.redraw();
}
}
if(updateScreen)
@@ -769,8 +935,19 @@ void CAdvMapInt::centerOn(int3 on)
{
bool switchedLevels = on.z != position.z;
on.x -= CGI->mh->frameW;
on.y -= CGI->mh->frameH;
switch (mode)
{
default:
case EAdvMapMode::NORMAL:
on.x -= CGI->mh->frameW; // is this intentional? frame size doesn't really have to correspond to camera size...
on.y -= CGI->mh->frameH;
break;
case EAdvMapMode::WORLD_VIEW:
on.x -= CGI->mh->tilesW / 2 / worldViewScale;
on.y -= CGI->mh->tilesH / 2 / worldViewScale;
break;
}
on = LOCPLINT->repairScreenPos(on);
@@ -778,9 +955,14 @@ void CAdvMapInt::centerOn(int3 on)
updateScreen=true;
underground->setIndex(on.z,true); //change underground switch button image
underground->redraw();
worldViewUnderground->setIndex(on.z, true);
worldViewUnderground->redraw();
if (switchedLevels)
minimap.setLevel(position.z);
minimap.redraw();
if (mode == EAdvMapMode::WORLD_VIEW)
terrain.redraw();
}
void CAdvMapInt::centerOn(const CGObjectInstance *obj)
@@ -790,6 +972,10 @@ void CAdvMapInt::centerOn(const CGObjectInstance *obj)
void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
{
if (mode == EAdvMapMode::WORLD_VIEW)
return;
ui8 Dir = 0;
int k = key.keysym.sym;
const CGHeroInstance *h = curHero(); //selected hero
@@ -836,6 +1022,10 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
if(isActive())
LOCPLINT->showPuzzleMap();
return;
case SDLK_v:
if(isActive())
LOCPLINT->viewWorldMap();
return;
case SDLK_r:
if(isActive() && LOCPLINT->ctrlPressed())
{
@@ -852,7 +1042,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
{
auto unlockPim = vstd::makeUnlockGuard(*LOCPLINT->pim);
//TODO!!!!!!! possible freeze, when GS mutex is locked and network thread can't apply package
//this thread leaves scope and tries to lock pim while holding gs,
//this thread leaves scope and tries to lock pim while holding gs,
//network thread tries to lock gs (appluy cl) while holding pim
//this thread should first lock pim, however gs locking/unlocking is done inside cb
LOCPLINT->cb->moveHero(h,h->pos);
@@ -916,12 +1106,12 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
//numpad arrow
if(CGuiHandler::isArrowKey(SDLKey(k)))
k = CGuiHandler::arrowToNum(SDLKey(k));
#ifdef VCMI_SDL1
k -= SDLK_KP0 + 1;
#else
k -= SDLK_KP_1;
#endif // VCMI_SDL1
#endif // VCMI_SDL1
if(k < 0 || k > 8)
return;
@@ -1039,8 +1229,9 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/)
void CAdvMapInt::mouseMoved( const SDL_MouseMotionEvent & sEvent )
{
//adventure map scrolling with mouse
if(!isCtrlKeyDown() && isActive())
// adventure map scrolling with mouse
// currently disabled in world view mode (as it is in OH3), but should work correctly if mode check is removed
if(!isCtrlKeyDown() && isActive() && mode == EAdvMapMode::NORMAL)
{
if(sEvent.x<15)
{
@@ -1092,16 +1283,9 @@ void CAdvMapInt::setPlayer(PlayerColor Player)
player = Player;
graphics->blueToPlayersAdv(bg,player);
kingOverview->setPlayerColor(player);
underground->setPlayerColor(player);
questlog->setPlayerColor(player);
sleepWake->setPlayerColor(player);
moveHero->setPlayerColor(player);
spellbook->setPlayerColor(player);
sysOptions->setPlayerColor(player);
advOptions->setPlayerColor(player);
nextHero->setPlayerColor(player);
endTurn->setPlayerColor(player);
panelMain->setPlayerColor(player);
panelWorldView->setPlayerColor(player);
panelWorldView->recolorIcons(player, worldViewIconsDef, player.getNum() * 19);
graphics->blueToPlayersAdv(resdatabar.bg,player);
//heroList.updateHList();
@@ -1143,6 +1327,8 @@ const CGObjectInstance* CAdvMapInt::getActiveObject(const int3 &mapPos)
void CAdvMapInt::tileLClicked(const int3 &mapPos)
{
if(mode != EAdvMapMode::NORMAL)
return;
if(!LOCPLINT->cb->isVisible(mapPos) || !LOCPLINT->makingTurn)
return;
@@ -1227,6 +1413,8 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
void CAdvMapInt::tileHovered(const int3 &mapPos)
{
if(mode != EAdvMapMode::NORMAL)
return;
if(!LOCPLINT->cb->isVisible(mapPos))
{
CCS->curh->changeGraphic(ECursor::ADVENTURE, 0);
@@ -1394,12 +1582,12 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
if (guardingCreature)
{
CCS->curh->changeGraphic(ECursor::ADVENTURE, 5 + turns*6);
}
}
else
{
if(pnode->land)
{
if(LOCPLINT->cb->getTile(h->getPosition(false))->terType != ETerrainType::WATER)
if(LOCPLINT->cb->getTile(h->getPosition(false))->terType != ETerrainType::WATER)
CCS->curh->changeGraphic(ECursor::ADVENTURE, 4 + turns*6);
else
CCS->curh->changeGraphic(ECursor::ADVENTURE, 7 + turns*6); //anchor
@@ -1421,6 +1609,8 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
void CAdvMapInt::tileRClicked(const int3 &mapPos)
{
if(mode != EAdvMapMode::NORMAL)
return;
if(spellBeingCasted)
{
leaveCastingMode();
@@ -1512,26 +1702,67 @@ void CAdvMapInt::adjustActiveness(bool aiTurnStart)
{
bool wasActive = isActive();
if(wasActive)
if(wasActive)
deactivate();
adventureInt->duringAITurn = aiTurnStart;
if(wasActive)
if(wasActive)
activate();
}
void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale /* = 0.4f */)
{
if (mode != newMode)
{
mode = newMode;
switch (mode)
{
case EAdvMapMode::NORMAL:
panelMain->activate();
panelWorldView->deactivate();
activeMapPanel = panelMain;
townList.activate();
heroList.activate();
infoBar.activate();
break;
case EAdvMapMode::WORLD_VIEW:
panelMain->deactivate();
panelWorldView->activate();
activeMapPanel = panelWorldView;
townList.deactivate();
heroList.deactivate();
infoBar.showSelection(); // to prevent new day animation interfering world view mode
infoBar.deactivate();
break;
}
worldViewScale = newScale;
redraw();
}
else if (worldViewScale != newScale) // still in world view mode, but the scale changed
{
worldViewScale = newScale;
redraw();
}
}
CAdventureOptions::CAdventureOptions():
CWindowObject(PLAYER_COLORED, "ADVOPTS")
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
viewWorld = new CButton(Point(24, 23), "ADVVIEW.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_v);
viewWorld->addCallback(std::bind(&CPlayerInterface::viewWorldMap, LOCPLINT));
exit = new CButton(Point(204, 313), "IOK6432.DEF", CButton::tooltip(), std::bind(&CAdventureOptions::close, this), SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);
scenInfo = new CButton(Point(24, 198), "ADVINFO.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_i);
scenInfo->addCallback(CAdventureOptions::showScenarioInfo);
//viewWorld = new CButton("","",std::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
puzzle = new CButton(Point(24, 81), "ADVPUZ.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_p);
puzzle->addCallback(std::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT));

View File

@@ -28,6 +28,12 @@ class IShipyard;
*
*/
enum class EAdvMapMode
{
NORMAL,
WORLD_VIEW
};
/// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
class CAdventureOptions : public CWindowObject
{
@@ -55,9 +61,12 @@ public:
void hover(bool on);
void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void showPath(const SDL_Rect * extRect, SDL_Surface * to);
int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
int3 whichTileIsIt(); //uses current cursor pos
/// @returns number of visible tiles on screen respecting current map scaling
int3 tileCountOnScreen();
};
/// Resources bar which shows information about how many gold, crystals,... you have
@@ -79,9 +88,9 @@ public:
void showAll(SDL_Surface * to);
};
/// That's a huge class which handles general adventure map actions and
/// shows the right menu(questlog, spellbook, end turn,..) from where you
/// can get to the towns and heroes.
/// That's a huge class which handles general adventure map actions and
/// shows the right menu(questlog, spellbook, end turn,..) from where you
/// can get to the towns and heroes.
class CAdvMapInt : public CIntObject
{
//Return object that must be active at this tile (=clickable)
@@ -105,7 +114,11 @@ public:
ui8 anim, animValHitCount; //animation frame
ui8 heroAnim, heroAnimValHitCount; //animation frame
EAdvMapMode mode;
float worldViewScale;
SDL_Surface * bg;
SDL_Surface * bgWorldView;
std::vector<CDefHandler *> gems;
CMinimap minimap;
CGStatusBar statusbar;
@@ -121,18 +134,30 @@ public:
CButton * nextHero;
CButton * endTurn;
CButton * worldViewUnderground;
CTerrainRect terrain; //visible terrain
CResDataBar resdatabar;
CHeroList heroList;
CTownList townList;
CInfoBar infoBar;
CAdvMapPanel *panelMain; // panel that holds all right-side buttons in normal view
CAdvMapWorldViewPanel *panelWorldView; // panel that holds all buttons and other ui in world view
CAdvMapPanel *activeMapPanel; // currently active panel (either main or world view, depending on current mode)
CDefHandler * worldViewIconsDef; // images for world view overlay
const CSpell *spellBeingCasted; //nullptr if none
const CArmedInstance *selection; //currently selected town/hero
//functions bound to buttons
void fshowOverview();
void fworldViewBack();
void fworldViewScale1x();
void fworldViewScale2x();
void fworldViewScale4x();
void fswitchLevel();
void fshowQuestlog();
void fsleepWake();
@@ -179,9 +204,15 @@ public:
const CGTownInstance * curTown() const;
const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
//button updates
void updateSleepWake(const CGHeroInstance *h);
void updateSleepWake(const CGHeroInstance *h);
void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
void updateNextHero(const CGHeroInstance *h);
/// called by player interface if it wants to reuse this object for new/loaded map
void restoreState();
/// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
void changeMode(EAdvMapMode newMode, float newScale = 0.36f);
};
extern CAdvMapInt *adventureInt;

View File

@@ -70,11 +70,11 @@ CFocusable * CFocusable::inputWithFocus;
#undef max
CRecruitmentWindow::CCreatureCard::CCreatureCard(CRecruitmentWindow *window, const CCreature *crea, int totalAmount):
CIntObject(LCLICK | RCLICK),
parent(window),
selected(false),
creature(crea),
amount(totalAmount)
CIntObject(LCLICK | RCLICK),
parent(window),
selected(false),
creature(crea),
amount(totalAmount)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
pic = new CCreaturePic(1,1, creature, true, true);
@@ -248,12 +248,12 @@ void CRecruitmentWindow::showAll(SDL_Surface * to)
}
CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const std::function<void(CreatureID,int)> &Recruit, int y_offset):
CWindowObject(PLAYER_COLORED, "TPRCRT"),
CWindowObject(PLAYER_COLORED, "TPRCRT"),
onRecruit(Recruit),
level(Level),
dst(Dst),
selected(nullptr),
dwelling(Dwelling)
level(Level),
dst(Dst),
selected(nullptr),
dwelling(Dwelling)
{
moveBy(Point(0, y_offset));
@@ -358,14 +358,14 @@ void CRecruitmentWindow::sliderMoved(int to)
}
CSplitWindow::CSplitWindow(const CCreature * creature, std::function<void(int, int)> callback_,
int leftMin_, int rightMin_, int leftAmount_, int rightAmount_):
CWindowObject(PLAYER_COLORED, "GPUCRDIV"),
callback(callback_),
leftAmount(leftAmount_),
rightAmount(rightAmount_),
leftMin(leftMin_),
rightMin(rightMin_),
slider(nullptr)
int leftMin_, int rightMin_, int leftAmount_, int rightAmount_):
CWindowObject(PLAYER_COLORED, "GPUCRDIV"),
callback(callback_),
leftAmount(leftAmount_),
rightAmount(rightAmount_),
leftMin(leftMin_),
rightMin(rightMin_),
slider(nullptr)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -443,8 +443,8 @@ void CSplitWindow::sliderMoved(int to)
}
CLevelWindow::CLevelWindow(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill> &skills, std::function<void(ui32)> callback):
CWindowObject(PLAYER_COLORED, "LVLUPBKG"),
cb(callback)
CWindowObject(PLAYER_COLORED, "LVLUPBKG"),
cb(callback)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -455,16 +455,16 @@ CLevelWindow::CLevelWindow(const CGHeroInstance *hero, PrimarySkill::PrimarySkil
//%s has gained a level.
new CLabel(192, 33, FONT_MEDIUM, CENTER, Colors::WHITE,
boost::str(boost::format(CGI->generaltexth->allTexts[444]) % hero->name));
boost::str(boost::format(CGI->generaltexth->allTexts[444]) % hero->name));
//%s is now a level %d %s.
new CLabel(192, 162, FONT_MEDIUM, CENTER, Colors::WHITE,
boost::str(boost::format(CGI->generaltexth->allTexts[445]) % hero->name % hero->level % hero->type->heroClass->name));
boost::str(boost::format(CGI->generaltexth->allTexts[445]) % hero->name % hero->level % hero->type->heroClass->name));
new CAnimImage("PSKIL42", pskill, 0, 174, 190);
new CLabel(192, 253, FONT_MEDIUM, CENTER, Colors::WHITE,
CGI->generaltexth->primarySkillNames[pskill] + " +1");
CGI->generaltexth->primarySkillNames[pskill] + " +1");
if (!skills.empty())
{
@@ -506,8 +506,8 @@ static void setBoolSetting(std::string group, std::string field, bool value)
}
CSystemOptionsWindow::CSystemOptionsWindow():
CWindowObject(PLAYER_COLORED, "SysOpBck"),
onFullscreenChanged(settings.listen["video"]["fullscreen"])
CWindowObject(PLAYER_COLORED, "SysOpBck"),
onFullscreenChanged(settings.listen["video"]["fullscreen"])
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
title = new CLabel(242, 32, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[568]);
@@ -590,16 +590,16 @@ CSystemOptionsWindow::CSystemOptionsWindow():
effectsVolume->addCallback(std::bind(&setIntSetting, "general", "sound", _1));
showReminder = new CToggleButton(Point(246, 87), "sysopchk.def", CGI->generaltexth->zelp[361],
[&] (bool value) { setBoolSetting("adventure", "heroReminder", value); });
[&] (bool value) { setBoolSetting("adventure", "heroReminder", value); });
quickCombat = new CToggleButton(Point(246, 87+32), "sysopchk.def", CGI->generaltexth->zelp[362],
[&] (bool value) { setBoolSetting("adventure", "quickCombat", value); });
[&] (bool value) { setBoolSetting("adventure", "quickCombat", value); });
spellbookAnim = new CToggleButton(Point(246, 87+64), "sysopchk.def", CGI->generaltexth->zelp[364],
[&] (bool value) { setBoolSetting("video", "spellbookAnimation", value); });
[&] (bool value) { setBoolSetting("video", "spellbookAnimation", value); });
fullscreen = new CToggleButton(Point(246, 215), "sysopchk.def", CButton::tooltip(texts["fullscreenButton"]),
[&] (bool value) { setBoolSetting("video", "fullscreen", value); });
[&] (bool value) { setBoolSetting("video", "fullscreen", value); });
showReminder->setSelected(settings["adventure"]["heroReminder"].Bool());
quickCombat->setSelected(settings["adventure"]["quickCombat"].Bool());
@@ -609,7 +609,7 @@ CSystemOptionsWindow::CSystemOptionsWindow():
onFullscreenChanged([&](const JsonNode &newState){ fullscreen->setSelected(newState.Bool());});
gameResButton = new CButton(Point(28, 275),"buttons/resolution", CButton::tooltip(texts["resolutionButton"]),
std::bind(&CSystemOptionsWindow::selectGameRes, this), SDLK_g);
std::bind(&CSystemOptionsWindow::selectGameRes, this), SDLK_g);
std::string resText;
resText += boost::lexical_cast<std::string>(settings["video"]["screenRes"]["width"].Float());
@@ -693,7 +693,7 @@ void CSystemOptionsWindow::closeAndPushEvent(int eventType, int code /*= 0*/)
}
CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj):
CWindowObject(PLAYER_COLORED, "TPTAVERN"),
CWindowObject(PLAYER_COLORED, "TPTAVERN"),
tavernObj(TavernObj)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -859,7 +859,7 @@ void CExchangeWindow::prepareBackground()
auto genTitle = [](const CGHeroInstance *h)
{
return boost::str(boost::format(CGI->generaltexth->allTexts[138])
% h->name % h->level % h->type->heroClass->name);
% h->name % h->level % h->type->heroClass->name);
};
new CLabel(147, 25, FONT_SMALL, CENTER, Colors::WHITE, genTitle(heroInst[0]));
@@ -876,7 +876,7 @@ void CExchangeWindow::prepareBackground()
//printing primary skills' amounts
for(int m=0; m<GameConstants::PRIMARY_SKILLS; ++m)
new CLabel(352 + 93 * b, 35 + 36 * m, FONT_SMALL, CENTER, Colors::WHITE,
boost::lexical_cast<std::string>(heroWArt.getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(m))));
boost::lexical_cast<std::string>(heroWArt.getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(m))));
//printing secondary skills
for(int m=0; m<heroInst[b]->secSkills.size(); ++m)
@@ -904,7 +904,7 @@ void CExchangeWindow::prepareBackground()
}
CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID):
CWindowObject(PLAYER_COLORED | BORDERED, "TRADE2")
CWindowObject(PLAYER_COLORED | BORDERED, "TRADE2")
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
heroInst[0] = LOCPLINT->cb->getHero(hero1);
@@ -1015,7 +1015,7 @@ CExchangeWindow::~CExchangeWindow() //d-tor
}
CShipyardWindow::CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const std::function<void()> &onBuy):
CWindowObject(PLAYER_COLORED, "TPSHIP")
CWindowObject(PLAYER_COLORED, "TPSHIP")
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -1057,9 +1057,9 @@ CShipyardWindow::CShipyardWindow(const std::vector<si32> &cost, int state, int b
}
CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio):
CWindowObject(PLAYER_COLORED | BORDERED, "PUZZLE"),
grailPos(GrailPos),
currentAlpha(SDL_ALPHA_OPAQUE)
CWindowObject(PLAYER_COLORED | BORDERED, "PUZZLE"),
grailPos(GrailPos),
currentAlpha(SDL_ALPHA_OPAQUE)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
CCS->soundh->playSound(soundBase::OBELISK);
@@ -1099,11 +1099,12 @@ void CPuzzleWindow::showAll(SDL_Surface * to)
{
int3 moveInt = int3(8, 9, 0);
Rect mapRect = genRect(544, 591, pos.x + 8, pos.y + 7);
int3 topTile = grailPos - moveInt;
CGI->mh->terrainRect
(grailPos - moveInt, adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
to, &mapRect, 0, 0, true, moveInt);
MapDrawingInfo info(topTile, &LOCPLINT->cb->getVisibilityMap(), &mapRect);
info.puzzleMode = true;
info.grailPos = grailPos;
CGI->mh->drawTerrainRectNew(to, &info);
CWindowObject::showAll(to);
}
@@ -1191,9 +1192,9 @@ void CTransformerWindow::updateGarrisons()
}
CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town):
CWindowObject(PLAYER_COLORED, "SKTRNBK"),
hero(_hero),
town(_town)
CWindowObject(PLAYER_COLORED, "SKTRNBK"),
hero(_hero),
town(_town)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
if (hero)
@@ -1233,7 +1234,7 @@ void CUniversityWindow::CItem::clickRight(tribool down, bool previousState)
if(down)
{
CRClickPopup::createAndPush(CGI->generaltexth->skillInfoTexts[ID][0],
new CComponent(CComponent::secskill, ID, 1));
new CComponent(CComponent::secskill, ID, 1));
}
}
@@ -1262,13 +1263,13 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to)
switch (state())
{
case 0: bar = parent->red;
break;
break;
case 1: bar = parent->yellow;
break;
break;
case 2: bar = parent->green;
break;
break;
default:bar = nullptr;
break;
break;
}
assert(bar);
@@ -1289,9 +1290,9 @@ CUniversityWindow::CItem::CItem(CUniversityWindow * _parent, int _ID, int X, int
}
CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market):
CWindowObject(PLAYER_COLORED, "UNIVERS1"),
hero(_hero),
market(_market)
CWindowObject(PLAYER_COLORED, "UNIVERS1"),
hero(_hero),
market(_market)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -1331,8 +1332,8 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket
}
CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available ):
CWindowObject(PLAYER_COLORED, "UNIVERS2.PCX"),
parent(PARENT)
CWindowObject(PLAYER_COLORED, "UNIVERS2.PCX"),
parent(PARENT)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -1372,9 +1373,9 @@ void CUnivConfirmWindow::makeDeal(int skill)
}
CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object):
CWindowObject(PLAYER_COLORED, "APHLFTBK"),
CWindowObject(PLAYER_COLORED, "APHLFTBK"),
fort(object),
hero(visitor)
hero(visitor)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -1449,11 +1450,11 @@ void CHillFortWindow::makeDeal(SlotID slot)
{
case 0:
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[314 + offset],
std::vector<CComponent*>(), soundBase::sound_todo);
std::vector<CComponent*>(), soundBase::sound_todo);
break;
case 1:
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[313 + offset],
std::vector<CComponent*>(), soundBase::sound_todo);
std::vector<CComponent*>(), soundBase::sound_todo);
break;
case 2:
for (int i=0; i<slotsCount; i++)
@@ -1554,7 +1555,7 @@ int CHillFortWindow::getState(SlotID slot)
}
CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
CWindowObject(PLAYER_COLORED | BORDERED, "TpRank"),
CWindowObject(PLAYER_COLORED | BORDERED, "TpRank"),
owner(_owner)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -1646,11 +1647,11 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
if(iter.second.details)
{
new CTextBox(CGI->generaltexth->allTexts[184], Rect(260 + 66*counter, 396, 52, 64),
0, FONT_TINY, TOPLEFT, Colors::WHITE);
0, FONT_TINY, TOPLEFT, Colors::WHITE);
for (int i=0; i<iter.second.details->primskills.size(); ++i)
{
new CLabel(310 + 66 * counter, 407 + 11*i, FONT_TINY, BOTTOMRIGHT, Colors::WHITE,
boost::lexical_cast<std::string>(iter.second.details->primskills[i]));
boost::lexical_cast<std::string>(iter.second.details->primskills[i]));
}
}
}
@@ -1671,14 +1672,14 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
for(auto & it : tgi.personality)
{
std::string text;
if(it.second == EAiTactic::NONE)
{
if(it.second == EAiTactic::NONE)
{
text = CGI->generaltexth->arraytxt[172];
}
else if(it.second != EAiTactic::RANDOM)
{
text = CGI->generaltexth->arraytxt[168 + it.second];
}
}
else if(it.second != EAiTactic::RANDOM)
{
text = CGI->generaltexth->arraytxt[168 + it.second];
}
new CLabel(283 + 66*counter, 459, FONT_SMALL, CENTER, Colors::WHITE, text);

View File

@@ -11,6 +11,7 @@
"gem2": { "x": 6, "y": 6, "graphic": "agemUL.def" },
"gem3": { "x": 556, "y": 6, "graphic": "agemUR.def" },
"background": "AdvMap.bmp",
"backgroundWorldView": "VWorld.bmp",
"HeroList": { "size": 5, "x": 609, "y": 196, "movePoints": "IMOBIL.DEF", "manaPoints": "IMANA.DEF", "arrowUp": "IAM012.DEF", "arrowDown": "IAM013.DEF" },
"TownList": { "size": 5, "x": 747, "y": 196, "arrowUp": "IAM014.DEF", "arrowDown": "IAM015.DEF" },
"Minimap": { "width": 144, "height": 144, "x": 630, "y": 26 },

View File

@@ -238,6 +238,7 @@ void config::CConfigHandler::init()
setGem(current->ac, 3, g["gem3"]);
current->ac.mainGraphic = g["background"].String();
current->ac.worldViewGraphic = g["backgroundWorldView"].String();
current->ac.hlistX = g["HeroList"]["x"].Float();
current->ac.hlistY = g["HeroList"]["y"].Float();

View File

@@ -135,6 +135,7 @@ namespace config
bool puzzleSepia;
//general properties
std::string mainGraphic;
std::string worldViewGraphic;
//buttons
ButtonInfo kingOverview, underground, questlog, sleepWake, moveHero, spellbook, advOptions,
sysOptions, nextHero, endTurn;

View File

@@ -109,6 +109,7 @@ public:
virtual void showShipyardDialog(const IShipyard *obj){} //obj may be town or shipyard; state: 0 - can buid, 1 - lack of resources, 2 - dest tile is blocked, 3 - no water
virtual void showPuzzleMap(){};
virtual void viewWorldMap(){};
virtual void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor){};
virtual void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor){};
virtual void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor){};