diff --git a/editor.conf.example b/editor.conf.example index 968bfcc..651c1b7 100644 --- a/editor.conf.example +++ b/editor.conf.example @@ -5,6 +5,9 @@ snapping = true # limiting stops node boxes going out of node bounds limiting = true +# If true, positions in nodebox properties are shown as multiples of 1/16 +fractional_positions = false + # Directory to save projects and export to. # Should be absolute path. save_directory = @@ -14,7 +17,7 @@ save_directory = # c://Games/Minetest/ # /home/rubenwardy/Game/Minetest/ # Do not include bin/minetest or bin/minetest.exe in the root. -minetest_root = +minetest_root = # The view of each viewport # can be: pers, front, back, top, bottom, left, right diff --git a/src/GUIHelpers.cpp b/src/GUIHelpers.cpp index 3ee256d..a62586c 100644 --- a/src/GUIHelpers.cpp +++ b/src/GUIHelpers.cpp @@ -41,6 +41,6 @@ void addBox(IGUIElement* parent, IGUIEnvironment* guienv, vector2di pos, int ind void addXYZ(IGUIElement* parent,IGUIEnvironment* guienv, vector2di pos, int startIndex){ addBox(parent, guienv, vector2di(pos.X, pos.Y), startIndex, L"X"); // 0,0 - addBox(parent, guienv, vector2di(pos.X, pos.Y + 30), startIndex + 1, L"Y"); // 80, 0 - addBox(parent, guienv, vector2di(pos.X, pos.Y + 60), startIndex + 2, L"Z"); // 160, 0 + addBox(parent, guienv, vector2di(pos.X, pos.Y + 25), startIndex + 1, L"Y"); // 80, 0 + addBox(parent, guienv, vector2di(pos.X, pos.Y + 50), startIndex + 2, L"Z"); // 160, 0 } diff --git a/src/main.cpp b/src/main.cpp index 6480afa..c820c4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,6 +88,7 @@ int main(int argc, char *argv[]) { } conf->set("snapping", "true"); conf->set("limiting", "true"); + conf->set("fractional_positions", "false"); conf->set("driver", "opengl"); conf->set("hide_sidebar", "false"); conf->set("save_directory", ""); diff --git a/src/modes/NBEditor.cpp b/src/modes/NBEditor.cpp index 831c09b..0e87018 100644 --- a/src/modes/NBEditor.cpp +++ b/src/modes/NBEditor.cpp @@ -19,6 +19,7 @@ enum NODEBOX_EDITOR_GUI_IDS { ENB_GUI_PROP_Y2, ENB_GUI_PROP_Z2, ENB_GUI_PROP_NAME, + ENB_GUI_PROP_DECIMALS, ENB_GUI_PROP_UPDATE, ENB_GUI_PROP_REVERT, ENB_GUI_FLP_X, @@ -128,13 +129,19 @@ void NBEditor::load() // Add positioning addXYZ(t, guienv, vector2di(10, 60), ENB_GUI_PROP_X1); - addXYZ(t, guienv, vector2di(10, 160), ENB_GUI_PROP_X2); // 60 + addXYZ(t, guienv, vector2di(10, 140), ENB_GUI_PROP_X2); + + // Add show decimals checkbox + bool fp = state->settings->getBool("fractional_positions"); + guienv->addCheckBox(fp, rect(30, 215, 200, 245), t, + ENB_GUI_PROP_DECIMALS, L"As fractions of 16")->setNotClipped(true); // Add buttons - guienv->addButton(rect(30, 250, 100, 280), t, ENB_GUI_PROP_UPDATE, + guienv->addButton(rect(30, 250, 100, 250+30), t, ENB_GUI_PROP_UPDATE, L"Update", L"")->setNotClipped(true); - guienv->addButton(rect(110, 250, 180, 280), t, ENB_GUI_PROP_REVERT, + guienv->addButton(rect(110, 250, 180, 250+30), t, ENB_GUI_PROP_REVERT, L"Revert", L"")->setNotClipped(true); + } load_ui(); } @@ -179,23 +186,30 @@ void NBEditor::fillProperties() IGUIStaticText *sidebar = state->menu->sidebar; Node *node = state->project->GetCurrentNode(); - if (!sidebar || !node) { + if (!sidebar || !node) return; - } NodeBox *nb = node->GetCurrentNodeBox(); - if (!nb) { + if (!nb) return; - } sidebar->getElementFromId(ENB_GUI_PROP)->setVisible(true); - fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_X1, nb->one.X); - fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Y1, nb->one.Y); - fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Z1, nb->one.Z); - fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_X2, nb->two.X); - fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Y2, nb->two.Y); - fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Z2, nb->two.Z); + + vector3df one = nb->one; + vector3df two = nb->two; + + if (state->settings->getBool("fractional_positions")) { + one *= 16; + two *= 16; + } + + fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_X1, one.X); + fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Y1, one.Y); + fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Z1, one.Z); + fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_X2, two.X); + fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Y2, two.Y); + fillTB(sidebar, ENB_GUI_PROP, ENB_GUI_PROP_Z2, two.Z); IGUIElement* element = sidebar->getElementFromId(ENB_GUI_PROP) ->getElementFromId(ENB_GUI_PROP_NAME); @@ -346,8 +360,8 @@ void CDR::update(NBEditor* editor, bool drag, rect offset) // Snapping wpos -= vector3df( - (f32)node->position.X, - (f32)node->position.Y, + (f32)node->position.X, + (f32)node->position.Y, (f32)node->position.Z ); @@ -382,6 +396,7 @@ void CDR::update(NBEditor* editor, bool drag, rect offset) } // Call required function + editor->fillProperties(); if (actualType < CDR_XZ) { box->resizeNodeBoxFace(editor->state, actualType, wpos, editor->state->keys[KEY_LCONTROL] == EKS_DOWN); @@ -435,7 +450,16 @@ void CDR::update(NBEditor* editor, bool drag, rect offset) bool NBEditor::OnEvent(const irr::SEvent &event) { if (event.EventType == EET_GUI_EVENT) { - if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) { + if (event.GUIEvent.EventType == EGET_CHECKBOX_CHANGED) { + switch (event.GUIEvent.Caller->getID()) { + case ENB_GUI_PROP_DECIMALS: { + bool fp = state->settings->getBool("fractional_positions"); + state->settings->set("fractional_positions", + fp?"false":"true"); + fillProperties(); + return true; + }} + } else if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) { switch (event.GUIEvent.Caller->getID()) { case GUI_PROJ_NEW_BOX: { Node* node = state->project->GetCurrentNode(); @@ -579,16 +603,27 @@ void NBEditor::updateProperties() try { irr::core::stringc name = prop->getElementFromId(ENB_GUI_PROP_NAME)->getText(); nb->name = str_replace(std::string(name.c_str(), name.size()), ' ', '_'); - nb->one = vector3df( - (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_X1)->getText(), NULL), - (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_Y1)->getText(), NULL), + vector3df one( + (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_X1)->getText(), NULL), + (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_Y1)->getText(), NULL), (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_Z1)->getText(), NULL) ); - nb->two = vector3df( - (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_X2)->getText(), NULL), - (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_Y2)->getText(), NULL), + vector3df two( + (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_X2)->getText(), NULL), + (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_Y2)->getText(), NULL), (f32)wcstod(prop->getElementFromId(ENB_GUI_PROP_Z2)->getText(), NULL) ); + + if (state->settings->getBool("fractional_positions")) { + one /= 16; + two /= 16; + } + + if (one != nb->one || two != nb->two) { + nb->one = one; + nb->two = two; + nb->rebuild_needed = true; + } node->remesh(); load_ui(); } catch(void* e) { diff --git a/src/modes/NBEditor.hpp b/src/modes/NBEditor.hpp index 63e7297..a40c0dc 100644 --- a/src/modes/NBEditor.hpp +++ b/src/modes/NBEditor.hpp @@ -5,7 +5,6 @@ class EditorState; class NBEditor; - class CDR { public: @@ -24,6 +23,7 @@ public: class EditorMode; class NBEditor :public EditorMode { + friend class CDR; public: NBEditor(EditorState* st);