Try again

This commit is contained in:
2025-05-13 21:55:58 -05:00
parent cca04a3594
commit cbf105266d

View File

@@ -21,13 +21,16 @@ public:
JGL::Texture* test_tilesheet;
int grid_pixel_width = 32;
int grid_pixel_height = 32;
int grid_pixel_width = 16;
int grid_pixel_height = 16;
int grid_rows = 32;
int grid_cols = 32;
int tileset_width = 420;
int tileset_height = 420;
int grid[32][32];
int grid_rows = 128;
int grid_cols = 128;
int grid[128][128];
int selected_quad = 0;
@@ -41,9 +44,9 @@ public:
std::vector<Quad> quads;
void PopulateQuads() {
quads.reserve(24);
for (int i = 0; i < 24; i++) {
Vector2i cell = IndexToCell(i, 16);
quads.reserve(tileset_width*tileset_height);
for (int i = 0; i < tileset_width*tileset_height; i++) {
Vector2i cell = IndexToCell(i, tileset_width);
quads[i] = Quad{cell.x*grid_pixel_width, cell.y*grid_pixel_height, grid_pixel_width, grid_pixel_height};
}
}
@@ -59,14 +62,24 @@ public:
return cell.y*width + cell.x;
}
EditorApp() : OpenGLWindow("Editor App", 1080, 768, GL_VER_MAJOR, GL_VER_MINOR) {
PopulateQuads();
EditorApp() : OpenGLWindow("Editor App", 1770, 768, GL_VER_MAJOR, GL_VER_MINOR) {
}
void LoadMisc() {
test_tilesheet = new JGL::Texture("../megacommando.png");
auto texture_size = test_tilesheet->GetDimensions();
tileset_width = texture_size.x / grid_pixel_width;
tileset_height = texture_size.y / grid_pixel_height;
PopulateQuads();
for (int x = 0; x < grid_rows; x++) {
for (int y = 0; y < grid_cols; y++) {
}
}
}
@@ -95,7 +108,7 @@ public:
overlay->ZIndex(2);
cell_indicator = new JUI::Rect(wind->Content());
cell_indicator->Size(UDim2::FromPixels(32, 32));
cell_indicator->Size(UDim2::FromPixels(grid_pixel_width, grid_pixel_height));
cell_indicator->BorderMode(JUI::BorderMode::Outline);
cell_indicator->BGColor(Colors::Transparent);
cell_indicator->BorderColor(Colors::Blues::CornflowerBlue);
@@ -210,12 +223,18 @@ public:
Vector2 rel_mouse = Vector2(GetTilesetCellFromMouse());
rel_mouse *= 32;
rel_mouse.x *= grid_pixel_width;
rel_mouse.y *= grid_pixel_height;
cell_indicator->Position(JUI::UDim2::FromPixels(rel_mouse.x, rel_mouse.y));
} else {
cell_indicator->Visible(false);
if (IsMouseButtonDown(MouseButtons::Left)) {
Vector2i grid_cell = GetGridCellFromMouse();
grid[grid_cell.x][grid_cell.y] = selected_quad;
}
}
}
@@ -305,14 +324,10 @@ public:
if (scene->ObserveMouseInput(btn, false)) return;
if (tileset_viewer->Content()->IsMouseInside()) {
} else {
Vector2i cell = GetTilesetCellFromMouse();
int index = CellToIndex(cell, 16);
int index = CellToIndex(cell, tileset_width);
selected_quad = index;
Vector2i grid_cell = GetGridCellFromMouse();
grid[grid_cell.x][grid_cell.y] = index;
}
// TODO: This always runs even if we release the mouse inside the window. ObserveMouseInput should handle the case.
}