Building core system & layout.
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
#include <ReWindow/types/Window.h>
|
||||
|
||||
#include "JGL/JGL.h"
|
||||
#include "JUI/Widgets/Image.hpp"
|
||||
#include "JUI/Widgets/Scene.hpp"
|
||||
#include "JUI/Widgets/UtilityBar.hpp"
|
||||
#include "JUI/Widgets/Window.hpp"
|
||||
|
||||
#define GL_VER_MAJOR 2
|
||||
#define GL_VER_MINOR 1
|
||||
@@ -14,18 +16,65 @@ using namespace JUI::UDimLiterals;
|
||||
class EditorApp : public OpenGLWindow {
|
||||
public:
|
||||
JUI::Scene* scene;
|
||||
JUI::Window* tileset_viewer;
|
||||
JUI::Rect* cell_indicator;
|
||||
JGL::Texture* test_tilesheet;
|
||||
|
||||
|
||||
int grid_pixel_width = 32;
|
||||
int grid_pixel_height = 32;
|
||||
|
||||
int grid[16][16];
|
||||
|
||||
EditorApp() : OpenGLWindow("Editor App", 1080, 768, GL_VER_MAJOR, GL_VER_MINOR) {
|
||||
|
||||
}
|
||||
|
||||
void LoadMisc() {
|
||||
test_tilesheet = new JGL::Texture("../platformer-tileset-template.png");
|
||||
}
|
||||
|
||||
|
||||
JUI::Window* CreateTilesetViewerWindow(JUI::Widget* parent) {
|
||||
using namespace JUI;
|
||||
|
||||
auto* wind = new Window(parent);
|
||||
wind->SetTitle("Tileset Viewer");
|
||||
wind->Size(JUI::UDim2::FromPixels(test_tilesheet->GetDimensions().x, test_tilesheet->GetDimensions().y+20));
|
||||
wind->SetResizable(false);
|
||||
|
||||
auto* img = new Image(wind->Content());
|
||||
img->Content(test_tilesheet);
|
||||
img->FitImageToParent(false);
|
||||
|
||||
auto* grid_overlay = new JGL::RenderTarget(test_tilesheet->GetDimensions());
|
||||
J2D::Begin(grid_overlay);
|
||||
DrawGrid(AABB2D({0,0}, Vector2(test_tilesheet->GetDimensions())), Colors::White);
|
||||
J2D::End();
|
||||
|
||||
auto* grid_overlay_tex = new JGL::Texture(*grid_overlay->GetTexture());
|
||||
|
||||
|
||||
auto* overlay = new JUI::Image(wind->Content());
|
||||
overlay->Content(grid_overlay_tex);
|
||||
overlay->ZIndex(2);
|
||||
|
||||
cell_indicator = new JUI::Rect(wind->Content());
|
||||
cell_indicator->Size(UDim2::FromPixels(32, 32));
|
||||
cell_indicator->BorderMode(JUI::BorderMode::Outline);
|
||||
cell_indicator->BGColor(Colors::Transparent);
|
||||
cell_indicator->BorderColor(Colors::Blues::CornflowerBlue);
|
||||
cell_indicator->BorderWidth(2);
|
||||
|
||||
|
||||
return wind;
|
||||
}
|
||||
|
||||
void CreateWidgets() {
|
||||
scene = new JUI::Scene();
|
||||
|
||||
|
||||
auto* topbar = new JUI::UtilityBar(scene);
|
||||
|
||||
|
||||
auto* file = topbar->AddSubmenu("File");
|
||||
file->SetFont(JGL::Fonts::Jupiteroid);
|
||||
file->AddButton("New");
|
||||
@@ -60,7 +109,7 @@ public:
|
||||
layer->AddButton("Export Layer");
|
||||
|
||||
|
||||
|
||||
tileset_viewer = CreateTilesetViewerWindow(scene);
|
||||
|
||||
}
|
||||
|
||||
@@ -81,6 +130,7 @@ public:
|
||||
// TODO: Delete when we update to the next release of JGL
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // NOTE: This MUST be called for text rendering to work properly!!!
|
||||
|
||||
LoadMisc();
|
||||
CreateWidgets();
|
||||
|
||||
return true;
|
||||
@@ -94,6 +144,57 @@ public:
|
||||
JGL::Update(vSize);
|
||||
scene->SetViewportSize(Vector2(vSize));
|
||||
scene->Update(elapsed);
|
||||
|
||||
auto maus = GetMouseCoordinates();
|
||||
|
||||
Vector2 mouse_v2(maus.x, maus.y);
|
||||
|
||||
if (tileset_viewer->IsMouseInside()) {
|
||||
cell_indicator->Visible(true);
|
||||
|
||||
Vector2 rel = tileset_viewer->Content()->GetAbsolutePosition();
|
||||
|
||||
Vector2 rel_mouse = mouse_v2 - rel;
|
||||
|
||||
rel_mouse = Vector2(
|
||||
Math::Floor(rel_mouse.x/32)*32,
|
||||
Math::Floor(rel_mouse.y/32)*32
|
||||
);
|
||||
|
||||
cell_indicator->Position(JUI::UDim2::FromPixels(rel_mouse.x, rel_mouse.y));
|
||||
|
||||
} else {
|
||||
cell_indicator->Visible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DrawGrid(const AABB2D& bounds, const Color4& color) {
|
||||
Vector2 viewport_topleft = bounds.minPoint;
|
||||
Vector2 viewport_bottomright = bounds.maxPoint;
|
||||
|
||||
int nearest_grid_left = Math::Floor(viewport_topleft.x / grid_pixel_width);
|
||||
int nearest_grid_right = Math::Floor(viewport_bottomright.x / grid_pixel_width);
|
||||
for (int x = nearest_grid_left; x <= nearest_grid_right; x++) {
|
||||
auto top = Vector2(x * grid_pixel_width, viewport_topleft.y);
|
||||
auto bottom = Vector2(x * grid_pixel_width, viewport_bottomright.y);
|
||||
JGL::J2D::DrawDashedLine(color, top, bottom, 4, 4, 1 / bounds.Width());
|
||||
}
|
||||
int nearest_grid_top = Math::Floor(viewport_topleft.y / grid_pixel_height);
|
||||
int nearest_grid_bottom = Math::Floor(viewport_bottomright.y / grid_pixel_height);
|
||||
for (int y = nearest_grid_top; y <= nearest_grid_bottom; y++) {
|
||||
auto left = Vector2(viewport_topleft.x, y * grid_pixel_height);
|
||||
auto right = Vector2(viewport_bottomright.x, y * grid_pixel_height);
|
||||
JGL::J2D::DrawDashedLine(color, left, right, 4, 4, 1 / bounds.Height());
|
||||
}
|
||||
}
|
||||
void DrawGrid(const Color4& color = {255,255,255,128}) {
|
||||
|
||||
float sw = GetWidth();
|
||||
float sh = GetHeight();
|
||||
|
||||
DrawGrid({{0,0}, {sw, sh}}, color);
|
||||
}
|
||||
|
||||
void Draw() {
|
||||
@@ -103,7 +204,8 @@ public:
|
||||
|
||||
|
||||
J2D::Begin();
|
||||
|
||||
J2D::DrawSprite(test_tilesheet, {32, 32}, 0, Vector2::Zero, Vector2::One, Colors::White);
|
||||
DrawGrid();
|
||||
J2D::End();
|
||||
|
||||
scene->Draw();
|
||||
|
@@ -1,8 +1,14 @@
|
||||
//
|
||||
// Created by dawsh on 5/12/25.
|
||||
//
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#ifndef LEVEL_HPP
|
||||
#define LEVEL_HPP
|
||||
class Level {
|
||||
public:
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string author;
|
||||
std::vector<std::string> tags;
|
||||
|
||||
#endif //LEVEL_HPP
|
||||
std::vector<TileLayer> tile_layers;
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
9
include/Tilesheet.hpp
Normal file
9
include/Tilesheet.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
/// A Texture atlas that maps to a series of unique tiles with associated metadata.
|
||||
class Tilesheet {
|
||||
public:
|
||||
Tilesheet(JGL::Texture* texture, int tile_width, int tile_height) {
|
||||
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user