Skip to content

Commit 444c857

Browse files
authored
Merge pull request #37 from Tokeiburu/fix-for-new-map
Reverted the view tile option back to on by default, crop window settings.
2 parents 6f7e51a + dcbad33 commit 444c857

File tree

10 files changed

+202
-55
lines changed

10 files changed

+202
-55
lines changed

BrowEdit3.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<ClCompile Include="browedit\util\Util.cpp" />
8787
<ClCompile Include="browedit\windows\CinematicModeWindow.cpp" />
8888
<ClCompile Include="browedit\windows\ColorEditWindow.cpp" />
89+
<ClCompile Include="browedit\windows\CropSettingsWindow.cpp" />
8990
<ClCompile Include="browedit\windows\ExportMapWindow.cpp" />
9091
<ClCompile Include="browedit\windows\GatEditWindow.cpp" />
9192
<ClCompile Include="browedit\windows\HeightEditWindow.cpp" />

BrowEdit3.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@
436436
<ClCompile Include="browedit\util\Console.cpp">
437437
<Filter>browedit\util</Filter>
438438
</ClCompile>
439+
<ClCompile Include="browedit\windows\CropSettingsWindow.cpp">
440+
<Filter>browedit\windows</Filter>
441+
</ClCompile>
439442
</ItemGroup>
440443
<ItemGroup>
441444
<ClInclude Include="lib\imgui\imgui.h">

browedit/BrowEdit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ void BrowEdit::run()
281281

282282
showLightmapSettingsWindow();
283283

284+
if (windowData.cropWindowVisible)
285+
showCropSettingsWindow();
286+
284287
if (windowData.progressWindowVisible)
285288
{
286289
std::lock_guard<std::mutex> guard(windowData.progressMutex);

browedit/BrowEdit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class BrowEdit
153153
std::map<std::string, Hotkey> hotkeys;
154154

155155
bool openLightmapSettings = false;
156+
bool cropWindowVisible = false;
156157

157158
//height edit
158159
struct HeightEdit
@@ -329,6 +330,7 @@ class BrowEdit
329330
void showWallWindow();
330331
void showHelpWindow();
331332
void showLightmapSettingsWindow();
333+
void showCropSettingsWindow();
332334
void showTextureBrushWindow();
333335
void showTextureManageWindow();
334336
void showHotkeyEditorWindow();

browedit/MapView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class MapView
208208
bool viewLighting = true;
209209
bool smoothColors = true;
210210
bool viewTextures = true;
211-
bool viewEmptyTiles = false;
211+
bool viewEmptyTiles = true;
212212
bool enableFaceCulling = true;
213213
bool viewGat = false;
214214
bool viewGatGat = true;

browedit/components/GndRenderer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,13 @@ void GndRenderer::setChunkDirty(int x, int y)
406406
void GndRenderer::setChunksDirty()
407407
{
408408
allDirty = true;
409+
}
410+
411+
void GndRenderer::rebuildChunks() {
412+
for (auto r : chunks)
413+
for (auto c : r)
414+
delete c;
415+
416+
chunks.clear();
417+
gnd = nullptr;
409418
}

browedit/components/GndRenderer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class GndRenderer : public Renderer
7575

7676
void setChunkDirty(int x, int y);
7777
void setChunksDirty();
78+
void rebuildChunks();
7879
bool gndShadowDirty = true;
7980

8081
GndRenderer();
@@ -92,5 +93,5 @@ class GndRenderer : public Renderer
9293
bool quickRenderLight_hideOthers = false;
9394
Node* quickRenderLightNode = nullptr;
9495

95-
bool viewEmptyTiles = false;
96+
bool viewEmptyTiles = true;
9697
};

browedit/components/Rsw.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ class Rsw : public Component, public ImguiProps
140140
NLOHMANN_DEFINE_TYPE_INTRUSIVE(LightmapSettings, quality, shadows, heightSelectionOnly, rangeX, rangeY);
141141
} lightmapSettings;
142142

