Commit 66a7a287 authored by Gerhard Stein's avatar Gerhard Stein

Improved loading of player sprites

parent f6ebe62e
......@@ -199,8 +199,20 @@ std::ofstream && OpenGameFileW(const std::string& path, const std::ios_base::ope
std::string GetFileContents(const std::string& path, bool absolute = false);
std::string ExtractDirectory(const std::string& path);
std::string JoinPaths(const std::string& path1, const std::string& path2);
// Join Path version where you can pass more than two parameters
template<typename T, typename... Args>
std::string JoinPaths(const T& path1, const T& path2, Args... args)
{
const auto path = JoinPaths(path1, path2);
return JoinPaths(path, args...);
}
std::string GetScriptInterpreterCommandForFile(const std::string& filename);
......
......@@ -13,7 +13,6 @@
#include <widgets/GsMenuController.h>
#include "engine/core/CBehaviorEngine.h"
//#include "CameraSettings.h"
#include "CVideoSettings.h"
#include <base/utils/Utils.h>
......
......@@ -112,6 +112,8 @@ private:
int mCurId = 0;
ComboSelection *mpComboSelection = nullptr;
};
......
......@@ -5,11 +5,17 @@ CPlayerSpriteVarSelection(const GsControl::Style style) :
GameMenu( GsRect<float>(0.25f, 0.2f, 0.5f, 0.5f), style )
{
mpMenuDialog->addControl( new GameButton( "Start",
new SelectPlayerSpriteVarEvent(mCurId),
style ) );
}
void
CPlayerSpriteVarSelection::
ponder(const float deltaT)
{
// TODO: Code for Player selection here!
GameMenu::ponder(deltaT);
}
......@@ -397,9 +397,9 @@ void GalaxyEngine::pumpEvent(const CEvent *evPtr)
{
gBehaviorEngine.mPlayers = pNewGame->mSelection;
// Ensure the Sprite variations are correctly setup
if(gBehaviorEngine.mPlayers > 1)
{
// Ensure the Sprite variations are correctly setup
mSpriteVars.clear();
for(int i=0 ; i<gBehaviorEngine.mPlayers ; i++ )
{
......@@ -449,7 +449,8 @@ void GalaxyEngine::pumpEvent(const CEvent *evPtr)
gEventManager.add( new OpenMenuEvent(
new CControlsettings(players, style) ) );
}
else if( const GMSwitchToPlayGameMode* pPlayGame = dynamic_cast<const GMSwitchToPlayGameMode*>(evPtr) )
else if( const GMSwitchToPlayGameMode* pPlayGame =
dynamic_cast<const GMSwitchToPlayGameMode*>(evPtr) )
{
const GMSwitchToPlayGameMode &playGame = const_cast<GMSwitchToPlayGameMode&>(*pPlayGame);
switchToGameplay(playGame.m_startlevel, mSpriteVars);
......
......@@ -1447,38 +1447,12 @@ bool CEGAGraphicsGalaxy::readSprites( const size_t numSprites,
// For the other variant let's exchange some colors
// Nice bonus: We can load own kylie bitmaps and let them become sprites
std::string kyliePath = JoinPaths(gKeenFiles.gameDir, "gfx/player/kylie");
// Second Player, could be kylie's own bitmaps
auto &SpriteVecPlayer2 = gGraphics.getSpriteVec(1);
int ctr = 0;
struct stat s;
S_ISDIR( s.st_mode );
if(StatFile(kyliePath, &s))
{
for( GsSprite &sprite : SpriteVecPlayer2)
{
std::string filename = "4SPR0000.bmp";
// Look for additional Kylie Sprites as bitmaps
// Ugly conversion of the filenames
const std::string numStr = to_string(ctr);
filename.replace(8-numStr.length(),numStr.length(),numStr);
const auto kylieFilePath = JoinPaths(kyliePath, filename);
if( sprite.loadHQSprite(kylieFilePath) )
{
sprite.applyTransparency();
}
ctr++;
}
}
else
//else
{
for( GsSprite &sprite : SpriteVecPlayer2)
{
......@@ -1521,6 +1495,62 @@ bool CEGAGraphicsGalaxy::readSprites( const size_t numSprites,
sprite.exchangeSpriteColor( 10, 13, 0 );
}
const std::string gfxDir = "gfx";
const std::string playerDir = "player";
const std::string playersPathList = JoinPaths(gKeenFiles.gameDir,
gfxDir,
playerDir);
std::set<std::string> playersList;
FileListAdder fileListAdder;
GetFileList(playersList, fileListAdder,
playersPathList, false, FM_DIR);
// For a list of players try to load the sprites
int numSpriteVar = 0;
for(const auto &player : playersList)
{
auto &SpriteVecPlayer = gGraphics.getSpriteVec(numSpriteVar);
const std::string curPlayerPath = JoinPaths(playersPathList, player);
std::set<std::string> spriteList;
FileListAdder spritefilesAdder;
GetFileList(spriteList, spritefilesAdder,
curPlayerPath, false, FM_REG);
for(const auto &spriteFile : spriteList)
{
const auto numStr = spriteFile.substr(spriteFile.length()-8,
spriteFile.length()-4);
int idx = atoi(numStr.c_str());
if(idx >= int(SpriteVecPlayer.size()))
{
gLogging << "Warning: Index " << idx << " out of reach.";
continue;
}
const auto spriteFilePath = JoinPaths(curPlayerPath,
spriteFile);
GsSprite &sprite = SpriteVecPlayer[idx];
if( sprite.loadHQSprite(spriteFilePath) )
{
sprite.applyTransparency();
}
else
{
gLogging << "Warning: " << spriteFile << " could not be loaded.";
}
}
numSpriteVar++;
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment