Skip to content

Commit 4000f1f

Browse files
authored
Merge pull request #479 from josephcsible/ePainttype
Make painttype an enum
2 parents 7c21e9c + d653f56 commit 4000f1f

File tree

1 file changed

+53
-46
lines changed

1 file changed

+53
-46
lines changed

mapeditor.cpp

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,8 @@ EX namespace mapeditor {
13301330
#if CAP_EDIT
13311331
int paintwhat = 0;
13321332
int paintwhat_alt_wall = 0;
1333-
int painttype = 0;
1333+
enum class ePainttype { monsters, items, lands, walls, copy, boundary, paint, select, teleport };
1334+
ePainttype painttype = ePainttype::monsters;
13341335
int paintstatueid = 0;
13351336
int radius = 0;
13361337
string paintwhat_str = "clear monster";
@@ -1465,8 +1466,8 @@ EX namespace mapeditor {
14651466

14661467
if(anyshiftclick) {
14671468
dialog::addInfo(
1468-
(painttype == 6 && (GDIM == 3)) ? "wall" :
1469-
painttype == 3 ? XLATN(winf[paintwhat_alt_wall].name) : "clear");
1469+
(painttype == ePainttype::paint && (GDIM == 3)) ? "wall" :
1470+
painttype == ePainttype::walls ? XLATN(winf[paintwhat_alt_wall].name) : "clear");
14701471
}
14711472
else
14721473
dialog::addInfo(paintwhat_str);
@@ -1476,39 +1477,39 @@ EX namespace mapeditor {
14761477
dialog::add_action([] {
14771478
dialog::editNumber(radius, 0, 9, 1, 1, XLAT("radius"), "");
14781479
});
1479-
dialog::addBoolItem(XLAT("boundary"), painttype == 5, 'b');
1480-
dialog::add_action([] { painttype = 5, paintwhat_str = XLAT("boundary"); });
1481-
dialog::addBoolItem(XLAT("monsters"), painttype == 0, 'm');
1482-
dialog::add_action([] { pushScreen(showList), painttype = 0, dialog::infix = ""; });
1483-
dialog::addBoolItem(XLAT("items"), painttype == 1, 'i');
1484-
dialog::add_action([] { pushScreen(showList), painttype = 1, dialog::infix = ""; });
1485-
dialog::addBoolItem(XLAT("lands"), painttype == 2, 'l');
1486-
dialog::add_action([] { pushScreen(showList), painttype = 2, dialog::infix = ""; });
1487-
dialog::addBoolItem(XLAT("walls"), painttype == 3, 'w');
1488-
dialog::add_action([] { pushScreen(showList), painttype = 3, dialog::infix = ""; });
1489-
dialog::addBoolItem(XLAT("paint"), painttype == 6, 'w');
1480+
dialog::addBoolItem(XLAT("boundary"), painttype == ePainttype::boundary, 'b');
1481+
dialog::add_action([] { painttype = ePainttype::boundary, paintwhat_str = XLAT("boundary"); });
1482+
dialog::addBoolItem(XLAT("monsters"), painttype == ePainttype::monsters, 'm');
1483+
dialog::add_action([] { pushScreen(showList), painttype = ePainttype::monsters, dialog::infix = ""; });
1484+
dialog::addBoolItem(XLAT("items"), painttype == ePainttype::items, 'i');
1485+
dialog::add_action([] { pushScreen(showList), painttype = ePainttype::items, dialog::infix = ""; });
1486+
dialog::addBoolItem(XLAT("lands"), painttype == ePainttype::lands, 'l');
1487+
dialog::add_action([] { pushScreen(showList), painttype = ePainttype::lands, dialog::infix = ""; });
1488+
dialog::addBoolItem(XLAT("walls"), painttype == ePainttype::walls, 'w');
1489+
dialog::add_action([] { pushScreen(showList), painttype = ePainttype::walls, dialog::infix = ""; });
1490+
dialog::addBoolItem(XLAT("paint"), painttype == ePainttype::paint, 'w');
14901491
dialog::add_action([] {
1491-
painttype = 6;
1492+
painttype = ePainttype::paint;
14921493
paintwhat_str = "paint";
1493-
dialog::openColorDialog((unsigned&)(paintwhat = (painttype ==6 ? paintwhat : 0x808080)));
1494+
dialog::openColorDialog((unsigned&)(paintwhat = (painttype == ePainttype::paint ? paintwhat : 0x808080)));
14941495
});
1495-
dialog::addBoolItem(XLAT("copy"), painttype == 4, 'c');
1496+
dialog::addBoolItem(XLAT("copy"), painttype == ePainttype::copy, 'c');
14961497
dialog::add_action([] {
1497-
if(mouseover) { copysource = mouseover_cw(true); painttype = 4; paintwhat_str = XLAT("copying"); }
1498-
else { painttype = 7; paintwhat_str = XLAT("select area to copy"); }
1498+
if(mouseover) { copysource = mouseover_cw(true); painttype = ePainttype::copy; paintwhat_str = XLAT("copying"); }
1499+
else { painttype = ePainttype::select; paintwhat_str = XLAT("select area to copy"); }
14991500
});
1500-
dialog::addBoolItem(XLAT("teleport player"), painttype == 8, 't');
1501+
dialog::addBoolItem(XLAT("teleport player"), painttype == ePainttype::teleport, 't');
15011502
dialog::add_action([] {
15021503
if(mouseover) {
15031504
playermoved = true;
15041505
cwt = mouseover_cw(true);
15051506
}
1506-
else { painttype = 8; paintwhat_str = XLAT("teleport where"); }
1507+
else { painttype = ePainttype::teleport; paintwhat_str = XLAT("teleport where"); }
15071508
});
1508-
if(painttype == 4) {
1509+
if(painttype == ePainttype::copy) {
15091510
dialog::addBoolItem_action(XLAT("flip"), copysource.mirrored, 'f');
15101511
}
1511-
else if(painttype == 3) {
1512+
else if(painttype == ePainttype::walls) {
15121513
dialog::addItem(XLAT("set Shift+click"), 'z');
15131514
dialog::add_action([] { paintwhat_alt_wall = paintwhat; });
15141515
}
@@ -1660,8 +1661,8 @@ EX namespace mapeditor {
16601661
if(!show_menu) {
16611662
if(anyshiftclick) {
16621663
displayfr(8, 8 + fs, 2, vid.fsize,
1663-
(painttype == 6 && (GDIM == 3)) ? "wall" :
1664-
painttype == 3 ? XLATN(winf[paintwhat_alt_wall].name) : "clear",
1664+
(painttype == ePainttype::paint && (GDIM == 3)) ? "wall" :
1665+
painttype == ePainttype::walls ? XLATN(winf[paintwhat_alt_wall].name) : "clear",
16651666
forecolor, 0);
16661667
}
16671668
else
@@ -1705,7 +1706,7 @@ EX namespace mapeditor {
17051706
int cdir = where.first.spin;
17061707
saveUndo(c);
17071708
switch(painttype) {
1708-
case 0: {
1709+
case ePainttype::monsters: {
17091710
if(anyshiftclick) { c->monst = moNone; mirror::destroyKilled(); break; }
17101711
eMonster last = c->monst;
17111712
c->monst = eMonster(paintwhat);
@@ -1736,15 +1737,15 @@ EX namespace mapeditor {
17361737
mirror::destroyKilled();
17371738
break;
17381739
}
1739-
case 1: {
1740+
case ePainttype::items: {
17401741
if(anyshiftclick) { c->item = itNone; break; }
17411742
eItem last = c->item;
17421743
c->item = eItem(paintwhat);
17431744
if(c->item == itBabyTortoise)
17441745
tortoise::babymap[c] = getBits(c) ^ (last == itBabyTortoise ? tortoise::getRandomBits() : 0);
17451746
break;
17461747
}
1747-
case 2: {
1748+
case ePainttype::lands: {
17481749
if(anyshiftclick) { c->land = laNone; c->wall = waNone; map_version++; break; }
17491750
eLand last = c->land;
17501751
c->land = eLand(paintwhat);
@@ -1760,7 +1761,7 @@ EX namespace mapeditor {
17601761
c->landparam = 0;
17611762
break;
17621763
}
1763-
case 3: {
1764+
case ePainttype::walls: {
17641765
eWall last = c->wall;
17651766
c->wall = eWall(anyshiftclick ? paintwhat_alt_wall : paintwhat);
17661767
map_version++;
@@ -1785,7 +1786,7 @@ EX namespace mapeditor {
17851786

17861787
break;
17871788
}
1788-
case 5:
1789+
case ePainttype::boundary:
17891790
map_version++;
17901791
c->land = laNone;
17911792
c->wall = waNone;
@@ -1794,13 +1795,13 @@ EX namespace mapeditor {
17941795
c->landparam = 0;
17951796
// c->tmp = -1;
17961797
break;
1797-
case 6:
1798+
case ePainttype::paint:
17981799
map_version++;
17991800
c->land = laCanvas;
18001801
c->wall = ((GDIM == 3) ^ anyshiftclick) ? waWaxWall : waNone;
18011802
c->landparam = paintwhat >> 8;
18021803
break;
1803-
case 4: {
1804+
case ePainttype::copy: {
18041805
map_version++;
18051806
cell *copywhat = where.second.at;
18061807
c->wall = copywhat->wall;
@@ -1816,14 +1817,14 @@ EX namespace mapeditor {
18161817
else c->mondir = gmod((where.first.mirrored == where.second.mirrored ? 1 : -1) * (copywhat->mondir - where.second.spin) + cdir, c->type);
18171818
break;
18181819
}
1819-
case 7:
1820+
case ePainttype::select:
18201821
if(c) {
18211822
copysource = c;
1822-
painttype = 4;
1823+
painttype = ePainttype::copy;
18231824
paintwhat_str = XLAT("copying");
18241825
}
18251826
break;
1826-
case 8:
1827+
case ePainttype::teleport:
18271828
playermoved = true;
18281829
cwt = c;
18291830
break;
@@ -1836,7 +1837,7 @@ EX namespace mapeditor {
18361837
void list_spill(cellwalker tgt, cellwalker src, manual_celllister& cl) {
18371838
spill_list.clear();
18381839
spill_list.emplace_back(tgt, src);
1839-
if(painttype == 7) return;
1840+
if(painttype == ePainttype::select) return;
18401841
int crad = 0, nextstepat = 0;
18411842
for(int i=0; i<isize(spill_list); i++) {
18421843
if(i == nextstepat) {
@@ -1859,13 +1860,13 @@ EX namespace mapeditor {
18591860

18601861
void editAt(cellwalker where, manual_celllister& cl) {
18611862

1862-
if(painttype == 4 && radius) {
1863+
if(painttype == ePainttype::copy && radius) {
18631864
if(where.at->type != copysource.at->type) return;
18641865
if(where.spin<0) where.spin=0;
18651866
if(BITRUNCATED && !ctof(mouseover) && ((where.spin&1) != (copysource.spin&1)))
18661867
where += 1;
18671868
}
1868-
if(painttype != 4) copysource.at = NULL;
1869+
if(painttype != ePainttype::copy) copysource.at = NULL;
18691870
list_spill(where, copysource, cl);
18701871

18711872
for(auto& st: spill_list)
@@ -1958,9 +1959,9 @@ EX namespace mapeditor {
19581959
EX void showList() {
19591960
string caption;
19601961
dialog::v.clear();
1961-
if(painttype == 4) painttype = 0;
1962+
if(painttype == ePainttype::copy) painttype = ePainttype::monsters;
19621963
switch(painttype) {
1963-
case 0:
1964+
case ePainttype::monsters:
19641965
caption = "monsters";
19651966
for(int i=0; i<motypes; i++) {
19661967
eMonster m = eMonster(i);
@@ -1975,18 +1976,24 @@ EX namespace mapeditor {
19751976
else dialog::vpush(i, minf[i].name);
19761977
}
19771978
break;
1978-
case 1:
1979+
case ePainttype::items:
19791980
caption = "items";
19801981
for(int i=0; i<ittypes; i++) dialog::vpush(i, iinf[i].name);
19811982
break;
1982-
case 2:
1983+
case ePainttype::lands:
19831984
caption = "lands";
19841985
for(int i=0; i<landtypes; i++) dialog::vpush(i, linf[i].name);
19851986
break;
1986-
case 3:
1987+
case ePainttype::walls:
19871988
caption = "walls";
19881989
for(int i=0; i<walltypes; i++) if(i != waChasmD) dialog::vpush(i, winf[i].name);
19891990
break;
1991+
case ePainttype::copy:
1992+
case ePainttype::boundary:
1993+
case ePainttype::paint:
1994+
case ePainttype::select:
1995+
case ePainttype::teleport:
1996+
break;
19901997
}
19911998
// sort(v.begin(), v.end());
19921999

@@ -2008,7 +2015,7 @@ EX namespace mapeditor {
20082015
mousepressed = false;
20092016
popScreen();
20102017

2011-
if(painttype == 3 && paintwhat == waEditStatue)
2018+
if(painttype == ePainttype::walls && paintwhat == waEditStatue)
20122019
dialog::editNumber(paintstatueid, 0, 127, 1, 1, XLAT1("editable statue"),
20132020
XLAT("These statues are designed to have their graphics edited in the Vector Graphics Editor. Each number has its own, separate graphics.")
20142021
);
@@ -3087,8 +3094,8 @@ EX namespace mapeditor {
30873094
}
30883095

30893096
auto hooks = addHook(hooks_clearmemory, 0, [] () {
3090-
if(mapeditor::painttype == 4)
3091-
mapeditor::painttype = 0, mapeditor::paintwhat = 0,
3097+
if(mapeditor::painttype == ePainttype::copy)
3098+
mapeditor::painttype = ePainttype::monsters, mapeditor::paintwhat = 0,
30923099
mapeditor::paintwhat_str = "clear monster";
30933100
mapeditor::copysource.at = NULL;
30943101
mapeditor::undo.clear();

0 commit comments

Comments
 (0)