2016-08-26 09:58:03 +00:00
|
|
|
// HyperRogue map editor
|
2018-02-08 23:40:26 +00:00
|
|
|
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
#if ISWINDOWS
|
2016-08-26 09:58:03 +00:00
|
|
|
#include "direntx.h"
|
|
|
|
#include "direntx.c"
|
|
|
|
#else
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mapeditor {
|
2017-04-15 02:48:59 +00:00
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
struct editwhat {
|
|
|
|
double dist;
|
|
|
|
int rotid, symid, pointid;
|
|
|
|
bool side;
|
|
|
|
cell *c;
|
|
|
|
} ew, ewsearch;
|
2017-08-06 12:50:16 +00:00
|
|
|
bool autochoose = ISMOBILE;
|
2017-06-18 16:52:15 +00:00
|
|
|
|
2018-02-03 13:31:17 +00:00
|
|
|
void scaleall(ld z) {
|
|
|
|
|
|
|
|
// (mx,my) = (xcb,ycb) + ss * (xpos,ypos) + (mrx,mry) * scale
|
|
|
|
|
|
|
|
// (mrx,mry) * (scale-scale') =
|
|
|
|
// ss * ((xpos',ypos')-(xpos,ypos))
|
|
|
|
|
|
|
|
// mx = xb + ssiz*xpos + mrx * scale
|
|
|
|
// mx = xb + ssiz*xpos' + mrx * scale'
|
|
|
|
|
|
|
|
ld mrx = (.0 + mousex - vid.xcenter) / vid.scale;
|
|
|
|
ld mry = (.0 + mousey - vid.ycenter) / vid.scale;
|
|
|
|
|
|
|
|
if(vid.xres > vid.yres) {
|
|
|
|
vid.xposition += (vid.scale - vid.scale*z) * mrx / vid.scrsize;
|
|
|
|
vid.yposition += (vid.scale - vid.scale*z) * mry / vid.scrsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
vid.scale *= z;
|
2018-02-13 22:25:44 +00:00
|
|
|
// printf("scale = " LDF "\n", vid.scale);
|
2018-02-03 13:31:17 +00:00
|
|
|
#if CAP_TEXTURE
|
2018-02-13 22:25:44 +00:00
|
|
|
// display(texture::itt);
|
2018-02-20 21:12:31 +00:00
|
|
|
texture::itt = xyscale(texture::itt, 1/z);
|
|
|
|
if(false && texture::tstate) {
|
2018-02-03 13:31:17 +00:00
|
|
|
calcparam();
|
|
|
|
texture::perform_mapping();
|
2018-02-20 21:12:31 +00:00
|
|
|
if(texture::tstate == texture::tsAdjusting)
|
|
|
|
texture::finish_mapping();
|
2018-02-03 13:31:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
#if CAP_EDIT
|
2017-03-23 10:53:57 +00:00
|
|
|
map<int, cell*> modelcell;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
void handleKeyMap(int sym, int uni);
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
void applyModelcell(cell *c) {
|
2017-12-09 02:48:30 +00:00
|
|
|
if(patterns::whichPattern == 'H') return;
|
2017-12-09 07:06:41 +00:00
|
|
|
auto si = patterns::getpatterninfo0(c);
|
|
|
|
cell *c2 = modelcell[si.id];
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c2) {
|
|
|
|
c->wall = c2->wall;
|
|
|
|
c->land = c2->land;
|
|
|
|
c->monst = c2->monst;
|
|
|
|
c->item = c2->item;
|
|
|
|
c->landparam = c2->landparam;
|
|
|
|
c->wparam = c2->wparam;
|
|
|
|
c->mondir = c2->mondir;
|
2017-11-12 23:37:18 +00:00
|
|
|
c->stuntime = c2->stuntime;
|
|
|
|
c->hitpoints = c2->hitpoints;
|
2017-12-09 07:06:41 +00:00
|
|
|
if(c2->mondir != NODIR) {
|
|
|
|
auto si2 = patterns::getpatterninfo0(c2);
|
|
|
|
c->mondir = (c2->mondir - si2.dir + si.dir + MODFIXER) % c->type;
|
|
|
|
// todo reflect
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
#if CAP_EDIT
|
2016-08-26 09:58:03 +00:00
|
|
|
namespace mapstream {
|
|
|
|
std::map<cell*, int> cellids;
|
|
|
|
vector<cell*> cellbyid;
|
|
|
|
vector<char> relspin;
|
|
|
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
void addToQueue(cell* c) {
|
|
|
|
if(cellids.count(c)) return;
|
|
|
|
int numcells = size(cellbyid);
|
|
|
|
cellbyid.push_back(c);
|
|
|
|
cellids[c] = numcells;
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveChar(char c) { fwrite(&c, 1, 1, f); }
|
|
|
|
template<class T> void save(T& c) { fwrite(&c, sizeof(T), 1, f); }
|
|
|
|
|
|
|
|
char loadChar() { char c; int i=fread(&c, 1, 1, f); if(i!=1) return 0; else return c; }
|
|
|
|
template<class T> int load(T& c) { return fread(&c, sizeof(T), 1, f); }
|
|
|
|
int32_t loadInt() { int i; if(load(i) < 1) return -1; else return i; }
|
|
|
|
|
|
|
|
void savePoint(const hyperpoint& h) {
|
|
|
|
for(int i=0; i<3; i++) { double x = h[i]; save(x); }
|
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint loadPoint() {
|
|
|
|
hyperpoint h;
|
|
|
|
for(int i=0; i<3; i++) { double x; load(x); h[i] = x; }
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool saveMap(const char *fname) {
|
|
|
|
f = fopen(fname, "wb");
|
|
|
|
if(!f) return false;
|
|
|
|
int32_t i = VERNUM; save(i);
|
2017-12-09 02:48:30 +00:00
|
|
|
save(patterns::whichPattern);
|
2017-11-07 13:08:50 +00:00
|
|
|
save(geometry);
|
2018-01-06 21:34:03 +00:00
|
|
|
save(nonbitrunc);
|
2017-11-07 13:08:50 +00:00
|
|
|
if(geometry == gTorus) {
|
|
|
|
save(torusconfig::qty);
|
|
|
|
save(torusconfig::dx);
|
|
|
|
save(torusconfig::dy);
|
|
|
|
}
|
|
|
|
if(geometry == gQuotient2) {
|
|
|
|
using namespace fieldpattern;
|
|
|
|
save(quotient_field_changed);
|
|
|
|
if(quotient_field_changed) {
|
|
|
|
save(current_extra);
|
|
|
|
save(fgeomextras[current_extra].current_prime_id);
|
|
|
|
}
|
|
|
|
}
|
2017-12-28 15:46:10 +00:00
|
|
|
addToQueue((bounded || euclid) ? currentmap->gamestart() : cwt.c->master->c7);
|
2016-08-26 09:58:03 +00:00
|
|
|
for(int i=0; i<size(cellbyid); i++) {
|
|
|
|
cell *c = cellbyid[i];
|
|
|
|
if(i) {
|
|
|
|
for(int j=0; j<c->type; j++) if(c->mov[j] && cellids.count(c->mov[j]) &&
|
|
|
|
cellids[c->mov[j]] < i) {
|
|
|
|
int32_t i = cellids[c->mov[j]];
|
|
|
|
save(i);
|
2017-03-23 10:53:57 +00:00
|
|
|
saveChar(c->spn(j));
|
2016-08-26 09:58:03 +00:00
|
|
|
saveChar(j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveChar(c->land);
|
|
|
|
saveChar(c->mondir);
|
|
|
|
saveChar(c->monst);
|
|
|
|
saveChar(c->wall);
|
|
|
|
// saveChar(c->barleft);
|
|
|
|
// saveChar(c->barright);
|
|
|
|
saveChar(c->item);
|
|
|
|
saveChar(c->mpdist);
|
|
|
|
// saveChar(c->bardir);
|
|
|
|
save(c->wparam); save(c->landparam);
|
|
|
|
saveChar(c->stuntime); saveChar(c->hitpoints);
|
|
|
|
for(int j=0; j<c->type; j++) {
|
|
|
|
cell *c2 = c->mov[j];
|
|
|
|
if(c2 && c2->land != laNone) addToQueue(c2);
|
|
|
|
}
|
|
|
|
}
|
2017-11-07 13:08:50 +00:00
|
|
|
printf("cells saved = %d\n", size(cellbyid));
|
2016-08-26 09:58:03 +00:00
|
|
|
int32_t n = -1; save(n);
|
|
|
|
int32_t id = cellids.count(cwt.c) ? cellids[cwt.c] : -1;
|
|
|
|
save(id);
|
|
|
|
|
|
|
|
for(int i=0; i<USERSHAPEGROUPS; i++) for(int j=0; j<USERSHAPEIDS; j++) {
|
|
|
|
usershape *us = usershapes[i][j];
|
|
|
|
if(!us) continue;
|
|
|
|
|
|
|
|
for(int l=0; l<USERLAYERS; l++) if(size(us->d[l].list)) {
|
|
|
|
usershapelayer& ds(us->d[l]);
|
|
|
|
save(i); save(j); save(l); save(ds.sym); save(ds.rots); save(ds.color);
|
|
|
|
n = size(ds.list); save(n);
|
|
|
|
savePoint(ds.shift);
|
|
|
|
savePoint(ds.spin);
|
|
|
|
for(int i=0; i<size(ds.list); i++) savePoint(ds.list[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n = -1; save(n);
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
cellids.clear();
|
|
|
|
cellbyid.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fixspin(int rspin, int dir, int t) {
|
|
|
|
if(dir >= 0 && dir < t)
|
|
|
|
return (dir + rspin) % t;
|
|
|
|
else
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2018-02-26 12:14:20 +00:00
|
|
|
bool loadMap(const string& fname) {
|
|
|
|
f = fopen(fname.c_str(), "rb");
|
2016-08-26 09:58:03 +00:00
|
|
|
if(!f) return false;
|
2017-11-07 13:39:54 +00:00
|
|
|
clearMemory();
|
2016-08-26 09:58:03 +00:00
|
|
|
int vernum = loadInt();
|
2017-12-09 02:48:30 +00:00
|
|
|
if(vernum >= 7400) load(patterns::whichPattern);
|
2017-11-07 13:08:50 +00:00
|
|
|
|
|
|
|
if(vernum >= 10203) {
|
|
|
|
load(geometry);
|
2018-01-06 21:34:03 +00:00
|
|
|
load(nonbitrunc);
|
2017-11-07 13:08:50 +00:00
|
|
|
if(geometry == gTorus) {
|
|
|
|
load(torusconfig::qty);
|
|
|
|
load(torusconfig::dx);
|
|
|
|
load(torusconfig::dy);
|
|
|
|
}
|
|
|
|
if(geometry == gQuotient2) {
|
|
|
|
using namespace fieldpattern;
|
|
|
|
load(quotient_field_changed);
|
|
|
|
if(quotient_field_changed) {
|
|
|
|
load(current_extra);
|
|
|
|
load(fgeomextras[current_extra].current_prime_id);
|
|
|
|
enableFieldChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetGeometry();
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
initcells();
|
|
|
|
if(shmup::on) shmup::init();
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
cell *c;
|
|
|
|
int rspin;
|
|
|
|
|
|
|
|
if(size(cellbyid) == 0) {
|
2017-04-04 09:13:15 +00:00
|
|
|
c = currentmap->gamestart();
|
2016-08-26 09:58:03 +00:00
|
|
|
rspin = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int32_t parent = loadInt();
|
|
|
|
|
|
|
|
if(parent<0 || parent >= size(cellbyid)) break;
|
|
|
|
int dir = loadChar();
|
|
|
|
cell *c2 = cellbyid[parent];
|
|
|
|
dir = fixspin(dir, relspin[parent], c2->type);
|
|
|
|
c = createMov(c2, dir);
|
2017-11-07 13:08:50 +00:00
|
|
|
// printf("%p:%d,%d -> %p\n", c2, relspin[parent], dir, c);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
// spinval becomes xspinval
|
2017-11-07 13:08:50 +00:00
|
|
|
rspin = (c2->spn(dir) - loadChar() + MODFIXER) % c->type;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cellbyid.push_back(c);
|
|
|
|
relspin.push_back(rspin);
|
|
|
|
c->land = (eLand) loadChar();
|
|
|
|
c->mondir = fixspin(rspin, loadChar(), c->type);
|
|
|
|
c->monst = (eMonster) loadChar();
|
|
|
|
c->wall = (eWall) loadChar();
|
|
|
|
// c->barleft = (eLand) loadChar();
|
|
|
|
// c->barright = (eLand) loadChar();
|
|
|
|
c->item = (eItem) loadChar();
|
|
|
|
c->mpdist = loadChar();
|
|
|
|
c->bardir = NOBARRIERS;
|
|
|
|
// fixspin(rspin, loadChar(), c->type);
|
|
|
|
if(vernum < 7400) {
|
|
|
|
load(c->aitmp);
|
|
|
|
c->wparam = c->aitmp;
|
|
|
|
}
|
|
|
|
else load(c->wparam);
|
|
|
|
load(c->landparam);
|
|
|
|
// backward compatibility
|
|
|
|
if(vernum < 7400 && !isIcyLand(c->land)) c->landparam = HEAT(c);
|
|
|
|
c->stuntime = loadChar();
|
|
|
|
c->hitpoints = loadChar();
|
|
|
|
|
2017-12-09 02:48:30 +00:00
|
|
|
if(patterns::whichPattern)
|
2017-12-09 07:06:41 +00:00
|
|
|
mapeditor::modelcell[patterns::getpatterninfo0(c).id] = c;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t whereami = loadInt();
|
|
|
|
if(whereami >= 0 && whereami < size(cellbyid))
|
|
|
|
cwt.c = cellbyid[whereami];
|
2017-04-04 09:13:15 +00:00
|
|
|
else cwt.c = currentmap->gamestart();
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
for(int i=0; i<size(cellbyid); i++) {
|
|
|
|
cell *c = cellbyid[i];
|
|
|
|
if(c->bardir != NODIR && c->bardir != NOBARRIERS)
|
|
|
|
extendBarrier(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int d=BARLEV-1; d>=0; d--)
|
|
|
|
for(int i=0; i<size(cellbyid); i++) {
|
|
|
|
cell *c = cellbyid[i];
|
|
|
|
if(c->mpdist <= d)
|
|
|
|
for(int j=0; j<c->type; j++) {
|
|
|
|
cell *c2 = createMov(c, j);
|
|
|
|
setdist(c2, d+1, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cellbyid.clear();
|
|
|
|
relspin.clear();
|
|
|
|
|
|
|
|
if(shmup::on) shmup::init();
|
|
|
|
|
|
|
|
timerstart = time(NULL); turncount = 0;
|
|
|
|
sagephase = 0; hardcoreAt = 0;
|
|
|
|
timerstopped = false;
|
|
|
|
savecount = 0; savetime = 0;
|
|
|
|
cheater = 1;
|
|
|
|
|
|
|
|
if(vernum >= 7400) while(true) {
|
|
|
|
int i = loadInt();
|
|
|
|
if(i == -1) break;
|
|
|
|
int j = loadInt(), l = loadInt();
|
|
|
|
if(i<0 || i >= USERSHAPEGROUPS) break;
|
|
|
|
if(j<0 || j >= USERSHAPEIDS) break;
|
|
|
|
if(l<0 || l >= USERLAYERS) break;
|
|
|
|
|
|
|
|
initShape(i, j);
|
|
|
|
usershapelayer& ds(usershapes[i][j]->d[l]);
|
|
|
|
|
|
|
|
load(ds.sym); load(ds.rots); load(ds.color);
|
|
|
|
ds.list.clear();
|
|
|
|
int siz = loadInt();
|
|
|
|
|
|
|
|
ds.shift = loadPoint();
|
|
|
|
ds.spin = loadPoint();
|
|
|
|
|
|
|
|
for(int i=0; i<siz; i++)
|
|
|
|
ds.list.push_back(loadPoint());
|
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
buildpolys();
|
2016-08-26 09:58:03 +00:00
|
|
|
bfs();
|
|
|
|
restartGraph();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mapeditor {
|
|
|
|
|
|
|
|
bool drawplayer = true;
|
|
|
|
|
2017-07-04 13:38:33 +00:00
|
|
|
cell *drawcell;
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
#if CAP_EDIT
|
2016-08-26 09:58:03 +00:00
|
|
|
int paintwhat = 0;
|
|
|
|
int painttype = 0;
|
|
|
|
int radius = 0;
|
|
|
|
string paintwhat_str = "clear monster";
|
2017-11-12 23:37:18 +00:00
|
|
|
|
|
|
|
cellwalker copysource;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
int whichpart;
|
2017-07-04 13:38:33 +00:00
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
const char *mapeditorhelp =
|
|
|
|
"This mode allows you to edit the map.\n\n"
|
|
|
|
"NOTE: Use at your own risk. Combinations which never "
|
|
|
|
"appear in the real game may work in an undefined way "
|
|
|
|
"(do not work, look strangely, give strange messages, or crash the game).\n\n"
|
|
|
|
"To get the most of this editor, "
|
|
|
|
"some knowledge of inner workings of HyperRogue is required. "
|
|
|
|
"Each cell has four main fields: land type, wall type, monster type, item type. "
|
|
|
|
"The same wall type (especially \"none\", \"sea\", or \"bonfire\") may look or "
|
|
|
|
"work a bit differently, based on the land it is in. Sometimes an object may "
|
|
|
|
"appear twice on the list due to subtle differences (for example, Demons could "
|
|
|
|
"move next turn or not).\n\n"
|
|
|
|
"Press w, i, l, or m to choose which aspect of cells to change, "
|
|
|
|
"then just click on the cells and they will change. Press 'c' while "
|
|
|
|
"hovering over a cell to copy that cell, this copies all information about it. "
|
|
|
|
"When copying large areas or placing multi-tile monsters, it might be important where "
|
|
|
|
"on the cell you are clicking.\n\n"
|
|
|
|
"You can also press 0-9 to apply your changes to a greater radius. "
|
|
|
|
"This also affects the copy/paste feature, allowing to copy a larger area.\n\n"
|
|
|
|
"Press F2 to save the current map (and F3 to load it). If you try this after "
|
|
|
|
"a long game of HyperRogue (without using Orbs of Safety), the filesize will "
|
|
|
|
"be very large! "
|
|
|
|
"Note however that large structures, such as "
|
|
|
|
"Great Walls, large circles and horocycles, are destroyed by this.\n\n"
|
|
|
|
"Press 'b' to mark cells as boundaries. Such cells, and cells beyond "
|
|
|
|
"them, are not copied by the copy/paste feature, nor saved by the "
|
|
|
|
"save feature.\n\n";
|
|
|
|
|
|
|
|
const char* patthelp =
|
|
|
|
"Press 'r' to choose a regular pattern. When a pattern is on, "
|
|
|
|
"editing a cell automatically edits all cells which are "
|
|
|
|
"equivalent according to this pattern. You can choose from "
|
|
|
|
"several patterns, and choose which symmetries matter "
|
|
|
|
"for equivalence. Also, you can press Space to switch between "
|
|
|
|
"the map and graphics editor quickly -- note that editing floors "
|
|
|
|
"with the graphics editor also adheres to the pattern.";
|
|
|
|
|
|
|
|
string mehelptext() {
|
|
|
|
return XLAT(mapeditorhelp) + XLAT(patthelp);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct undo_info {
|
|
|
|
cell *c;
|
|
|
|
eWall w;
|
|
|
|
eItem i;
|
|
|
|
eMonster m;
|
|
|
|
eLand l;
|
|
|
|
char wparam;
|
|
|
|
int32_t lparam;
|
|
|
|
char dir;
|
|
|
|
};
|
|
|
|
|
|
|
|
vector<undo_info> undo;
|
|
|
|
|
|
|
|
bool checkEq(undo_info& u) {
|
|
|
|
return u.w == u.c->wall && u.i == u.c->item && u.m == u.c->monst && u.l == u.c->land &&
|
|
|
|
u.dir == u.c->mondir && u.lparam == u.c->landparam && u.wparam == u.c->wparam;
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveUndo(cell *c) {
|
|
|
|
undo_info u;
|
|
|
|
u.c=c; u.w = c->wall; u.i = c->item; u.m = c->monst; u.l = c->land; u.dir = c->mondir;
|
|
|
|
u.wparam = c->wparam; u.lparam = c->landparam;
|
|
|
|
undo.push_back(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_info& lastUndo() { return undo[size(undo)-1]; }
|
|
|
|
|
|
|
|
void undoLock() {
|
|
|
|
if(!size(undo) || lastUndo().c) {
|
|
|
|
undo_info i; i.c = NULL; undo.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyUndo() {
|
|
|
|
while(size(undo) && !lastUndo().c) undo.pop_back();
|
|
|
|
while(size(undo)) {
|
|
|
|
undo_info& i(lastUndo());
|
|
|
|
if(!i.c) break;
|
|
|
|
i.c->wall = i.w;
|
|
|
|
i.c->item = i.i;
|
|
|
|
i.c->monst = i.m;
|
|
|
|
i.c->land = i.l;
|
|
|
|
i.c->mondir = i.dir;
|
|
|
|
i.c->wparam = i.wparam;
|
|
|
|
i.c->landparam = i.lparam;
|
|
|
|
undo.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkUndo() {
|
|
|
|
if(checkEq(undo[size(undo)-1])) undo.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
int itc(int k) {
|
|
|
|
if(k == 0) return 0;
|
|
|
|
if(k == 1) return 0x40;
|
|
|
|
if(k == 2) return 0x80;
|
|
|
|
if(k == 3) return 0xFF;
|
|
|
|
return 0x20;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool choosefile = false;
|
|
|
|
|
|
|
|
void displayFunctionKeys() {
|
2017-08-06 12:50:16 +00:00
|
|
|
int fs = min(vid.fsize + 5, vid.yres/26);
|
2017-03-23 10:53:57 +00:00
|
|
|
displayButton(8, vid.yres-8-fs*11, XLAT("F1 = help"), SDLK_F1, 0);
|
|
|
|
displayButton(8, vid.yres-8-fs*10, XLAT("F2 = save"), SDLK_F2, 0);
|
|
|
|
displayButton(8, vid.yres-8-fs*9, XLAT("F3 = load"), SDLK_F3, 0);
|
|
|
|
displayButton(8, vid.yres-8-fs*7, XLAT("F5 = restart"), SDLK_F5, 0);
|
|
|
|
displayButton(8, vid.yres-8-fs*6, XLAT("F6 = HQ shot"), SDLK_F6, 0);
|
|
|
|
displayButton(8, vid.yres-8-fs*5, XLAT("F7 = player on/off"), SDLK_F7, 0);
|
2017-08-06 12:50:16 +00:00
|
|
|
#if CAP_SVG
|
2017-03-23 10:53:57 +00:00
|
|
|
displayButton(8, vid.yres-8-fs*4, XLAT("F8 = SVG shot"), SDLK_F8, 0);
|
2017-08-06 12:50:16 +00:00
|
|
|
#endif
|
2016-08-26 09:58:03 +00:00
|
|
|
displayButton(8, vid.yres-8-fs*3, XLAT("SPACE = map/graphics"), ' ', 0);
|
|
|
|
displayButton(8, vid.yres-8-fs*2, XLAT("ESC = return to the game"), SDLK_ESCAPE, 0);
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
void showMapEditor() {
|
2017-07-12 17:50:39 +00:00
|
|
|
cmode = sm::MAP;
|
2017-07-10 18:47:38 +00:00
|
|
|
gamescreen(0);
|
|
|
|
|
2017-08-06 12:50:16 +00:00
|
|
|
int fs = min(vid.fsize + 5, vid.yres/26);
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
getcstat = '-';
|
|
|
|
|
|
|
|
displayfr(8, 8 + fs, 2, vid.fsize, paintwhat_str, forecolor, 0);
|
|
|
|
displayfr(8, 8+fs*2, 2, vid.fsize, XLAT("use at your own risk!"), 0x800000, 0);
|
|
|
|
|
|
|
|
displayButton(8, 8+fs*4, XLAT("0-9 = radius (%1)", its(radius)), ('0' + (radius+1)%10), 0);
|
|
|
|
displayButton(8, 8+fs*5, XLAT("b = boundary"), 'b', 0);
|
|
|
|
displayButton(8, 8+fs*6, XLAT("m = monsters"), 'm', 0);
|
|
|
|
displayButton(8, 8+fs*7, XLAT("w = walls"), 'w', 0);
|
|
|
|
displayButton(8, 8+fs*8, XLAT("i = items"), 'i', 0);
|
|
|
|
displayButton(8, 8+fs*9, XLAT("l = lands"), 'l', 0);
|
|
|
|
displayfr(8, 8+fs*10, 2, vid.fsize, XLAT("c = copy"), 0xC0C0C0, 0);
|
|
|
|
displayButton(8, 8+fs*11, XLAT("u = undo"), 'u', 0);
|
|
|
|
if(painttype == 4)
|
2017-11-12 23:37:18 +00:00
|
|
|
displayButton(8, 8+fs*12, XLAT("f = flip %1", ONOFF(copysource.mirrored)), 'u', 0);
|
2017-07-10 18:47:38 +00:00
|
|
|
displayButton(8, 8+fs*13, XLAT("r = regular"), 'r', 0);
|
|
|
|
displayButton(8, 8+fs*14, XLAT("p = paint"), 'p', 0);
|
2017-12-03 17:24:34 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
displayFunctionKeys();
|
|
|
|
|
|
|
|
keyhandler = handleKeyMap;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int spillinc() {
|
|
|
|
if(radius>=2) return 0;
|
|
|
|
if(anyshiftclick) return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int drawcellShapeGroup() {
|
2017-10-04 19:25:40 +00:00
|
|
|
if(drawcell == cwt.c && drawplayer) return 0;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(drawcell->monst) return 1;
|
|
|
|
if(drawcell->item) return 2;
|
2017-12-22 20:37:30 +00:00
|
|
|
return 3;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int drawcellShapeID() {
|
2018-01-04 17:28:07 +00:00
|
|
|
if(drawcell == cwt.c && drawplayer) return vid.cs.charid;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(drawcell->monst) return drawcell->monst;
|
|
|
|
if(drawcell->item) return drawcell->item;
|
2017-12-09 07:06:41 +00:00
|
|
|
return patterns::getpatterninfo0(drawcell).id;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool editingShape(int group, int id) {
|
|
|
|
if(group != mapeditor::drawcellShapeGroup()) return false;
|
2017-12-09 07:06:41 +00:00
|
|
|
return id == drawcellShapeID();
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:37:18 +00:00
|
|
|
void editCell(const pair<cellwalker, cellwalker>& where) {
|
|
|
|
cell *c = where.first.c;
|
|
|
|
int cdir = where.first.spin;
|
2016-08-26 09:58:03 +00:00
|
|
|
saveUndo(c);
|
|
|
|
switch(painttype) {
|
|
|
|
case 0:
|
|
|
|
c->monst = eMonster(paintwhat);
|
|
|
|
c->hitpoints = 3;
|
|
|
|
c->stuntime = 0;
|
|
|
|
c->mondir = cdir;
|
|
|
|
|
|
|
|
if((isWorm(c) || isIvy(c) || isMutantIvy(c)) && c->mov[cdir] &&
|
|
|
|
!isWorm(c->mov[cdir]) && !isIvy(c->mov[cdir]))
|
|
|
|
c->mondir = NODIR;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
c->item = eItem(paintwhat);
|
2017-03-23 10:53:57 +00:00
|
|
|
if(c->item == itBabyTortoise)
|
|
|
|
tortoise::babymap[c] = getBits(c) ^ tortoise::getRandomBits();
|
2016-08-26 09:58:03 +00:00
|
|
|
break;
|
|
|
|
case 2: {
|
|
|
|
eLand last = c->land;
|
|
|
|
c->land = eLand(paintwhat);
|
|
|
|
if(isIcyLand(c) && isIcyLand(last))
|
|
|
|
HEAT(c) += spillinc() / 100.;
|
|
|
|
else if(last == laDryForest && c->land == laDryForest)
|
|
|
|
c->landparam += spillinc();
|
|
|
|
else if(last == laOcean && c->land == laOcean)
|
|
|
|
c->landparam += spillinc();
|
|
|
|
else if(last == laHive && c->land == laHive)
|
|
|
|
c->landparam += spillinc();
|
|
|
|
else
|
|
|
|
c->landparam = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
eWall last = c->wall;
|
|
|
|
c->wall = eWall(paintwhat);
|
|
|
|
|
|
|
|
if(last != c->wall) {
|
|
|
|
if(hasTimeout(c))
|
|
|
|
c->wparam = 10;
|
|
|
|
else if(c->wall == waWaxWall)
|
|
|
|
c->landparam = hrand(0xFFFFFF + 1);
|
|
|
|
}
|
|
|
|
else if(hasTimeout(c))
|
|
|
|
c->wparam += spillinc();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
c->land = laNone;
|
|
|
|
c->wall = waNone;
|
|
|
|
c->item = itNone;
|
|
|
|
c->monst = moNone;
|
|
|
|
c->landparam = 0;
|
|
|
|
// c->tmp = -1;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
c->land = laCanvas;
|
|
|
|
c->wall = waNone;
|
2017-03-23 10:53:57 +00:00
|
|
|
c->landparam = paintwhat >> 8;
|
2016-08-26 09:58:03 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2017-11-12 23:37:18 +00:00
|
|
|
cell *copywhat = where.second.c;
|
2016-08-26 09:58:03 +00:00
|
|
|
c->wall = copywhat->wall;
|
|
|
|
c->item = copywhat->item;
|
|
|
|
c->land = copywhat->land;
|
|
|
|
c->monst = copywhat->monst;
|
|
|
|
c->landparam = copywhat->landparam;
|
|
|
|
c->wparam = copywhat->wparam;
|
2017-11-12 23:37:18 +00:00
|
|
|
c->hitpoints = copywhat->hitpoints;
|
|
|
|
c->stuntime = copywhat->stuntime;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(copywhat->mondir == NODIR) c->mondir = NODIR;
|
2017-11-12 23:37:18 +00:00
|
|
|
else c->mondir = ((where.first.mirrored == where.second.mirrored ? 1 : -1) * (copywhat->mondir - where.second.spin) + cdir + MODFIXER) % c->type;
|
2016-08-26 09:58:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
checkUndo();
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:37:18 +00:00
|
|
|
vector<pair<cellwalker, cellwalker> > spill_list;
|
|
|
|
|
|
|
|
void list_spill(cellwalker tgt, cellwalker src) {
|
|
|
|
spill_list.clear(); sval++;
|
|
|
|
spill_list.emplace_back(tgt, src);
|
|
|
|
int crad = 0, nextstepat = 0;
|
|
|
|
for(int i=0; i<size(spill_list); i++) {
|
|
|
|
if(i == nextstepat) {
|
|
|
|
crad++; nextstepat = size(spill_list);
|
|
|
|
if(crad > radius) break;
|
|
|
|
}
|
|
|
|
auto sd = spill_list[i];
|
|
|
|
for(int i=0; i<sd.first.c->type; i++) {
|
|
|
|
auto sd2 = sd;
|
|
|
|
cwspin(sd2.first, i); cwstep(sd2.first);
|
|
|
|
if(eq(sd2.first.c->aitmp, sval)) continue;
|
|
|
|
sd2.first.c->aitmp = sval;
|
|
|
|
if(sd2.second.c) {
|
|
|
|
cwspin(sd2.second, i); cwstep(sd2.second);
|
|
|
|
if(sd2.second.c->land == laNone) continue;
|
|
|
|
}
|
|
|
|
spill_list.push_back(sd2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-05 13:19:22 +00:00
|
|
|
|
2018-01-20 16:50:30 +00:00
|
|
|
#if CAP_SDL
|
2018-01-05 13:19:22 +00:00
|
|
|
void saveHighQualityShotX() {
|
|
|
|
static string hqfile = "hqshot.png";
|
|
|
|
if(anyshiftclick)
|
|
|
|
saveHighQualityShot();
|
|
|
|
else
|
|
|
|
dialog::openFileDialog(hqfile, XLAT("F6 = HQ shot"), ".png", [] () {
|
|
|
|
saveHighQualityShot(hqfile.c_str());
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveSvgShotX() {
|
|
|
|
static string hqfile = "svgshot.svg";
|
|
|
|
if(anyshiftclick)
|
|
|
|
svg::render();
|
|
|
|
else
|
|
|
|
dialog::openFileDialog(hqfile, XLAT("F8 = SVG shot"), ".svg", [] () {
|
|
|
|
svg::render(hqfile.c_str());
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2018-01-20 16:50:30 +00:00
|
|
|
#endif
|
2017-11-12 23:37:18 +00:00
|
|
|
|
|
|
|
void editAt(cellwalker where) {
|
|
|
|
|
|
|
|
if(painttype == 4 && radius) {
|
|
|
|
if(where.c->type != copysource.c->type) return;
|
|
|
|
if(where.spin<0) where.spin=0;
|
2018-01-06 21:34:03 +00:00
|
|
|
if(!nonbitrunc && !ctof(mouseover) && ((where.spin&1) != (copysource.spin&1)))
|
2017-11-12 23:37:18 +00:00
|
|
|
cwspin(where, 1);
|
|
|
|
}
|
|
|
|
if(painttype != 4) copysource.c = NULL;
|
|
|
|
list_spill(where, copysource);
|
|
|
|
|
|
|
|
for(auto& st: spill_list)
|
|
|
|
editCell(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
void allInPattern(cellwalker where) {
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-09 02:48:30 +00:00
|
|
|
if(!patterns::whichPattern) {
|
2017-11-12 23:37:18 +00:00
|
|
|
editAt(where);
|
2016-08-26 09:58:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<cell*> v;
|
2017-11-12 23:37:18 +00:00
|
|
|
v.push_back(where.c);
|
2016-08-26 09:58:03 +00:00
|
|
|
sval++;
|
2017-11-12 23:37:18 +00:00
|
|
|
where.c->aitmp = sval;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
int at = 0;
|
|
|
|
while(at < size(v)) {
|
|
|
|
cell *c2 = v[at];
|
|
|
|
at++;
|
|
|
|
|
2017-11-12 23:37:18 +00:00
|
|
|
forCellEx(c3, c2)
|
|
|
|
if(!eq(c3->aitmp, sval))
|
|
|
|
c3->aitmp = sval, v.push_back(c3);
|
|
|
|
}
|
|
|
|
|
2017-12-09 07:06:41 +00:00
|
|
|
auto si = patterns::getpatterninfo0(where.c);
|
2017-11-12 23:37:18 +00:00
|
|
|
int cdir = where.spin;
|
2017-12-09 07:06:41 +00:00
|
|
|
if(cdir >= 0) cdir = cdir - si.dir;
|
2017-11-12 23:37:18 +00:00
|
|
|
|
2017-12-09 07:06:41 +00:00
|
|
|
for(cell* c2: v) {
|
|
|
|
auto si2 = patterns::getpatterninfo0(c2);
|
|
|
|
if(si2.id == si.id) {
|
|
|
|
editAt(cellwalker(c2, cdir>=0 ? fixdir(cdir + si2.dir, c2) : -1));
|
|
|
|
modelcell[si2.id] = c2;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-12-09 07:06:41 +00:00
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:37:18 +00:00
|
|
|
cellwalker mouseover_cw(bool fix) {
|
|
|
|
int d = neighborId(mouseover, mouseover2);
|
|
|
|
if(d == -1 && fix) d = hrand(mouseover->type);
|
|
|
|
return cellwalker(mouseover, d);
|
|
|
|
}
|
|
|
|
|
2017-12-09 02:48:30 +00:00
|
|
|
void showList() {
|
2017-12-09 03:01:56 +00:00
|
|
|
dialog::v.clear();
|
2017-12-09 02:48:30 +00:00
|
|
|
if(painttype == 4) painttype = 0;
|
|
|
|
switch(painttype) {
|
|
|
|
case 0:
|
|
|
|
for(int i=0; i<motypes; i++) {
|
|
|
|
eMonster m = eMonster(i);
|
|
|
|
if(
|
|
|
|
m == moTongue || m == moPlayer || m == moFireball || m == moBullet ||
|
|
|
|
m == moFlailBullet || m == moShadow || m == moAirball ||
|
|
|
|
m == moWolfMoved || m == moGolemMoved ||
|
|
|
|
m == moTameBomberbirdMoved || m == moKnightMoved ||
|
|
|
|
m == moDeadBug || m == moLightningBolt || m == moDeadBird ||
|
|
|
|
m == moMouseMoved || m == moPrincessMoved || m == moPrincessArmedMoved) ;
|
2017-12-09 03:01:56 +00:00
|
|
|
else if(m == moDragonHead) dialog::vpush(i, "Dragon Head");
|
|
|
|
else dialog::vpush(i, minf[i].name);
|
2017-12-09 02:48:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2017-12-09 03:01:56 +00:00
|
|
|
for(int i=0; i<ittypes; i++) dialog::vpush(i, iinf[i].name);
|
2017-12-09 02:48:30 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-12-09 03:01:56 +00:00
|
|
|
for(int i=0; i<landtypes; i++) dialog::vpush(i, linf[i].name);
|
2017-12-09 02:48:30 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2017-12-09 03:01:56 +00:00
|
|
|
for(int i=0; i<walltypes; i++) if(i != waChasmD) dialog::vpush(i, winf[i].name);
|
2017-12-09 02:48:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// sort(v.begin(), v.end());
|
|
|
|
|
2017-12-09 03:01:56 +00:00
|
|
|
if(dialog::infix != "") mouseovers = dialog::infix;
|
2017-12-09 02:48:30 +00:00
|
|
|
|
2017-12-09 03:01:56 +00:00
|
|
|
int q = dialog::v.size();
|
2017-12-09 02:48:30 +00:00
|
|
|
int percolumn = vid.yres / (vid.fsize+5) - 4;
|
|
|
|
int columns = 1 + (q-1) / percolumn;
|
|
|
|
|
|
|
|
for(int i=0; i<q; i++) {
|
|
|
|
int x = 16 + (vid.xres * (i/percolumn)) / columns;
|
|
|
|
int y = (vid.fsize+5) * (i % percolumn) + vid.fsize*2;
|
|
|
|
|
|
|
|
int actkey = 1000 + i;
|
2017-12-09 03:01:56 +00:00
|
|
|
string vv = dialog::v[i].first;
|
2017-12-09 02:48:30 +00:00
|
|
|
if(i < 9) { vv += ": "; vv += ('1' + i); }
|
|
|
|
|
|
|
|
displayButton(x, y, vv, actkey, 0);
|
|
|
|
}
|
|
|
|
keyhandler = [] (int sym, int uni) {
|
|
|
|
if(uni >= '1' && uni <= '9') uni = 1000 + uni - '1';
|
|
|
|
if(sym == SDLK_RETURN || sym == SDLK_KP_ENTER || sym == '-' || sym == SDLK_KP_MINUS) uni = 1000;
|
2017-12-09 03:01:56 +00:00
|
|
|
for(int z=0; z<size(dialog::v); z++) if(1000 + z == uni) {
|
|
|
|
paintwhat = dialog::v[z].second;
|
|
|
|
paintwhat_str = dialog::v[z].first;
|
2017-12-09 02:48:30 +00:00
|
|
|
mousepressed = false;
|
|
|
|
popScreen();
|
|
|
|
return;
|
|
|
|
}
|
2017-12-09 03:01:56 +00:00
|
|
|
if(dialog::editInfix(uni)) ;
|
2017-12-09 02:48:30 +00:00
|
|
|
else if(doexiton(sym, uni)) popScreen();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
void handleKeyMap(int sym, int uni) {
|
|
|
|
handlePanning(sym, uni);
|
|
|
|
|
|
|
|
// left-clicks are coded with '-', and right-clicks are coded with sym F1
|
2017-11-06 22:22:13 +00:00
|
|
|
if(uni == '-' && !holdmouse) undoLock();
|
|
|
|
if(uni == '-' && mouseover) {
|
2017-11-12 23:37:18 +00:00
|
|
|
allInPattern(mouseover_cw(false));
|
2017-11-06 22:22:13 +00:00
|
|
|
holdmouse = true;
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
if(mouseover) for(int i=0; i<mouseover->type; i++) createMov(mouseover, i);
|
|
|
|
if(uni == 'u') applyUndo();
|
|
|
|
else if(uni == 'v' || sym == SDLK_F10 || sym == SDLK_ESCAPE) popScreen();
|
|
|
|
else if(uni >= '0' && uni <= '9') radius = uni - '0';
|
2017-12-09 03:01:56 +00:00
|
|
|
else if(uni == 'm') pushScreen(showList), painttype = 0, dialog::infix = "";
|
|
|
|
else if(uni == 'i') pushScreen(showList), painttype = 1, dialog::infix = "";
|
|
|
|
else if(uni == 'l') pushScreen(showList), painttype = 2, dialog::infix = "";
|
|
|
|
else if(uni == 'w') pushScreen(showList), painttype = 3, dialog::infix = "";
|
2017-12-09 02:48:30 +00:00
|
|
|
else if(uni == 'r') pushScreen(patterns::showPattern);
|
2017-07-10 18:47:38 +00:00
|
|
|
else if(uni == 't' && mouseover) {
|
2017-11-12 23:37:18 +00:00
|
|
|
playermoved = true;
|
|
|
|
cwt = mouseover_cw(true);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
else if(uni == 'b') painttype = 5, paintwhat_str = XLAT("boundary");
|
|
|
|
else if(uni == 'p') {
|
|
|
|
painttype = 6;
|
2016-08-26 09:58:03 +00:00
|
|
|
paintwhat_str = "paint";
|
2017-07-16 21:00:55 +00:00
|
|
|
dialog::openColorDialog((unsigned&)(paintwhat = (painttype ==6 ? paintwhat : 0x808080)));
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
else if(sym == SDLK_F5) {
|
|
|
|
restartGame();
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(sym == SDLK_F2) {
|
2018-01-08 22:23:00 +00:00
|
|
|
dialog::openFileDialog(levelfile, XLAT("level to save:"), ".lev", [] () {
|
2017-12-14 11:10:40 +00:00
|
|
|
if(mapstream::saveMap(levelfile.c_str())) {
|
|
|
|
addMessage(XLAT("Map saved to %1", levelfile));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addMessage(XLAT("Failed to save map to %1", levelfile));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-12-14 11:10:40 +00:00
|
|
|
else if(sym == SDLK_F3)
|
2018-01-08 22:23:00 +00:00
|
|
|
dialog::openFileDialog(levelfile, XLAT("level to load:"), ".lev", [] () {
|
2017-12-14 11:10:40 +00:00
|
|
|
if(mapstream::loadMap(levelfile.c_str())) {
|
|
|
|
addMessage(XLAT("Map loaded from %1", levelfile));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addMessage(XLAT("Failed to load map from %1", levelfile));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2017-12-09 03:01:56 +00:00
|
|
|
#if CAP_SDL
|
2017-07-10 18:47:38 +00:00
|
|
|
else if(sym == SDLK_F6) {
|
2018-01-05 13:19:22 +00:00
|
|
|
saveHighQualityShotX();
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_SVG
|
2017-07-10 18:47:38 +00:00
|
|
|
else if(sym == SDLK_F8) {
|
2018-01-05 13:19:22 +00:00
|
|
|
saveSvgShotX();
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
#endif
|
2017-07-10 18:47:38 +00:00
|
|
|
else if(sym == SDLK_F7) {
|
|
|
|
drawplayer = !drawplayer;
|
|
|
|
}
|
|
|
|
else if(uni == 'c') {
|
2017-11-12 23:37:18 +00:00
|
|
|
copysource = mouseover_cw(true);
|
|
|
|
painttype = 4;
|
2017-07-10 18:47:38 +00:00
|
|
|
paintwhat_str = XLAT("copying");
|
|
|
|
}
|
|
|
|
else if(uni == 'f') {
|
2017-11-12 23:37:18 +00:00
|
|
|
copysource.mirrored = !copysource.mirrored;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
else if(uni == 'h' || sym == SDLK_F1)
|
|
|
|
gotoHelp(mehelptext());
|
|
|
|
else if(uni == ' ') {
|
|
|
|
popScreen();
|
|
|
|
pushScreen(showDrawEditor);
|
|
|
|
initdraw(mouseover ? mouseover : cwt.c);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VECTOR GRAPHICS EDITOR
|
|
|
|
|
|
|
|
const char* drawhelp =
|
|
|
|
"In this mode you can draw your own player characters, "
|
|
|
|
"floors, monsters, and items. Press 'e' while hovering over "
|
|
|
|
"an object to edit it. Start drawing shapes with 'n', and "
|
|
|
|
"add extra vertices with 'a'. Press 0-9 to draw symmetric "
|
|
|
|
"pictures easily. More complex pictures can "
|
|
|
|
"be created by using several layers ('l'). See the edges of "
|
|
|
|
"the screen for more keys.";
|
|
|
|
|
|
|
|
string drawhelptext() {
|
2017-07-10 18:47:38 +00:00
|
|
|
return XLAT(drawhelp);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int dslayer;
|
|
|
|
bool coloring;
|
2017-07-16 21:00:55 +00:00
|
|
|
unsigned int colortouse = 0xC0C0C0FFu;
|
2017-10-04 19:25:40 +00:00
|
|
|
// fake key sent to change the color
|
|
|
|
static const int COLORKEY = (-10000);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
transmatrix drawtrans, drawtransnew;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
void loadShape(int sg, int id, hpcshape& sh, int d, int layer) {
|
|
|
|
usershapelayer *dsCur = &usershapes[sg][id]->d[layer];
|
|
|
|
dsCur->list.clear();
|
|
|
|
dsCur->sym = d==2;
|
|
|
|
for(int i=sh.s; i < sh.s + (sh.e-sh.s)/d; i++)
|
|
|
|
dsCur->list.push_back(hpc[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGhosts(cell *c, const transmatrix& V, int ct) {
|
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint ccenter = C0;
|
|
|
|
hyperpoint coldcenter = C0;
|
|
|
|
|
2017-12-22 20:23:17 +00:00
|
|
|
unsigned gridcolor = 0xC0C0C040;
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
void drawGrid() {
|
2017-12-22 20:23:17 +00:00
|
|
|
for(int d=0; d<S84; d++) {
|
|
|
|
transmatrix d2 = drawtrans * rgpushxto0(ccenter) * rspintox(inverse(drawtrans * rgpushxto0(ccenter)) * coldcenter);
|
|
|
|
unsigned lightgrid = gridcolor;
|
|
|
|
lightgrid -= (lightgrid & 0xFF) / 2;
|
|
|
|
unsigned col = (d % (S84/drawcell->type) == 0) ? gridcolor : lightgrid;
|
|
|
|
queueline(d2 * C0, d2 * spin(M_PI*d/S42)* xpush(1) * C0, col, 4);
|
2017-07-10 18:47:38 +00:00
|
|
|
for(int u=2; u<=20; u++) {
|
|
|
|
queueline(
|
2017-12-22 20:23:17 +00:00
|
|
|
d2 * spin(M_PI*d/S42)* xpush(u/20.) * C0,
|
|
|
|
d2 * spin(M_PI*(d+1)/S42)* xpush(u/20.) * C0,
|
|
|
|
(u%5==0) ? gridcolor : lightgrid, 0);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2017-12-22 20:23:17 +00:00
|
|
|
queueline(drawtrans*ccenter, drawtrans*coldcenter, gridcolor, 4);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
void drawHandleKey(int sym, int uni);
|
2017-12-22 20:57:55 +00:00
|
|
|
|
2017-12-22 21:34:01 +00:00
|
|
|
static ld brush_sizes[10] = {
|
|
|
|
0.001, 0.002, 0.005, 0.0075, 0.01, 0.015, 0.02, 0.05, 0.075, 0.1};
|
|
|
|
|
|
|
|
static unsigned texture_colors[] = {
|
|
|
|
11,
|
|
|
|
0x000000FF,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFF0000FF,
|
|
|
|
0xFFFF00FF,
|
|
|
|
0x00FF00FF,
|
|
|
|
0x00FFFFFF,
|
|
|
|
0x0000FFFF,
|
|
|
|
0xFF00FFFF,
|
|
|
|
0xC0C0C0FF,
|
|
|
|
0x808080FF,
|
|
|
|
0x404040FF,
|
|
|
|
0x804000FF
|
|
|
|
};
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
void showDrawEditor() {
|
2017-07-12 17:50:39 +00:00
|
|
|
cmode = sm::DRAW;
|
2017-07-16 21:00:55 +00:00
|
|
|
gamescreen(0);
|
2017-07-10 18:47:38 +00:00
|
|
|
drawGrid();
|
2017-12-03 17:24:34 +00:00
|
|
|
callhandlers(false, hooks_prestats);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
if(!mouseout()) getcstat = '-';
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
int sg;
|
2016-08-26 09:58:03 +00:00
|
|
|
string line1, line2;
|
2017-12-17 23:24:56 +00:00
|
|
|
|
|
|
|
usershape *us = NULL;
|
2017-12-22 20:57:55 +00:00
|
|
|
|
|
|
|
bool intexture = false;
|
2017-12-21 10:36:07 +00:00
|
|
|
|
|
|
|
#if CAP_TEXTURE
|
2017-12-17 23:24:56 +00:00
|
|
|
if(texture::tstate == texture::tsActive) {
|
|
|
|
sg = 16;
|
|
|
|
line1 = "texture";
|
|
|
|
line2 = "";
|
|
|
|
texture::update();
|
2017-12-22 20:57:55 +00:00
|
|
|
intexture = true;
|
2017-12-17 23:24:56 +00:00
|
|
|
}
|
2017-12-21 10:36:07 +00:00
|
|
|
#else
|
|
|
|
if(0);
|
|
|
|
#endif
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
else {
|
|
|
|
|
2017-12-21 10:36:07 +00:00
|
|
|
sg = drawcellShapeGroup();
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
switch(sg) {
|
|
|
|
case 0:
|
|
|
|
line1 = XLAT("character");
|
|
|
|
line2 = csname(vid.cs);
|
|
|
|
break;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
case 1:
|
|
|
|
line1 = XLAT("monster");
|
|
|
|
line2 = XLAT1(minf[drawcell->monst].name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
line1 = XLAT("item");
|
|
|
|
line2 = XLAT1(iinf[drawcell->item].name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
line1 = XLAT("floor");
|
|
|
|
line2 = XLAT(ishept(drawcell) ? "heptagonal" :
|
|
|
|
ishex1(drawcell) ? "hexagonal #1" : "hexagonal");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
line1 = XLAT("floor/pattern");
|
|
|
|
line2 = "#" + its(patterns::getpatterninfo0(drawcell).id);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-18 22:42:08 +00:00
|
|
|
us =usershapes[drawcellShapeGroup()][drawcellShapeID()];
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 12:50:16 +00:00
|
|
|
int fs = min(vid.fsize + 5, vid.yres/28);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
// displayButton(8, 8+fs*9, XLAT("l = lands"), 'l', 0);
|
|
|
|
displayfr(8, 8+fs, 2, vid.fsize, line1, 0xC0C0C0, 0);
|
2017-12-22 20:57:55 +00:00
|
|
|
|
|
|
|
if(!intexture) {
|
|
|
|
if(sg >= 3)
|
|
|
|
displayButton(8, 8+fs*2, line2 + XLAT(" (r = complex tesselations)"), 'r', 0);
|
|
|
|
else
|
|
|
|
displayfr(8, 8+fs*2, 2, vid.fsize, line2, 0xC0C0C0, 0);
|
|
|
|
displayButton(8, 8+fs*3, XLAT("l = layers: %1", its(dslayer)), 'l', 0);
|
|
|
|
}
|
2017-12-17 23:24:56 +00:00
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
if(us && size(us->d[dslayer].list)) {
|
2016-08-26 09:58:03 +00:00
|
|
|
usershapelayer& ds(us->d[dslayer]);
|
|
|
|
displayButton(8, 8+fs*4, XLAT("1-9 = rotations: %1", its(ds.rots)), '1' + (ds.rots % 9), 0);
|
|
|
|
displayButton(8, 8+fs*5, XLAT(ds.sym ? "0 = symmetry" : "0 = asymmetry"), '0', 0);
|
|
|
|
|
|
|
|
displayfr(8, 8+fs*7, 2, vid.fsize, XLAT("%1 vertices", its(size(ds.list))), 0xC0C0C0, 0);
|
2017-06-18 16:52:15 +00:00
|
|
|
displaymm('a', 8, 8+fs*8, 2, vid.fsize, XLAT("a = add v"), 0);
|
|
|
|
if(autochoose) {
|
|
|
|
displaymm('m', 8, 8+fs*9, 2, vid.fsize, XLAT("m = move v"), 0);
|
|
|
|
displaymm('d', 8, 8+fs*10, 2, vid.fsize, XLAT("d = delete v"), 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
displayButton(8, 8+fs*9, XLAT("m = move v"), 'm', 0);
|
|
|
|
displayButton(8, 8+fs*10, XLAT("d = delete v"), 'd', 0);
|
|
|
|
}
|
|
|
|
displaymm('c', 8, 8+fs*11, 2, vid.fsize, XLAT(autochoose ? "autochoose" : "c = choose"), 0);
|
|
|
|
displayButton(8, 8+fs*12, XLAT("b = switch auto"), 'b', 0);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
displayfr(8, 8+fs*14, 2, vid.fsize, XLAT("t = shift"), 0xC0C0C0, 0);
|
|
|
|
displayfr(8, 8+fs*15, 2, vid.fsize, XLAT("y = spin"), 0xC0C0C0, 0);
|
2017-12-22 20:23:17 +00:00
|
|
|
if(mousekey == 'g')
|
|
|
|
displayButton(8, 8+fs*16, XLAT("p = grid color"), 'p', 0);
|
|
|
|
else
|
|
|
|
displayButton(8, 8+fs*16, XLAT("p = paint"), 'p', 0);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
}
|
2017-12-21 10:36:07 +00:00
|
|
|
#if CAP_TEXTURE
|
2017-12-17 23:24:56 +00:00
|
|
|
else if(texture::tstate == texture::tsActive) {
|
2017-12-22 20:57:55 +00:00
|
|
|
displayButton(8, 8+fs*2, XLAT(texture::texturesym ? "0 = symmetry" : "0 = asymmetry"), '0', 0);
|
2018-01-04 11:25:02 +00:00
|
|
|
if(mousekey == 'g')
|
|
|
|
displayButton(8, 8+fs*16, XLAT("p = grid color"), 'p', 0);
|
|
|
|
else
|
|
|
|
displayButton(8, 8+fs*16, XLAT("p = color"), 'p', 0);
|
2017-12-22 21:34:01 +00:00
|
|
|
displayButton(8, 8+fs*4, XLAT("b = brush size: %1", fts4(texture::penwidth)), 'b', 0);
|
2017-12-22 20:57:55 +00:00
|
|
|
displayButton(8, 8+fs*5, XLAT("u = undo"), 'u', 0);
|
2018-01-04 11:25:02 +00:00
|
|
|
displaymm('d', 8, 8+fs*7, 2, vid.fsize, XLAT("d = draw"), 0);
|
|
|
|
displaymm('l', 8, 8+fs*8, 2, vid.fsize, XLAT("l = line"), 0);
|
|
|
|
displaymm('c', 8, 8+fs*9, 2, vid.fsize, XLAT("c = circle"), 0);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-12-21 10:36:07 +00:00
|
|
|
#endif
|
2016-08-26 09:58:03 +00:00
|
|
|
else {
|
2017-08-06 12:50:16 +00:00
|
|
|
displaymm('n', 8, 8+fs*5, 2, vid.fsize, XLAT("'n' to start"), 0);
|
2017-10-04 20:27:51 +00:00
|
|
|
displaymm('u', 8, 8+fs*6, 2, vid.fsize, XLAT("'u' to load current"), 0);
|
2017-08-06 12:50:16 +00:00
|
|
|
if(mousekey == 'a' || mousekey == 'd' || mousekey == 'd' ||
|
|
|
|
mousekey == 'c') mousekey = 'n';
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 12:50:16 +00:00
|
|
|
displaymm('g', vid.xres-8, 8+fs*4, 2, vid.fsize, XLAT("g = grid"), 16);
|
2018-01-05 16:30:03 +00:00
|
|
|
|
|
|
|
#if CAP_TEXTURE
|
2017-12-22 21:34:01 +00:00
|
|
|
if(intexture) for(int i=0; i<10; i++) {
|
|
|
|
if(8 + fs * (6+i) < vid.yres - 8 - fs * 7)
|
|
|
|
displayColorButton(vid.xres-8, 8+fs*(6+i), "###", 1000 + i, 16, 1, dialog::displaycolor(texture_colors[i+1]));
|
2018-01-05 16:30:03 +00:00
|
|
|
|
2017-12-22 21:34:01 +00:00
|
|
|
if(displayfr(vid.xres-8 - fs * 3, 8+fs*(6+i), 0, vid.fsize, its(i+1), texture::penwidth == brush_sizes[i] ? 0xFF8000 : 0xC0C0C0, 16))
|
|
|
|
getcstat = 2000+i;
|
|
|
|
}
|
2017-12-21 10:36:07 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
if(texture::tstate != texture::tsActive)
|
|
|
|
displaymm('e', vid.xres-8, 8+fs, 2, vid.fsize, XLAT("e = edit this"), 16);
|
2017-12-21 10:36:07 +00:00
|
|
|
#endif
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-06-09 01:41:33 +00:00
|
|
|
if(!mouseout()) {
|
2017-12-22 20:23:17 +00:00
|
|
|
hyperpoint mh = inverse(drawtrans * rgpushxto0(ccenter) * rspintox(inverse(drawtrans * rgpushxto0(ccenter)) * coldcenter)) * mouseh;
|
2016-08-26 09:58:03 +00:00
|
|
|
displayfr(vid.xres-8, vid.yres-8-fs*6, 2, vid.fsize, XLAT("x: %1", fts4(mh[0])), 0xC0C0C0, 16);
|
|
|
|
displayfr(vid.xres-8, vid.yres-8-fs*5, 2, vid.fsize, XLAT("y: %1", fts4(mh[1])), 0xC0C0C0, 16);
|
|
|
|
displayfr(vid.xres-8, vid.yres-8-fs*4, 2, vid.fsize, XLAT("z: %1", fts4(mh[2])), 0xC0C0C0, 16);
|
2017-03-23 10:53:57 +00:00
|
|
|
displayfr(vid.xres-8, vid.yres-8-fs*2, 2, vid.fsize, XLAT("r: %1", fts4(hdist0(mh))), 0xC0C0C0, 16);
|
2016-08-26 09:58:03 +00:00
|
|
|
displayfr(vid.xres-8, vid.yres-8-fs, 2, vid.fsize, XLAT("ϕ: %1°", fts4(-atan2(mh[1], mh[0]) * 360 / 2 / M_PI)), 0xC0C0C0, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
displayFunctionKeys();
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
keyhandler = drawHandleKey;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
bool rebuildPolys = false;
|
2017-10-04 20:27:51 +00:00
|
|
|
|
|
|
|
void loadShapes(int sg, int id) {
|
|
|
|
delete usershapes[sg][id];
|
|
|
|
usershapes[sg][id] = NULL;
|
|
|
|
|
|
|
|
initquickqueue();
|
|
|
|
|
|
|
|
dynamicval<bool> ws(mmspatial, false);
|
|
|
|
|
|
|
|
if(sg == 0) {
|
|
|
|
multi::cpid = id, drawMonsterType(moPlayer, drawcell, Id, 0xC0C0C0, 0);
|
|
|
|
}
|
|
|
|
else if(sg == 1) {
|
|
|
|
drawMonsterType(eMonster(id), drawcell, Id, minf[id].color, 0);
|
|
|
|
}
|
|
|
|
else if(sg == 2) {
|
|
|
|
drawItemType(eItem(id), drawcell, Id, iinf[id].color, 0, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
warpfloor(drawcell, Id, 0, PPR_FLOOR, isWarped(drawcell));
|
|
|
|
}
|
|
|
|
|
|
|
|
sortquickqueue();
|
|
|
|
|
|
|
|
int layer = 0;
|
|
|
|
|
|
|
|
initShape(sg, id);
|
|
|
|
|
|
|
|
for(int i=0; i<size(ptds); i++) {
|
|
|
|
auto& ptd = ptds[i];
|
|
|
|
if(ptd.kind != pkPoly) continue;
|
|
|
|
|
|
|
|
auto& p = ptd.u.poly;
|
|
|
|
int cnt = p.cnt;
|
|
|
|
|
|
|
|
usershapelayer *dsCur = &usershapes[sg][id]->d[layer];
|
|
|
|
dsCur->list.clear();
|
|
|
|
dsCur->color = ptd.col;
|
|
|
|
dsCur->sym = false;
|
|
|
|
dsCur->rots = 1;
|
|
|
|
|
|
|
|
for(auto& v: symmetriesAt)
|
2018-02-11 18:08:17 +00:00
|
|
|
if(v[0] == p.offset) {
|
2017-10-04 20:27:51 +00:00
|
|
|
dsCur->rots = v[1];
|
|
|
|
dsCur->sym = v[2] == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int d = dsCur->rots * (dsCur->sym ? 2 : 1);
|
|
|
|
|
|
|
|
for(int i=0; i < cnt/d; i++)
|
2018-02-11 18:08:17 +00:00
|
|
|
dsCur->list.push_back(p.V * glhr::gltopoint((*p.tab)[i+p.offset]));
|
2017-10-04 20:27:51 +00:00
|
|
|
|
|
|
|
layer++;
|
|
|
|
if(layer == USERLAYERS) break;
|
|
|
|
}
|
|
|
|
rebuildPolys = true;
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
void applyToShape(int sg, int id, int uni, hyperpoint mh) {
|
|
|
|
bool haveshape = usershapes[sg][id];
|
|
|
|
bool xnew = false;
|
2017-06-18 16:52:15 +00:00
|
|
|
|
|
|
|
if(uni == '-') uni = mousekey;
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
if(!haveshape) {
|
2017-10-04 20:27:51 +00:00
|
|
|
if(uni == 'n')
|
2016-08-26 09:58:03 +00:00
|
|
|
initShape(sg, id);
|
2017-10-04 20:27:51 +00:00
|
|
|
else if(uni == 'u') ;
|
2016-08-26 09:58:03 +00:00
|
|
|
else if(uni >= '0' && uni <= '9') {
|
|
|
|
initShape(sg, id);
|
|
|
|
xnew = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
usershapelayer *dsCur = &usershapes[sg][id]->d[dslayer];
|
2017-06-18 16:52:15 +00:00
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
if(uni == 'n' || xnew) {
|
|
|
|
dsCur->list.clear();
|
|
|
|
dsCur->list.push_back(mh);
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 20:27:51 +00:00
|
|
|
if(uni == 'u')
|
|
|
|
loadShapes(sg, id);
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
if(uni == 'a' && haveshape) {
|
2017-06-18 16:52:15 +00:00
|
|
|
mh = spin(2*M_PI*-ew.rotid/dsCur->rots) * mh;
|
|
|
|
if(ew.symid) mh = Mirror * mh;
|
|
|
|
|
|
|
|
if(ew.pointid < 0 || ew.pointid >= size(dsCur->list))
|
|
|
|
ew.pointid = size(dsCur->list)-1, ew.side = 1;
|
|
|
|
|
|
|
|
dsCur->list.insert(dsCur->list.begin()+ew.pointid+(ew.side?1:0), mh);
|
|
|
|
if(ew.side) ew.pointid++;
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(uni == 'D') {
|
|
|
|
delete usershapes[sg][id];
|
|
|
|
usershapes[sg][id] = NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
if(uni == 'm' || uni == 'd') {
|
|
|
|
|
|
|
|
int i = ew.pointid;
|
|
|
|
|
|
|
|
if(i < 0 || i >= size(dsCur->list)) return;
|
|
|
|
|
|
|
|
mh = spin(2*M_PI*-ew.rotid/dsCur->rots) * mh;
|
|
|
|
if(ew.symid) mh = Mirror * mh;
|
|
|
|
|
|
|
|
if(uni == 'm' || uni == 'M')
|
2016-08-26 09:58:03 +00:00
|
|
|
dsCur->list[i] = mh;
|
2017-06-18 16:52:15 +00:00
|
|
|
if(uni == 'd' || uni == 'b') {
|
2016-08-26 09:58:03 +00:00
|
|
|
dsCur->list.erase(dsCur->list.begin() + i);
|
2017-06-18 16:52:15 +00:00
|
|
|
if(ew.side == 1 && ew.pointid >= i) ew.pointid--;
|
|
|
|
if(ew.side == 0 && ew.pointid > i) ew.pointid--;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-06-18 16:52:15 +00:00
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
if(uni == 'K') {
|
|
|
|
if(vid.cs.charid >= 4) {
|
|
|
|
loadShape(sg, id, shCatBody, 2, 0);
|
|
|
|
loadShape(sg, id, shCatHead, 2, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(!(vid.cs.charid&1)) loadShape(sg, id, shPBody, 2, 0);
|
|
|
|
else loadShape(sg, id, shFemaleBody, 2, 0);
|
|
|
|
|
|
|
|
loadShape(sg, id, shPSword, 1, 1);
|
|
|
|
|
|
|
|
if(vid.cs.charid&1)
|
|
|
|
loadShape(sg, id, shFemaleDress, 2, 2);
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
/* if(vid.cs.charid&1)
|
2016-08-26 09:58:03 +00:00
|
|
|
loadShape(sg, id, shPrincessDress, 1, 3);
|
|
|
|
else
|
2017-03-23 10:53:57 +00:00
|
|
|
loadShape(sg, id, shPrinceDress, 2, 3); */
|
|
|
|
|
|
|
|
loadShape(sg, id, shRatCape2, 1, 3);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
if(vid.cs.charid&1)
|
|
|
|
loadShape(sg, id, shFemaleHair, 2, 4);
|
|
|
|
else
|
|
|
|
loadShape(sg, id, shPHead, 2, 4);
|
|
|
|
|
|
|
|
loadShape(sg, id, shPFace, 2, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
// loadShape(sg, id, shWolf, 2, dslayer);
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(uni == '+') dsCur->rots++;
|
|
|
|
|
|
|
|
if(uni >= '1' && uni <= '9') {
|
|
|
|
dsCur->rots = uni - '0';
|
|
|
|
if(dsCur->rots == 9) dsCur->rots = 21;
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
if(uni == '0') {
|
|
|
|
dsCur->sym = !dsCur->sym;
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(uni == 't') {
|
|
|
|
dsCur->shift = mh;
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
if(uni == 'y') {
|
|
|
|
dsCur->spin = mh;
|
2017-03-23 10:53:57 +00:00
|
|
|
rebuildPolys = true;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(uni == COLORKEY) dsCur->color = colortouse;
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeHyperpoint(FILE *f, hyperpoint h) {
|
|
|
|
for(int i=0; i<3; i++) fprintf(f, "%lf ", double(h[i]));
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint readHyperpoint(FILE *f) {
|
|
|
|
hyperpoint h;
|
|
|
|
for(int i=0; i<3; i++) {
|
|
|
|
double d;
|
|
|
|
int err = fscanf(f, "%lf", &d);
|
2017-11-07 13:42:12 +00:00
|
|
|
if(err != 1) printf("Warning: read error\n");
|
2016-08-26 09:58:03 +00:00
|
|
|
h[i] = d;
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
string drawHelpLine() {
|
|
|
|
return XLAT("vector graphics editor");
|
|
|
|
}
|
|
|
|
|
2017-09-03 19:11:33 +00:00
|
|
|
bool onelayeronly;
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
bool loadPicFile(const string& s) {
|
2017-12-03 08:52:17 +00:00
|
|
|
FILE *f = fopen(picfile.c_str(), "rt");
|
|
|
|
if(!f) {
|
|
|
|
addMessage(XLAT("Failed to load pictures from %1", picfile));
|
2017-12-14 11:10:40 +00:00
|
|
|
return false;
|
2017-12-03 08:52:17 +00:00
|
|
|
}
|
|
|
|
int err;
|
|
|
|
char buf[200];
|
|
|
|
if(!fgets(buf, 200, f)) {
|
|
|
|
addMessage(XLAT("Failed to load pictures from %1", picfile));
|
2017-12-14 11:10:40 +00:00
|
|
|
fclose(f); return false;
|
2017-12-03 08:52:17 +00:00
|
|
|
}
|
|
|
|
int vernum; err = fscanf(f, "%x", &vernum);
|
|
|
|
printf("vernum = %x\n", vernum);
|
2017-12-22 20:37:30 +00:00
|
|
|
|
|
|
|
if(vernum >= 0xA0A0) {
|
|
|
|
int tg, nt, wp;
|
|
|
|
fscanf(f, "%d%d%d%d\n", &tg, &nt, &wp, &patterns::subpattern_flags);
|
|
|
|
patterns::whichPattern = wp;
|
|
|
|
if(tg != geometry) { targetgeometry = eGeometry(tg); restartGame('g', 0, true); }
|
2018-01-06 21:34:03 +00:00
|
|
|
if(nt != nonbitrunc) { restartGame('7', 0, true); }
|
2017-12-22 20:37:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-03 08:52:17 +00:00
|
|
|
while(true) {
|
|
|
|
int i, j, l, sym, rots, color, siz;
|
|
|
|
err = fscanf(f, "%d%d%d%d%d%x%d", &i, &j, &l, &sym, &rots, &color, &siz);
|
|
|
|
if(i == -1 || err < 6) break;
|
|
|
|
if(siz < 0 || siz > 1000) break;
|
2017-12-22 20:37:30 +00:00
|
|
|
|
|
|
|
if(i >= 4) {
|
|
|
|
if(i < 8) patterns::whichPattern = "xxxxfpzH"[i];
|
|
|
|
patterns::subpattern_flags = 0;
|
|
|
|
i = 3;
|
|
|
|
}
|
|
|
|
|
2017-12-03 08:52:17 +00:00
|
|
|
initShape(i, j);
|
|
|
|
usershapelayer& ds(usershapes[i][j]->d[l]);
|
|
|
|
ds.shift = readHyperpoint(f);
|
|
|
|
ds.spin = readHyperpoint(f);
|
|
|
|
ds.list.clear();
|
|
|
|
for(int i=0; i<siz; i++) {
|
|
|
|
ds.list.push_back(readHyperpoint(f));
|
|
|
|
writeHyperpoint(stdout, ds.list[i]);
|
|
|
|
}
|
|
|
|
ds.sym = sym;
|
|
|
|
ds.rots = rots;
|
|
|
|
ds.color = color;
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
addMessage(XLAT("Pictures loaded from %1", picfile));
|
|
|
|
|
|
|
|
buildpolys();
|
2017-12-14 11:10:40 +00:00
|
|
|
return true;
|
2017-12-03 08:52:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 11:10:40 +00:00
|
|
|
bool savePicFile(const string& s) {
|
2017-12-03 08:52:17 +00:00
|
|
|
FILE *f = fopen(picfile.c_str(), "wt");
|
|
|
|
if(!f) {
|
|
|
|
addMessage(XLAT("Failed to save pictures to %1", picfile));
|
2017-12-14 11:10:40 +00:00
|
|
|
return false;
|
2017-12-03 08:52:17 +00:00
|
|
|
}
|
|
|
|
fprintf(f, "HyperRogue saved picture\n");
|
|
|
|
fprintf(f, "%x\n", VERNUM_HEX);
|
2017-12-22 20:37:30 +00:00
|
|
|
if(VERNUM_HEX >= 0xA0A0)
|
2018-01-06 21:34:03 +00:00
|
|
|
fprintf(f, "%d %d %d %d\n", geometry, nonbitrunc, patterns::whichPattern, patterns::subpattern_flags);
|
2017-12-03 08:52:17 +00:00
|
|
|
for(int i=0; i<USERSHAPEGROUPS; i++) for(int j=0; j<USERSHAPEIDS; j++) {
|
|
|
|
usershape *us = usershapes[i][j];
|
|
|
|
if(!us) continue;
|
|
|
|
|
|
|
|
for(int l=0; l<USERLAYERS; l++) if(size(us->d[l].list)) {
|
|
|
|
usershapelayer& ds(us->d[l]);
|
|
|
|
fprintf(f, "\n%d %d %d %d %d %6x %d\n",
|
|
|
|
i, j, l, ds.sym, ds.rots, ds.color, int(size(ds.list)));
|
|
|
|
writeHyperpoint(f, ds.shift);
|
|
|
|
writeHyperpoint(f, ds.spin);
|
|
|
|
fprintf(f,"\n");
|
|
|
|
for(int i=0; i<size(ds.list); i++)
|
|
|
|
writeHyperpoint(f, ds.list[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(f, "\n-1\n");
|
|
|
|
fclose(f);
|
|
|
|
addMessage(XLAT("Pictures saved to %1", picfile));
|
2017-12-14 11:10:40 +00:00
|
|
|
return true;
|
2017-12-03 08:52:17 +00:00
|
|
|
}
|
2017-12-22 21:34:01 +00:00
|
|
|
|
2018-01-04 11:25:02 +00:00
|
|
|
hyperpoint lstart;
|
|
|
|
cell *lstartcell;
|
2017-12-25 09:26:50 +00:00
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
void drawHandleKey(int sym, int uni) {
|
2017-06-18 16:52:15 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
handlePanning(sym, uni);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-22 20:23:17 +00:00
|
|
|
if(uni == SETMOUSEKEY) {
|
2017-12-25 09:26:50 +00:00
|
|
|
if(mousekey == newmousekey)
|
2017-12-22 20:23:17 +00:00
|
|
|
mousekey = '-';
|
|
|
|
else
|
|
|
|
mousekey = newmousekey;
|
|
|
|
}
|
2017-12-03 17:24:34 +00:00
|
|
|
|
|
|
|
if(uni == 'r') {
|
2017-12-09 02:48:30 +00:00
|
|
|
pushScreen(patterns::showPattern);
|
2017-12-03 17:24:34 +00:00
|
|
|
if(drawplayer)
|
|
|
|
addMessage(XLAT("Hint: use F7 to edit floor under the player"));
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
hyperpoint mh = inverse(drawtrans) * mouseh;
|
2017-12-22 20:23:17 +00:00
|
|
|
|
2018-01-04 11:25:02 +00:00
|
|
|
bool clickused = false;
|
|
|
|
|
2017-12-22 20:23:17 +00:00
|
|
|
if((uni == 'p' && mousekey == 'g') || (uni == 'g' && coldcenter == ccenter && ccenter == mh)) {
|
|
|
|
static unsigned grid_colors[] = {
|
|
|
|
8,
|
|
|
|
0x00000040,
|
|
|
|
0xFFFFFF40,
|
|
|
|
0xFF000040,
|
|
|
|
0x0000F040,
|
|
|
|
0x00000080,
|
|
|
|
0xFFFFFF80,
|
|
|
|
0xFF000080,
|
|
|
|
0x0000F080,
|
|
|
|
};
|
|
|
|
dialog::openColorDialog(gridcolor, grid_colors);
|
2018-01-04 11:25:02 +00:00
|
|
|
clickused = true;
|
2017-12-22 20:23:17 +00:00
|
|
|
}
|
2017-12-25 09:26:50 +00:00
|
|
|
|
|
|
|
char mkuni = uni == '-' ? mousekey : uni;
|
|
|
|
|
|
|
|
if(mkuni == 'g')
|
|
|
|
coldcenter = ccenter, ccenter = mh, clickused = true;
|
2018-01-04 11:25:02 +00:00
|
|
|
|
|
|
|
if(uni == 'd' || uni == 'l' || uni == 'c')
|
|
|
|
mousekey = uni;
|
2017-12-22 20:23:17 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
if(uni == ' ' && cheater) {
|
|
|
|
popScreen();
|
|
|
|
pushScreen(showMapEditor);
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
if(sym == SDLK_F7) {
|
|
|
|
drawplayer = !drawplayer;
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
|
|
|
|
#if CAP_SDL
|
2016-08-26 09:58:03 +00:00
|
|
|
if(sym == SDLK_F6) {
|
2018-01-05 13:19:22 +00:00
|
|
|
saveHighQualityShotX();
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
#endif
|
2017-08-06 12:50:16 +00:00
|
|
|
|
|
|
|
#if CAP_SVG
|
2017-03-23 10:53:57 +00:00
|
|
|
if(sym == SDLK_F8) {
|
2018-01-05 13:19:22 +00:00
|
|
|
saveSvgShotX();
|
2017-03-23 10:53:57 +00:00
|
|
|
}
|
2017-08-06 12:50:16 +00:00
|
|
|
#endif
|
2017-03-23 10:53:57 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
if(sym == SDLK_ESCAPE) popScreen();
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
if(sym == SDLK_F1) {
|
2017-07-10 18:47:38 +00:00
|
|
|
gotoHelp(drawhelptext());
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
if(sym == SDLK_F10) popScreen();
|
2017-03-23 10:53:57 +00:00
|
|
|
|
2017-12-21 10:36:07 +00:00
|
|
|
#if CAP_TEXTURE
|
2017-12-17 23:24:56 +00:00
|
|
|
if(texture::tstate == texture::tsActive) {
|
2018-01-04 11:25:02 +00:00
|
|
|
|
|
|
|
int tcolor = (texture::paint_color >> 8) | ((texture::paint_color & 0xFF) << 24);
|
|
|
|
|
2017-12-25 09:26:50 +00:00
|
|
|
if(uni == '-' && !clickused) {
|
2018-01-04 11:25:02 +00:00
|
|
|
if(mousekey == 'l' || mousekey == 'c') {
|
|
|
|
if(!holdmouse) lstart = mouseh, lstartcell = mouseover, holdmouse = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(!holdmouse) texture::undoLock();
|
|
|
|
texture::drawPixel(mouseover, mouseh, tcolor);
|
|
|
|
holdmouse = true; lstartcell = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sym == PSEUDOKEY_RELEASE) {
|
|
|
|
printf("release\n");
|
|
|
|
if(mousekey == 'l') {
|
|
|
|
texture::undoLock();
|
|
|
|
texture::where = mouseover;
|
|
|
|
texture::drawPixel(mouseover, mouseh, tcolor);
|
|
|
|
texture::drawLine(mouseh, lstart, tcolor);
|
|
|
|
lstartcell = NULL;
|
|
|
|
}
|
|
|
|
if(mousekey == 'c') {
|
|
|
|
texture::undoLock();
|
|
|
|
ld rad = hdist(lstart, mouseh);
|
|
|
|
int circp = int(1 + 3 * (circlelength(rad) / texture::penwidth));
|
|
|
|
if(circp > 1000) circp = 1000;
|
|
|
|
transmatrix T = rgpushxto0(lstart);
|
|
|
|
texture::where = lstartcell;
|
|
|
|
for(int i=0; i<circp; i++)
|
|
|
|
texture::drawPixel(T * spin(2 * M_PI * i / circp) * xpush(rad) * C0, tcolor);
|
|
|
|
lstartcell = NULL;
|
|
|
|
}
|
2017-12-22 21:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(uni >= 1000 && uni < 1010)
|
|
|
|
texture::paint_color = texture_colors[uni - 1000 + 1];
|
|
|
|
|
|
|
|
if(uni >= 2000 && uni < 2010)
|
|
|
|
texture::penwidth = brush_sizes[uni - 2000];
|
2017-12-18 22:42:08 +00:00
|
|
|
|
2017-12-22 20:57:55 +00:00
|
|
|
if(uni == '0')
|
|
|
|
texture::texturesym = !texture::texturesym;
|
|
|
|
|
2017-12-22 19:59:04 +00:00
|
|
|
if(uni == 'u') {
|
|
|
|
texture::undo();
|
|
|
|
}
|
|
|
|
|
2017-12-18 22:42:08 +00:00
|
|
|
if(uni == 'p') {
|
2018-01-04 11:25:02 +00:00
|
|
|
if(!clickused)
|
|
|
|
dialog::openColorDialog(texture::paint_color, texture_colors);
|
2017-12-18 22:42:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 21:34:01 +00:00
|
|
|
if(uni == 'b')
|
|
|
|
dialog::editNumber(texture::penwidth, 0, 0.1, 0.005, 0.02, XLAT("brush size"), XLAT("brush size"));
|
2017-12-17 23:24:56 +00:00
|
|
|
}
|
2017-12-21 10:36:07 +00:00
|
|
|
#else
|
|
|
|
if(0);
|
|
|
|
#endif
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
else {
|
|
|
|
dslayer %= USERLAYERS;
|
2017-12-22 20:37:30 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
int sg = drawcellShapeGroup();
|
2017-12-22 20:37:30 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
for(int i=0; i<USERSHAPEIDS; i++) if(editingShape(sg, i))
|
|
|
|
applyToShape(sg, i, uni, mh);
|
2017-12-22 20:37:30 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
if(uni == 'e' || (uni == '-' && mousekey == 'e')) {
|
|
|
|
initdraw(mouseover ? mouseover : cwt.c);
|
|
|
|
}
|
|
|
|
if(uni == 'l') { dslayer++; dslayer %= USERLAYERS; }
|
|
|
|
if(uni == 'L') { dslayer--; if(dslayer < 0) dslayer += USERLAYERS; }
|
|
|
|
if(uni == 'l' - 96) onelayeronly = !onelayeronly;
|
|
|
|
|
|
|
|
if(uni == 'c') ew = ewsearch;
|
|
|
|
if(uni == 'b') autochoose = !autochoose;
|
|
|
|
|
|
|
|
if(uni == 'S') {
|
|
|
|
for(int i=0; i<USERSHAPEGROUPS; i++) for(int j=0; j<USERSHAPEIDS; j++) {
|
|
|
|
usershape *us = usershapes[i][j];
|
|
|
|
if(!us) continue;
|
|
|
|
|
|
|
|
for(int l=0; l<USERLAYERS; l++) if(size(us->d[l].list)) {
|
|
|
|
usershapelayer& ds(us->d[l]);
|
|
|
|
printf("// %d %d %d [%06X]\n", i, j, l, ds.color);
|
|
|
|
printf(" ID, %d, %d, ", us->d[l].rots, us->d[l].sym?2:1);
|
|
|
|
for(int i=0; i<size(us->d[l].list); i++)
|
|
|
|
printf("%lf,%lf, ", double(us->d[l].list[i][0]), double(us->d[l].list[i][1]));
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(uni == 'p') {
|
|
|
|
dialog::openColorDialog(colortouse);
|
2017-12-19 13:34:38 +00:00
|
|
|
dialog::reaction = [] () {
|
|
|
|
drawHandleKey(COLORKEY, COLORKEY);
|
|
|
|
};
|
2017-12-17 23:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sym == SDLK_F2)
|
2018-01-08 22:23:00 +00:00
|
|
|
dialog::openFileDialog(picfile, XLAT("pics to save:"), ".pic",
|
2017-12-17 23:24:56 +00:00
|
|
|
[] () {
|
|
|
|
return savePicFile(picfile);
|
|
|
|
});
|
|
|
|
|
|
|
|
if(sym == SDLK_F3)
|
2018-01-08 22:23:00 +00:00
|
|
|
dialog::openFileDialog(picfile, XLAT("pics to load:"), ".pic",
|
2017-12-17 23:24:56 +00:00
|
|
|
[] () {
|
|
|
|
return loadPicFile(picfile);
|
|
|
|
});
|
|
|
|
|
|
|
|
if(sym == SDLK_F5) {
|
|
|
|
for(int i=0; i<USERSHAPEGROUPS; i++)
|
|
|
|
for(int j=0; j<USERSHAPEIDS; j++)
|
|
|
|
if(usershapes[i][j]) delete usershapes[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
if(rebuildPolys)
|
|
|
|
buildpolys(), rebuildPolys = false;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
auto hooks = addHook(clearmemory, 0, [] () {
|
|
|
|
if(mapeditor::painttype == 4)
|
|
|
|
mapeditor::painttype = 0, mapeditor::paintwhat = 0,
|
|
|
|
mapeditor::paintwhat_str = "clear monster";
|
2017-11-12 23:37:18 +00:00
|
|
|
mapeditor::copysource.c = NULL;
|
2017-07-10 18:47:38 +00:00
|
|
|
mapeditor::undo.clear();
|
2017-12-09 02:48:30 +00:00
|
|
|
if(!cheater) patterns::displaycodes = 0;
|
|
|
|
if(!cheater) patterns::whichShape = 0;
|
2017-07-10 18:47:38 +00:00
|
|
|
modelcell.clear();
|
2018-01-26 00:45:49 +00:00
|
|
|
}) +
|
|
|
|
addHook(hooks_removecells, 0, [] () {
|
|
|
|
modelcell.clear();
|
|
|
|
set_if_removed(mapeditor::copysource.c, NULL);
|
|
|
|
});;;
|
2017-03-23 10:53:57 +00:00
|
|
|
#endif
|
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
void initdraw(cell *c) {
|
|
|
|
mapeditor::drawcell = c;
|
|
|
|
ew.c = c;
|
|
|
|
ew.rotid = 0;
|
|
|
|
ew.symid = 0;
|
|
|
|
ew.pointid = -1;
|
|
|
|
ew.side = 0;
|
|
|
|
ewsearch = ew;
|
|
|
|
}
|
2017-12-17 23:24:56 +00:00
|
|
|
|
|
|
|
transmatrix textrans;
|
2018-01-04 11:25:02 +00:00
|
|
|
|
2018-01-05 16:30:03 +00:00
|
|
|
#if CAP_TEXTURE
|
2018-01-04 11:25:02 +00:00
|
|
|
void queue_hcircle(transmatrix Ctr, ld radius) {
|
|
|
|
vector<hyperpoint> pts;
|
|
|
|
int circp = 6;
|
|
|
|
if(radius > 0.04) circp *= 2;
|
|
|
|
if(radius > .1) circp *= 2;
|
|
|
|
|
|
|
|
for(int j=0; j<circp; j++)
|
|
|
|
pts.push_back(Ctr * tC0(spin(M_PI*j*2/circp) * xpush(radius)));
|
|
|
|
for(int j=0; j<circp; j++)
|
|
|
|
queueline(pts[j], pts[(j+1)%circp], texture::paint_color, 0, PPR_LINE);
|
|
|
|
}
|
2018-01-05 16:30:03 +00:00
|
|
|
#endif
|
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
bool drawUserShape(transmatrix V, int group, int id, int color, cell *c) {
|
2017-08-06 12:50:16 +00:00
|
|
|
#if !CAP_EDIT
|
2017-06-18 16:52:15 +00:00
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
|
2017-12-03 17:24:34 +00:00
|
|
|
id = id % USERSHAPEIDS;
|
|
|
|
|
2017-06-18 16:52:15 +00:00
|
|
|
usershape *us = usershapes[group][id];
|
|
|
|
if(us) {
|
|
|
|
for(int i=0; i<USERLAYERS; i++) {
|
2017-09-03 19:11:33 +00:00
|
|
|
if(i != dslayer && onelayeronly) continue;
|
2017-06-18 16:52:15 +00:00
|
|
|
usershapelayer& ds(us->d[i]);
|
|
|
|
hpcshape& sh(ds.sh);
|
|
|
|
|
|
|
|
if(sh.s != sh.e)
|
|
|
|
queuepoly(V, sh, ds.color ? ds.color : color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 11:25:02 +00:00
|
|
|
if(cmode & sm::DRAW) {
|
2017-12-21 10:36:07 +00:00
|
|
|
|
|
|
|
#if CAP_TEXTURE
|
2018-01-04 11:25:02 +00:00
|
|
|
if(texture::tstate == texture::tsActive && lmouseover && !mouseout() && (lstartcell || !holdmouse)) {
|
|
|
|
cell *ls = lstartcell ? lstartcell : lmouseover;
|
|
|
|
auto sio = patterns::getpatterninfo0(ls);
|
2017-12-17 23:24:56 +00:00
|
|
|
auto sih = patterns::getpatterninfo0(c);
|
|
|
|
|
|
|
|
if(sio.id == sih.id) {
|
2018-01-04 11:25:02 +00:00
|
|
|
if(c == ls)
|
|
|
|
textrans = inverse(V * applyPatterndir(ls, sio));
|
|
|
|
|
2017-12-18 22:42:08 +00:00
|
|
|
transmatrix mh = textrans * rgpushxto0(mouseh);
|
2018-01-04 11:25:02 +00:00
|
|
|
transmatrix ml = textrans * rgpushxto0(lstart);
|
|
|
|
|
2017-12-22 20:57:55 +00:00
|
|
|
for(int j=0; j<=texture::texturesym; j++)
|
2017-12-17 23:24:56 +00:00
|
|
|
for(int i=0; i<c->type; i += sih.symmetries) {
|
2018-01-04 11:25:02 +00:00
|
|
|
transmatrix M2 = V * applyPatterndir(c, sih) * spin(2*M_PI*i/c->type);
|
2017-12-22 20:57:55 +00:00
|
|
|
if(j) M2 = M2 * Mirror;
|
2018-01-04 11:25:02 +00:00
|
|
|
switch(holdmouse ? mousekey : 'd') {
|
|
|
|
case 'c':
|
|
|
|
queue_hcircle(M2 * ml, hdist(lstart, mouseh));
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
queueline(M2 * mh * C0, M2 * ml * C0, texture::paint_color, 4, PPR_LINE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
queue_hcircle(M2 * mh, texture::penwidth);
|
|
|
|
}
|
2017-12-17 23:24:56 +00:00
|
|
|
}
|
2018-01-04 11:25:02 +00:00
|
|
|
}
|
2017-12-17 23:24:56 +00:00
|
|
|
}
|
2017-12-21 10:36:07 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
if(mapeditor::editingShape(group, id)) {
|
2017-06-18 16:52:15 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
/* for(int a=0; a<size(ds.list); a++) {
|
|
|
|
hyperpoint P2 = V * ds.list[a];
|
|
|
|
|
|
|
|
int xc, yc, sc;
|
|
|
|
getcoord(P2, xc, yc, sc);
|
|
|
|
queuechr(xc, yc, sc, 10, 'x',
|
|
|
|
a == 0 ? 0x00FF00 :
|
|
|
|
a == size(ds.list)-1 ? 0xFF0000 :
|
|
|
|
0xFFFF00);
|
|
|
|
} */
|
|
|
|
|
|
|
|
if(c == ew.c) mapeditor::drawtrans = V;
|
|
|
|
|
|
|
|
if(!us) return false;
|
|
|
|
|
|
|
|
usershapelayer &ds(us->d[mapeditor::dslayer]);
|
|
|
|
|
|
|
|
hyperpoint mh = inverse(mapeditor::drawtrans) * mouseh;
|
|
|
|
|
|
|
|
for(int a=0; a<ds.rots; a++)
|
|
|
|
for(int b=0; b<(ds.sym?2:1); b++) {
|
|
|
|
|
|
|
|
if(mouseout()) break;
|
|
|
|
|
|
|
|
hyperpoint P2 = V * spin(2*M_PI*a/ds.rots) * (b?Mirror*mh:mh);
|
|
|
|
|
|
|
|
queuechr(P2, 10, 'x', 0xFF00FF);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(size(ds.list) == 0) return us;
|
|
|
|
|
|
|
|
hyperpoint Plast = V * spin(-2*M_PI/ds.rots) * (ds.sym?Mirror*ds.list[0]:ds.list[size(ds.list)-1]);
|
|
|
|
int state = 0;
|
|
|
|
int gstate = 0;
|
|
|
|
double dist2 = 0;
|
|
|
|
hyperpoint lpsm;
|
|
|
|
|
|
|
|
for(int a=0; a<ds.rots; a++)
|
|
|
|
for(int b=0; b<(ds.sym?2:1); b++) {
|
|
|
|
|
|
|
|
hyperpoint mh2 = spin(2*M_PI*-ew.rotid/ds.rots) * mh;
|
|
|
|
if(ew.symid) mh2 = Mirror * mh2;
|
|
|
|
hyperpoint pseudomouse = V * spin(2*M_PI*a/ds.rots) * mirrorif(mh2, b);
|
|
|
|
|
|
|
|
for(int t=0; t<size(ds.list); t++) {
|
|
|
|
int ti = b ? size(ds.list)-1-t : t;
|
2017-06-18 16:52:15 +00:00
|
|
|
|
2017-12-17 23:24:56 +00:00
|
|
|
hyperpoint P2 = V * spin(2*M_PI*a/ds.rots) * mirrorif(ds.list[ti], b);
|
|
|
|
|
|
|
|
if(!mouseout()) {
|
|
|
|
double d = hdist(mouseh, P2);
|
|
|
|
if(d < ewsearch.dist)
|
|
|
|
ewsearch.dist = d,
|
|
|
|
ewsearch.rotid = a,
|
|
|
|
ewsearch.symid = b,
|
|
|
|
ewsearch.pointid = ti,
|
|
|
|
ewsearch.c = c,
|
|
|
|
ewsearch.side = b,
|
|
|
|
state = 1,
|
|
|
|
dist2 = d + hdist(mouseh, Plast) - hdist(P2, Plast);
|
|
|
|
|
|
|
|
else if(state == 1) {
|
|
|
|
double dist3 = d + hdist(mouseh, Plast) - hdist(P2, Plast);
|
|
|
|
if(dist3 < dist2)
|
|
|
|
ewsearch.side = !ewsearch.side;
|
|
|
|
state = 2;
|
|
|
|
}
|
2017-06-18 16:52:15 +00:00
|
|
|
}
|
2017-12-17 23:24:56 +00:00
|
|
|
|
|
|
|
queuechr(P2, 10, 'o',
|
|
|
|
0xC000C0);
|
|
|
|
|
|
|
|
if(!mouseout()) {
|
|
|
|
if(gstate == 1) queueline(lpsm, P2, 0x90000080), gstate = 0;
|
|
|
|
if(ti == ew.pointid) {
|
|
|
|
queueline(pseudomouse, P2, 0xF0000080);
|
|
|
|
if(ew.side == b) queueline(pseudomouse, Plast, 0x90000080);
|
|
|
|
else gstate = 1, lpsm = pseudomouse;
|
|
|
|
}
|
2017-06-18 16:52:15 +00:00
|
|
|
}
|
2017-12-17 23:24:56 +00:00
|
|
|
|
|
|
|
Plast = P2;
|
2017-06-18 16:52:15 +00:00
|
|
|
}
|
2017-12-17 23:24:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(gstate == 1) queueline(lpsm, V * ds.list[0], 0x90000080), gstate = 0;
|
|
|
|
if(state == 1) {
|
|
|
|
hyperpoint P2 = V * ds.list[0];
|
|
|
|
if(hdist(mouseh, P2) + hdist(mouseh, Plast) - hdist(P2, Plast) < dist2)
|
|
|
|
ewsearch.side = 1;
|
2017-06-18 16:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return us;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-05-27 19:40:40 +00:00
|
|
|
|