Skip to content

Commit 4983998

Browse files
committed
base preview
1 parent 0384853 commit 4983998

File tree

9 files changed

+118
-22
lines changed

9 files changed

+118
-22
lines changed

GLSMAC_data/default/ui/parts/game/bottom_bar/object_preview.gls.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ return {
2929
return;
3030
}
3131
const cls = #classof(object);
32-
if (cls == 'Base') {
33-
return; // TODO
34-
}
3532
if (this.last_object_class != cls) {
3633
if (this.last_object_class != null) {
3734
this.previews[this.last_object_class].hide();
@@ -85,15 +82,15 @@ return {
8582

8683
this.lines = this.frame.listview({
8784
left: 3,
88-
right: 3, // TODO: fix
85+
right: 3,
8986
top: 86,
9087
bottom: 3,
9188
itemsize: 17,
9289
});
9390

9491
const f_line = (text, size, align) => {
9592
this.lines.text({
96-
align: 'top ' + align, // TODO: fix centered align
93+
align: 'top ' + align,
9794
color: 'rgb(116,156,56)',
9895
font: 'arialnb.ttf:' + #to_string(size),
9996
text: text,
@@ -126,6 +123,11 @@ return {
126123
break;
127124
}
128125
case 'Base': {
126+
127+
f_line(object.name, 14, 'center');
128+
129+
f_line('Producing:', 14, 'left'); // TODO
130+
129131
break;
130132
}
131133
default: {

src/game/backend/base/Base.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ WRAPIMPL_DESERIALIZE( Base )
113113

114114
WRAPIMPL_DYNAMIC_GETTERS( Base )
115115
WRAPIMPL_GET_CUSTOM( "id", Int, m_id )
116+
WRAPIMPL_GET_CUSTOM( "name", String, m_name )
116117
WRAPIMPL_LINK( "get_owner", m_owner )
117118
WRAPIMPL_LINK( "get_tile", m_tile )
118119
{

src/game/frontend/Game.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@
5353
#include "GLSMAC.h"
5454
#include "game/backend/unit/UnitManager.h"
5555
#include "game/backend/unit/Unit.h"
56+
#include "game/backend/base/BaseManager.h"
57+
#include "game/backend/base/Base.h"
5658
#include "game/backend/map/Map.h"
5759
#include "game/backend/map/tile/Tile.h"
5860
#include "ui/UI.h"
5961
#include "ui/dom/Widget.h"
6062
#include "widget/Minimap.h"
6163
#include "widget/TilePreview.h"
6264
#include "widget/UnitPreview.h"
65+
#include "widget/BasePreview.h"
6366
#include "gse/value/Null.h"
6467

6568
#define INITIAL_CAMERA_ANGLE { -M_PI * 0.5, M_PI * 0.75, 0 }
@@ -2647,6 +2650,22 @@ void Game::UpdateUnitPreview( const unit::Unit* const unit ) {
26472650
);
26482651
}
26492652

2653+
void Game::UpdateBasePreview( const base::Base* const base ) {
2654+
auto* const b = base
2655+
? m_game->GetBM()->GetBase( base->GetId() )
2656+
: nullptr;
2657+
Trigger(
2658+
m_game->GetMap(), "base_preview", ARGS_F( &b ) {
2659+
{
2660+
"base",
2661+
b
2662+
? b->Wrap( GSE_CALL )
2663+
: VALUE( gse::value::Null ),
2664+
},
2665+
}; }
2666+
);
2667+
}
2668+
26502669
void Game::UpdatePreviews( tile::Tile* const tile, const unit::Unit* const unit ) {
26512670
// new ui
26522671
UpdateTilePreview( tile );
@@ -2656,7 +2675,14 @@ void Game::UpdatePreviews( tile::Tile* const tile, const unit::Unit* const unit
26562675
else {
26572676
const auto* const selected_unit = m_um->GetSelectedUnit();
26582677
if ( !selected_unit || selected_unit->GetTile() != tile ) {
2659-
UpdateUnitPreview( tile->GetMostImportantUnit() );
2678+
const auto* const important_unit = tile->GetMostImportantUnit();
2679+
const auto* base = tile->GetBase();
2680+
if ( !important_unit && base ) {
2681+
UpdateBasePreview( base );
2682+
}
2683+
else {
2684+
UpdateUnitPreview( important_unit );
2685+
}
26602686
}
26612687
}
26622688
}

src/game/frontend/Game.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ namespace frontend {
9393
#define X_WIDGETS \
9494
X_WIDGET( Minimap ) \
9595
X_WIDGET( TilePreview ) \
96-
X_WIDGET( UnitPreview )
96+
X_WIDGET( UnitPreview ) \
97+
X_WIDGET( BasePreview )
9798

9899
namespace widget {
99100
#define X_WIDGET( _x ) class _x;
@@ -531,6 +532,7 @@ CLASS( Game, common::Module )
531532
void SetSelectedTile( tile::Tile* tile );
532533
void UpdateTilePreview( tile::Tile* const tile );
533534
void UpdateUnitPreview( const unit::Unit* const unit );
535+
void UpdateBasePreview( const base::Base* const base );
534536
void UpdatePreviews( tile::Tile* const tile, const unit::Unit* const unit );
535537
void RefreshSelectedTile( unit::Unit* selected_unit = nullptr );
536538
void RefreshSelectedTileIf( tile::Tile* if_tile, const unit::Unit* const selected_unit );
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "BasePreview.h"
2+
3+
#include "ui/UI.h"
4+
#include "ui/dom/Widget.h"
5+
#include "game/frontend/base/Base.h"
6+
#include "types/mesh/Rectangle.h"
7+
#include "ui/geometry/Rectangle.h"
8+
#include "scene/actor/Mesh.h"
9+
#include "game/frontend/Game.h"
10+
#include "game/backend/base/Base.h"
11+
#include "game/frontend/base/BaseManager.h"
12+
13+
namespace game {
14+
namespace frontend {
15+
namespace widget {
16+
17+
BasePreview::BasePreview( const Game* const game, ui::UI* const ui )
18+
: Widget(
19+
game, ui, ui::WT_BASE_PREVIEW, "base-preview", {
20+
{ "base", { gse::VT_OBJECT, ::game::backend::base::Base::WRAP_CLASS } },
21+
}
22+
) {}
23+
24+
void BasePreview::Register( ui::dom::Widget* const widget ) {
25+
widget->OnUpdate(
26+
F_WIDGET_UPDATE( this ) {
27+
const auto* const u = ::game::backend::base::Base::Unwrap( data->value.at( "base" ) );
28+
ASSERT( u, "invalid base ptr" );
29+
const auto* const base = m_game->GetBM()->GetBaseById( u->m_id );
30+
ASSERT( base, "invalid base" );
31+
Update( widget, base );
32+
}
33+
);
34+
}
35+
36+
void BasePreview::Update( ui::dom::Widget* const widget, const base::Base* const base ) {
37+
widget->Clear();
38+
39+
const auto& render = base->GetRenderData();
40+
41+
size_t index = 0;
42+
43+
ASSERT( render.base.mesh->GetType() == types::mesh::Mesh::MT_RECTANGLE, "base mesh not rectangle" ); // TODO: 3d bases
44+
45+
AddMeshAndTexture( widget, index++, render.base.mesh, render.base.texture, true );
46+
AddMeshAndTexture( widget, index++, render.badge.mesh, render.badge.texture, true, { 0.16f, 0.27f }, { 0.04f, 0.04f } );
47+
}
48+
49+
}
50+
}
51+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include "Widget.h"
4+
5+
namespace game {
6+
namespace frontend {
7+
8+
namespace base {
9+
class Base;
10+
}
11+
12+
namespace widget {
13+
14+
CLASS( BasePreview, Widget )
15+
public:
16+
BasePreview( const Game* const game, ui::UI* const ui );
17+
18+
void Update( ui::dom::Widget* const widget, const base::Base* const unit );
19+
20+
protected:
21+
void Register( ui::dom::Widget* const widget ) override;
22+
23+
};
24+
25+
}
26+
}
27+
}

src/game/frontend/widget/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ SET( SRC ${SRC}
44
${PWD}/Minimap.cpp
55
${PWD}/TilePreview.cpp
66
${PWD}/UnitPreview.cpp
7+
${PWD}/BasePreview.cpp
78

89
PARENT_SCOPE )

src/game/frontend/widget/UnitPreview.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
#include "Widget.h"
44

5-
namespace scene::actor {
6-
class Mesh;
7-
}
8-
9-
namespace types::texture {
10-
class Texture;
11-
}
12-
135
namespace game {
146
namespace frontend {
157

@@ -28,13 +20,6 @@ CLASS( UnitPreview, Widget )
2820
protected:
2921
void Register( ui::dom::Widget* const widget ) override;
3022

31-
private:
32-
struct preview_layer_t {
33-
scene::actor::Mesh* object;
34-
types::texture::Texture* texture;
35-
};
36-
std::vector< preview_layer_t > m_preview_layers = {}; // multiple layers of textures
37-
3823
};
3924

4025
}

src/ui/Types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum widget_type_t {
4848
WT_MINIMAP,
4949
WT_TILE_PREVIEW,
5050
WT_UNIT_PREVIEW,
51+
WT_BASE_PREVIEW,
5152
};
5253

5354
typedef std::function< void( ::ui::dom::Widget* const widget ) > f_with_widget_t;

0 commit comments

Comments
 (0)