Skip to content

Commit 02d150b

Browse files
committed
scrollview fixes
1 parent 0c848e0 commit 02d150b

File tree

6 files changed

+71
-35
lines changed

6 files changed

+71
-35
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,16 @@ return {
8585
});
8686

8787
const f_line = (text, size, align) => {
88+
let left = #undefined;
89+
if (align == 'left') {
90+
left = 3;
91+
}
8892
this.lines.text({
8993
align: 'top ' + align,
9094
color: 'rgb(116,156,56)',
9195
font: 'arialnb.ttf:' + #to_string(size),
9296
text: text,
93-
left: 3,
97+
left: left,
9498
});
9599
};
96100

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

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ return {
22

33
selected_tile: null,
44

5-
selected_unit: null,
5+
selected_object: null,
66

77
unit_items: {},
88
base_items: {},
99
active_item: null,
1010

11-
set_active_item: (object) => {
11+
set_active_item: (item) => {
1212
if (this.active_item != null) {
1313
this.active_item.class = 'bottombar-objects-list-item';
1414
this.active_item.border = #undefined; // TODO: fix class switching logic to also apply modifier styles correctly
1515
}
16-
this.active_item = object;
16+
this.active_item = item;
1717
if (this.active_item != null) {
1818
this.active_item.class = 'bottombar-objects-list-item-active';
1919
}
@@ -82,10 +82,10 @@ return {
8282
return true;
8383
});
8484
item.on('mouseout', (e) => {
85-
this.p.sections.object_preview.show(this.selected_unit);
85+
this.p.sections.object_preview.show(this.selected_object);
8686
return true;
8787
});
88-
if (object == this.selected_unit) {
88+
if (cls == 'Unit' && object == this.selected_object) {
8989
this.set_active_item(item);
9090
}
9191
},
@@ -108,18 +108,18 @@ return {
108108
has_vscroll: false,
109109
});
110110

111-
let left = 0;
111+
this.list_width = 0;
112112

113113
const base = tile.get_base();
114114

115115
if (base != null) {
116-
this.add_object(base, left);
117-
left += this.object_width;
116+
this.add_object(base, this.list_width);
117+
this.list_width = this.list_width + this.object_width;
118118
}
119119

120120
for (unit of tile.get_units()) {
121-
this.add_object(unit, left);
122-
left += this.object_width;
121+
this.add_object(unit, this.list_width);
122+
this.list_width = this.list_width + this.object_width;
123123
}
124124

125125
this.selected_tile = tile;
@@ -169,30 +169,46 @@ return {
169169
});
170170

