map editor:: building mode

This commit is contained in:
Zeno Rogue 2022-10-27 09:45:03 +02:00
parent 87921fe0f9
commit 6ef282173f
3 changed files with 53 additions and 8 deletions

View File

@ -5075,7 +5075,46 @@ EX shiftmatrix cview(ld base_shift IS(0)) {
EX int point_direction;
EX int through_wall(hyperpoint at) {
ld dist = hdist0(at);
int nei = -1;
for(int i=0; i<centerover->type; i++) {
ld dist1 = hdist0(currentmap->ray_iadj(centerover, i) * at);
if(dist1 < dist) nei = i, dist = dist1;
}
return nei;
}
EX void precise_mouseover() {
if(WDIM == 3 && (cmode & (sm::EDIT_INSIDE_WALLS | sm::EDIT_BEFORE_WALLS))) {
transmatrix T = view_inverse(View);
transmatrix ori = Id;
if(prod) ori = ortho_inverse(NLP);
ld step = 0.2;
cell *c = centerover;
for(int i=0; i<100; i++) {
apply_parallel_transport(T, ori, ztangent(step));
int pd = through_wall(T * C0);
if(pd != -1) {
color_t col;
cell *c1 = c->cmove(pd);
if(isWall3(c1, col)) {
mouseover = c;
mouseover2 = c1;
point_direction = pd;
if(cmode & sm::EDIT_INSIDE_WALLS) {
swap(mouseover, mouseover2);
point_direction =c->c.spin(pd);
}
return;
}
else {
T = currentmap->iadj(c, pd) * T;
c = c1;
}
}
}
}
if(WDIM == 3) {
mouseover2 = mouseover = centerover;
ld best = HUGE_VAL;
@ -5690,6 +5729,8 @@ namespace sm {
static const int NOSCR = (1<<22); // do not show the game background
static const int AUTO_VALUES = (1<<23); // automatic place for values
static const int NARROW_LINES = (1<<24); // do make the lines narrower if we needed to reduce width
static const int EDIT_BEFORE_WALLS = (1<<25); // mouseover targets before walls
static const int EDIT_INSIDE_WALLS = (1<<26); // mouseover targets inside walls
}
#endif

View File

@ -546,13 +546,8 @@ EX void shift_view_portal(hyperpoint H) {
EX const connection_data* through_portal() {
transmatrix iView = view_inverse(View);
ld dist = hdist0(iView * C0);
int nei = -1;
for(int i=0; i<centerover->type; i++) {
ld dist1 = hdist0(currentmap->ray_iadj(centerover, i) * iView * C0);
if(dist1 < dist) nei = i, dist = dist1;
}
int nei = through_wall(iView * C0);
if(nei == -1) return nullptr;
auto cw1 = cellwalker(centerover, nei);
return at_or_null(connections, cw1);
}

View File

@ -16,6 +16,7 @@ EX namespace mapeditor {
EX bool drawing_tool;
EX bool intexture;
EX bool snapping;
EX bool building_mode = true;
#if HDR
enum eShapegroup { sgPlayer, sgMonster, sgItem, sgFloor, sgWall };
@ -1378,6 +1379,10 @@ EX namespace mapeditor {
EX void showMapEditor() {
cmode = sm::MAP | sm::PANNING;
if(building_mode) {
if(anyshiftclick) cmode |= sm::EDIT_INSIDE_WALLS;
else cmode |= sm::EDIT_BEFORE_WALLS;
}
gamescreen();
int fs = editor_fsize();
@ -1415,6 +1420,8 @@ EX namespace mapeditor {
displayButton(8, 8+fs*14, XLAT("p = paint"), 'p', 0);
if(painttype == 3)
displayButton(8, 8+fs*15, XLAT("z = set Shift+click"), 'z', 0);
if(WDIM == 3)
displayButton(8, 8+fs*16, XLAT("B = build on walls ") + ONOFF(building_mode), 'B', 0);
displayFunctionKeys();
displayButton(8, vid.yres-8-fs*4, XLAT("F8 = settings"), SDLK_F8, 0);
@ -1772,7 +1779,8 @@ EX namespace mapeditor {
if(uni == '-' && !holdmouse) undoLock();
if(uni == '-' && mouseover) {
allInPattern(mouseover_cw(false));
holdmouse = true;
if(!(GDIM == 3 && building_mode))
holdmouse = true;
}
if(mouseover) for(int i=0; i<mouseover->type; i++) createMov(mouseover, i);
@ -1785,6 +1793,7 @@ EX namespace mapeditor {
else if(uni == 'l') pushScreen(showList), painttype = 2, dialog::infix = "";
else if(uni == 'w') pushScreen(showList), painttype = 3, dialog::infix = "";
else if(uni == 'z' && painttype == 3) paintwhat_alt_wall = paintwhat;
else if(uni == 'B') building_mode = !building_mode;
else if(uni == 'r') pushScreen(patterns::showPattern);
else if(uni == 't' && mouseover) {
playermoved = true;