143+
class CropSettings
144+
{
145+
public:
146+
bool heightSelectionOnly = true;
147+
int cropLeft = 0;
148+
int cropTop = 0;
149+
int cropRight = 0;
150+
int cropBottom = 0;
151+
} cropSettings;
152+
143153
std::vector<Track> cinematicTracks;
144154
float cinematicLength;
145155

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#include <browedit/BrowEdit.h>
2+
#include <browedit/Map.h>
3+
#include <browedit/Node.h>
4+
#include <browedit/components/Gnd.h>
5+
#include <browedit/components/Rsw.h>
6+
#include <glm/gtc/type_ptr.hpp>
7+
#include <browedit/components/GndRenderer.h>
8+
#include <browedit/components/GatRenderer.h>
9+
#include <browedit/components/RsmRenderer.h>
10+
#include <browedit/components/WaterRenderer.h>
11+
12+
void BrowEdit::showCropSettingsWindow()
13+
{
14+
if (activeMapView == nullptr)
15+
return;
16+
17+
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
18+
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
19+
ImGui::Begin("Crop Settings");
20+
21+
auto gnd = activeMapView->map->rootNode->getComponent<Gnd>();
22+
auto rsw = activeMapView->map->rootNode->getComponent<Rsw>();
23+
24+
if (gnd == nullptr || rsw == nullptr)
25+
return;
26+
27+
auto& settings = rsw->cropSettings;
28+
29+
std::string info = "Current map size: " + std::to_string(gnd->width) + " / " + std::to_string(gnd->height);
30+
ImGui::Text(info.c_str());
31+
ImGui::Checkbox("Height Edit Mode Selection Only", &settings.heightSelectionOnly);
32+
ImGui::DragInt("Crop left", &settings.cropLeft, 1, -gnd->width, gnd->width);
33+
ImGui::DragInt("Crop right", &settings.cropRight, 1, -gnd->width, gnd->width);
34+
ImGui::DragInt("Crop top", &settings.cropTop, 1, -gnd->height, gnd->height);
35+
ImGui::DragInt("Crop bottom", &settings.cropBottom, 1, -gnd->height, gnd->height);
36+
37+
if (ImGui::Button("Crop!"))
38+
{
39+
auto gat = activeMapView->map->rootNode->getComponent<Gat>();
40+
std::vector<std::vector<Gnd::Cube*>> cubes;
41+
std::vector<std::vector<Gat::Cube*>> gatCubes;
42+
glm::ivec2 min(gnd->width, gnd->height);
43+
glm::ivec2 max(0);
44+
45+
if (settings.heightSelectionOnly && activeMapView->map->tileSelection.size() == 0) {
46+
// Nothing selected!
47+
}
48+
else {
49+
auto gndRenderer = activeMapView->map->rootNode->getComponent<GndRenderer>();
50+
glm::ivec2 oldGndSize(gnd->width, gnd->height);
51+
glm::ivec2 oldGatSize(gat->width, gat->height);
52+
53+
if (settings.heightSelectionOnly) {
54+
for (const auto& tile : activeMapView->map->tileSelection)
55+
{ //TODO: can this be done with 2 min calls?
56+
min.x = glm::min(min.x, tile.x);
57+
min.y = glm::min(min.y, tile.y);
58+
max.x = glm::max(max.x, tile.x);
59+
max.y = glm::max(max.y, tile.y);
60+
}
61+
}
62+
else {
63+
min = glm::ivec2(0);
64+
max = glm::ivec2(gnd->width - 1, gnd->height - 1);
65+
66+
min.x += settings.cropLeft;
67+
min.y += settings.cropBottom;
68+
max.x -= settings.cropRight;
69+
max.y -= settings.cropTop;
70+
}
71+
72+
max.x++;
73+
max.y++;
74+
75+
if (min.x < max.x && min.y < max.y) {
76+
glm::vec3 cameraOffset(0);
77+
glm::vec3 rswObjectOffset(0);
78+
79+
cameraOffset.x = min.x * 10.0f;
80+
cameraOffset.z = (gnd->height - max.y) * 10.0f;
81+
82+
rswObjectOffset.x = -min.x * 10.0f + 5 * gnd->width;
83+
rswObjectOffset.z = (gnd->height - max.y) * 10.0f - 5 * gnd->height;
84+
85+
gnd->width = max.x - min.x;
86+
gnd->height = max.y - min.y;
87+
88+
rswObjectOffset.x -= 5 * gnd->width;
89+
rswObjectOffset.z += 5 * gnd->height;
90+
91+
for (int x = min.x; x < max.x; x++)
92+
{
93+
std::vector<Gnd::Cube*> row;
94+
for (int y = min.y; y < max.y; y++)
95+
{
96+
if (x < 0 || x >= oldGndSize.x || y < 0 || y >= oldGndSize.y)
97+
row.push_back(new Gnd::Cube());
98+
else
99+
row.push_back(gnd->cubes[x][y]);
100+
}
101+
cubes.push_back(row);
102+
}
103+
for (int x = min.x * 2; x < max.x * 2; x++)
104+
{
105+
std::vector<Gat::Cube*> row;
106+
for (int y = min.y * 2; y < max.y * 2; y++)
107+
{
108+
if (x < 0 || x >= oldGatSize.x || y < 0 || y >= oldGatSize.y) {
109+
auto gatCube = new Gat::Cube();
110+
gatCube->gatType = 0;
111+
gatCube->normal = glm::vec3(0, -1, 0);
112+
row.push_back(gatCube);
113+
}
114+
else
115+
row.push_back(gat->cubes[x][y]);
116+
}
117+
118+
gatCubes.push_back(row);
119+
}
120+
121+
gnd->cubes = cubes;
122+
gnd->width = glm::max(1, max.x - min.x);
123+
gnd->height = glm::max(1, max.y - min.y);
124+
glm::vec3 newCenterOffset(5 * -gnd->width, 0, 5 * -gnd->height);
125+
126+
if (!settings.heightSelectionOnly && (settings.cropLeft < 0 || settings.cropBottom < 0 || settings.cropRight < 0 || settings.cropTop < 0))
127+
gndRenderer->rebuildChunks();
128+
else
129+
gndRenderer->setChunksDirty();
130+
131+
activeMapView->map->tileSelection.clear();
132+
activeMapView->map->rootNode->getComponent<WaterRenderer>()->setDirty();
133+
134+
gat->cubes = gatCubes;
135+
gat->width = 2 * (max.x - min.x);
136+
gat->height = 2 * (max.y - min.y);
137+
activeMapView->map->rootNode->getComponent<GatRenderer>()->setChunksDirty();
138+
139+
activeMapView->map->rootNode->traverse([&rswObjectOffset](Node* n)
140+
{
141+
auto rsmRenderer = n->getComponent<RsmRenderer>();
142+
if (rsmRenderer) {
143+
rsmRenderer->setDirty();
144+
}
145+
auto rswObject = n->getComponent<RswObject>();
146+
if (rswObject) {
147+
rswObject->position += rswObjectOffset;
148+
}
149+
});
150+
151+
// only moves for left crop or top crop
152+
activeMapView->cameraCenter -= cameraOffset;
153+
154+
auto rsw = activeMapView->map->rootNode->getComponent<Rsw>();
155+
delete rsw->quadtree;
156+
rsw->quadtree = new Rsw::QuadTreeNode(10 * -gnd->width / 2.0f, 10 * -gnd->height / 2.0f, (float)gnd->width * 10 - 1.0f, (float)gnd->height * 10 - 1.0f, 0);
157+
rsw->recalculateQuadtree(nullptr);
158+
}
159+
}
160+
}
161+
162+
ImGui::SameLine();
163+
164+
if (ImGui::Button("Cancel"))
165+
{
166+
windowData.cropWindowVisible = false;
167+
}
168+
169+
ImGui::End();
170+
}

