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 12, 2024
2 parents 96ab706 + c640ab6 commit a3c865d
Show file tree
Hide file tree
Showing 35 changed files with 645 additions and 164 deletions.
2 changes: 1 addition & 1 deletion src/env/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern debug_stats_t g_debug_stats;

#define NEW( _var, _class, ... ) \
_var = new _class( __VA_ARGS__ ); \
debug::g_memory_watcher->New( _var, sizeof( _class ), __FILE__, __LINE__ );
debug::g_memory_watcher->New( _var, sizeof( _class ), __FILE__, __LINE__ )

#define NEWV( _var, _class, ... ) \
_class* _var; \
Expand Down
34 changes: 24 additions & 10 deletions src/game/frontend/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,10 @@ void Game::Initialize(
break;
}
case ::ui::event::K_ENTER: {
if ( m_turn_status == backend::turn::TS_TURN_COMPLETE ) {
CompleteTurn();
break;
}
auto* const unit = m_um->GetSelectedUnit();
if ( unit ) {
ASSERT( unit->IsActive(), "selected unit not active" );
Expand All @@ -1345,10 +1349,6 @@ void Game::Initialize(
}
}
}
if ( m_turn_status == backend::turn::TS_TURN_COMPLETE ) {
CompleteTurn();
break;
}
break;
}
default: {
Expand Down Expand Up @@ -1891,6 +1891,8 @@ void Game::DeselectTileOrUnit() {

void Game::OpenBasePopup( base::Base* base ) {
if ( !m_base_popup ) {
m_tile_selected_before_base_popup = m_tm->GetPreviouslyDeselectedTile();
m_unit_selected_before_base_popup = m_um->GetPreviouslyDeselectedUnit();
NEW( m_base_popup, ui::popup::base_popup::BasePopup, this, base );
m_base_popup->Open();
}
Expand Down Expand Up @@ -2355,6 +2357,12 @@ void Game::ScrollToSelectedTile( const bool center_on_tile ) {
ScrollToTile( m_tm->GetSelectedTile(), center_on_tile );
}

void Game::SelectAnyUnitAtTile( tile::Tile* tile ) {
m_tile_at_query_purpose = backend::TQP_UNIT_SELECT;
SelectTileOrUnit( tile );
ScrollToTile( tile, true );
}

void Game::SelectUnitOrSelectedTile( unit::Unit* selected_unit ) {
ASSERT( m_tm->GetSelectedTile(), "tile not selected" );
m_tile_at_query_purpose = backend::TQP_UNIT_SELECT;
Expand Down Expand Up @@ -2383,15 +2391,21 @@ Game::map_data_t::map_data_t()

void Game::OnBasePopupClose() {
ASSERT( m_base_popup, "base popup not open" );
auto* const unit = m_um->GetPreviouslyDeselectedUnit();
if ( unit ) {
m_um->SelectUnit( unit, true );
if ( m_unit_selected_before_base_popup ) {
m_um->SelectUnit( m_unit_selected_before_base_popup, true );
//ScrollToTile( m_unit_selected_before_base_popup->GetTile(), true );
}
else {
m_tile_at_query_purpose = backend::TQP_UNIT_SELECT;
SelectTileOrUnit( m_base_popup->GetBase()->GetTile() );
else if ( m_tile_selected_before_base_popup ) {
m_tile_at_query_purpose = backend::TQP_TILE_SELECT;
SelectTileOrUnit( m_tile_selected_before_base_popup );
//ScrollToTile( m_tile_selected_before_base_popup, true );
}
m_base_popup = nullptr;
m_unit_selected_before_base_popup = nullptr;
}

void Game::SetBasePopupSelectedUnit( unit::Unit* unit ) {
m_unit_selected_before_base_popup = unit;
}

}
Expand Down
10 changes: 10 additions & 0 deletions src/game/frontend/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class Theme;
}
namespace popup::base_popup {
class BasePopup;
namespace bottom_bar {
class UnitsList;
}
}
}

Expand Down Expand Up @@ -468,6 +471,8 @@ CLASS( Game, common::Module )
void SendAnimationFinished( const size_t animation_id );

ui::popup::base_popup::BasePopup* m_base_popup = nullptr;
unit::Unit* m_unit_selected_before_base_popup = nullptr;
tile::Tile* m_tile_selected_before_base_popup = nullptr;

private:
friend class unit::UnitManager;
Expand All @@ -481,13 +486,18 @@ CLASS( Game, common::Module )
void RefreshSelectedTile( unit::Unit* selected_unit );
void RefreshSelectedTileIf( tile::Tile* if_tile, unit::Unit* selected_unit );
void ScrollToSelectedTile( const bool center_on_tile );
void SelectAnyUnitAtTile( tile::Tile* tile );
void SelectUnitOrSelectedTile( unit::Unit* selected_unit );
unit::Unit* GetSelectedTileMostImportantUnit() const;

private:
friend class ui::popup::base_popup::BasePopup;
void OnBasePopupClose();

private:
friend class ui::popup::base_popup::bottom_bar::UnitsList;
void SetBasePopupSelectedUnit( unit::Unit* unit );

};

}
Expand Down
8 changes: 8 additions & 0 deletions src/game/frontend/base/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ const size_t Base::GetId() const {
return m_id;
}

const std::string& Base::GetName() const {
return m_name;
}

faction::Faction* const Base::GetFaction() const {
return m_faction;
}

const bool Base::IsOwned() const {
return m_is_owned;
}
Expand Down
2 changes: 2 additions & 0 deletions src/game/frontend/base/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Base : public TileObject {
~Base();

const size_t GetId() const;
const std::string& GetName() const;
faction::Faction* const GetFaction() const;
const bool IsOwned() const;
tile::Tile* GetTile() const;

Expand Down
39 changes: 39 additions & 0 deletions src/game/frontend/base/BaseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ void BaseManager::SpawnBase(
)
}
);
auto it = m_faction_base_ids.find( faction );
if ( it == m_faction_base_ids.end() ) {
it = m_faction_base_ids.insert(
{
faction,
{}
}
).first;
}
ASSERT( it->second.find( base_id ) == it->second.end(), "faction base id already exists" );
it->second.insert( base_id );

