Erweiterung, um aus einem vom gmtool heraus aufgerufenen Skript Regionen zu highlighten oder zu selektieren. Noch ungetestet.

This commit is contained in:
Enno Rehling 2006-05-25 14:56:10 +00:00
parent 42ede42656
commit 964387c834
3 changed files with 47 additions and 16 deletions

View File

@ -691,6 +691,21 @@ region2coord(const region * r, coordinate * c)
#define FAST_RIGHT KEY_SRIGHT #define FAST_RIGHT KEY_SRIGHT
#endif #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 }; enum { MODE_HIGHLIGHT = 0x0, MODE_SELECT = 0x1 };
static void static void
@ -731,11 +746,10 @@ select_regions(state * st, int selectmode)
statusline(st->wnd_status->handle, sbuffer); statusline(st->wnd_status->handle, sbuffer);
for (r=regions;r;r=r->next) { for (r=regions;r;r=r->next) {
if (r->units) { if (r->units) {
coordinate coord;
if (selectmode&MODE_SELECT) { if (selectmode&MODE_SELECT) {
tag_region(st->selected, region2coord(r, &coord)); select_coordinate(st->selected, r->x, r->y);
} else { } 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); statusline(st->wnd_status->handle, sbuffer);
for (r=regions;r;r=r->next) { for (r=regions;r;r=r->next) {
if (r->ships) { if (r->ships) {
coordinate coord;
if (selectmode&MODE_SELECT) { if (selectmode&MODE_SELECT) {
tag_region(st->selected, region2coord(r, &coord)); select_coordinate(st->selected, r->x, r->y);
} else { } else {
r->flags |= RF_MAPPER_HIGHLIGHT; highlight_region(r);
} }
} }
} }
@ -764,16 +777,15 @@ select_regions(state * st, int selectmode)
if (f!=NULL) { if (f!=NULL) {
unit * u; unit * u;
coordinate coord;
sprintf(sbuffer, "%sfaction: %s", status, itoa36(f->no)); sprintf(sbuffer, "%sfaction: %s", status, itoa36(f->no));
statusline(st->wnd_status->handle, sbuffer); statusline(st->wnd_status->handle, sbuffer);
for (u=f->units;u;u=u->nextF) { for (u=f->units;u;u=u->nextF) {
region * r = u->region; region * r = u->region;
if (selectmode&MODE_SELECT) { if (selectmode&MODE_SELECT) {
tag_region(st->selected, region2coord(r, &coord)); select_coordinate(st->selected, r->x, r->y);
} else { } else {
r->flags |= RF_MAPPER_HIGHLIGHT; highlight_region(r);
} }
} }
} else { } else {
@ -794,11 +806,10 @@ select_regions(state * st, int selectmode)
statusline(st->wnd_status->handle, sbuffer); statusline(st->wnd_status->handle, sbuffer);
for (r=regions;r;r=r->next) { for (r=regions;r;r=r->next) {
if (r->terrain==terrain) { if (r->terrain==terrain) {
coordinate coord;
if (selectmode&MODE_SELECT) { if (selectmode&MODE_SELECT) {
tag_region(st->selected, region2coord(r, &coord)); select_coordinate(st->selected, r->x, r->y);
} else { } else {
r->flags |= RF_MAPPER_HIGHLIGHT; highlight_region(r);
} }
} }
} }

View File

@ -17,6 +17,10 @@ extern "C" {
struct lua_State; struct lua_State;
extern int gmmain(int argc, char *argv[]); extern int gmmain(int argc, char *argv[]);
extern int curses_readline(struct lua_State * L, const char * prompt); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -3,6 +3,7 @@
#include "bindings.h" #include "bindings.h"
#include "list.h" #include "list.h"
#include "../gmtool.h"
#include "../gmtool_structs.h" #include "../gmtool_structs.h"
#include <kernel/region.h> #include <kernel/region.h>
@ -57,12 +58,27 @@ selected_regions(void)
return eressea::list<region *, tag *, selectedregion>(next_tag(0, current_state)); return eressea::list<region *, tag *, selectedregion>(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 void
bind_gmtool(lua_State * L) bind_gmtool(lua_State * L)
{ {
module(L)[ module(L, "gmtool")[
def("selected_regions", &selected_regions, return_stl_iterator), def("selection", &selected_regions, return_stl_iterator),
def("current_region", &current_region) def("cursor", &current_region),
def("highlight", &highlight_region),
def("select", &gmtool_select_region),
def("select_at", &gmtool_select_coordinate)
]; ];
#ifdef LUABIND_NO_EXCEPTIONS #ifdef LUABIND_NO_EXCEPTIONS
luabind::set_error_callback(error_callback); luabind::set_error_callback(error_callback);