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
#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);
}
}
}

View File

@ -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

View File

@ -3,6 +3,7 @@
#include "bindings.h"
#include "list.h"
#include "../gmtool.h"
#include "../gmtool_structs.h"
#include <kernel/region.h>
@ -57,12 +58,27 @@ selected_regions(void)
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
bind_gmtool(lua_State * L)
{
module(L)[
def("selected_regions", &selected_regions, return_stl_iterator),
def("current_region", &current_region)
module(L, "gmtool")[
def("selection", &selected_regions, return_stl_iterator),
def("cursor", &current_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);