browedit/windows/HeightEditWindow.cpp

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -166,61 +166,9 @@ void BrowEdit::showHeightWindow()
166166

167167
if (ImGui::Button("Crop Map (NO UNDO)", ImVec2(ImGui::GetContentRegionAvailWidth(), 0)))
168168
{
169-
auto gat = activeMapView->map->rootNode->getComponent<Gat>();
170-
std::vector<std::vector<Gnd::Cube*>> cubes;
171-
std::vector<std::vector<Gat::Cube*>> gatCubes;
172-
glm::ivec2 min(gnd->width, gnd->height);
173-
glm::ivec2 max(0);
174-
for (const auto& tile : activeMapView->map->tileSelection)
175-
{ //TODO: can this be done with 2 min calls?
176-
min.x = glm::min(min.x, tile.x);
177-
min.y = glm::min(min.y, tile.y);
178-
max.x = glm::max(max.x, tile.x);
179-
max.y = glm::max(max.y, tile.y);
180-
}
181-
182-
for (int x = min.x; x < max.x; x++)
183-
{
184-
std::vector<Gnd::Cube*> row;
185-
for (int y = min.y; y < max.y; y++)
186-
row.push_back(gnd->cubes[x][y]);
187-
cubes.push_back(row);
188-
}
189-
for (int x = min.x*2; x < max.x*2; x++)
190-
{
191-
std::vector<Gat::Cube*> row;
192-
for (int y = min.y*2; y < max.y*2; y++)
193-
row.push_back(gat->cubes[x][y]);
194-
gatCubes.push_back(row);
195-
}
196-
197-
gnd->cubes = cubes;
198-
gnd->width = max.x - min.x;
199-
gnd->height = max.y - min.y;
200-
gndRenderer->setChunksDirty();
201-
202-
activeMapView->map->tileSelection.clear();
203-
activeMapView->map->rootNode->getComponent<WaterRenderer>()->setDirty();
204-
205-
gat->cubes = gatCubes;
206-
gat->width = 2 * (max.x - min.x);
207-
gat->height = 2 * (max.y - min.y);
208-
activeMapView->map->rootNode->getComponent<GatRenderer>()->setChunksDirty();
209-
210-
activeMapView->map->rootNode->traverse([](Node* n)
211-
{
212-
auto rsmRenderer = n->getComponent<RsmRenderer>();
213-
if (rsmRenderer)
214-
rsmRenderer->setDirty();
215-
});
216-
217-
auto rsw = activeMapView->map->rootNode->getComponent<Rsw>();
218-
delete rsw->quadtree;
219-
rsw->quadtree = new Rsw::QuadTreeNode(-(gnd->width) * 5.0f, -(gnd->height) * 5.0f, gnd->width * 10.0f, gnd->height * 10.0f, 0);
220-
rsw->recalculateQuadtree(nullptr);
169+
windowData.cropWindowVisible = true;
221170
}
222171

223-
224172
if (ImGui::Button("Finish my map with AI", ImVec2(ImGui::GetContentRegionAvailWidth(), 0)))
225173
std::cout << "Coming soon®" << std::endl;
226174
ImGui::TreePop();

0 commit comments

Comments
 (0)