Skip to content

Commit

Permalink
Merge branch 'main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Oct 19, 2024
2 parents 3e51746 + 4bf8aac commit c946673
Show file tree
Hide file tree
Showing 34 changed files with 785 additions and 66 deletions.
2 changes: 1 addition & 1 deletion GLSMAC_data/default/main.gls.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ units.init();
}
}
}
if (#game.random.get_int(0, 2) == 0) {
if (#game.random.get_int(0, 5) == 0) {
let has_adjactent_bases = false;
for (neighbour of tile.get_surrounding_tiles()) {
if (neighbour.get_base() != null) {
Expand Down
6 changes: 6 additions & 0 deletions src/game/frontend/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ void Game::Initialize(
if ( tile ) {
auto* const base = tile->GetBase();
if ( base ) {
DeselectTileOrUnit();
OpenBasePopup( base );
break;
}
Expand Down Expand Up @@ -2408,5 +2409,10 @@ void Game::SetBasePopupSelectedUnit( unit::Unit* unit ) {
m_unit_selected_before_base_popup = unit;
}

void Game::SelectBase( base::Base* base ) {
DeselectTileOrUnit();
m_bm->SelectBase( base );
}

}
}
4 changes: 4 additions & 0 deletions src/game/frontend/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ CLASS( Game, common::Module )
friend class ui::popup::base_popup::bottom_bar::UnitsList;
void SetBasePopupSelectedUnit( unit::Unit* unit );

private:
friend class base::Base;
void SelectBase( base::Base* base );

};

}
Expand Down
16 changes: 11 additions & 5 deletions src/game/frontend/base/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Base::Base(
, m_render(
{
render_coords,
nullptr,
render_name_sprite,
false,
0,
Expand Down Expand Up @@ -90,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 All @@ -103,14 +108,15 @@ sprite::Sprite* Base::GetSprite() const {

void Base::Show() {
if ( !m_render.is_rendered ) {

const auto& c = m_render.coords;

sprite::Sprite* sprite = GetSprite();
m_render.sprite = GetSprite();

if ( !m_render.instance_id ) {
m_render.instance_id = sprite->next_instance_id++;
m_render.instance_id = m_render.sprite->next_instance_id++;
}
sprite->instanced_sprite->actor->SetInstance(
m_render.sprite->instanced_sprite->actor->SetInstance(
m_render.instance_id, {
c.x,
c.y,
Expand All @@ -134,7 +140,7 @@ void Base::Show() {

void Base::Hide() {
if ( m_render.is_rendered ) {
GetSprite()->instanced_sprite->actor->RemoveInstance( m_render.instance_id );
m_render.sprite->instanced_sprite->actor->RemoveInstance( m_render.instance_id );
m_render.name_sprite->Hide();
HideBadge();
m_render.is_rendered = false;
Expand Down Expand Up @@ -251,7 +257,7 @@ void Base::DestroyOnBottomBarPreview( ui::ObjectPreview* element, void* state )
}

const bool Base::OnBottomBarListActivate( Game* game ) {
game->GetBM()->SelectBase( this );
game->SelectBase( this );
return false; // because previously active unit should stay active, base popup will have it's own bottombar
}

Expand Down
6 changes: 4 additions & 2 deletions src/game/frontend/base/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace texture {
class Texture;
}
namespace mesh {
class Mesh;
class Simple;
}
}

Expand Down 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 All @@ -76,7 +77,7 @@ class Base : public TileObject {
void Update();

struct meshtex_t {
const types::mesh::Mesh* mesh = nullptr;
const types::mesh::Simple* mesh = nullptr;
types::texture::Texture* texture = nullptr;
};
struct render_data_t {
Expand Down Expand Up @@ -106,6 +107,7 @@ class Base : public TileObject {

struct {
types::Vec3 coords = {};
sprite::Sprite* sprite = nullptr;
text::InstancedText* name_sprite = nullptr;
bool is_rendered = false;
size_t instance_id = 0;
Expand Down
41 changes: 30 additions & 11 deletions src/game/frontend/tile/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,33 @@ void Tile::Update( const backend::map::tile::Tile& tile, const backend::map::til
const auto& layer = ts.layers[ lt ];

backend::map::tile::tile_vertices_t selection_coords = {};
backend::map::tile::tile_vertices_t preview_coords = {};
backend::map::tile::tile_vertices_t preview_coords = {
{
0.0f,
0.0f,
0.0f
},
{
-0.5f,
0.0f,
0.0f,
},
{
0.0f,
-0.5f,
0.0f,
},
{
0.5f,
0.0f,
0.0f,
},
{
0.0f,
0.5f,
0.0f,
}
};

#define x( _k ) selection_coords._k = layer.coords._k
x( center );
Expand All @@ -305,14 +331,7 @@ void Tile::Update( const backend::map::tile::Tile& tile, const backend::map::til
}
}

#define x( _k ) preview_coords._k = layer.coords._k
x( center );
x( left );
x( top );
x( right );
x( bottom );
#undef x
// absolute coords to relative
// absolute coords to relative
#define x( _k ) preview_coords._k -= preview_coords.center
x( left );
x( top );
Expand Down Expand Up @@ -358,9 +377,9 @@ void Tile::Update( const backend::map::tile::Tile& tile, const backend::map::til

auto tint = l.colors;

//Log( "Coords = " + preview_coords.center.ToString() + " " + preview_coords.left.ToString() + " " + preview_coords.top.ToString() + " " + preview_coords.right.ToString() + " " + preview_coords.bottom.ToString() );
std::string c = "Coords = " + preview_coords.center.ToString() + " " + preview_coords.left.ToString() + " " + preview_coords.top.ToString() + " " + preview_coords.right.ToString() + " " + preview_coords.bottom.ToString();

#define x( _k ) auto _k = mesh->AddVertex( preview_coords._k, l.tex_coords._k, tint._k * tint_modifier )
#define x( _k ) auto _k = mesh->AddVertex( { preview_coords._k.x, preview_coords._k.y, preview_coords._k.z }, l.tex_coords._k, tint._k * tint_modifier )
x( center );
x( left );
x( top );
Expand Down
3 changes: 2 additions & 1 deletion src/game/frontend/tile/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Tile {
Tile* SW;
Tile* GetNeighbour( const backend::map::tile::direction_t direction );

const types::Vec2< size_t > m_coords;

struct render_data_t {
types::Vec3 coords = {};
backend::map::tile::tile_vertices_t selection_coords = {};
Expand All @@ -84,7 +86,6 @@ class Tile {
void Update( const backend::map::tile::Tile& tile, const backend::map::tile::TileState& ts );

private:
const types::Vec2< size_t > m_coords;

struct {
unit::Unit* currently_rendered_unit = nullptr;
Expand Down
10 changes: 6 additions & 4 deletions src/game/frontend/ui/popup/base_popup/BasePopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "Nutrients.h"
#include "Commerce.h"
#include "GlobalInfo.h"
#include "CenterArea.h"
#include "game/frontend/ui/popup/base_popup/center_area/CenterArea.h"
#include "Yields.h"
#include "Energy.h"
#include "Facilities.h"
Expand Down Expand Up @@ -67,7 +67,7 @@ void BasePopup::Create() {
NEW( m_sections.global_info, GlobalInfo, this );
AddChild( m_sections.global_info );

NEW( m_sections.center_area, CenterArea, this );
NEW( m_sections.center_area, center_area::CenterArea, this );
AddChild( m_sections.center_area );

NEW( m_sections.yields, Yields, this );
Expand All @@ -81,6 +81,8 @@ void BasePopup::Create() {

NEW( m_sections.buttons, Buttons, this );
AddChild( m_sections.buttons );

m_sections.center_area->Update( m_base );
}

void BasePopup::Destroy() {
Expand Down Expand Up @@ -114,8 +116,7 @@ void BasePopup::OnOpen() {
g_engine->GetUI()->AddObject( m_bottom_bar );
AddEventsTarget( m_bottom_bar );

Update( m_base );

m_bottom_bar->Update( m_base );
}

void BasePopup::OnClose() {
Expand All @@ -134,6 +135,7 @@ void BasePopup::Update( base::Base* base ) {
m_game->SelectAnyUnitAtTile( m_base->GetTile() );
}
m_bottom_bar->Update( m_base );
m_sections.center_area->Update( m_base );
}

void BasePopup::SelectNextBase() {
Expand Down
6 changes: 5 additions & 1 deletion src/game/frontend/ui/popup/base_popup/BasePopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class Governor;
class Nutrients;
class Commerce;
class GlobalInfo;

namespace center_area {
class CenterArea;
}

class Yields;
class Energy;
class Facilities;
Expand Down Expand Up @@ -57,7 +61,7 @@ CLASS( BasePopup, Popup )
Nutrients* nutrients = nullptr;
Commerce* commerce = nullptr;
GlobalInfo* global_info = nullptr;
CenterArea* center_area = nullptr;
center_area::CenterArea* center_area = nullptr;
Yields* yields = nullptr;
Energy* energy = nullptr;
Facilities* facilities = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/game/frontend/ui/popup/base_popup/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SUBDIR( bottom_bar )
SUBDIR( center_area )

SET( SRC ${SRC}

Expand All @@ -8,7 +9,6 @@ SET( SRC ${SRC}
${PWD}/Nutrients.cpp
${PWD}/Commerce.cpp
${PWD}/GlobalInfo.cpp
${PWD}/CenterArea.cpp
${PWD}/Yields.cpp
${PWD}/Energy.cpp
${PWD}/Facilities.cpp
Expand Down
16 changes: 0 additions & 16 deletions src/game/frontend/ui/popup/base_popup/CenterArea.cpp

This file was deleted.

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
Loading

0 comments on commit c946673

Please sign in to comment.