Refactoring, load and save levels from console-command.
This commit is contained in:
@@ -157,6 +157,9 @@ public:
|
||||
/// Saves the current editor's data to test.lvl.
|
||||
/// @note Placeholder until FileDialogs are added.
|
||||
void SaveCurrentLevel() const;
|
||||
|
||||
void SaveCurrentLevelAs(const std::string &filename) const;
|
||||
|
||||
void LoadLevel(const std::filesystem::path& level_meta_path);
|
||||
void CreateTestLevel();
|
||||
|
||||
@@ -178,7 +181,9 @@ public:
|
||||
|
||||
bool Open() override;
|
||||
|
||||
Vector2i GetTilesetCellFromMouse();
|
||||
Vector2 GetMouseV2() const;
|
||||
|
||||
Vector2i GetMouseV2i() const;
|
||||
|
||||
Vector2i GetGridCellFromMouse();
|
||||
|
||||
|
@@ -33,13 +33,11 @@ public:
|
||||
}
|
||||
void UpdateComponents(const Level* level)
|
||||
{
|
||||
|
||||
|
||||
|
||||
for (auto entry : entry_elements) {
|
||||
entry->Parent(nullptr);
|
||||
delete entry;
|
||||
}
|
||||
|
||||
entry_elements.clear();
|
||||
|
||||
for (auto layer : level->layers)
|
||||
|
@@ -4,7 +4,12 @@
|
||||
|
||||
class TilesetView : public JUI::Window {
|
||||
public:
|
||||
int tileset_width;
|
||||
int tileset_height;
|
||||
Tileset* stored_tileset;
|
||||
Texture* stored_texture;
|
||||
Event<int> TileSelected;
|
||||
bool is_focusing;
|
||||
TilesetView() : JUI::Window() {
|
||||
Title("Tileset View");
|
||||
|
||||
@@ -18,10 +23,13 @@ public:
|
||||
}
|
||||
|
||||
TilesetView(Tileset* tileset, JGL::Texture* texture) {
|
||||
|
||||
stored_tileset = tileset;
|
||||
stored_texture = texture;
|
||||
|
||||
Title(std::format("Tileset View : {}", tileset->name));
|
||||
Size(JUI::UDim2::FromPixels(texture->GetDimensions().x, texture->GetDimensions().y));
|
||||
|
||||
|
||||
auto grid_overlay_target = new JGL::RenderTarget(texture->GetDimensions());
|
||||
J2D::Begin(grid_overlay_target);
|
||||
AABB2D aabb({0,0}, Vector2(texture->GetDimensions()));
|
||||
@@ -34,7 +42,12 @@ public:
|
||||
overlay->Content(grid_overlay);
|
||||
overlay->ZIndex(2);
|
||||
|
||||
//cell_indicator = new JUI::Rect(Content());
|
||||
cell_indicator = new JUI::Rect(Content());
|
||||
cell_indicator->BorderMode(JUI::BorderMode::Outline);
|
||||
cell_indicator->BorderColor(Colors::Blues::CornflowerBlue);
|
||||
cell_indicator->BorderWidth(2);
|
||||
|
||||
SetCellSizeIndicatorToTilesetSize();
|
||||
}
|
||||
TilesetView(Widget* parent) {
|
||||
Parent(parent);
|
||||
@@ -42,9 +55,71 @@ public:
|
||||
TilesetView(Tileset* tileset, JGL::Texture* texture, Widget* parent) : TilesetView(tileset, texture) {
|
||||
Parent(parent);
|
||||
}
|
||||
|
||||
Vector2i GetTilesetCell(const Vector2& pos) {
|
||||
|
||||
}
|
||||
|
||||
Vector2i GetTilesetCellFromMouse(const Vector2& mouse) {
|
||||
Vector2 rel = Content()->GetAbsolutePosition();
|
||||
|
||||
Vector2 rel_mouse = mouse - rel;
|
||||
|
||||
return Vector2i(
|
||||
Math::Floor(rel_mouse.x/stored_tileset->tile_width),
|
||||
Math::Floor(rel_mouse.y/stored_tileset->tile_height));
|
||||
}
|
||||
|
||||
|
||||
void SetCellSizeIndicatorToTilesetSize() {
|
||||
cell_indicator->Size(JUI::UDim2::FromPixels(stored_tileset->tile_width, stored_tileset->tile_height));
|
||||
}
|
||||
|
||||
void UpdateCellIndicator(float elapsed) {
|
||||
if (IsMouseInside() && Content()->IsMouseInside()) {
|
||||
is_focusing = true;
|
||||
cell_indicator->Visible(true);
|
||||
|
||||
Vector2 rel = Vector2(GetTilesetCellFromMouse(last_known_mouse_pos));
|
||||
|
||||
rel.x = tileset_width;
|
||||
rel.y = tileset_height;
|
||||
|
||||
|
||||
cell_indicator->Position(JUI::UDim2::FromPixels(rel.x, rel.y));
|
||||
} else {
|
||||
cell_indicator->Visible(false);
|
||||
is_focusing = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ObserveMouseInput(JUI::MouseButton btn, bool pressed) override {
|
||||
if (pressed == false) {
|
||||
if (btn == JUI::MouseButton::Left) {
|
||||
if (Content()->IsMouseInside()) {
|
||||
Vector2i cell = GetTilesetCellFromMouse(last_known_mouse_pos);
|
||||
int index = CellToIndex(cell, stored_tileset->rows);
|
||||
TileSelected.Invoke(index);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IsFocusing() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Update(float delta) override {
|
||||
Window::Update(delta);
|
||||
UpdateCellIndicator(delta);
|
||||
}
|
||||
|
||||
protected:
|
||||
JUI::Image* tilesheet;
|
||||
JGL::Texture* grid_overlay;
|
||||
JUI::Image* tilesheet = nullptr;
|
||||
JGL::Texture* grid_overlay = nullptr;
|
||||
JUI::Rect* cell_indicator = nullptr;
|
||||
protected:
|
||||
Color4 grid_overlay_color = {255, 255, 255, 64};
|
||||
Color4 cell_pointer_outline_color = Colors::Blues::LightSteelBlue;
|
||||
|
@@ -45,3 +45,6 @@ template <> inline void Lerped<Vector2>::Step(float elapsed) { current = Vector2
|
||||
|
||||
std::string read_file_contents(const std::filesystem::path& file_path);
|
||||
bool write_file_contents(const std::filesystem::path& file_path, const std::string& contents);
|
||||
|
||||
std::vector<std::string> split (const std::string &s, char delim);
|
||||
|
||||
|
Reference in New Issue
Block a user