Skip to content

Commit 7d6309d

Browse files
committed
small fixes
1 parent f34dcd4 commit 7d6309d

File tree

7 files changed

+41
-10
lines changed

7 files changed

+41
-10
lines changed

GLSMAC_data/default/game/event/game_settings.gls.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ return {
1212
apply: (e) => {
1313
let old_settings = [];
1414
let settings = e.game.get_settings().global.map;
15+
let changes = [];
1516
for (c of e.data.changes) {
17+
if (c[0] == 'planet_size') {
18+
const xy = #split(c[1], 'x');
19+
changes :+['size_x', #to_int(xy[0])];
20+
changes :+['size_y', #to_int(xy[1])];
21+
} else {
22+
changes :+c;
23+
}
24+
}
25+
for (c of changes) {
1626
const oldv = settings[c[0]]; // TODO: fix deref
1727
if (#is_defined(oldv)) { // TODO: support all fields
1828
old_settings :+[c[0], oldv];

GLSMAC_data/default/ui/parts/mainmenu/steps/multiplayer_lobby/game_settings.gls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ return (i) => {
6464
['140x70', 'Large planet'],
6565
['180x90', 'Huge planet'],
6666
], #to_string(settings.map.size_x) + 'x' + #to_string(settings.map.size_y), (v) => {
67-
return v; // TODO
67+
return v; // parsed in event
6868
});
6969

7070
make_line('ocean_coverage', 'Ocean Coverage', [

src/gse/builtins/String.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "gse/callable/Native.h"
77
#include "gse/Exception.h"
88
#include "gse/value/String.h"
9+
#include "gse/value/Array.h"
910
#include "util/String.h"
1011

1112
namespace gse {
@@ -34,6 +35,22 @@ void String::AddToContext( gc::Space* const gc_space, context::Context* ctx, gse
3435
return VALUE( value::String,, text );
3536
} ), ep );
3637

38+
ctx->CreateBuiltin( "split", NATIVE_CALL() {
39+
N_EXPECT_ARGS( 2 );
40+
N_GETVALUE( text, 0, String );
41+
N_GETVALUE( sep, 1, String );
42+
if ( sep.size() != 1 ) {
43+
GSE_ERROR( EC.INVALID_CALL, "For now splitting is only possible by single character (got: " + sep + ")" );
44+
}
45+
const auto results = util::String::Split( text, sep[0] );
46+
value::array_elements_t elements = {};
47+
elements.reserve( results.size() );
48+
for ( const auto& result : results ) {
49+
elements.push_back( VALUE( value::String,, result ) );
50+
}
51+
return VALUE( value::Array,, elements );
52+
} ), ep );
53+
3754
}
3855

3956
}

src/ui/dom/Button.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ const bool Button::ProcessEventImpl( GSE_CALLABLE, const input::Event& event ) {
5858
bool result = false;
5959
switch ( event.type ) {
6060
case input::EV_MOUSE_DOWN: {
61+
if ( m_on_mousedown ) {
62+
m_on_mousedown();
63+
break;
64+
}
6165
AddModifier( GSE_CALL, CM_ACTIVE );
6266
m_last_button = event.data.mouse.button;
6367
result = true;
@@ -71,14 +75,13 @@ const bool Button::ProcessEventImpl( GSE_CALLABLE, const input::Event& event ) {
7175
if ( m_on_click ) {
7276
// managed by parent
7377
m_on_click();
78+
break;
7479
}
75-
else {
76-
m_sound->Play();
77-
input::Event e;
78-
e.SetType( input::EV_CLICK );
79-
e.data.mouse = event.data.mouse;
80-
ProcessEvent( GSE_CALL, e );
81-
}
80+
m_sound->Play();
81+
input::Event e;
82+
e.SetType( input::EV_CLICK );
83+
e.data.mouse = event.data.mouse;
84+
ProcessEvent( GSE_CALL, e );
8285
}
8386
m_last_button = input::MB_NONE;
8487
result = true;

src/ui/dom/Button.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Button : public Panel {
2828
private:
2929
friend class Select;
3030
typedef std::function< void() > f_on_click_t;
31+
f_on_click_t m_on_mousedown = nullptr;
3132
f_on_click_t m_on_click = nullptr;
3233

3334
};

src/ui/dom/ChoiceList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void ChoiceList::SetItems( GSE_CALLABLE, const gse::value::array_elements_t& ite
182182
} }
183183
).first->second;
184184
m_choices_order.push_back( k );
185-
element->On( GSE_CALL, "click", NATIVE_CALL( this, choice ) {
185+
element->On( GSE_CALL, "mousedown", NATIVE_CALL( this, choice ) {
186186
const bool was_actually_changed = !m_selected_choice || m_selected_choice->value != choice.value;
187187
if ( was_actually_changed ) {
188188
Select( GSE_CALL, choice, true );

src/ui/dom/Select.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Select::Select( DOM_ARGS )
2626

2727
m_active_element = new Button( GSE_CALL, ui, this, {} );
2828
ForwardProperty( GSE_CALL, "itemclass", "class", m_active_element );
29-
m_active_element->m_on_click = [ this, ctx, si, ep ]() {
29+
m_active_element->m_on_mousedown = [ this, ctx, si, ep ]() {
3030
if ( m_readonly ) {
3131
return;
3232
}

0 commit comments

Comments
 (0)