mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 06:55:02 +01:00
Add brush mode randomisation
This commit is contained in:
@@ -68,6 +68,12 @@ bool editor_mode::update()
|
||||
Console::Update(); // to i tak trzeba wywoływać
|
||||
#endif
|
||||
m_userinterface->update();
|
||||
|
||||
// brush settings window
|
||||
editor_ui *ui = static_cast<editor_ui *>(m_userinterface.get());
|
||||
auto const mode = static_cast<editor_ui *>(m_userinterface.get())->mode();
|
||||
ui->toggleBrushSettings(mode == nodebank_panel::BRUSH);
|
||||
|
||||
if (mouseHold)
|
||||
{
|
||||
auto const mode = static_cast<editor_ui *>(m_userinterface.get())->mode();
|
||||
@@ -83,7 +89,9 @@ bool editor_mode::update()
|
||||
|
||||
if (mode == nodebank_panel::BRUSH)
|
||||
{
|
||||
|
||||
const std::string *src = ui->get_active_node_template();
|
||||
|
||||
// std::string name = "editor_" + std::to_string(LocalRandom(0.0, 100000.0));
|
||||
std::string name = "editor_" + generate_uuid_v4();
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ editor_ui::editor_ui()
|
||||
add_external_panel(&m_itempropertiespanel);
|
||||
add_external_panel(&m_nodebankpanel);
|
||||
add_external_panel(&m_functionspanel);
|
||||
add_external_panel(&m_brushobjects);
|
||||
}
|
||||
|
||||
// updates state of UI elements
|
||||
@@ -41,6 +42,16 @@ void editor_ui::update()
|
||||
ui_layer::update();
|
||||
m_itempropertiespanel.update(m_node);
|
||||
m_functionspanel.update(m_node);
|
||||
|
||||
auto ptr = get_active_node_template(true);
|
||||
if (ptr)
|
||||
m_brushobjects.update(*ptr);
|
||||
}
|
||||
|
||||
void editor_ui::toggleBrushSettings(bool isVisible)
|
||||
{
|
||||
if (m_brushobjects.is_open != isVisible)
|
||||
m_brushobjects.is_open = isVisible;
|
||||
}
|
||||
|
||||
void editor_ui::set_node(scene::basic_node *Node)
|
||||
@@ -53,8 +64,12 @@ void editor_ui::add_node_template(const std::string &desc)
|
||||
m_nodebankpanel.add_template(desc);
|
||||
}
|
||||
|
||||
std::string const *editor_ui::get_active_node_template()
|
||||
std::string const *editor_ui::get_active_node_template(bool bypassRandom)
|
||||
{
|
||||
if (!bypassRandom && m_brushobjects.is_open && m_brushobjects.useRandom && m_brushobjects.Objects.size() > 0)
|
||||
{
|
||||
return m_brushobjects.GetRandomObject();
|
||||
}
|
||||
return m_nodebankpanel.get_active_template();
|
||||
}
|
||||
|
||||
@@ -64,7 +79,7 @@ nodebank_panel::edit_mode editor_ui::mode()
|
||||
}
|
||||
float editor_ui::getSpacing()
|
||||
{
|
||||
return m_nodebankpanel.spacing;
|
||||
return m_brushobjects.spacing;
|
||||
}
|
||||
|
||||
functions_panel::rotation_mode editor_ui::rot_mode()
|
||||
|
||||
@@ -33,14 +33,16 @@ class editor_ui : public ui_layer
|
||||
float rot_val();
|
||||
bool rot_from_last();
|
||||
functions_panel::rotation_mode rot_mode();
|
||||
const std::string *get_active_node_template();
|
||||
const std::string *get_active_node_template(bool bypassRandom = false);
|
||||
nodebank_panel::edit_mode mode();
|
||||
float getSpacing();
|
||||
void toggleBrushSettings(bool isVisible);
|
||||
|
||||
private:
|
||||
// members
|
||||
itemproperties_panel m_itempropertiespanel{"Node Properties", true};
|
||||
functions_panel m_functionspanel{"Functions", true};
|
||||
nodebank_panel m_nodebankpanel{"Node Bank", true};
|
||||
brush_object_list m_brushobjects{"Brush properties", false};
|
||||
scene::basic_node *m_node{nullptr}; // currently bound scene node, if any
|
||||
};
|
||||
|
||||
@@ -322,6 +322,75 @@ bool itemproperties_panel::render_group()
|
||||
return true;
|
||||
}
|
||||
|
||||
brush_object_list::brush_object_list(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen)
|
||||
{
|
||||
size_min = {50, 100};
|
||||
size_max = {1000, 500};
|
||||
}
|
||||
|
||||
bool brush_object_list::VectorGetter(void *data, int idx, const char **out_text)
|
||||
{
|
||||
auto *vec = static_cast<std::vector<std::string> *>(data);
|
||||
|
||||
if (idx < 0 || idx >= vec->size())
|
||||
return false;
|
||||
|
||||
*out_text = (*vec)[idx].c_str();
|
||||
return true;
|
||||
}
|
||||
|
||||
void brush_object_list::update(std::string nodeTemplate)
|
||||
{
|
||||
Template = nodeTemplate;
|
||||
}
|
||||
std::string *brush_object_list::GetRandomObject()
|
||||
{
|
||||
static std::string empty; // fallback
|
||||
|
||||
if (Objects.empty())
|
||||
return ∅
|
||||
|
||||
static std::mt19937 rng{std::random_device{}()};
|
||||
std::uniform_int_distribution<size_t> dist(0, Objects.size() - 1);
|
||||
|
||||
return &Objects[dist(rng)];
|
||||
}
|
||||
|
||||
void brush_object_list::render()
|
||||
{
|
||||
if (false == is_open)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto flags = ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoCollapse | (size.x > 0 ? ImGuiWindowFlags_NoResize : 0);
|
||||
if (ImGui::Begin("Brush random set", nullptr, flags))
|
||||
{
|
||||
ImGui::SliderFloat("Spacing", &spacing, 0.1f, 20.0f, "%.1f m");
|
||||
ImGui::Checkbox("Enable brush random from set", &useRandom);
|
||||
if (useRandom)
|
||||
{
|
||||
ImGui::Text("Set of objects to choose from:");
|
||||
ImGui::ListBox("", &idx, VectorGetter, (void *)&Objects, Objects.size(), 6);
|
||||
if (ImGui::Button("Add"))
|
||||
{
|
||||
if (!Template.empty())
|
||||
Objects.push_back(Template);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Remove") && idx >= 0 && idx < Objects.size())
|
||||
{
|
||||
Objects.erase(Objects.begin() + idx);
|
||||
}
|
||||
if (ImGui::Button("Remove all") && idx >= 0 && idx < Objects.size())
|
||||
{
|
||||
Objects.clear();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
nodebank_panel::nodebank_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen)
|
||||
{
|
||||
size_min = {100, 50};
|
||||
@@ -386,7 +455,6 @@ void nodebank_panel::nodebank_reload()
|
||||
|
||||
void nodebank_panel::render()
|
||||
{
|
||||
|
||||
if (false == is_open)
|
||||
{
|
||||
return;
|
||||
@@ -422,7 +490,7 @@ void nodebank_panel::render()
|
||||
|
||||
if (mode == BRUSH)
|
||||
{
|
||||
ImGui::SliderFloat("Spacing", &spacing, 0.1f, 20.0f, "%.1f m");
|
||||
// ImGui::SliderFloat("Spacing", &spacing, 0.1f, 20.0f, "%.1f m");
|
||||
}
|
||||
|
||||
ImGui::PushItemWidth(-1);
|
||||
|
||||
@@ -47,6 +47,25 @@ class itemproperties_panel : public ui_panel
|
||||
std::vector<text_line> m_grouplines;
|
||||
};
|
||||
|
||||
class brush_object_list : public ui_panel
|
||||
{
|
||||
private:
|
||||
int idx;
|
||||
static bool VectorGetter(void *data, int idx, const char **out_text);
|
||||
std::string Template;
|
||||
|
||||
public:
|
||||
brush_object_list(std::string const &Name, bool const Isopen);
|
||||
void render() override;
|
||||
void update(std::string nodeTemplate);
|
||||
|
||||
// class use
|
||||
std::vector<std::string> Objects;
|
||||
std::string *GetRandomObject();
|
||||
bool useRandom = {false};
|
||||
float spacing{1.0f};
|
||||
};
|
||||
|
||||
class nodebank_panel : public ui_panel
|
||||
{
|
||||
|
||||
@@ -60,8 +79,6 @@ class nodebank_panel : public ui_panel
|
||||
};
|
||||
edit_mode mode = MODIFY;
|
||||
|
||||
float spacing{1.0f};
|
||||
|
||||
nodebank_panel(std::string const &Name, bool const Isopen);
|
||||
void nodebank_reload();
|
||||
void render() override;
|
||||
|
||||
Reference in New Issue
Block a user