MapGen aliases

master
bzt 2019-12-10 12:55:01 +01:00
parent 3432d1571b
commit 9257759fbb
18 changed files with 795 additions and 732 deletions

BIN
data/Cut_Sandstone_00.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 702 B

File diff suppressed because it is too large Load Diff

View File

@ -8,12 +8,13 @@ See also the [GUI usage](https://gitlab.com/bztsrc/mtsedit/blob/master/docs/usag
```
MineTest Schematics Editor by bzt Copyright (C) 2019 MIT license
./mtsedit [-v] [-l <lang>] [-d|-p|-P] [-m map] <.mts|.schematic> [out.mts]
./mtsedit [-v] [-l lang] [-d|-p|-P] [-m map] <.mts|.schematic> [out.mts]
./mtsedit -g <block.png>
./mtsedit -t <blockimgs.csv> [blockid]
./mtsedit -i [Minetest mods dir]
-v: verbose output
-l lang: set language
-d: dump layers to output
-p: save preview
-P: save preview, cut structure in half
@ -48,7 +49,7 @@ You can also convert MTS files using different block types:
./mtsedit -m "Minetest Game" mcl2.mts mtg.mts
```
Where the parameter to "-m" is a coloumn name in [blocks.csv](https://gitlab.com/bztsrc/mtsedit/blob/master/docs/usage.md) file.
You can also use numbers, starting from 1 (which means the 4th coloumn, as the first three are reserved for special use).
You can also use numbers, starting from 1 (which means the 5th coloumn, as the first four are reserved for special use).
```
./mtsedit -m 1 mtg.mts mcl2.mts
```
@ -56,9 +57,9 @@ You can also use numbers, starting from 1 (which means the 4th coloumn, as the f
### Generate Preview
```
./mtsedit -p structure.mts
./mtsedit -p somedir/structure.mts
```
This will save "structure.png".
This will save a file by the same name as the MTS but with ".png" extension, like "somedir/structure.png".
```
./mtsedit -P structure.mts

View File

@ -26,7 +26,7 @@ from within the game (with all your desired mods enabled).
### Header
The first row is special, it defines the coloumn names. The first 3 coloumns are irrelevant and not parsed, others
The first row is special, it defines the coloumn names. The first 4 coloumns are irrelevant and not parsed, others
define the name of the block mapping.
### Coloumns
@ -36,7 +36,8 @@ define the name of the block mapping.
| 1st | string | block id, canonical name of the block (also used to identify block images) |
| 2nd | intlist | list of slash '/' separated integer numbers, the Minecraft BlockID in schematic files |
| 3rd | string | an optional biome specific name for the block (like "biome:node_stone") |
| 4th+ | string | block's name in the mapping (this coloumn may be repated as many times as you like) |
| 4th | string | an optional mapgen alias name for the block |
| 5th+ | string | block's name in the mapping (this coloumn may be repated as many times as you like) |
Block mapping are also referenced as palette.
@ -45,7 +46,7 @@ Block Images
Each block type may have more, but must have at least one image in the `data` directory. These are named as:
```
(block type)_(param2).png
(block id)_(param2).png
```
The first part "block type" cames from the canonical name (1st coloumn), but with spaces converted to underscores '\_'. The
second part, "param2" is a hexa-decimal value and represents the orientation. If the block has only one image, then it must be

Binary file not shown.

View File

@ -131,13 +131,12 @@ end
-- Export node data into CSV
function mtsedit.export(param)
minetest.chat_send_player(name, "mtseditEXP: " .. param)
if param == nil or param == "" then
return false, S("Specify <palette> (like \"Mineclone2\", \"Minetest Game\" etc.)")
end
local fn = minetest.get_worldpath() .. "/blocks.csv"
local defpalettes = { "_Name", "BlockID", "Biome Specific", param }
local defpalettes = { "_Name", "BlockID", "Biome Specific", "MapGen Alias", param }
local palettes, nodes, known, s = {}, {}, {}, {}
local line, node, i, cnt, idx = 0, "", 0, 1, 0
@ -152,7 +151,7 @@ minetest.chat_send_player(name, "mtseditEXP: " .. param)
palettes = defpalettes
end
end
for i,t in ipairs(palettes) do if (cnt > 3 and t == param) then idx = i end cnt = cnt + 1 end
for i,t in ipairs(palettes) do if (cnt > 4 and t == param) then idx = i end cnt = cnt + 1 end
if (idx == 0) then
table.insert(palettes, param)
idx = cnt
@ -182,8 +181,8 @@ minetest.chat_send_player(name, "mtseditEXP: " .. param)
if (blockid ~= nil and blockid ~= "") then
-- if new node
if (nodes[blockid] == nil) then
i = 3
nodes[blockid] = { "", "" }
i = 4
nodes[blockid] = { "", "", "" }
while (i < cnt) do table.insert(nodes[blockid], node) i = i + 1 end
end
-- if no biome specific name given already check if there's one
@ -198,8 +197,18 @@ minetest.chat_send_player(name, "mtseditEXP: " .. param)
end
end
end
-- mapgen specific name
if (nodes[blockid][3] == nil) then nodes[blockid][3] = "" end
if (nodes[blockid][3] == "") then
for mapgen,oname in pairs(minetest.registered_aliases) do
if (oname == node) then
nodes[blockid][3] = mapgen
break
end
end
end
-- replace block names
i = 3
i = 4
while (i < cnt) do
if (i == idx or nodes[blockid][i] == nil or nodes[blockid][i] == "") then nodes[blockid][i] = node end
i = i + 1

View File

@ -8,7 +8,7 @@ TARGET = mtsedit
SRCS = $(filter-out bin2h.c,$(wildcard *.c))
OBJS = $(SRCS:.c=.o)
CFLAGS = -Wall -Wextra -ansi -pedantic
CFLAGS = -Wall -Wextra -ansi -pedantic -g
# MacOSX
ifneq ("$(wildcard $(MACSDL)/SDL.h)","")

View File

@ -163,11 +163,11 @@ void blocks_parse()
}
/* parse header */
for(e = data, i = j = 0; *e && *e != '\r' && *e != '\n' && i < 3; e++) {
for(e = data, i = j = 0; *e && *e != '\r' && *e != '\n' && i < 4; e++) {
if(*e == '\"') j ^= 1;
if(!j && (*e == ',' || *e == ';' || *e == '\t')) i++;
}
if(i != 3 || !*e || *e == '\r' || *e == '\n') errorcsv(1);
if(i != 4 || !*e || *e == '\r' || *e == '\n') errorcsv(1);
while(*e && *e != '\r' && *e != '\n') {
while(*e == ',' || *e == ';' || *e == '\t' || *e == ' ') e++;
if(*e == '\"') { e++; c = '\"'; } else c = ',';
@ -196,10 +196,10 @@ void blocks_parse()
blocks[0].name = (char*)malloc(strlen(t)+1);
if(!blocks[0].name) error(lang[ERR_MEM]);
strcpy(blocks[0].name, t);
blocks[0].blocknames = (char**)malloc((numpalettes + 1) * sizeof(char*));
blocks[0].blocknames = (char**)malloc((numpalettes + 2) * sizeof(char*));
if(!blocks[0].blocknames) error(lang[ERR_MEM]);
blocks[0].blocknames[0] = NULL;
for(i = 1; i < (unsigned int)numpalettes + 1; i++) {
for(i = 1; i < (unsigned int)numpalettes + 2; i++) {
blocks[0].blocknames[i] = (char*)malloc(4);
if(!blocks[0].blocknames[i]) error(lang[ERR_MEM]);
memcpy(blocks[0].blocknames[i], "air", 4);
@ -220,9 +220,9 @@ 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].blocknames = (char**)malloc((numpalettes + 1) * sizeof(char*));
blocks[j].blocknames = (char**)malloc((numpalettes + 2) * sizeof(char*));
if(!blocks[j].blocknames) error(lang[ERR_MEM]);
memset(blocks[j].blocknames, 0, (numpalettes + 1) * sizeof(char*));
memset(blocks[j].blocknames, 0, (numpalettes + 2) * sizeof(char*));
for(k = 0; s + k < e; k++)
if(s[k] == ' ' || s[k] == '\'') s[k] = '_';
/* translate block name */
@ -316,7 +316,7 @@ void blocks_parse()
memcpy(blocks[j].blocknames[k], s, e - s + 1);
blocks[j].blocknames[k][e - s] = 0;
}
k++; if(k > (unsigned int)numpalettes + 1) errorcsv(j+2);
k++; if(k > (unsigned int)numpalettes + 2) errorcsv(j+2);
while(*e && *e != ',' && *e != ';' && *e != '\t' && *e != '\r' && *e != '\n') e++;
}
if(!numblocks || numblocks > 65535) error(lang[ERR_CSV]);
@ -347,7 +347,7 @@ void blocks_free()
for(i = 0; i < numblocks; i++) {
free(blocks[i].name);
if(blocks[i].blocknames) {
for(j = 0; j < numpalettes; j++)
for(j = 0; j < numpalettes + 2; j++)
if(blocks[i].blocknames[j]) free(blocks[i].blocknames[j]);
free(blocks[i].blocknames);
}

View File

@ -36,6 +36,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
{
"en",
"verbose output",
"set language",
"dump layers to output",
"save preview",
"save preview, cut structure in half",
@ -92,6 +93,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Save Schematic to File",
"Filename:",
"Mapping:",
"MapGen type:",
"Biome type:",
"Save",
"Type:",
@ -111,6 +113,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
{
"hu",
"részletes kimenet",
"nyelv beállítása",
"kidumpolja a rétegeket a kimenetre",
"előnézeti képet ment",
"előnézet félbevágott struktúráról",
@ -167,6 +170,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Sematika mentése fájlba",
"Fájlnév:",
"Paletta:",
"MapGen típus:",
"Biom típus:",
"Elment",
"Típus:",
@ -186,6 +190,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
{
"es",
"salida detallada",
"elegir lenguaje",
"volcar capas a la salida",
"guardar vista previa",
"guardar vista previa, cortar la estructura por la mitad",
@ -242,6 +247,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Guardar esquema en archivo",
"Nombre:",
"Cartografía:",
"Utilizar MapGen:",
"Utilizar bioma:",
"Salvar",
"Tipo:",
@ -261,6 +267,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
{
"fr",
"sortie prolixe",
"définir la langue",
"vider les couches à la sortie",
"enregistrer l'aperçu",
"enregistrer l'aperçu, couper la structure en deux",
@ -317,6 +324,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Enregistrer le schéma dans un fichier",
"Nom de fichier:",
"Cartographie:",
"Utiliser MapGen:",
"Utiliser biome:",
"Sauver",
"Type:",
@ -336,6 +344,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
{
"de",
"ausführliche Ausgabe",
"Sprache einstellen",
"Dump Layeren zu Konsole",
"Vorschau speichern",
"Vorschau speichern, Struktur halbieren",
@ -392,6 +401,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Schaltplan in Datei speichern",
"Dateiname:",
"Kartierung:",
"MapGen-Aliase:",
"Verwenden Biome:",
"Aufspeichern",
"Typ:",
@ -411,6 +421,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
{
"pl",
"gadatliwe wyjście",
"ustaw język",
"zrzuć warstwy na wyjście",
"zapisz podgląd",
"zapisz podgląd, wytnij strukturę na pół",
@ -467,6 +478,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Zapisz schemat do pliku",
"Nazwa pliku:",
"Mapowanie:",
"Aliasy MapGen:",
"Użyj biomu:",
"Zapisać",
"Rodzaj:",
@ -486,6 +498,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
{
"ru",
"подробный вывод",
"установить язык",
"выгрузить слои на вывод",
"сохранить предварительный просмотр",
"сохранить предварительный просмотр, разрезать структуру пополам",
@ -542,6 +555,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Сохранить схему в файл",
"Имя файла:",
"Отображение:",
"Мапген псевдонимы:",
"Используйте Биом:",
"Сохранить",
"Тип:",

View File

@ -29,6 +29,7 @@
enum {
INF_VERB = 0,
INF_LANG,
INF_DUMP,
INF_PRE1,
INF_PRE2,
@ -85,6 +86,7 @@ enum {
SAVEAS,
FILENAME,
MAPPING,
MAPGENTYPE,
BIOMETYPE,
SAVEBTN,
TYPE,

View File

@ -84,7 +84,7 @@ void load_redraw()
SDL_FillRect(screen, &rect, theme[THEME_BG]);
strmaxw = screen->w - 5;
sdlprint((screen->w - 47 - strlen(lang[LOADFROM]) * (font->width+1)) / 2 + 47, 4, THEME_INPUT, THEME_BG, lang[LOADFROM]);
sdlprint((screen->w - 47 - mbstrlen(lang[LOADFROM]) * (font->width+1)) / 2 + 47, 4, THEME_INPUT, THEME_BG, lang[LOADFROM]);
rect.y = 12 + font->height;
sdlprint(42, rect.y, THEME_FG, THEME_BG, lang[FILENAME]);
@ -118,7 +118,7 @@ void load_redraw()
rect.y = j + 4;
rect.h = font->height + 2;
SDL_FillRect(screen, &rect, theme[loadfld == 2 ? THEME_INPUT : THEME_FG]);
sdlprint((screen->w - 47 - strlen(lang[LOADBTN]) * (font->width+1)) / 2 + 42, rect.y+1,
sdlprint((screen->w - 47 - mbstrlen(lang[LOADBTN]) * (font->width+1)) / 2 + 42, rect.y+1,
THEME_BG, loadfld == 2 ? THEME_INPUT : THEME_FG, lang[LOADBTN]);
}

View File

@ -167,14 +167,14 @@ int main(int argc, char** argv, char** envp)
if(argc < 2) {
usage: printf("MineTest Schematics Editor by bzt Copyright (C) 2019 MIT license\r\n\r\n"
"./mtsedit [-v] [-l <lang>] [-d|-p|-P] [-m map] <.mts|.schematic> [out.mts]\r\n"
"./mtsedit [-v] [-l lang] [-d|-p|-P] [-m map] <.mts|.schematic> [out.mts]\r\n"
"./mtsedit -g <block.png>\r\n"
"./mtsedit -t <blockimgs.csv> [blockid]\r\n"
"./mtsedit -i [Minetest mods dir]\r\n"
"\r\n -v: %s\r\n -d: %s\r\n -p: %s\r\n -P: %s\r\n -m map: %s\r\n -g: %s\r\n -t: %s\r\n"
" -i: %s\r\n out.mts: %s\r\n",
lang[INF_VERB], lang[INF_DUMP], lang[INF_PRE1], lang[INF_PRE2], lang[INF_MAP], lang[INF_GEN], lang[INF_BLK],
lang[INF_MOD], lang[INF_OUT]);
"\r\n -v: %s\r\n -l lang: %s\r\n -d: %s\r\n -p: %s\r\n -P: %s\r\n -m map: %s\r\n -g: %s\r\n"
" -t: %s\r\n -i: %s\r\n out.mts: %s\r\n",
lang[INF_VERB], lang[INF_LANG], lang[INF_DUMP], lang[INF_PRE1], lang[INF_PRE2], lang[INF_MAP],
lang[INF_GEN], lang[INF_BLK], lang[INF_MOD], lang[INF_OUT]);
exit(0);
}
i = 1;

View File

@ -99,7 +99,8 @@ typedef struct {
unsigned char *tr[32];
} mtsblock_t;
extern int numpalettes, lenpalettes, palette[16], strmaxw, strsep, savelen, savepos, savepal, savebiome, numresults, *results;
extern int numpalettes, lenpalettes, palette[16], strmaxw, strsep, savelen, savepos, savepal, savemapgen, savebiome;
extern int numresults, *results;
extern int currlayer, gndlayer, mts_x, mts_y, mts_z, mix, miy, miz, max, may, maz, bound_valid, dx, dz, cx, cz, ox, oy, up, zoom;
extern int zx, zz, zs, shift, ctrl, activetool, activeblock, quitting, verbose, x0, x1, y0, y1, y3, brush_type, brush_hollow;
extern char **palettes, layerprob[256];
@ -178,6 +179,7 @@ unsigned char *readfile(char *file, unsigned int *size);
void readschem();
void error(char *msg);
void errorcsv(int line);
int mbstrlen(char *s);
unsigned char ahtoi(char *s);
int isdir(char *path);
int listdir(char *path, char ***files, int type);

View File

@ -118,12 +118,16 @@ void mts_load(unsigned char *data, unsigned int size)
j = buff[1];
buff += 2;
for(k = 0; k < numblocks; k++)
for(l = 0; l < numpalettes + 1; l++)
if((!blocks[k].blocknames && l && (int)strlen(blocks[k].name) == j &&
for(l = 0; l < numpalettes + 2; l++)
if((!blocks[k].blocknames && (int)strlen(blocks[k].name) == j &&
!memcmp(blocks[k].name, buff, j)) || (blocks[k].blocknames && blocks[k].blocknames[l] &&
(int)strlen(blocks[k].blocknames[l]) == j && !memcmp(blocks[k].blocknames[l], buff, j))) {
if(!l && k) { blocks[k].dobiome = 1; savebiome = 1; }
if(l) palref[l - 1]++;
if(k)
switch(l) {
case 0: blocks[k].dobiome = 1; savebiome = 1; break;
case 1: if(!memcmp(buff, "mapgen", 6)) { savemapgen = 1; } break;
default: palref[l - 2]++; break;
}
tr[i] = k;
break;
}
@ -266,8 +270,9 @@ int mts_save()
if(savepal < 0 || savepal >= numpalettes) savepal = 0;
for(i = 0; i < j; i++) {
c = !blocks[tr[i]].blocknames ? blocks[tr[i]].name : (savebiome && blocks[tr[i]].blocknames[0] &&
blocks[tr[i]].dobiome ? blocks[tr[i]].blocknames[0] : (blocks[tr[i]].blocknames[savepal+1] ?
blocks[tr[i]].blocknames[savepal+1] : blocks[tr[i]].name));
blocks[tr[i]].dobiome ? blocks[tr[i]].blocknames[0] : (savemapgen && blocks[tr[i]].blocknames[1] &&
blocks[tr[i]].blocknames[1][0] ? blocks[tr[i]].blocknames[1] : (blocks[tr[i]].blocknames[savepal+2] &&
blocks[tr[i]].blocknames[savepal+2][0] ? blocks[tr[i]].blocknames[savepal+2] : blocks[tr[i]].name)));
hdr[1] = strlen(c);
fwrite(hdr, 2, 1, f);
fwrite(c, hdr[1], 1, f);

View File

@ -29,7 +29,8 @@
#include "main.h"
int savelen, savepos, savefld = 0, savepal = 0, savebiome = 0, biomepos = 0, biomeblk = -1, maxbiome = 0, biomescr = 0;
int savelen, savepos, savefld = 0, savepal = 0, savemapgen = 0, savebiome = 0;
int biomepos = 0, biomeblk = -1, maxbiome = 0, biomescr = 0;
extern char cur[2];
/**
@ -45,7 +46,7 @@ void save_redraw()
SDL_FillRect(screen, &rect, theme[THEME_BG]);
strmaxw = screen->w - 5;
sdlprint((screen->w - 47 - strlen(lang[SAVEAS]) * (font->width+1)) / 2 + 47, 4, THEME_INPUT, THEME_BG, lang[SAVEAS]);
sdlprint((screen->w - 47 - mbstrlen(lang[SAVEAS]) * (font->width+1)) / 2 + 47, 4, THEME_INPUT, THEME_BG, lang[SAVEAS]);
rect.y = 12 + font->height;
sdlprint(42, rect.y, THEME_FG, THEME_BG, lang[FILENAME]);
rect.x = 200; rect.w = screen->w - 205; rect.h = font->height + 2;
@ -69,13 +70,20 @@ void save_redraw()
sdlprint(200 + rect.w, rect.y+1, THEME_BG, savefld == 1 ? THEME_INPUT : THEME_FG, "\031");
rect.y = 20 + 3*font->height;
sdlprint(42, rect.y, THEME_FG, THEME_BG, lang[BIOMETYPE]);
sdlprint(42, rect.y, THEME_FG, THEME_BG, lang[MAPGENTYPE]);
rect.x = 200; rect.w = font->width + font->width/2 + 2; rect.h = font->height + 2;
SDL_FillRect(screen, &rect, theme[THEME_INPBG]);
sdlprint(rect.x + font->width/4 + 1, rect.y + 1, savefld == 3 ? THEME_INPUT : THEME_FG, THEME_INPBG,
savemapgen ? "x" : " ");
rect.y = 24 + 4*font->height;
sdlprint(42, rect.y, THEME_FG, THEME_BG, lang[BIOMETYPE]);
rect.x = 200; rect.w = font->width + font->width/2 + 2; rect.h = font->height + 2;
SDL_FillRect(screen, &rect, theme[THEME_INPBG]);
sdlprint(rect.x + font->width/4 + 1, rect.y + 1, savefld == 4 ? THEME_INPUT : THEME_FG, THEME_INPBG,
savebiome ? "x" : " ");
rect.y = 24 + 4*font->height; rect.x = 42; rect.w = screen->w - 47;
rect.y = 28 + 5*font->height; rect.x = 42; rect.w = screen->w - 47;
if(savebiome) {
j = screen->h - 2*font->height - 8;
rect.h = j - rect.y;
@ -85,10 +93,11 @@ void save_redraw()
if(k >= biomescr) {
if(biomeblk == k) blocks[i].dobiome ^= 1;
strmaxw = screen->w / 2 - 4;
sdlprint(44,rect.y, savefld == 4 && biomepos == k ? THEME_INPUT : THEME_INACT, THEME_INPBG, blocks[i].name);
sdlprint(44,rect.y, savefld == 5 && biomepos == k ? THEME_INPUT : THEME_INACT, THEME_INPBG, blocks[i].name);
strmaxw = screen->w - 5;
sdlprint(screen->w/2,rect.y, savefld == 4 && biomepos == k ? THEME_INPUT : THEME_INACT, THEME_INPBG,
blocks[i].blocknames[blocks[i].dobiome ? 0 : savepal + 1]);
sdlprint(screen->w/2,rect.y, savefld == 5 && biomepos == k ? THEME_INPUT : THEME_INACT, THEME_INPBG,
blocks[i].blocknames[blocks[i].dobiome ? 0 : (savemapgen && blocks[i].blocknames[1] &&
blocks[i].blocknames[1][0] ? 1 : savepal + 2)]);
rect.y += font->height;
}
k++;
@ -100,15 +109,15 @@ void save_redraw()
rect.y = j + 4;
}
rect.h = font->height + 2;
SDL_FillRect(screen, &rect, theme[savefld == 5 ? THEME_SAVEACT : THEME_SAVEINACT]);
sdlprint((screen->w - 47 - strlen(lang[SAVEBTN]) * (font->width+1)) / 2 + 42, rect.y+1,
savefld == 5 ? THEME_INPUT : THEME_FG,
savefld == 5 ? THEME_SAVEACT : THEME_SAVEINACT, lang[SAVEBTN]);
SDL_FillRect(screen, &rect, theme[savefld == 6 ? THEME_SAVEACT : THEME_SAVEINACT]);
sdlprint((screen->w - 47 - mbstrlen(lang[SAVEBTN]) * (font->width+1)) / 2 + 42, rect.y+1,
savefld == 6 ? THEME_INPUT : THEME_FG,
savefld == 6 ? THEME_SAVEACT : THEME_SAVEINACT, lang[SAVEBTN]);
if(savefld == 2) {
rect.w = l; rect.x = 200 + font->width; rect.y = 16 + 3*font->height; rect.h = font->height;
rect.w = l + 8; rect.x = 200 + font->width; rect.y = 16 + 3*font->height; rect.h = font->height;
for(i = 0; (int)i < numpalettes; i++, rect.y += rect.h) {
SDL_FillRect(screen, &rect, theme[savepal == (int)i ? THEME_INPUT : THEME_INPBG]);
sdlprint(rect.x, rect.y, savepal == (int)i ? THEME_BG : THEME_FG, savepal == (int)i ? THEME_INPUT : THEME_INPBG,
sdlprint(rect.x + 4, rect.y, savepal == (int)i ? THEME_BG : THEME_FG, savepal == (int)i ? THEME_INPUT : THEME_INPBG,
palettes[i]);
}
}
@ -130,14 +139,15 @@ void save_scroll(SDL_Event *event)
*/
void save_mousedown(SDL_Event *event)
{
int i = savebiome ? screen->h - 2*font->height - 4 : 24 + 4*font->height;
int i = savebiome ? screen->h - 2*font->height - 4 : 24 + 5*font->height;
if(event->button.x < 42) return;
if(savefld == 2) {
if(event->button.x >= (int)(200 + font->width) && event->button.x < (int)(200 + (lenpalettes+1) * (font->width + 1)) &&
event->button.y >= (int)(16 + 3*font->height) && event->button.y < (int)(16 + (3+numpalettes)*font->height)) {
savefld = 3;
savepal = (event->button.y - 16 - 3*font->height) / font->height;
}
} else
savefld = 1;
return;
}
if(event->button.y >= (int)(12 + font->height) && event->button.y < (int)(16 + 2*font->height) && savefld) {
@ -148,13 +158,17 @@ void save_mousedown(SDL_Event *event)
}
if(event->button.y >= (int)(20 + 3*font->height) && event->button.y < (int)(24 + 4*font->height)) {
savefld = 3;
savemapgen ^= 1;
}
if(event->button.y >= (int)(24 + 4*font->height) && event->button.y < (int)(28 + 5*font->height)) {
savefld = 4;
savebiome ^= 1;
biomepos = 0;
}
if(event->button.y >= i && event->button.y < (int)(i + font->height)) sdldo(1);
else if(savebiome && event->button.y >= (int)(24 + 4*font->height) && event->button.y < i) {
biomepos = biomescr + (event->button.y - (24 + 4*font->height)) / font->height;
if(savefld != 4) savefld = 4;
else if(savebiome && event->button.y >= (int)(28 + 5*font->height) && event->button.y < i) {
biomepos = biomescr + (event->button.y - (28 + 5*font->height)) / font->height;
if(savefld != 5) savefld = 5;
else biomeblk = biomepos;
}
}
@ -180,9 +194,9 @@ void save_key(SDL_Event *event)
case SDL_KEYUP:
switch (event->key.keysym.sym) {
case SDLK_TAB:
if(savefld == 5) savefld = 0; else
if(savefld == 6) savefld = 0; else
if(savefld == 1) savefld = 3; else savefld++;
if(!savebiome && savefld == 4) savefld++;
if(!savebiome && savefld == 5) savefld++;
break;
case SDLK_BACKSPACE:
if(!savefld && savepos) {
@ -202,10 +216,10 @@ void save_key(SDL_Event *event)
if(savefld == 1 || savefld == 2) {
if(!savepal) savepal = numpalettes - 1; else savepal--;
}
if(savefld == 4) {
if(savefld == 5) {
if(!biomepos && maxbiome) biomepos = maxbiome - 1; else biomepos--;
if(biomepos < biomescr) biomescr = biomepos;
i = ((screen->h - 2*font->height - 8) - (24 + 4*font->height)) / font->height;
i = ((screen->h - 2*font->height - 8) - (24 + 5*font->height)) / font->height;
if(biomepos >= biomescr + i) biomescr = biomepos - i;
}
break;
@ -214,10 +228,10 @@ void save_key(SDL_Event *event)
if(savefld == 1 || savefld == 2) {
if(savepal + 1 >= numpalettes) savepal = 0; else savepal++;
}
if(savefld == 4) {
if(savefld == 5) {
if(biomepos + 1 >= maxbiome) biomepos = 0; else biomepos++;
if(biomepos < biomescr) biomescr = biomepos;
i = ((screen->h - 2*font->height - 8) - (24 + 4*font->height)) / font->height;
i = ((screen->h - 2*font->height - 8) - (24 + 5*font->height)) / font->height;
if(biomepos >= biomescr + i) biomescr = biomepos - i;
}
break;
@ -236,8 +250,9 @@ void save_key(SDL_Event *event)
case SDLK_RETURN: sdldo(1); break;
default:
if(savefld == 1) savefld = 2; else if(savefld == 2) savefld = 1;
if(savefld == 3) { savebiome ^= 1; biomepos = 0; }
if(savefld == 4) { biomeblk = biomepos; }
if(savefld == 3) { savemapgen ^= 1; }
if(savefld == 4) { savebiome ^= 1; biomepos = 0; }
if(savefld == 5) { biomeblk = biomepos; }
break;
}
break;

View File

@ -121,7 +121,7 @@ void sdlhelp()
SDL_Rect rect;
i = screen->w * 3 / 4;
rect.w = strlen(lang[HELP]) * (font->width+1) + 8;
rect.w = mbstrlen(lang[HELP]) * (font->width+1) + 8;
if(i > rect.w) rect.w = i;
rect.h = ((int)(sizeof(helpkeys)/sizeof(helpkeys[0])) + 1) * (font->height + 4) + 8;
rect.x = (screen->w - rect.w)/2;
@ -135,7 +135,7 @@ void sdlhelp()
sdlprint(rect.x + 136, rect.y, THEME_FG, THEME_BG, lang[(int)helpkeys[i].text]);
rect.y += font->height + 4;
}
sdlprint(rect.x + (rect.w - strlen(lang[HELP]) * (font->width+1)) / 2, rect.y, THEME_INACT, THEME_BG, lang[HELP]);
sdlprint(rect.x + (rect.w - mbstrlen(lang[HELP]) * (font->width+1)) / 2, rect.y, THEME_INACT, THEME_BG, lang[HELP]);
}
/**

View File

@ -89,7 +89,7 @@ void readschem()
blocks[x].numref = 0;
}
blocks[0].numref = 256 * 256 * 256;
savepal = savebiome = 0;
savepal = savemapgen = savebiome = 0;
currlayer = cx = cz = 127;
status = lang[ERR_LOAD];
@ -168,6 +168,22 @@ void errorimgcsv(int line)
sprintf(msg, "blockimgs.csv(%d): %s", line, lang[ERR_IMGCSV]);
}
/**
* UTF-8 strlen
*/
int mbstrlen(char *s)
{
int r = 0;
for(; *s; s++, r++) {
if((*s & 128) != 0) {
if(!(*s & 32)) s++; else
if(!(*s & 16)) s += 2; else
if(!(*s & 8)) *s += 3;
}
}
return r;
}
/**
* Convert an ascii hex value int integer
*/