171171
p.map.on('unit_preview', (e) => {
172-
if (e.unit != this.selected_unit || (this.selected_unit != null && e.unit.movement != this.selected_unit.movement)) { // TODO: dynamic updates of wrapped objects
173-
this.selected_unit = e.unit;
174-
if (this.selected_unit != null) {
175-
const tile = this.selected_unit.get_tile();
172+
if (e.unit != this.selected_object || (this.selected_object != null && e.unit.movement != this.selected_object.movement)) { // TODO: dynamic updates of wrapped objects
173+
this.selected_object = e.unit;
174+
if (this.selected_object != null) {
175+
const tile = this.selected_object.get_tile();
176176
if (tile != this.selected_tile) {
177177
this.update_tile(tile);
178178
} else {
179-
const key = #to_string(this.selected_unit.id);
180-
if (#is_defined(this.unit_items[key])) {
181-
this.set_active_item(this.unit_items[key]);
179+
{
180+
const key = #to_string(e.unit.id);
181+
if (!#is_defined(this.unit_items[key])) {
182+
this.add_object(e.unit, this.list_width);
183+
this.list_width = this.list_width + this.object_width;
184+
}
185+
}
186+
{
187+
const key = #to_string(this.selected_object.id);
188+
if (#is_defined(this.unit_items[key])) {
189+
this.set_active_item(this.unit_items[key]);
190+
}
182191
}
183192
}
184193
}
185194
}
186195
});
187196

188197
p.map.on('base_preview', (e) => {
189-
this.selected_unit = null;
190-
this.set_active_item(null);
191-
this.update_tile(e.base.get_tile());
198+
if (e.base != this.selected_object) {
199+
this.selected_object = e.base;
200+
this.set_active_item(null);
201+
const tile = e.base.get_tile();
202+
if (tile != this.selected_tile) {
203+
this.update_tile(tile);
204+
}
205+
}
192206
});
193207

194208
p.map.on('tile_preview', (e) => {
195-
this.update_tile(e.tile);
209+
if (e.tile != this.selected_tile) {
210+
this.update_tile(e.tile);
211+
}
196212
});
197213

198214
},

src/graphics/opengl/OpenGL.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -564,20 +564,19 @@ void OpenGL::LoadTexture( types::texture::Texture* texture, const bool smoothen
564564

565565
void OpenGL::UnloadTexture( const types::texture::Texture* texture ) {
566566
std::lock_guard guard( m_texture_objs_to_unload_mutex );
567-
m_textures_map::iterator it = m_textures.find( texture );
568-
if ( it != m_textures.end() ) {
569-
//Log( "Unloading texture '" + texture->m_name + "'" );
570-
m_texture_objs_to_unload.push_back( it->second.obj );
571-
m_textures.erase( it );
572-
}
567+
m_texture_objs_to_unload.push_back( texture );
573568
}
574569

575570
void OpenGL::WithTexture( const types::texture::Texture* texture, const f_t& f ) {
576571
GLuint obj;
577572
if ( texture ) {
578573
auto it = m_textures.find( texture );
579-
ASSERT( it != m_textures.end(), "texture to be enabled ( " + texture->GetFilename() + " ) not found" );
580-
obj = it->second.obj;
574+
if ( it != m_textures.end() ) {
575+
obj = it->second.obj;
576+
}
577+
else {
578+
obj = m_no_texture;
579+
}
581580
}
582581
else {
583582
obj = m_no_texture;
@@ -752,9 +751,14 @@ void OpenGL::UpdateViewportSize( const size_t width, const size_t height ) {
752751

753752
void OpenGL::ProcessPendingUnloads() {
754753
std::lock_guard guard( m_texture_objs_to_unload_mutex );
755-
for ( auto& obj : m_texture_objs_to_unload ) {
756-
glActiveTexture( GL_TEXTURE0 );
757-
glDeleteTextures( 1, &obj );
754+
for ( auto& texture : m_texture_objs_to_unload ) {
755+
m_textures_map::iterator it = m_textures.find( texture );
756+
if ( it != m_textures.end() ) {
757+
//Log( "Unloading texture '" + texture->m_name + "'" );
758+
glActiveTexture( GL_TEXTURE0 );
759+
glDeleteTextures( 1, &it->second.obj );
760+
m_textures.erase( it );
761+
}
758762
}
759763
m_texture_objs_to_unload.clear();
760764
}

src/graphics/opengl/OpenGL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ CLASS( OpenGL, Graphics )
130130

131131
// unload requests can be done from multiple threads but actual unloading done from main one
132132
std::mutex m_texture_objs_to_unload_mutex;
133-
std::vector< GLuint > m_texture_objs_to_unload = {};
133+
std::vector< const types::texture::Texture* > m_texture_objs_to_unload = {};
134134
void ProcessPendingUnloads();
135135

136136
std::mutex m_render_mutex;

src/ui/dom/Scrollview.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,17 @@ void Scrollview::UpdateScrollbars( size_t width, size_t height ) {
194194
outer_w -= vscroll_w;
195195
inner_g->SetWidth( outer_w );
196196
}
197+
else if ( inner_g->GetWidth() < outer_w ) {
198+
inner_g->SetWidth( outer_w );
199+
}
200+
197201
if ( need_h ) {
198202
outer_h -= hscroll_h;
199203
inner_g->SetHeight( outer_h );
200204
}
205+
else if ( inner_g->GetHeight() < outer_h ) {
206+
inner_g->SetHeight( outer_h );
207+
}
201208

202209
if ( !need_v ) {
203210
m_vscroll->Hide();

src/ui/geometry/Geometry.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,12 @@ void Geometry::UpdateEffectiveArea( const bool is_update_from_parent ) {
480480
ASSERT( effective_area.bottom >= 0 && effective_area.bottom <= maxy, "effective area bottom overflow" );
481481
const bool should_resize = std::round( effective_area.width ) != std::round( m_effective_area.width ) || std::round( effective_area.height ) != std::round( m_effective_area.height );
482482
if ( should_resize && m_on_resize ) {
483-
m_on_resize( effective_area.width, effective_area.height );
483+
if ( m_overflow_mode == OM_RESIZE ) {
484+
m_on_resize( m_boundaries.width, m_boundaries.height );
485+
}
486+
else {
487+
m_on_resize( effective_area.width, effective_area.height );
488+
}
484489
}
485490
m_effective_area = effective_area;
486491
if ( m_parent && !is_update_from_parent ) {

0 commit comments

Comments
 (0)