X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrlugburz;a=blobdiff_plain;f=tools%2Fdunger%2Fsrc%2Flview.c;fp=tools%2Fdunger%2Fsrc%2Flview.c;h=48014cc5658c759fcfc8fbeeab9d517447d5153a;hp=e0001fe2da1d8910ce45f04f4877a5484c34ff41;hb=8de1d701e4e9a45e7ed69ccf1fc298514fed5d8f;hpb=76c3689b01d18e5949e91d0658deb278714f882b diff --git a/tools/dunger/src/lview.c b/tools/dunger/src/lview.c index e0001fe..48014cc 100644 --- a/tools/dunger/src/lview.c +++ b/tools/dunger/src/lview.c @@ -1,6 +1,7 @@ #include #include #include "lview.h" +#include "app.h" static struct level *lvl; static struct cell *sel; @@ -12,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; @@ -51,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; } } } @@ -72,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); @@ -118,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); @@ -131,9 +158,7 @@ void draw_lview(void) glEnd(); if(sel) { - int cidx = sel - lvl->cells; - int row = cidx / lvl->width; - int col = cidx % lvl->width; + cell_coords(sel, &col, &row); glMatrixMode(GL_MODELVIEW); glPushMatrix(); @@ -168,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; +}