lua-skripting für gmtool fertig

This commit is contained in:
Enno Rehling 2006-04-16 16:32:14 +00:00
parent 1e5aeac0e5
commit 7c80bbfebb
4 changed files with 28 additions and 14 deletions

View File

@ -48,6 +48,7 @@ LUASERVER_SOURCES =
GMTOOL_SOURCES = GMTOOL_SOURCES =
$(SHARED_BINDINGS) $(SHARED_BINDINGS)
<lua>gm.cpp
<curses>listbox.c <curses>listbox.c
console.c console.c
editing.c editing.c

View File

@ -45,7 +45,7 @@ lua_init(void)
bind_unit(L); bind_unit(L);
bind_ship(L); bind_ship(L);
bind_building(L); bind_building(L);
bind_gmtool(L);
lua_readline = curses_readline; lua_readline = curses_readline;
return L; return L;
} }

View File

@ -275,7 +275,7 @@ init_curses(void)
map_region * map_region *
mr_get(const view * vi, int xofs, int yofs) mr_get(const view * vi, int xofs, int yofs)
{ {
return vi->regions + xofs + yofs * vi->extent.width; return vi->regions + xofs + yofs * vi->size.width;
} }
static coordinate * static coordinate *
@ -987,9 +987,22 @@ handlekey(state * st, int c)
break; break;
case 'L': case 'L':
if (global.vm_state) { if (global.vm_state) {
move(0, 0);
refresh();
lua_do((lua_State*)global.vm_state); lua_do((lua_State*)global.vm_state);
/* todo: do this from inside the script */
clear();
st->wnd_info->update |= 1;
st->wnd_status->update |= 1;
st->wnd_map->update |= 1;
} }
break; break;
case 12: /* Ctrl-L */
clear();
st->wnd_info->update |= 1;
st->wnd_status->update |= 1;
st->wnd_map->update |= 1;
break;
case 'H': case 'H':
select_regions(st, MODE_HIGHLIGHT); select_regions(st, MODE_HIGHLIGHT);
break; break;
@ -1125,17 +1138,17 @@ init_view(view * display, WINDOW * win)
display->topleft.y = 1; display->topleft.y = 1;
display->topleft.p = 0; display->topleft.p = 0;
display->plane = 0; display->plane = 0;
display->extent.width = getmaxx(win)/TWIDTH; display->size.width = getmaxx(win)/TWIDTH;
display->extent.height = getmaxy(win)/THEIGHT; display->size.height = getmaxy(win)/THEIGHT;
display->regions = calloc(display->extent.height * display->extent.width, sizeof(map_region)); display->regions = calloc(display->size.height * display->size.width, sizeof(map_region));
} }
static void static void
update_view(view * vi) update_view(view * vi)
{ {
int i, j; int i, j;
for (i=0;i!=vi->extent.width;++i) { for (i=0;i!=vi->size.width;++i) {
for (j=0;j!=vi->extent.height;++j) { for (j=0;j!=vi->size.height;++j) {
map_region * mr = mr_get(vi, i, j); map_region * mr = mr_get(vi, i, j);
mr->coord.x = vi->topleft.x + i - j/2; mr->coord.x = vi->topleft.x + i - j/2;
mr->coord.y = vi->topleft.y + j; mr->coord.y = vi->topleft.y + j;
@ -1206,19 +1219,19 @@ run_mapper(void)
st.wnd_map->update |= 1; st.wnd_map->update |= 1;
} }
if (p.y < tl.y) { if (p.y < tl.y) {
vi->topleft.y = st.cursor.y-vi->extent.height/2; vi->topleft.y = st.cursor.y-vi->size.height/2;
st.wnd_map->update |= 1; st.wnd_map->update |= 1;
} }
else if (p.y >= tl.y + vi->extent.height * THEIGHT) { else if (p.y >= tl.y + vi->size.height * THEIGHT) {
vi->topleft.y = st.cursor.y-vi->extent.height/2; vi->topleft.y = st.cursor.y-vi->size.height/2;
st.wnd_map->update |= 1; st.wnd_map->update |= 1;
} }
if (p.x <= tl.x) { if (p.x <= tl.x) {
vi->topleft.x = st.cursor.x+(st.cursor.y-vi->topleft.y)/2-vi->extent.width / 2; vi->topleft.x = st.cursor.x+(st.cursor.y-vi->topleft.y)/2-vi->size.width / 2;
st.wnd_map->update |= 1; st.wnd_map->update |= 1;
} }
else if (p.x >= tl.x + vi->extent.width * TWIDTH-1) { else if (p.x >= tl.x + vi->size.width * TWIDTH-1) {
vi->topleft.x = st.cursor.x+(st.cursor.y-vi->topleft.y)/2-vi->extent.width / 2; vi->topleft.x = st.cursor.x+(st.cursor.y-vi->topleft.y)/2-vi->size.width / 2;
st.wnd_map->update |= 1; st.wnd_map->update |= 1;
} }

View File

@ -42,7 +42,7 @@ typedef struct view {
struct map_region * regions; struct map_region * regions;
int plane; int plane;
coordinate topleft; /* upper left corner in map. */ coordinate topleft; /* upper left corner in map. */
extent extent; /* dimensions. */ extent size; /* dimensions. */
} view; } view;
typedef struct tag { typedef struct tag {