Skip to content

Commit

Permalink
sqapi: ADD gui.open_info_win_at to open scenario info window at speci…
Browse files Browse the repository at this point in the history
…fic tab

git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@8220 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Dwachs committed Apr 29, 2017
1 parent 6410804 commit df0ecd0
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 23 deletions.
4 changes: 2 additions & 2 deletions dataobj/scenario.cc
Expand Up @@ -736,15 +736,15 @@ plainstring scenario_t::load_language_file(const char* filename)
return text;
}

bool scenario_t::open_info_win() const
bool scenario_t::open_info_win(const char* tab) const
{
// pop up for the win
scenario_info_t *si = (scenario_info_t*)win_get_magic(magic_scenario_info);
if (si == NULL) {
si = new scenario_info_t();
create_win(si, w_info, magic_scenario_info);
}
si->open_result_tab();
si->open_tab(tab);
return true; // dummy return value
}

Expand Down
4 changes: 2 additions & 2 deletions dataobj/scenario.h
Expand Up @@ -277,9 +277,9 @@ class scenario_t
void update_scenario_texts();

/**
* opens scenario info window at result tab
* opens scenario info window at tab @p tab.
*/
bool open_info_win() const;
bool open_info_win(const char* tab = "result") const;


/**
Expand Down
26 changes: 15 additions & 11 deletions gui/scenario_info.cc
Expand Up @@ -20,6 +20,18 @@ void scenario_info_t::update_dynamic_texts(gui_flowtext_t &flow, dynamic_string
}


uint16 scenario_info_t::get_tab_index(const char* which)
{
const char *shorts[] = { "info", "goal", "rules", "result", "about" };
for (uint i = 0; i<lengthof(shorts); i++) {
if (strcmp(which, shorts[i]) == 0) {
return i;
}
}
return 0;
}


scenario_info_t::scenario_info_t() :
gui_frame_t( translator::translate("Scenario information") ),
scrolly_info(&info),
Expand Down Expand Up @@ -147,25 +159,17 @@ bool scenario_info_t::action_triggered( gui_action_creator_t *comp, value_t v)
}
}
else {
const char *shorts[] = { "info", "goal", "rules", "result", "about" };
for (uint i = 0; i<lengthof(shorts); i++) {
if (strcmp(link, shorts[i]) == 0) {
tabs.set_active_tab_index(i);
resize(scr_coord(0,0));
set_dirty();
return true;
}
}
open_tab(link);
}
}
}
return true;
}


void scenario_info_t::open_result_tab()
void scenario_info_t::open_tab(const char* which)
{
tabs.set_active_tab_index(3);
tabs.set_active_tab_index(get_tab_index(which));
resize(scr_coord(0,0));
set_dirty();
}
4 changes: 2 additions & 2 deletions gui/scenario_info.h
Expand Up @@ -34,7 +34,7 @@ class scenario_info_t : public gui_frame_t, private action_listener_t

void update_dynamic_texts(gui_flowtext_t &flow, dynamic_string &text, scr_size size, bool init);


uint16 get_tab_index(const char* which);
public:
scenario_info_t();

Expand All @@ -58,7 +58,7 @@ class scenario_info_t : public gui_frame_t, private action_listener_t

void update_scenario_texts(bool init);

void open_result_tab();
void open_tab(const char* which);
};

#endif
1 change: 1 addition & 0 deletions script/api/Doxyfile_SQAPI
Expand Up @@ -21,6 +21,7 @@ INPUT = api_factory.cc \
api_line.cc \
api_map_objects.cc \
api_obj_desc.cc \
api_pathfinding.cc \
api_player.cc \
api_schedule.cc \
api_settings.cc \
Expand Down
19 changes: 15 additions & 4 deletions script/api/api_gui.cc
Expand Up @@ -33,6 +33,10 @@ call_tool_init add_scenario_message(player_t* player, const char* text)
return call_tool_init(TOOL_ADD_MESSAGE | SIMPLE_TOOL, (const char*)buf, 0, player ? player : welt->get_active_player());
}

bool open_info_win_result(scenario_t* scen)
{
return scen->open_info_win();
}

void export_gui(HSQUIRRELVM vm, bool scenario)
{
Expand All @@ -43,10 +47,17 @@ void export_gui(HSQUIRRELVM vm, bool scenario)

if (scenario) {
/**
* Opens scenario info window.
* @note Only available in scenario mode.
*/
STATIC register_method(vm, &scenario_t::open_info_win, "open_info_win");
* Opens scenario info window and shows 'result' tab.
* @note Only available in scenario mode.
*/
STATIC register_method(vm, &open_info_win_result, "open_info_win", true);

/**
* Opens scenario info window with specific tab open.
* @param tab possible values are "info", "goal", "rules", "result", "about"
* @note Only available in scenario mode.
*/
STATIC register_method(vm, &scenario_t::open_info_win, "open_info_win_at");

/**
* Adds message to the players mailboxes.
Expand Down
5 changes: 3 additions & 2 deletions script/api/changelog.h
Expand Up @@ -4,10 +4,11 @@
*
* @section api-trunk Current trunk
*
* - Added simple_heap_x, way_planner_x, bridge_planner_x
* - Added @ref simple_heap_x, @ref way_planner_x, @ref bridge_planner_x
* - Added map_object_x::is_marked
* - Added gui::open_info_win_at
*
* @section api-120-2 Release 120.2
* @section api-120-2-2 Release 120.2.2
*
* - Added map_object_x::mark and unmark
*
Expand Down
1 change: 1 addition & 0 deletions script/api/squirrel_types_scenario.awk
Expand Up @@ -134,6 +134,7 @@ BEGIN {
export_types["good_desc_x::get_weight_per_unit"] = "integer()"
export_types["good_desc_x::calc_revenue"] = "integer(way_types, integer)"
export_types["::open_info_win"] = "bool()"
export_types["::open_info_win_at"] = "bool(string)"
export_types["gui::add_message_at"] = "void(string, coord)"
export_types["gui::add_message"] = "string(player_x, string)"
export_types["halt_x::get_name"] = "string()"
Expand Down

0 comments on commit df0ecd0

Please sign in to comment.