diff --git a/script/script_tool_manager.cc b/script/script_tool_manager.cc index 7d8b9fb83..d369aa201 100644 --- a/script/script_tool_manager.cc +++ b/script/script_tool_manager.cc @@ -33,6 +33,20 @@ bool script_tool_manager_t::check_file( const char *path ) } +koord parse_coord(const char* p, bool size = false) { + sint16 ax = atoi(p); + while(*p!=',' && *p!='\0') { + p++; + } + p++; + sint16 ay = atoi(p); + if( size ) { + ax = max(ax, 1); + ay = max(ay, 1); + } + return koord(ax, ay); +} + const scripted_tool_info_t* script_tool_manager_t::get_script_info(const char* path) { scripted_tool_info_t* info = new scripted_tool_info_t(); @@ -49,6 +63,8 @@ const scripted_tool_info_t* script_tool_manager_t::get_script_info(const char* p info->title = contents.get_string("title", path); info->menu_arg = contents.get_string("menu", ""); info->tooltip = contents.get_string("tooltip", ""); + info->cursor_area = parse_coord(contents.get_string("cursor_area", "1,1"), true); + info->cursor_offset = parse_coord(contents.get_string("cursor_offset", "0,0")); const char* skin_name = contents.get_string("icon", ""); info->desc = skinverwaltung_t::get_extra(skin_name, strlen(skin_name), skinverwaltung_t::cursor); diff --git a/simtool-scripted.cc b/simtool-scripted.cc index 8bdc95dc7..40076df7d 100644 --- a/simtool-scripted.cc +++ b/simtool-scripted.cc @@ -220,6 +220,15 @@ tool_exec_script_t::tool_exec_script_t(const scripted_tool_info_t *info) : tool_ bool tool_exec_script_t::init(player_t* player) { bool res = false; + cursor_area = get_cursor_area(); + cursor_offset = get_cursor_offset(); + // rotate area and offset + for(uint8 i=0; iget_settings().get_rotation(); i++) { + koord old_area = cursor_area; + koord old_offset = cursor_offset; + cursor_area = koord(old_area.y, old_area.x); + cursor_offset = koord(old_area.y-1-old_offset.y, old_offset.x); + } return init_vm(player) && call_function(script_vm_t::FORCE, "init", player, res)== NULL && res; } diff --git a/simtool-scripted.h b/simtool-scripted.h index ef7228a87..8b2640834 100644 --- a/simtool-scripted.h +++ b/simtool-scripted.h @@ -35,12 +35,16 @@ struct scripted_tool_info_t { const skin_desc_t* desc; ///< skin object used for cursor (0), icon (1), and maybe marker (2) bool restart; ///< true, if script vm has to be restarted after work() bool is_one_click; ///< true, if tool is one-click (otherwise needs two clicks/coordinates to work) + koord cursor_area; ///< size of cursor defined in tool_t + koord cursor_offset; ///< cursor offset defined in tool_t /// sets default values scripted_tool_info_t() { desc = NULL; restart = true; is_one_click = true; + cursor_area = koord(1,1); + cursor_offset = koord(0,0); } }; @@ -77,6 +81,8 @@ public: void step(player_t* player); const char *get_tooltip(const player_t *) const { return info ? info->tooltip.c_str() : ""; } + koord get_cursor_area() const { return info->cursor_area; } + koord get_cursor_offset() const { return info->cursor_offset; } };