diff --git a/map.cpp b/map.cpp index a6a2158..1a1dc91 100644 --- a/map.cpp +++ b/map.cpp @@ -15,7 +15,8 @@ static std::list entities; static EntityBase *selected_entity = NULL; static EntityBase *to_delete = NULL; static Vec2 offset0(0, 0); -static double cutoff = 1500; +static double cutoff = 1500; +static float bgcolor[3] = {0.0f, 0.0f, 0.0f}; void ui_map() { @@ -32,6 +33,7 @@ void ui_map() { for (EntityBase *e: entities) delete e; entities.clear(); + selected_entity = NULL; std::istringstream is(buf_code); std::string line; @@ -58,8 +60,15 @@ void ui_map() { e = new LevelTransition(); CMD("CAMERA_FOCUS") e = new CameraFocus(); + CMD("FILL_BOX") + e = new FillBox; CMD("CUTOFF") cutoff = strtod(strtok(NULL, " "), NULL); + CMD("BACKGROUND") { + bgcolor[0] = strtof(TOKEN, NULL) / 255.0f; + bgcolor[1] = strtof(TOKEN, NULL) / 255.0f; + bgcolor[2] = strtof(TOKEN, NULL) / 255.0f; + } if (e != NULL) { e->from_strtok(); @@ -106,8 +115,14 @@ void ui_map() { entities.push_back((new CameraFocus())->setpos(center)); selected_entity = entities.back(); } + ig::SameLine(); + if (ig::Button("Fill Box")) { + entities.push_back((new FillBox())->setpos(center)); + selected_entity = entities.back(); + } DragDouble("Cutoff depth", &cutoff); + ImGui::ColorEdit3("Background", bgcolor, ImGuiColorEditFlags_PickerHueWheel); ig::SeparatorText("Entities"); if (ig::Selectable("<<< CLEAR >>>", selected_entity == NULL)) @@ -126,6 +141,10 @@ void ui_map() { } ig::End(); + ImVec2 screen_size = ig::GetIO().DisplaySize; + ImDrawList *drawlist = ig::GetBackgroundDrawList(); + drawlist->AddRectFilled(ImVec2(0, 0), screen_size, ImGui::ColorConvertFloat4ToU32(ImVec4(bgcolor[0], bgcolor[1], bgcolor[2], 1.0f))); + if (ig::Begin("Properities") && selected_entity != NULL) { ig::PushID(selected_entity); selected_entity->imgui(); @@ -133,12 +152,12 @@ void ui_map() { } ig::End(); - ImVec2 screen_size = ig::GetIO().DisplaySize; - ImDrawList *drawlist = ig::GetBackgroundDrawList(); drawlist->AddLine(ImVec2(0, offset.y), ImVec2(screen_size.x, offset.y), IM_COL32_WHITE); drawlist->AddLine(ImVec2(offset.x, 0), ImVec2(offset.x, screen_size.y), IM_COL32_WHITE); drawlist->AddLine(ImVec2(0, cutoff + offset.y), ImVec2(screen_size.x, cutoff + offset.y), IM_COL32(255, 0, 0, 255)); // Draw every entity + for (EntityBase *e: entities) + e->draw_prev(offset, e == selected_entity); for (EntityBase *e: entities) e->draw(offset, e == selected_entity); @@ -146,6 +165,7 @@ void ui_map() { static std::string buff; buff.clear(); buff = "CUTOFF " + std::to_string((int)std::round(cutoff)) + "\n"; + buff += "BACKGROUND " + std::to_string((int)std::round(bgcolor[0] * 255.0f)) + " " + std::to_string((int)std::round(bgcolor[1] * 255.0f)) + " " + std::to_string((int)std::round(bgcolor[2] * 255.0f)) + "\n"; for (EntityBase *e: entities) { buff += e->to_file(); } diff --git a/map_types.hpp b/map_types.hpp index e45b568..776a4e1 100644 --- a/map_types.hpp +++ b/map_types.hpp @@ -19,6 +19,7 @@ public: // Pointer to the entity base is pushed outside virtual void imgui() {} + virtual void draw_prev(Vec2 offset, bool selected) {} virtual void draw(Vec2 offset, bool selected) {} virtual EntityBase *setpos(Vec2 pos) { return this; } }; @@ -312,3 +313,40 @@ public: Box2 box; }; + +class FillBox: public EntityBase { +public: + std::string type() override { return "fill_box"; } + std::string to_file() override { + snprintf(buf, sizeof(buf), "FILL_BOX %.0f %.0f %.0f %.0lf %.0lf %.0lf %.0lf\n", color[0] * 255, color[1] * 255, color[2] * 255, box.lefttop.x, box.lefttop.y, box.size.x, box.size.y); + return buf; + } + void from_strtok() override { + color[0] = TOKEN_DOUBLE / 255.0; + color[1] = TOKEN_DOUBLE / 255.0; + color[2] = TOKEN_DOUBLE / 255.0; + double a, b, c, d; + a = TOKEN_DOUBLE; + b = TOKEN_DOUBLE; + c = TOKEN_DOUBLE; + d = TOKEN_DOUBLE; + box = Box2(a, b, c, d); + } + + void imgui() override { + ig::ColorEdit3("Fill", color, ImGuiColorEditFlags_PickerHueWheel); + DragBox2("", &box); + } + void draw_prev(Vec2 offset, bool selected) override { + ImDrawList *d = ig::GetBackgroundDrawList(); + Box2 world = box.offset(offset); + d->AddRectFilled(world.lefttop.im(), (world.lefttop + world.size).im(), ImColor(color[0], color[1], color[2])); + } + EntityBase *setpos(Vec2 pos) override { + box.lefttop = pos; + return this; + } + + Box2 box; + float color[3]; +};