Skip to content

Commit aec1cb6

Browse files
committed
fixed ui bugs
1 parent f56c2b1 commit aec1cb6

File tree

16 files changed

+179
-51
lines changed

16 files changed

+179
-51
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ return {
5050
ui: p.ui,
5151
el: el,
5252
sections: {},
53+
get_stats_str: (object) => {
54+
switch (#classof(object)) {
55+
case 'Unit': {
56+
let stats_str = '';
57+
// tmp
58+
const def = object.get_def();
59+
if (def.id == 'SporeLauncher') {
60+
stats_str += '(?)';
61+
} else {
62+
stats_str += '?';
63+
}
64+
stats_str += ' - ? - ' + #to_string(#round(def.movement_per_turn));
65+
return stats_str;
66+
}
67+
}
68+
return '';
69+
},
5370
};
5471
for (s of ['object_preview', 'tile_preview', 'middle_area', 'objects_list', 'mini_map']) {
5572
pp.sections[s] = #include(s);

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,8 @@ return {
103103
const def = object.get_def();
104104

105105
f_line(def.name, 16, 'center');
106-
let stats_str = '';
107106

108-
// tmp
109-
if (def.id == 'SporeLauncher') {
110-
stats_str += '(?)';
111-
} else {
112-
stats_str += '?';
113-
}
114-
stats_str += ' - ? - ' + #to_string(#round(def.movement_per_turn));
115-
f_line(stats_str, 14, 'center');
107+
f_line(this.p.get_stats_str(object), 14, 'center');
116108

117109
f_line(this.get_morale('NATIVE', object.morale), 14, 'left');
118110

@@ -125,7 +117,7 @@ return {
125117
case 'Base': {
126118

127119
f_line(object.name, 14, 'center');
128-
120+
129121
f_line('Producing:', 14, 'left'); // TODO
130122

131123
break;
@@ -138,6 +130,8 @@ return {
138130

139131
init: (p) => {
140132

133+
this.p = p;
134+
141135
this.um = p.game.get_um();
142136

143137
this.frame = p.el.panel({

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

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,98 @@
11
return {
22

3+
add_object: (object, left) => {
4+
const cls = #classof(object);
5+
let type = null;
6+
let data = {};
7+
let top = 0;
8+
switch (cls) {
9+
case 'Unit': {
10+
type = 'unit-preview';
11+
data.unit = object;
12+
top = -2;
13+
break;
14+
}
15+
case 'Base': {
16+
type = 'base-preview';
17+
data.base = object;
18+
top = 2;
19+
break;
20+
}
21+
default: {
22+
throw Error('Unknown object type: ' + #classof(object));
23+
}
24+
}
25+
26+
let item = this.list.panel({
27+
class: 'bottombar-objects-list-item',
28+
left: left,
29+
});
30+
item.widget({
31+
type: type,
32+
data: data,
33+
class: 'bottombar-objects-list-item-preview',
34+
top: top,
35+
});
36+
if (cls == 'Unit') {
37+
const p = this.p; // TODO: make this work within object
38+
item.text({
39+
class: 'bottombar-objects-list-item-text',
40+
text: p.get_stats_str(object),
41+
});
42+
}
43+
},
44+
345
update_units: (tile) => {
446
if (#is_defined(this.list)) {
547
this.list.remove();
648
}
749
this.list = this.frame.scrollview({
850
left: 2,
951
right: 2,
10-
top: -6,
11-
bottom: -4,
52+
top: -8,
53+
bottom: -6,
1254
padding: 10,
1355
});
1456

15-
const width = 64;
1657
let left = 0;
1758

59+
const base = tile.get_base();
60+
61+
if (base != null) {
62+
this.add_object(base, left);
63+
left += this.object_width;
64+
}
65+
1866
for (unit of tile.get_units()) {
19-
#print('UNIT', unit);
20-
this.list.widget({
21-
type: 'unit-preview',
22-
data: {
23-
unit: unit,
24-
},
25-
left: left,
26-
width: width,
27-
height: 48,
28-
});
29-
left += width;
67+
this.add_object(unit, left);
68+
left += this.object_width;
3069
}
3170
},
3271

3372
init: (p) => {
3473

74+
this.p = p;
75+
76+
this.object_width = 57;
77+
78+
const width = this.object_width; // TODO: fix so that this works inside properties
79+
80+
p.ui.class('bottombar-objects-list-item').set({
81+
width: width,
82+
height: 48,
83+
});
84+
85+
p.ui.class('bottombar-objects-list-item-preview').set({
86+
width: width,
87+
height: 43,
88+
});
89+
90+
p.ui.class('bottombar-objects-list-item-text').set({
91+
font: 'arialnb.ttf:12',
92+
color: 'rgb(235,235,235)',
93+
align: 'bottom center',
94+
});
95+
3596
this.frame = p.el.panel({
3697
class: 'bottombar-frame',
3798
align: 'bottom',

src/common/Common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "Assert.h"
88

9+
#define VERY_BIG_NUMBER 99999999999 // to detect sign overflows
10+
911
// used in multiline ToString() implementations
1012

1113
#define TS_DEF() const std::string ToString( const std::string& prefix ) const override;

src/game/frontend/Game.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ void Game::ProcessRequest( const FrontendRequest* request ) {
12651265
case FrontendRequest::FR_BASE_UPDATE: {
12661266
const auto& d = request->data.base_update;
12671267
auto* base = m_bm->GetBaseById( d.base_id );
1268+
ASSERT( base, "base is null" );
12681269
base->SetName( *d.name );
12691270
// TODO: update slot index
12701271
if ( base->GetFaction()->m_id != *d.faction_id ) {
@@ -1521,6 +1522,7 @@ void Game::Initialize(
15211522
case ::ui_legacy::event::_altkey: { \
15221523
td = backend::map::tile::_direction; \
15231524
is_tile_selected = true; \
1525+
m_tile_at_query_purpose = backend::TQP_TILE_SELECT; \
15241526
break; \
15251527
}
15261528
X( K_LEFT, K_KP_LEFT, D_W )
@@ -2326,7 +2328,6 @@ void Game::GetMinimapTexture( scene::Camera* camera, const types::Vec2< size_t >
23262328
Log( "Canceling minimap texture request" );
23272329
m_actors.terrain->GetMeshActor()->CancelDataRequest( m_minimap_texture_request_id );
23282330
}
2329-
Log( "Requesting minimap texture" );
23302331
m_minimap_texture_request_id = m_actors.terrain->GetMeshActor()->CaptureToTexture( camera, texture_dimensions );
23312332
}
23322333

@@ -2349,6 +2350,7 @@ void Game::UpdateMinimap() {
23492350
if ( !minimap_size.x || !minimap_size.y ) {
23502351
return;
23512352
}
2353+
Log( "Requesting minimap ( " + std::to_string( minimap_size.x ) + "x" + std::to_string( minimap_size.y ) + " )" );
23522354

23532355
const float sx = minimap_size.x / (float)( m_map_data.width ) / (float)backend::map::s_consts.tc.texture_pcx.dimensions.x;
23542356
const float sy = minimap_size.y / (float)( m_map_data.height ) / (float)backend::map::s_consts.tc.texture_pcx.dimensions.y;

src/game/frontend/base/BaseManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ BaseManager::~BaseManager() {
4646
}
4747

4848
base::Base* BaseManager::GetBaseById( const size_t id ) const {
49-
ASSERT( m_bases.find( id ) != m_bases.end(), "base id not found" );
50-
return m_bases.at( id );
49+
const auto& it = m_bases.find( id );
50+
return it != m_bases.end()
51+
? it->second
52+
: nullptr;
5153
}
5254

5355
void BaseManager::DefinePop( const backend::base::PopDef* def ) {

src/game/frontend/widget/BasePreview.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ void BasePreview::Register( ui::dom::Widget* const widget ) {
2727
const auto* const u = ::game::backend::base::Base::Unwrap( data->value.at( "base" ) );
2828
ASSERT( u, "invalid base ptr" );
2929
const auto* const base = m_game->GetBM()->GetBaseById( u->m_id );
30-
ASSERT( base, "invalid base" );
31-
Update( widget, base );
30+
if ( base ) {
31+
Update( widget, base );
32+
}
3233
}
3334
);
3435
}

src/game/frontend/widget/Minimap.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ void Minimap::Update( const types::texture::Texture* minimap_texture ) {
3636
WITH_WIDGET( &minimap_texture ) {
3737
// TODO: downscale in case of multiple minimaps of different sizes
3838
auto* const texture = widget->GetTexture();
39-
texture->AddFrom( minimap_texture, types::texture::AM_MIRROR_Y, 0, 0, texture->GetWidth() - 1, texture->GetHeight() - 1 );
40-
texture->FullUpdate();
39+
const auto w = minimap_texture->GetWidth();
40+
const auto h = minimap_texture->GetHeight();
41+
if ( w == texture->GetWidth() && h == texture->GetHeight() ) { // update only if matches exactly (won't match for example during resize)
42+
texture->AddFrom( minimap_texture, types::texture::AM_MIRROR_Y, 0, 0, w - 1, h - 1 );
43+
texture->FullUpdate();
44+
}
4145
} );
4246
}
4347

src/gse/Wrappable.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ Value* const Wrappable::Trigger( GSE_CALLABLE, const std::string& event, gse::va
130130
m_callbacks_mutex.lock(); // to prevent error when guard exits
131131
throw e;
132132
}
133-
catch ( const std::runtime_error& e ) {
134-
m_callbacks_mutex.lock(); // to prevent error when guard exits
135-
throw e;
136-
}
137133
m_callbacks_mutex.lock();
138134
if ( expected_return_type.has_value() ) {
139135
if ( !result || result->type != expected_return_type.value() ) {

src/types/texture/Texture.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void Texture::Resize( const size_t width, const size_t height ) {
5555
if ( m_width != width || m_height != height ) {
5656

5757
//Log( "Setting texture size to " + std::to_string( width ) + "x" + std::to_string( height ) );
58+
ASSERT( width < VERY_BIG_NUMBER, "texture width overflow" );
59+
ASSERT( height < VERY_BIG_NUMBER, "texture height overflow" );
5860

5961
m_width = width;
6062
m_height = height;
@@ -158,6 +160,9 @@ void Texture::Fill( const size_t x1, const size_t y1, const size_t x2, const siz
158160
void Texture::AddFrom( const types::texture::Texture* source, add_flag_t flags, const size_t x1, const size_t y1, const size_t x2, const size_t y2, const size_t dest_x, const size_t dest_y, const rotate_t rotate, const float alpha, util::random::Random* rng, util::Perlin* perlin ) {
159161
ASSERT( x2 >= x1, "invalid source x size ( " + std::to_string( x2 ) + " < " + std::to_string( x1 ) + " )" );
160162
ASSERT( y2 >= y1, "invalid source y size ( " + std::to_string( y2 ) + " < " + std::to_string( y1 ) + " )" );
163+
ASSERT( source, "source texture is null" );
164+
ASSERT( x2 < source->m_width, "source x overflow ( " + std::to_string( x2 ) + " >= " + std::to_string( source->m_width ) + " )" );
165+
ASSERT( y2 < source->m_height, "source y overflow ( " + std::to_string( y2 ) + " >= " + std::to_string( source->m_height ) + " )" );
161166
ASSERT( dest_x + ( x2 - x1 ) < m_width, "destination x overflow ( " + std::to_string( dest_x + ( x2 - x1 ) ) + " >= " + std::to_string( m_width ) + " )" );
162167
ASSERT( dest_y + ( y2 - y1 ) < m_height, "destination y overflow (" + std::to_string( dest_y + ( y2 - y1 ) ) + " >= " + std::to_string( m_height ) + " )" );
163168
ASSERT( alpha >= 0, "invalid alpha value ( " + std::to_string( alpha ) + " < 0 )" );
@@ -177,8 +182,11 @@ void Texture::AddFrom( const types::texture::Texture* source, add_flag_t flags,
177182
const size_t w = x2 - x1 + 1;
178183
const size_t h = y2 - y1 + 1;
179184

180-
const void* from;
181-
void* to;
185+
ASSERT( w > 0, "w is zero" );
186+
ASSERT( h > 0, "h is zero" );
187+
188+
const void* from = nullptr;
189+
void* to = nullptr;
182190

183191
ASSERT( rotate < 4, "invalid rotate value " + std::to_string( rotate ) );
184192
if ( rotate > 0 ) {
@@ -884,21 +892,28 @@ Texture* Texture::FromColor( const Color& color ) {
884892
}
885893

886894
void Texture::Update( const updated_area_t updated_area ) {
887-
//Log( "Need texture update [ "+ std::to_string( updated_area.left ) + " " + std::to_string( updated_area.top ) + " " + std::to_string( updated_area.right ) + " " + std::to_string( updated_area.bottom ) + " ]" );
895+
//Log( "Need texture update [ " + std::to_string( updated_area.left ) + " " + std::to_string( updated_area.top ) + " " + std::to_string( updated_area.right ) + " " + std::to_string( updated_area.bottom ) + " ]" );
896+
ASSERT( updated_area.right > updated_area.left && updated_area.right < VERY_BIG_NUMBER, "invalid area right" );
897+
ASSERT( updated_area.bottom > updated_area.top && updated_area.bottom < VERY_BIG_NUMBER, "invalid area right" );
888898
m_updated_areas.push_back( updated_area );
889899
m_update_counter++;
890900
}
891901

892902
void Texture::FullUpdate() {
893903
ClearUpdatedAreas();
894-
Update(
895-
{
896-
0,
897-
0,
898-
m_width,
899-
m_height
900-
}
901-
);
904+
if ( m_width > 0 && m_height > 0 ) {
905+
Update(
906+
{
907+
0,
908+
0,
909+
m_width,
910+
m_height
911+
}
912+
);
913+
}
914+
else {
915+
m_update_counter++;
916+
}
902917
}
903918

904919
const size_t Texture::UpdatedCount() const {

0 commit comments

Comments
 (0)