From 964387c834295667f8fad406f63525ecffce99f1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 25 May 2006 14:56:10 +0000 Subject: [PATCH] Erweiterung, um aus einem vom gmtool heraus aufgerufenen Skript Regionen zu highlighten oder zu selektieren. Noch ungetestet. --- src/eressea/gmtool.c | 37 ++++++++++++++++++++++++------------- src/eressea/gmtool.h | 4 ++++ src/eressea/lua/gm.cpp | 22 +++++++++++++++++++--- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/eressea/gmtool.c b/src/eressea/gmtool.c index cc0aa4acb..506981c0e 100644 --- a/src/eressea/gmtool.c +++ b/src/eressea/gmtool.c @@ -691,6 +691,21 @@ region2coord(const region * r, coordinate * c) #define FAST_RIGHT KEY_SRIGHT #endif +void +highlight_region(region *r) +{ + if (r!=NULL) r->flags |= RF_MAPPER_HIGHLIGHT; +} + +void +select_coordinate(selection * selected, int x, int y) +{ + coordinate coord = { 0 }; + coord.x = x; + coord.y = y; + tag_region(selected, &coord); +} + enum { MODE_HIGHLIGHT = 0x0, MODE_SELECT = 0x1 }; static void @@ -731,11 +746,10 @@ select_regions(state * st, int selectmode) statusline(st->wnd_status->handle, sbuffer); for (r=regions;r;r=r->next) { if (r->units) { - coordinate coord; if (selectmode&MODE_SELECT) { - tag_region(st->selected, region2coord(r, &coord)); + select_coordinate(st->selected, r->x, r->y); } else { - r->flags |= RF_MAPPER_HIGHLIGHT; + highlight_region(r); } } } @@ -746,11 +760,10 @@ select_regions(state * st, int selectmode) statusline(st->wnd_status->handle, sbuffer); for (r=regions;r;r=r->next) { if (r->ships) { - coordinate coord; if (selectmode&MODE_SELECT) { - tag_region(st->selected, region2coord(r, &coord)); + select_coordinate(st->selected, r->x, r->y); } else { - r->flags |= RF_MAPPER_HIGHLIGHT; + highlight_region(r); } } } @@ -764,16 +777,15 @@ select_regions(state * st, int selectmode) if (f!=NULL) { unit * u; - coordinate coord; - + sprintf(sbuffer, "%sfaction: %s", status, itoa36(f->no)); statusline(st->wnd_status->handle, sbuffer); for (u=f->units;u;u=u->nextF) { region * r = u->region; if (selectmode&MODE_SELECT) { - tag_region(st->selected, region2coord(r, &coord)); + select_coordinate(st->selected, r->x, r->y); } else { - r->flags |= RF_MAPPER_HIGHLIGHT; + highlight_region(r); } } } else { @@ -794,11 +806,10 @@ select_regions(state * st, int selectmode) statusline(st->wnd_status->handle, sbuffer); for (r=regions;r;r=r->next) { if (r->terrain==terrain) { - coordinate coord; if (selectmode&MODE_SELECT) { - tag_region(st->selected, region2coord(r, &coord)); + select_coordinate(st->selected, r->x, r->y); } else { - r->flags |= RF_MAPPER_HIGHLIGHT; + highlight_region(r); } } } diff --git a/src/eressea/gmtool.h b/src/eressea/gmtool.h index 93259b3ea..7645da4f4 100644 --- a/src/eressea/gmtool.h +++ b/src/eressea/gmtool.h @@ -17,6 +17,10 @@ extern "C" { struct lua_State; extern int gmmain(int argc, char *argv[]); extern int curses_readline(struct lua_State * L, const char * prompt); + + extern void highlight_region(struct region *r); + extern void select_coordinate(struct selection * selected, int x, int y); + #ifdef __cplusplus } #endif diff --git a/src/eressea/lua/gm.cpp b/src/eressea/lua/gm.cpp index 10a7c776d..1043ff731 100644 --- a/src/eressea/lua/gm.cpp +++ b/src/eressea/lua/gm.cpp @@ -3,6 +3,7 @@ #include "bindings.h" #include "list.h" +#include "../gmtool.h" #include "../gmtool_structs.h" #include @@ -57,12 +58,27 @@ selected_regions(void) return eressea::list(next_tag(0, current_state)); } +static void +gmtool_select_coordinate(int x, int y) +{ + select_coordinate(current_state->selected, x, y); +} + +static void +gmtool_select_region(region& r) +{ + select_coordinate(current_state->selected, r.x, r.y); +} + void bind_gmtool(lua_State * L) { - module(L)[ - def("selected_regions", &selected_regions, return_stl_iterator), - def("current_region", ¤t_region) + module(L, "gmtool")[ + def("selection", &selected_regions, return_stl_iterator), + def("cursor", ¤t_region), + def("highlight", &highlight_region), + def("select", &gmtool_select_region), + def("select_at", &gmtool_select_coordinate) ]; #ifdef LUABIND_NO_EXCEPTIONS luabind::set_error_callback(error_callback);