Skip to content

Commit

Permalink
dummy population icons
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Oct 19, 2024
1 parent 18e53e8 commit 4bf8aac
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/game/frontend/base/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++ ) {
Expand Down
1 change: 1 addition & 0 deletions src/game/frontend/base/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
34 changes: 34 additions & 0 deletions src/game/frontend/ui/popup/base_popup/bottom_bar/Population.cpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
}

}
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/game/frontend/ui/popup/base_popup/bottom_bar/Population.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#pragma once

#include <vector>

#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 {
Expand All @@ -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();

};

Expand Down
18 changes: 18 additions & 0 deletions src/game/frontend/ui/style/BottomBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
12 changes: 12 additions & 0 deletions src/loader/texture/TextureLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down
60 changes: 41 additions & 19 deletions src/resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ ResourceManager::ResourceManager()
PCX_ICONS,
"icons.pcx"
},
{
PCX_NEWICONS,
"newicons.pcx"
},
{
PCX_ALIENCIT,
"aliencit.pcx"
},
{
PCX_FLAGS,
"flags.pcx"
Expand Down Expand Up @@ -228,34 +236,34 @@ 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",
"fx"
},
}, 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",
Expand All @@ -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 ) {
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/resource/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4bf8aac

Please sign in to comment.