master
bzt 2020-02-24 13:55:59 +01:00
parent 35f7221c0e
commit c4dfe622df
12 changed files with 86 additions and 30 deletions

View File

@ -135,9 +135,10 @@ Main editor window:
| <kbd>Shift</kbd> + <kbd>V</kbd> | duplicate current Z layer |
| <kbd>Ctrl</kbd> + <kbd>V</kbd> | remove current Z layer |
| <kbd>B</kbd> | select brush (use geometric objects) |
| <kbd>N</kbd> | toggle grid |
| <kbd>N</kbd> | pick node |
| <kbd>A</kbd> | toggle show all / show current layer only |
| <kbd>M</kbd> / <kbd>Tab</kbd> | open block map, search all available blocks |
| <kbd>;</kbd> | toggle grid |
| <kbd>,</kbd> / <kbd>&lt;</kbd> | zoom out |
| <kbd>.</kbd> / <kbd>&gt;</kbd> | zoom in |
| <kbd>0</kbd>, <kbd>Backquote</kbd> | select Air block (erase mode) |

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -252,6 +252,7 @@ void blocks_parse()
blocks = (mtsblock_t*)realloc(blocks, numblocks * sizeof(mtsblock_t));
if(!blocks) error(lang[ERR_MEM]);
memset(&blocks[j], 0, sizeof(mtsblock_t));
blocks[j].rotate = 1;
blocks[j].blocknames = (char**)malloc((numpalettes + 3) * sizeof(char*));
if(!blocks[j].blocknames) error(lang[ERR_MEM]);
memset(blocks[j].blocknames, 0, (numpalettes + 3) * sizeof(char*));
@ -281,7 +282,7 @@ void blocks_parse()
blocks[j].img = (unsigned char*)stbi__png_load(&sc, &w, &h, &r, 0, &ri);
free(img);
if(blocks[j].img) {
blocks[j].numpar2 = (h >> 5) & PARAM2_MAX;
blocks[j].numpar2 = (h >> 5) & 0xFF;
if(r != 4) {
tmp = (unsigned int *)malloc(w * h * 4);
if(!tmp) error(lang[ERR_MEM]);

View File

@ -64,6 +64,26 @@ void edit_placenode(int y, int z, int x, int i)
status = i ? blocks[i].name : NULL;
}
/**
* Add node at cursor to palette
*/
void edit_pipette(int y, int z, int x)
{
int j, k;
if(x >= 0 && x < 256 && y >= 0 && y < 256 && z >=0 && z < 256 && nodes[y][z][x].param0) {
if(nodes[y][z][x].param0) {
for(k = 0, j = 1; j < 15; j++)
if(palette[j] == nodes[y][z][x].param0) { activeblock = k = j; break; }
if(!k) {
for(j = 15; j > 1; j--) palette[j] = palette[j - 1];
activeblock = 1;
palette[activeblock] = nodes[y][z][x].param0;
}
}
status = blocks[nodes[y][z][x].param0].name;
}
}
/**
* Zoom in
*/
@ -122,7 +142,7 @@ void edit_redraw(int full)
continue;
i = nodes[y][Z][X].param0;
if(i) {
j = nodes[y][Z][X].param2 & PARAM2_MAX;
j = nodes[y][Z][X].param2;
if(blocks[i].numpar2) j %= (int)blocks[i].numpar2; else j = 0;
if(!blocks[i].dr) {
s = 32 * (blocks[i].numpar2 ? blocks[i].numpar2 : 1)*32 * 4;
@ -188,7 +208,7 @@ void edit_redraw(int full)
continue;
i = nodes[y][Z][X].param0;
if(i) {
j = nodes[y][Z][X].param2 & PARAM2_MAX;
j = nodes[y][Z][X].param2;
if(blocks[i].numpar2) j %= (int)blocks[i].numpar2; else j = 0;
if(!blocks[i].tr) {
s = 32 * (blocks[i].numpar2 ? blocks[i].numpar2 : 1)*32 * 4;
@ -234,7 +254,7 @@ void edit_redraw(int full)
SDL_BlitScaled(blk, &src, cl, &dst);
}
if(i) {
j = nodes[currlayer][Z][X].param2 & PARAM2_MAX;
j = nodes[currlayer][Z][X].param2;
if(blocks[i].numpar2) j %= (int)blocks[i].numpar2; else j = 0;
s = 32 * 32 * 4;
if(nodes[currlayer][Z][X].param1 & 0x80) {
@ -351,7 +371,7 @@ void edit_key(SDL_Event *event)
status = blocks[nodes[currlayer][cz][cx].param0].name;
}
break;
case SDLK_n: grid ^= 1; break;
case SDLK_SEMICOLON: grid ^= 1; break;
case SDLK_a: curronly ^= 1; break;
case SDLK_PLUS: case SDLK_EQUALS: mts_layerprob(+1); break;
case SDLK_MINUS: mts_layerprob(-1); break;
@ -363,6 +383,7 @@ void edit_key(SDL_Event *event)
if(palette[event->key.keysym.sym - SDLK_0])
activeblock = event->key.keysym.sym - SDLK_0;
break;
case SDLK_n: edit_pipette(currlayer, cz, cx); break;
case SDLK_x: sdldo(6 + ctrl); break;
case SDLK_c: sdldo(8 + ctrl); break;
case SDLK_v: sdldo(10 + ctrl); break;
@ -435,11 +456,8 @@ void edit_rotate(int y, int z, int x, int ccw)
if(!nodes[y][z][x].param0) return;
if(ccw) {
nodes[y][z][x].param2++;
if(nodes[y][z][x].param2 > 31)
nodes[y][z][x].param2 = 0;
} else {
if(nodes[y][z][x].param2 > 0) nodes[y][z][x].param2--;
else nodes[y][z][x].param2 = 31;
nodes[y][z][x].param2--;
}
if(oldparam2 != nodes[y][z][x].param2) {
hist_prepare(HIST_NODE, 0);

View File

@ -41,6 +41,7 @@ extern char cur[2];
void load_do()
{
char *fn, d = loadfiles[loadpos][0] == '/';
if(isdir(mtsfile)) {
fn = mtsfile + strlen(mtsfile);
if(fn[-1] != DIRSEP) { *fn++ = DIRSEP; *fn = 0; }
@ -69,7 +70,8 @@ void load_do()
freedir(loadmax, &loadfiles);
if(d) loadpos = loadscr = loadmax = 0;
savelen = savepos = strlen(mtsfile);
sdldo(-2);
if(!isdir(mtsfile))
sdldo(-2);
}
/**

View File

@ -42,8 +42,6 @@
#define _register
#endif
#define PARAM2_MAX 0x1F /* must be 2^n - 1 */
#define THEME_INPUT 0
#define THEME_TABA 1
#define THEME_FG 2
@ -98,6 +96,7 @@ typedef struct {
char **blocknames;
int numref;
char numpar2;
char rotate;
char dobiome;
uint32_t color;
unsigned short blockids[4];
@ -241,6 +240,7 @@ int sdlmain(int opt);
/* edit.c */
void edit_placenode(int y, int z, int x, int i);
void edit_pipette(int y, int z, int x);
int edit_zoomin();
int edit_zoomout();
void edit_redraw(int full);

View File

@ -349,7 +349,7 @@ int mts_view(int type)
dst.y = h - lh + dz * ((z-miz) + (x-mix)) - (y-miy) * l;
i = nodes[y][z][x].param0;
if(i && blocks[i].img) {
j = nodes[y][z][x].param2 & PARAM2_MAX;
j = nodes[y][z][x].param2;
j %= (int)blocks[i].numpar2;
memcpy(tmpblk, blocks[i].img + j * 32 * 32 * 4, 32 * 32 * 4);
for(j = 0; j < 32 * 32 * 4; j += 4) {
@ -573,7 +573,7 @@ void mts_layerprob(int diff)
*/
void mts_rotate(int ccw)
{
int nx, nz, x, y, z;
int nx, nz, x, y, z, o;
node_t layer[256][256];
mts_getbounds(0, NULL, NULL);
@ -586,8 +586,18 @@ void mts_rotate(int ccw)
for(x = mix; x <= max; x++) {
if(ccw) { nz = 255-x; nx = z; } else { nz = x; nx = 255-z; }
memcpy(&nodes[y][nz][nx], &layer[z][x], sizeof(node_t));
if(nodes[y][nz][nx].param0)
edit_rotate(y, nz, nx, ccw);
if(nodes[y][nz][nx].param0 && blocks[nodes[y][nz][nx].param0].rotate) {
o = nodes[y][nz][nx].param2;
if(ccw)
nodes[y][nz][nx].param2 = (nodes[y][nz][nx].param2 & ~3) | (((nodes[y][nz][nx].param2 & 3)-1) & 3);
else
nodes[y][nz][nx].param2 = (nodes[y][nz][nx].param2 & ~3) | (((nodes[y][nz][nx].param2 & 3)+1) & 3);
if(o != nodes[y][nz][nx].param2) {
hist_prepare(HIST_NODE, 0);
hist_add(y, nz, nx, nodes[y][nz][nx].param0, o, nodes[y][nz][nx].param0, nodes[y][nz][nx].param2);
hist_commit();
}
}
}
}
bound_valid = 0;
@ -599,7 +609,7 @@ void mts_rotate(int ccw)
*/
void mts_flip()
{
int x, y, z;
int x, y, z, o;
node_t layer[256][256];
mts_getbounds(0, NULL, NULL);
@ -610,9 +620,14 @@ void mts_flip()
for(z = miz; z <= maz; z++)
for(x = mix; x <= max; x++) {
memcpy(&nodes[y][z][x], &layer[maz-z+miz][x], sizeof(node_t));
if(nodes[y][z][x].param0) {
edit_rotate(y, z, x, 0);
edit_rotate(y, z, x, 0);
if(nodes[y][z][x].param0 && blocks[nodes[y][z][x].param0].rotate) {
o = nodes[y][z][x].param2;
nodes[y][z][x].param2 = (nodes[y][z][x].param2 & ~3) | (((nodes[y][z][x].param2 & 3)+2) & 3);
if(o != nodes[y][z][x].param2) {
hist_prepare(HIST_NODE, 0);
hist_add(y, z, x, nodes[y][z][x].param0, o, nodes[y][z][x].param0, nodes[y][z][x].param2);
hist_commit();
}
}
}
}

View File

@ -373,7 +373,7 @@ void m3d_load(unsigned char *data, unsigned int size)
if(m >= 0 && m < nt && py+y >= 0 && py+y < 256 && pz+z >= 0 && pz+z < 256 && px+x >= 0 && px+x < 256) {
nodes[py+y][pz+z][px+x].param0 = tr[m] & 0xFFFFFF;
nodes[py+y][pz+z][px+x].param1 = tr[m] ? 127 : 0;
nodes[py+y][pz+z][px+x].param2 = (tr[m] >> 24) & PARAM2_MAX;
nodes[py+y][pz+z][px+x].param2 = (tr[m] >> 24) & 0xFF;
blocks[nodes[py+y][py+z][px+x].param0].numref++;
blocks[0].numref--;
}
@ -385,7 +385,7 @@ void m3d_load(unsigned char *data, unsigned int size)
if(m >= 0 && m < nt && py+y >= 0 && py+y < 256 && pz+z >= 0 && pz+z < 256 && px+x >= 0 && px+x < 256) {
nodes[py+y][pz+z][px+x].param0 = tr[m] & 0xFFFFFF;
nodes[py+y][pz+z][px+x].param1 = tr[m] ? 127 : 0;
nodes[py+y][pz+z][px+x].param2 = (tr[m] >> 24) & PARAM2_MAX;
nodes[py+y][pz+z][px+x].param2 = (tr[m] >> 24) & 0xFF;
blocks[nodes[py+y][py+z][px+x].param0].numref++;
blocks[0].numref--;
}

View File

@ -69,7 +69,7 @@ help_t helpkeys[] = {
{ UNDO, " Z " },
{ REDO, " Y " },
{ BRUSH, " B " },
{ GRID, " N " },
{ GRID, " ; " },
{ GROUNDLEVEL, " G " },
{ LAYERUP, " PgUp " },
{ LAYERDOWN, " PgDn " },
@ -144,7 +144,7 @@ void sdlhelp()
void sdltoolbar()
{
int i, m;
char *s = status, str[5];
char *s = status, str[16];
SDL_Rect src, dst;
strmaxw = screen->w - 5;
@ -224,12 +224,18 @@ void sdltoolbar()
sprintf(str, "%3d%%", layerprob[currlayer] * 100 / 127);
sdlprint(2, screen->h - font->height, THEME_INACT, THEME_BG, str);
/* status bar */
src.x = 16; src.y = 8 * 32 + 80; dst.x = screen->w - 13 * font->width - 11 - 60; dst.y = screen->h - font->height / 2 - 8;
src.x = 16; src.y = 8 * 32 + 80; dst.x = screen->w - 16 * font->width - 20 - 60; dst.y = screen->h - font->height / 2 - 8;
if(nodes[currlayer][cz][cx].param0 && dst.x >= 0) {
sprintf(str, "%02X", nodes[currlayer][cz][cx].param2 & PARAM2_MAX);
sprintf(str, "%02X %02X", nodes[currlayer][cz][cx].param1, nodes[currlayer][cz][cx].param2);
sdlprint(dst.x, screen->h - font->height, THEME_FG, THEME_BG, str);
} else if(overtool == -3) {
sprintf(str, "%3d", layerprob[currlayer]);
sdlprint(dst.x, screen->h - font->height, THEME_FG, THEME_BG, str);
} else if(overtool == -4) {
sprintf(str, "%3d", currlayer);
sdlprint(dst.x, screen->h - font->height, THEME_FG, THEME_BG, str);
}
dst.x += 2*font->width + 6;
dst.x += 5*font->width + 15;
if((nodes[currlayer][cz][cx].param1 & 0x80) && dst.x >= 0) {
strsepar = 0;
sdlprint(dst.x, screen->h - font->height, THEME_FG, THEME_BG, "\004\005");
@ -297,6 +303,20 @@ void sdlredraw()
SDL_UpdateWindowSurface(window);
}
/**
* Set window title
*/
void sdltitle()
{
char *fn, *title;
fn = strrchr(mtsfile, DIRSEP);
if(fn) fn++; else fn = mtsfile;
title = (char*)malloc(strlen(fn) + 10);
sprintf(title, "MTSEdit: %s", fn);
SDL_SetWindowTitle(window, title);
free(title);
}
/**
* UI for various MTS operations
*/
@ -308,7 +328,7 @@ void sdldo(int opt)
SDL_SetCursor(working);
switch(opt) {
case -1: activetool = -1; break;
case -2: readschem(); if(mts_x && mts_y && mts_z) { activetool = -1; activeblock = 0; } break;
case -2: readschem(); if(mts_x && mts_y && mts_z) { sdltitle(); activetool = -1; activeblock = 0; } break;
case 0: activetool = 0; break;
case 1: mts_save(); activetool = -1; activeblock = 0; break;
case 2: mts_view(shift); break;

View File

@ -141,7 +141,6 @@ void readschem()
for(x = 0; x < 256; x++)
if(nodes[y][z][x].param0) {
if(!(nodes[y][z][x].param1 & 0x7F)) nodes[y][z][x].param1 |= 127;
nodes[y][z][x].param2 &= PARAM2_MAX;
}
currlayer = gndlayer;
}