diff --git a/script/script_tool_manager.cc b/script/script_tool_manager.cc index 7d8b9fb83..886e3beed 100644 --- a/script/script_tool_manager.cc +++ b/script/script_tool_manager.cc @@ -49,6 +49,12 @@ 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 = contents.get_koord("cursor_area", koord(1,1)); + info->cursor_offset = contents.get_koord("cursor_offset", koord(0,0)); + if( info->cursor_area.x<1 || info->cursor_area.y<1 ) { + dbg->warning("script_tool_manager_t::get_script_info()", "The cursor area of scripted tool %s must have at least 1 tile length. Sanitized to (1,1).", info->title.c_str()); + info->cursor_area = koord(1,1); + } 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; } };