diff --git a/src/game/frontend/base/Base.cpp b/src/game/frontend/base/Base.cpp index 9012307e..6ecd7783 100644 --- a/src/game/frontend/base/Base.cpp +++ b/src/game/frontend/base/Base.cpp @@ -91,6 +91,10 @@ tile::Tile* Base::GetTile() const { return m_tile; } +const size_t Base::GetPopulation() const { + return m_population; +} + sprite::Sprite* Base::GetSprite() const { uint8_t size = 0; for ( uint8_t i = 0 ; i < s_base_render_population_thresholds.size() ; i++ ) { diff --git a/src/game/frontend/base/Base.h b/src/game/frontend/base/Base.h index 0bac1963..3d7dfac3 100644 --- a/src/game/frontend/base/Base.h +++ b/src/game/frontend/base/Base.h @@ -68,6 +68,7 @@ class Base : public TileObject { faction::Faction* const GetFaction() const; const bool IsOwned() const; tile::Tile* GetTile() const; + const size_t GetPopulation() const; sprite::Sprite* GetSprite() const; diff --git a/src/game/frontend/ui/popup/base_popup/bottom_bar/BottomBar.cpp b/src/game/frontend/ui/popup/base_popup/bottom_bar/BottomBar.cpp index 43c4cc2d..73e70c93 100644 --- a/src/game/frontend/ui/popup/base_popup/bottom_bar/BottomBar.cpp +++ b/src/game/frontend/ui/popup/base_popup/bottom_bar/BottomBar.cpp @@ -62,6 +62,7 @@ void BottomBar::Destroy() { void BottomBar::Update( base::Base* base ) { m_sections.base_title->Update( base ); + m_sections.population->Update( base ); m_sections.units_list->ListObjects( base->GetTile()->GetOrderedObjects(), 0 ); } diff --git a/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.cpp b/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.cpp index 289ac14e..2f812a5f 100644 --- a/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.cpp +++ b/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.cpp @@ -1,5 +1,9 @@ #include "Population.h" +#include "ui/object/Surface.h" +#include "game/frontend/base/Base.h" +#include "game/frontend/faction/Faction.h" + namespace game { namespace frontend { namespace ui { @@ -18,10 +22,40 @@ void Population::Create() { } void Population::Destroy() { + HideIcons(); BBSection::Destroy(); } +void Population::Update( base::Base* base ) { + // TODO: use actual pop objects + HideIcons(); + auto icon_class = SubClass( + base->GetFaction()->m_is_progenitor + ? "IconProgenitor" + : "IconHuman" + ); + const auto population = base->GetPopulation(); + float w = 40.0f; + if ( w * ( population - 1 ) > 390.0f ) { + w = 390.0f / ( population - 1 ); + } + m_icons.reserve( population ); + for ( size_t i = 0 ; i < population ; i++ ) { + NEWV( icon, ::ui::object::Surface, icon_class ); + icon->SetLeft( i * w ); + AddChild( icon ); + m_icons.push_back( icon ); + } +} + +void Population::HideIcons() { + for ( const auto& icon : m_icons ) { + RemoveChild( icon ); + } + m_icons.clear(); +} + } } } diff --git a/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.h b/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.h index 6ae3e39f..a254b590 100644 --- a/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.h +++ b/src/game/frontend/ui/popup/base_popup/bottom_bar/Population.h @@ -1,10 +1,20 @@ #pragma once +#include + #include "game/frontend/ui/bottom_bar/BBSection.h" +namespace ui::object { +class Surface; +} + namespace game { namespace frontend { +namespace base { +class Base; +} + namespace ui { namespace popup { namespace base_popup { @@ -17,7 +27,12 @@ CLASS( Population, BBSection ) void Create() override; void Destroy() override; + void Update( base::Base* base ); + private: + std::vector< ::ui::object::Surface* > m_icons = {}; + + void HideIcons(); }; diff --git a/src/game/frontend/ui/style/BottomBar.cpp b/src/game/frontend/ui/style/BottomBar.cpp index c1c33c57..54b108fd 100644 --- a/src/game/frontend/ui/style/BottomBar.cpp +++ b/src/game/frontend/ui/style/BottomBar.cpp @@ -945,6 +945,24 @@ void BottomBar::AddStyles() { s->Set( ::ui::A_BOTTOM, 85 ); } ); + AddStyle( + "PopulationIcon", SH() { + s->Set( ::ui::A_ALIGN, ::ui::ALIGN_LEFT | ::ui::ALIGN_VCENTER ); + s->Set( ::ui::A_WIDTH, 38 ); + s->Set( ::ui::A_HEIGHT, 48 ); + } + ); + AddStyle( + "PopulationIconHuman", { "PopulationIcon" }, SH() { + s->SetTexture( ::ui::A_TEXTURE, resource::PCX_NEWICONS, 79, 501, 116, 548 ); + } + ); + AddStyle( + "PopulationIconProgenitor", { "PopulationIcon" }, SH() { + s->SetTexture( ::ui::A_TEXTURE, resource::PCX_ALIENCIT, 40, 41, 77, 88 ); + } + ); + AddStyle( "SupportedUnits", SH() { s->Set( ::ui::A_ALIGN, ::ui::ALIGN_TOP | ::ui::ALIGN_RIGHT ); diff --git a/src/loader/texture/TextureLoader.cpp b/src/loader/texture/TextureLoader.cpp index 923391c5..8c3e461f 100644 --- a/src/loader/texture/TextureLoader.cpp +++ b/src/loader/texture/TextureLoader.cpp @@ -71,6 +71,18 @@ static const std::unordered_map< resource::resource_t, TextureLoader::transparen s_tc_purple, } }, + { + resource::PCX_NEWICONS, + { + s_tc_pink, + } + }, + { + resource::PCX_ALIENCIT, + { + s_tc_pink, + } + }, { resource::PCX_CONSOLE_X, { diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index 42aed580..a9479bf6 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -27,6 +27,14 @@ ResourceManager::ResourceManager() PCX_ICONS, "icons.pcx" }, + { + PCX_NEWICONS, + "newicons.pcx" + }, + { + PCX_ALIENCIT, + "aliencit.pcx" + }, { PCX_FLAGS, "flags.pcx" @@ -228,12 +236,12 @@ void ResourceManager::Init( std::vector< std::string > possible_smac_paths, cons // GOG / Planetary Pack if ( ( smac_type == config::ST_GOG || smac_type == config::ST_PP || smac_type == config::ST_AUTO ) && - CheckFiles( - path, { - "terran.exe", - "terranx.exe" - }, print_errors - ) && ResolveBuiltins( + CheckFiles( + path, { + "terran.exe", + "terranx.exe" + }, print_errors + ) && ResolveBuiltins( path, { { ".wav", @@ -241,21 +249,21 @@ void ResourceManager::Init( std::vector< std::string > possible_smac_paths, cons }, }, PM_NONE, print_errors ) - ) { + ) { return; // found GOG } // Loki if ( ( smac_type == config::ST_LOKI || smac_type == config::ST_AUTO ) && - CheckFiles( - path, { - "smac", - "smac.sh", - "smacx", - "smacx.sh", - }, print_errors - ) && ResolveBuiltins( + CheckFiles( + path, { + "smac", + "smac.sh", + "smacx", + "smacx.sh", + }, print_errors + ) && ResolveBuiltins( path + util::FS::PATH_SEPARATOR + "data", { { ".wav", @@ -267,7 +275,7 @@ void ResourceManager::Init( std::vector< std::string > possible_smac_paths, cons } }, PM_SPACES_TO_UNDERSCORES, print_errors ) - ) { + ) { return; // found Loki } if ( smac_type != config::ST_AUTO ) { @@ -281,7 +289,7 @@ void ResourceManager::Init( std::vector< std::string > possible_smac_paths, cons const std::string msg = "Unable to find SMAC distribution (tried paths: " + paths + "). Run from SMAC directory or pass it with --smacpath argument"; Log( msg ); if ( smac_type == config::ST_AUTO ) { - Log("Also try --smactype with your SMAC installation type (e.g. GoG, Loki, Planetary Pack), this will give more descriptive errors if some files are not found."); + Log( "Also try --smactype with your SMAC installation type (e.g. GoG, Loki, Planetary Pack), this will give more descriptive errors if some files are not found." ); } THROW( msg ); } @@ -346,7 +354,14 @@ const bool ResourceManager::CheckFiles( const std::string& path, const std::vect const auto resolved_file = util::FS::GetExistingCaseSensitivePath( path, file ); if ( resolved_file.empty() || !util::FS::IsFile( resolved_file ) ) { if ( print_errors ) { - Log( "Could not find file: " + util::FS::GeneratePath( { path, file } ) ); + Log( + "Could not find file: " + util::FS::GeneratePath( + { + path, + file + } + ) + ); } return false; } @@ -361,7 +376,14 @@ const bool ResourceManager::ResolveBuiltins( const std::string& path, const exte const auto resolved_file = util::FS::GetExistingCaseSensitivePath( path, GetFixedPath( it.second, extension_path_map, path_modifiers ) ); if ( resolved_file.empty() || !util::FS::IsFile( resolved_file ) ) { if ( print_errors ) { - Log( "Could not resolve file: " + util::FS::GeneratePath( { path, it.second } ) ); + Log( + "Could not resolve file: " + util::FS::GeneratePath( + { + path, + it.second + } + ) + ); } return false; } diff --git a/src/resource/Types.h b/src/resource/Types.h index 3aee662a..1df8eae5 100644 --- a/src/resource/Types.h +++ b/src/resource/Types.h @@ -12,6 +12,8 @@ enum resource_t : uint8_t { PCX_INTERFACE, PCX_JACKAL, PCX_ICONS, + PCX_NEWICONS, + PCX_ALIENCIT, PCX_FLAGS, PCX_UNITS, PCX_TEXTURE,