diff --git a/onefile/shisen.c b/onefile/shisen.c index f1ebd63..baaa9e1 100644 --- a/onefile/shisen.c +++ b/onefile/shisen.c @@ -7,10 +7,12 @@ #include "helianthus.h" -#define COLS 16 -#define ROWS 9 -#define MAXLETTERS 256 +#define COLS 16 +#define ROWS 9 +#define ACTIVELETTERS 20 +#define MAXLETTERS 256 #define RMTIME 1.0 +#define EXTIME 2.0 #define COUNT (ROWS*COLS) @@ -39,6 +41,7 @@ typedef struct { } Cell; +Letter menuLetter; Letter letters[MAXLETTERS]; int lettersCount; int cellWidth = 1; @@ -49,10 +52,12 @@ Pos selected = { -1, -1 }; Track tracks[COUNT]; int tracksCount; Animation bgtex; -int glyphsMask = 15; +int glyphsMask = 0; int mode; +double exitTm; void clearBoard() { + exitTm = 0; mode = 0; memset(tracks, 0, sizeof(tracks)); memset(board, 0, sizeof(board)); @@ -66,6 +71,7 @@ void clearLetters() { for(int j = 0; j < letters[i].glyphsCount; ++j) animationDestroy(letters[i].glyphs[j]); memset(letters, 0, sizeof(letters)); + memset(&menuLetter, 0, sizeof(menuLetter)); lettersCount = 0; cellWidth = cellHeight = 1; } @@ -101,11 +107,13 @@ int loadLetters(const char *filename, int rows, int cols) { if (!visible) continue; letter->glyphs[ letter->glyphsCount++ ] = createAnimationFromImage(ww, hh, buf, TRUE); } + if (letter->glyphsCount > menuLetter.glyphsCount) menuLetter = *letter; if (letter->glyphsCount > 0) ++letter; } lettersCount = letter - letters; cellWidth = ww; cellHeight = hh; + assert(menuLetter.glyphsCount == 4); free(buf); free(pixels); @@ -326,21 +334,23 @@ void draw() { double d = (1 - s)/2; double a = glyphsMask & (1 << i) ? 1.0 : 0.5; fill(colorByRGBA(1, 1, 1, a)); - rectTextured(letters[0].glyphs[i], (i + d)*cellWidth, d*cellHeight, cellWidth*s, cellHeight*s); + rectTextured(menuLetter.glyphs[i], (i + d)*cellWidth, d*cellHeight, cellWidth*s, cellHeight*s); } if (glyphsMask) { noFill(); stroke(colorByRGBA(0.0, 0.0, 0.0, 0.75)); - textAlign(HALIGN_CENTER, HALIGN_CENTER); + textAlign(HALIGN_CENTER, VALIGN_CENTER); textSize(cellHeight*0.5); text(2*cellWidth, 1.5*cellHeight, "press enter"); if ( keyWentDown("any enter") || (mr == 1 && mc >= 0 && mc < 4 && mouseWentDown("left")) ) - generateBoard(glyphsMask, 30); + generateBoard(glyphsMask, ACTIVELETTERS); } + + if (keyWentDown("escape")) windowStop(); } else { - double kw = w/(cellWidth*(COLS + 2)); + double kw = w/(cellWidth*(COLS + 4)); double kh = h/(cellHeight*(ROWS + 2)); double k = kw < kh ? kw: kh; zoom(k); @@ -348,13 +358,27 @@ void draw() { translate(-0.5*COLS*cellWidth, -0.5*ROWS*cellHeight); strokeWidth(0.1*cellWidth); - if (keyWentDown("escape")) clearBoard(); + saveState(); + noFill(); + stroke(colorByRGBA(0.0, 0.0, 0.0, 0.75)); + textSize(cellWidth*0.5); + textAlign(HALIGN_RIGHT, VALIGN_BOTTOM); + text(-0.2*cellWidth, -0.2*cellHeight, "back"); + textAlign(HALIGN_LEFT, VALIGN_TOP); + text((COLS + 0.2)*cellWidth, (ROWS + 0.2)*cellHeight, "hint"); + restoreState(); double mx = mouseTransformedX(); double my = mouseTransformedY(); Pos hover = {}; - hover.c = (int)floor(mx/cellWidth); hover.r = (int)floor(my/cellHeight); + hover.c = (int)floor(mx/cellWidth); + + if (hover.r < 0 && hover.c < 0 && mouseDown("left")) + exitTm += dt/EXTIME; else exitTm = 0; + if (keyWentDown("escape") || exitTm >= 1) + clearBoard(); + if (mouseWentDown("left")) { Track t = findTrack(selected, hover); if (t.len) { @@ -365,12 +389,22 @@ void draw() { ca->tm = cb->tm = t.tm; tracks[tracksCount++] = t; } - selected = hover; + + if (hover.r == selected.r && hover.c == selected.c) + selected.r = selected.c = -1; + else + if ( !(hover.r < 0 && hover.c < 0) // ignore hint or exit pressing + && !(hover.r >= ROWS && hover.c >= COLS) ) + selected = hover; } Letter *hl = mouseDown("right") ? get(hover) : NULL; - - if (keyWentDown("h")) hint(); + if (keyWentDown("h") || (!hl && mouseWentDown("right"))) + hint(); + if (hover.r >= ROWS && hover.c >= COLS) { + hl = mouseDown("left") ? get(selected) : NULL; + if (!hl && mouseWentDown("left")) hint(); + } // draw letters for(int r = 0; r < ROWS; ++r) @@ -414,6 +448,12 @@ void draw() { } tracksCount -= j; memmove(tracks, tracks + j, sizeof(*tracks)*tracksCount); + + // draw exiting + noFill(); + stroke(colorByRGBA(1, 0, 0, exitTm)); + double r = cellHeight/2; + arc(mx - r, my - r, 2*r, 2*r, 0, 360*exitTm); } restoreState();