X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Fdunger%2Fsrc%2Flview.c;h=48014cc5658c759fcfc8fbeeab9d517447d5153a;hb=67b9bf8d28722bbc8c03c897c0a46d202286bd16;hp=8e0ee270b891e35426931e3ea0d713e219de664d;hpb=d2306fabd6ad4a568174fe0f17dec0b24c202eac;p=vrlugburz diff --git a/tools/dunger/src/lview.c b/tools/dunger/src/lview.c index 8e0ee27..48014cc 100644 --- a/tools/dunger/src/lview.c +++ b/tools/dunger/src/lview.c @@ -1,5 +1,7 @@ #include +#include #include "lview.h" +#include "app.h" static struct level *lvl; static struct cell *sel; @@ -11,7 +13,8 @@ int init_lview(struct level *l) { lvl = l; sel = 0; - panx = pany = 0; + panx = 0; + pany = -12; zoom = 1; zoom_lview(0); return 0; @@ -50,16 +53,36 @@ static int bnstate[8]; void lview_mbutton(int bn, int press, int x, int y) { + int cx, cy; float hsz = cellsz / 2.0f; sel = pos_to_cell(x + hsz - vpx, vph - y + hsz - vpy, 0, 0); bnstate[bn] = press; if(press) { if(!sel) return; - if(bn == 0) { - sel->type = CELL_WALK; - } else if(bn == 2) { - sel->type = CELL_SOLID; + + switch(tool) { + case TOOL_DRAW: + if(bn == 0) { + sel->type = CELL_WALK; + } else if(bn == 2) { + sel->type = CELL_SOLID; + } + break; + + case TOOL_PSTART: + cell_coords(sel, &cx, &cy); + if(bn == 0) { + if(sel->type == CELL_WALK) { + lvl->px = cx; + lvl->py = cy; + } + } else if(bn == 2) { + if(lvl->px == cx && lvl->py == cy) { + lvl->px = lvl->py = -1; + } + } + break; } } } @@ -71,32 +94,37 @@ void lview_mouse(int x, int y) return; } - if(bnstate[0]) { - sel->type = CELL_WALK; - } else if(bnstate[2]) { - sel->type = CELL_SOLID; + switch(tool) { + case TOOL_DRAW: + if(bnstate[0]) { + sel->type = CELL_WALK; + } else if(bnstate[2]) { + sel->type = CELL_SOLID; + } + break; } } #define LTHICK 0.5f static void draw_cell(struct cell *cell) { - int cidx, row, col; + int row, col; float x, y, hsz; static const float colors[][3] = {{0, 0, 0}, {0.6, 0.6, 0.6}, {0.4, 0.2, 0.1}}; hsz = cellsz * 0.5f; - cidx = cell - lvl->cells; - row = cidx / lvl->width; - col = cidx % lvl->width; - + cell_coords(cell, &col, &row); cell_to_pos(col, row, &x, &y); if(sel == cell) { - glColor3f(0.4, 1.0f, 0.4); + glColor3f(1, 1, 1); } else { - glColor3f(0.5f, 0.5f, 0.5f); + if(col == lvl->px && row == lvl->py) { + glColor3f(0, 1, 0); + } else { + glColor3f(0.5f, 0.5f, 0.5f); + } } glVertex2f(x - hsz, y - hsz); glVertex2f(x + hsz, y - hsz); @@ -117,7 +145,7 @@ static void draw_cell(struct cell *cell) void draw_lview(void) { - int i, j; + int i, j, row, col; struct cell *cell; glBegin(GL_QUADS); @@ -129,6 +157,19 @@ void draw_lview(void) } glEnd(); + if(sel) { + cell_coords(sel, &col, &row); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef(10, 10, 0); + + glColor3f(1, 1, 1); + dtx_printf("(%d, %d)", col, row); + dtx_flush(); + + glPopMatrix(); + } } void cell_to_pos(int cx, int cy, float *px, float *py) @@ -152,3 +193,10 @@ struct cell *pos_to_cell(float px, float py, int *cx, int *cy) } return 0; } + +void cell_coords(struct cell *cell, int *col, int *row) +{ + int cidx = cell - lvl->cells; + *row = cidx / lvl->width; + *col = cidx % lvl->width; +}