Skip to content

Commit

Permalink
CHG: show area of makro skript before building
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11467 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Dec 14, 2024
1 parent a32db29 commit c48ef76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
11 changes: 6 additions & 5 deletions src/simutrans/gui/script_generator_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#include "../tool/simtool.h"


script_generator_frame_t::script_generator_frame_t(tool_generate_script_t* tl, const char *_p, cbuffer_t &cmd)
script_generator_frame_t::script_generator_frame_t(tool_generate_script_t* tl, const char *_p, cbuffer_t &cmd, koord a)
: savegame_frame_t("", false, _p, false)
{
this->tool = tl;
command = cmd;
area = a;
set_name(translator::translate("Save generated script"));
set_focus(NULL);
}
Expand All @@ -23,14 +24,14 @@ script_generator_frame_t::script_generator_frame_t(tool_generate_script_t* tl, c
*/
bool script_generator_frame_t::item_action(const char *fullpath)
{
tool->save_script(fullpath,command);
tool->save_script(fullpath,command,area);
return true;
}


bool script_generator_frame_t::ok_action(const char *fullpath)
{
tool->save_script(fullpath,command);
tool->save_script(fullpath,command,area);
return true;
}

Expand All @@ -41,7 +42,7 @@ const char *script_generator_frame_t::get_info(const char *)
}


bool script_generator_frame_t::check_file( const char *, const char * )
bool script_generator_frame_t::check_file( const char *f, const char * )
{
return true;
return *f;
}
3 changes: 2 additions & 1 deletion src/simutrans/gui/script_generator_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class script_generator_frame_t : public savegame_frame_t
private:
tool_generate_script_t* tool;
cbuffer_t command;
koord area;

protected:
/**
Expand All @@ -34,7 +35,7 @@ class script_generator_frame_t : public savegame_frame_t
bool check_file( const char *filename, const char *suffix ) OVERRIDE;

public:
script_generator_frame_t(tool_generate_script_t*, const char *path, cbuffer_t &cmd);
script_generator_frame_t(tool_generate_script_t*, const char *path, cbuffer_t &cmd, koord area);

/**
* Set the window associated helptext
Expand Down
18 changes: 11 additions & 7 deletions src/simutrans/tool/simtool-script-generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,28 +335,31 @@ char const* tool_generate_script_t::do_work(player_t*, const koord3d& start, con
koord3d e = end == koord3d::invalid ? start : end;
koord k1 = koord(min(start.x, e.x), min(start.y, e.y));
koord k2 = koord(max(start.x, e.x), max(start.y, e.y));
koord area( k2.x-k1.x+1, k2.y-k1.y+1 );

cbuffer_t generated_script_buf;
generated_script_buf.printf("// automated rebuild scrip with size (%d,%d)\n\n", area.x, area.y); // comment
generated_script_buf.append("include(\"hm_toolkit_v1a\")\n\nfunction hm_build() {\n"); // header

write_command(generated_script_buf, write_slope_at, k1, k2, start);
write_way_command_t(generated_script_buf, k1, k2, start).write();
write_wayobj_command_t(generated_script_buf, k1, k2, start).write();
write_command_halt(generated_script_buf, write_station_at, k1, k2, start);
write_command(generated_script_buf, write_sign_at, k1, k2, start);
koord3d begin(k1, start.z);
write_command(generated_script_buf, write_slope_at, k1, k2, begin);
write_way_command_t(generated_script_buf, k1, k2, begin).write();
write_wayobj_command_t(generated_script_buf, k1, k2, begin).write();
write_command_halt(generated_script_buf, write_station_at, k1, k2, begin);
write_command(generated_script_buf, write_sign_at, k1, k2, begin);

generated_script_buf.append("}\n"); // footer

cbuffer_t dir_buf;
dir_buf.printf("%saddons%s%stool%s", env_t::user_dir, PATH_SEPARATOR, env_t::pak_name.c_str(), PATH_SEPARATOR);
dr_mkdir(dir_buf.get_str());

create_win(new script_generator_frame_t(this, dir_buf.get_str(), generated_script_buf), w_info, magic_script_generator);
create_win(new script_generator_frame_t(this, dir_buf.get_str(), generated_script_buf, area ), w_info, magic_script_generator);
return NULL;
}


bool tool_generate_script_t::save_script(const char* fullpath, const char *command) const
bool tool_generate_script_t::save_script(const char* fullpath, const char *command, koord area) const
{
dr_mkdir(fullpath);
cbuffer_t fname;
Expand All @@ -373,6 +376,7 @@ bool tool_generate_script_t::save_script(const char* fullpath, const char *comma
fname.printf("%s%sdescription.tab", fullpath, PATH_SEPARATOR);
if (file = dr_fopen(fname, "w")) {
fprintf(file, "title=Building %s\n", short_name.get_str());
fprintf(file, "cursor_area=%d,%d\n", area.x, area.y);
fprintf(file, "type=one_click\ntooltip=Building %s created by Simutrans\nrestart=1\ncursor=BuilderScript\n", short_name.get_str());
fclose(file);
}
Expand Down
2 changes: 1 addition & 1 deletion src/simutrans/tool/simtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ class tool_generate_script_t : public two_click_tool_t {
tool_generate_script_t() : two_click_tool_t(TOOL_GENERATE_SCRIPT | GENERAL_TOOL) {}
char const* get_tooltip(player_t const*) const OVERRIDE { return translator::translate("generate script"); }
bool is_init_keeps_game_state() const OVERRIDE { return true; }
bool save_script(const char *fullpath, const char *command) const;
bool save_script(const char *fullpath, const char *command, koord area) const;
private:
char const* do_work(player_t*, koord3d const&, koord3d const&) OVERRIDE;
void mark_tiles(player_t*, koord3d const&, koord3d const&) OVERRIDE;
Expand Down

0 comments on commit c48ef76

Please sign in to comment.