m_game->RenderTile( tile, m_game->GetUM()->GetSelectedUnit() );

Expand Down Expand Up @@ -115,6 +126,34 @@ void BaseManager::SelectBase( Base* base ) {
m_game->OpenBasePopup( base );
}

Base* BaseManager::GetBaseBefore( Base* base ) const {
const auto& ids_it = m_faction_base_ids.find( base->GetFaction() );
ASSERT( ids_it != m_faction_base_ids.end(), "faction ids not found" );
const auto& ids = ids_it->second;
auto it = ids.find( base->GetId() );
ASSERT( it != ids.end(), "base not in faction ids" );
if ( it == ids.begin() ) {
it = ids.end();
}
it--;
ASSERT( m_bases.find( *it ) != m_bases.end(), "base id not found" );
return m_bases.at( *it );
}

Base* BaseManager::GetBaseAfter( Base* base ) const {
const auto& ids_it = m_faction_base_ids.find( base->GetFaction() );
ASSERT( ids_it != m_faction_base_ids.end(), "faction ids not found" );
const auto& ids = ids_it->second;
auto it = ids.find( base->GetId() );
ASSERT( it != ids.end(), "base not in faction ids" );
it++;
if ( it == ids.end() ) {
it = ids.begin();
}
ASSERT( m_bases.find( *it ) != m_bases.end(), "base id not found" );
return m_bases.at( *it );
}

text::InstancedFont* BaseManager::GetBadgeFont() const {
return m_badge_font;
}
Expand Down
6 changes: 5 additions & 1 deletion src/game/frontend/base/BaseManager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <unordered_map>
#include <vector>
#include <set>

#include "common/Common.h"

Expand Down Expand Up @@ -65,6 +65,8 @@ CLASS( BaseManager, common::Class )
void DefineSlotBadges( const size_t slot_index, const faction::Faction* faction );

void SelectBase( Base* base );
Base* GetBaseBefore( Base* base ) const;
Base* GetBaseAfter( Base* base ) const;

private:
friend class Base;
Expand All @@ -84,6 +86,8 @@ CLASS( BaseManager, common::Class )
std::unordered_map< size_t, SlotBadges* > m_slot_badges = {};

std::unordered_map< size_t, base::Base* > m_bases = {};
typedef std::set< size_t > ordered_base_ids_t;
std::unordered_map< faction::Faction*, ordered_base_ids_t > m_faction_base_ids = {};

};

Expand Down
5 changes: 5 additions & 0 deletions src/game/frontend/tile/TileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,17 @@ void TileManager::SelectTile( Tile* tile ) {
}

void TileManager::DeselectTile() {
m_previously_deselected_tile = m_selected_tile;
if ( m_selected_tile ) {
m_selected_tile->Render();
m_selected_tile = nullptr;
}
}

Tile* TileManager::GetPreviouslyDeselectedTile() const {
return m_previously_deselected_tile;
}

}
}
}
2 changes: 2 additions & 0 deletions src/game/frontend/tile/TileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CLASS( TileManager, ::common::Class )
Tile* GetSelectedTile() const;
void SelectTile( Tile* tile );
void DeselectTile();
Tile* GetPreviouslyDeselectedTile() const;

private:

Expand All @@ -37,6 +38,7 @@ CLASS( TileManager, ::common::Class )
std::unordered_map< size_t, Tile > m_tiles = {};

Tile* m_selected_tile = nullptr;
Tile* m_previously_deselected_tile = nullptr;

};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SET( SRC ${SRC}

${PWD}/ObjectsListBase.cpp
${PWD}/ObjectsList.cpp
${PWD}/ObjectsListItem.cpp

Expand Down
Loading

0 comments on commit a3c865d

Please sign in to comment.