From f7455f44518d36cc688f915e5d6cc046eaa65896 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 17 May 2025 23:12:46 -0700 Subject: X-macro and palette editing menu --- src/ui.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'src/ui.cpp') diff --git a/src/ui.cpp b/src/ui.cpp index f870a24..64a8a91 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -71,6 +71,32 @@ enum BrushType_ { BrushType_Circle, }; +static const char* TILE_NAMES = +#define X(_0, str, _2) str "\0" +#include "x/tile_types.inc" +#undef X + ; + +static const char* FLUID_NAMES = +#define X(_0, str, _2) str "\0" +#include "x/fluid_types.inc" +#undef X + ; + +static void edit_tile_palette(Tile& palette) { + int tile = palette.so; + ImGui::Combo("Tile", &tile, TILE_NAMES); + palette.so = static_cast(tile); + + int fluid = palette.fl; + ImGui::Combo("Fluid", &fluid, FLUID_NAMES); + palette.fl = static_cast(fluid); + + int fmass = palette.fmass; + ImGui::InputInt("Fluid mass", &fmass, 1); + palette.fmass = std::clamp(fmass, 1, 255); +} + static void paint_sand(Sandbox& sb, const Tile& palette, Pt pt, BrushType type, int size) { switch (type) { case BrushType_Box: { @@ -142,15 +168,21 @@ void ShowEverything() { ImGui::SameLine(); bool step = ImGui::Button("Step"); - static Tile palette{ .so = Tile::SAND }; + static Tile palette{ .so = Tile::Ti_Sand }; static int brush_size = 1; static BrushType brush_type = BrushType_Box; - ImGui::SliderInt("Brush radius", &brush_size, 1, 20); - ImGui::Combo("Brush type", - &brush_type, - "Box\0" - "Circle"); + if (ImGui::CollapsingHeader("Palette")) { + edit_tile_palette(palette); + } + + if (ImGui::CollapsingHeader("Brush")) { + ImGui::SliderInt("Brush radius", &brush_size, 1, 20); + ImGui::Combo("Brush type", + &brush_type, + "Box\0" + "Circle"); + } ImGui::End(); -- cgit v1.2.3-70-g09d2