diff --git a/src/noggit/Red/NodeEditor/NodeRegistry.hpp b/src/noggit/Red/NodeEditor/NodeRegistry.hpp index 3ba3a29d..2d9cd2b0 100644 --- a/src/noggit/Red/NodeEditor/NodeRegistry.hpp +++ b/src/noggit/Red/NodeEditor/NodeRegistry.hpp @@ -62,6 +62,12 @@ #include #include +#include +#include +#include +#include +#include + #include #include #include @@ -107,6 +113,10 @@ #include #include +#include +#include +#include + using QtNodes::DataModelRegistry; using QtNodes::FlowScene; using QtNodes::FlowView; @@ -192,6 +202,14 @@ namespace noggit ret->registerModel("Data//String"); ret->registerModel("Data//String"); + + // Random + ret->registerModel("Data//Random"); + ret->registerModel("Data//Random"); + ret->registerModel("Data//Random"); + ret->registerModel("Data//Random"); + ret->registerModel("Data//Random"); + // Noise ret->registerModel("Data//Noise//Generators"); ret->registerModel("Data//Noise//Generators"); @@ -281,51 +299,67 @@ namespace noggit static void setStyle() { - ConnectionStyle::setConnectionStyle( - R"( - { - "FlowViewStyle": { - "BackgroundColor": [53, 53, 53], - "FineGridColor": [60, 60, 60], - "CoarseGridColor": [25, 25, 25] - }, - "NodeStyle": { - "NormalBoundaryColor": [255, 255, 255], - "SelectedBoundaryColor": [255, 165, 0], - "GradientColor0": "gray", - "GradientColor1": [80, 80, 80], - "GradientColor2": [64, 64, 64], - "GradientColor3": [58, 58, 58], - "ShadowColor": [20, 20, 20], - "FontColor" : "white", - "FontColorFaded" : "gray", - "ConnectionPointColor": [169, 169, 169], - "FilledConnectionPointColor": "cyan", - "ErrorColor": "red", - "WarningColor": [128, 128, 0], + QSettings settings; + QString theme = settings.value("theme", 1).toString(); + QDir theme_dir = QDir("./themes/"); - "PenWidth": 1.0, - "HoveredPenWidth": 1.5, + if (theme != "System" && theme_dir.exists() && QDir(theme_dir.path() + "/" + theme).exists("nodes_theme.json")) + { + QFile json_file = QFile(QDir(theme_dir.path() + "/" + theme).filePath("nodes_theme.json")); + json_file.open(QIODevice::ReadOnly); - "ConnectionPointDiameter": 8.0, + QByteArray save_data = json_file.readAll(); - "Opacity": 0.8 - }, - "ConnectionStyle": { - "ConstructionColor": "gray", - "NormalColor": "darkcyan", - "SelectedColor": [100, 100, 100], - "SelectedHaloColor": "orange", - "HoveredColor": "lightcyan", + ConnectionStyle::setConnectionStyle(save_data); + } + else + { + ConnectionStyle::setConnectionStyle( + R"( + { + "FlowViewStyle": { + "BackgroundColor": [53, 53, 53], + "FineGridColor": [60, 60, 60], + "CoarseGridColor": [25, 25, 25] + }, + "NodeStyle": { + "NormalBoundaryColor": [255, 255, 255], + "SelectedBoundaryColor": [255, 165, 0], + "GradientColor0": "gray", + "GradientColor1": [80, 80, 80], + "GradientColor2": [64, 64, 64], + "GradientColor3": [58, 58, 58], + "ShadowColor": [20, 20, 20], + "FontColor" : "white", + "FontColorFaded" : "gray", + "ConnectionPointColor": [169, 169, 169], + "FilledConnectionPointColor": "cyan", + "ErrorColor": "red", + "WarningColor": [128, 128, 0], - "LineWidth": 3.0, - "ConstructionLineWidth": 2.0, - "PointDiameter": 10.0, + "PenWidth": 1.0, + "HoveredPenWidth": 1.5, - "UseDataDefinedColors": true + "ConnectionPointDiameter": 8.0, + + "Opacity": 0.8 + }, + "ConnectionStyle": { + "ConstructionColor": "gray", + "NormalColor": "darkcyan", + "SelectedColor": [100, 100, 100], + "SelectedHaloColor": "orange", + "HoveredColor": "lightcyan", + + "LineWidth": 3.0, + "ConstructionLineWidth": 2.0, + "PointDiameter": 10.0, + + "UseDataDefinedColors": true + } } - } )"); + } } } } diff --git a/src/noggit/Red/NodeEditor/Nodes/Data/Random/RandomSeedNode.cpp b/src/noggit/Red/NodeEditor/Nodes/Data/Random/RandomSeedNode.cpp new file mode 100644 index 00000000..99979eef --- /dev/null +++ b/src/noggit/Red/NodeEditor/Nodes/Data/Random/RandomSeedNode.cpp @@ -0,0 +1,34 @@ +// This file is part of Noggit3, licensed under GNU General Public License (version 3). + +#include "RandomSeedNode.hpp" + +#include +#include +#include +#include + +using namespace noggit::Red::NodeEditor::Nodes; + +RandomSeedNode::RandomSeedNode() +: LogicNodeBase() +{ + setName("RandomSeedNode"); + setCaption("Random Seed"); + _validation_state = NodeValidationState::Valid; + + addPort(PortType::In, "Logic", true); + addPort(PortType::Out, "Logic", true); + addPort(PortType::Out, "Seed", true); +} + +void RandomSeedNode::compute() +{ + _out_ports[0].out_value = std::make_shared(true); + Q_EMIT dataUpdated(0); + std::srand(time(nullptr)); + _out_ports[1].out_value = std::make_shared(std::rand()); + Q_EMIT dataUpdated(1); +} + + + diff --git a/src/noggit/Red/NodeEditor/Nodes/Data/Random/RandomSeedNode.hpp b/src/noggit/Red/NodeEditor/Nodes/Data/Random/RandomSeedNode.hpp new file mode 100644 index 00000000..7290e899 --- /dev/null +++ b/src/noggit/Red/NodeEditor/Nodes/Data/Random/RandomSeedNode.hpp @@ -0,0 +1,33 @@ +// This file is part of Noggit3, licensed under GNU General Public License (version 3). + +#ifndef NOGGIT_RANDOMSEEDNODE_HPP +#define NOGGIT_RANDOMSEEDNODE_HPP + +#include + +using QtNodes::PortType; +using QtNodes::PortIndex; +using QtNodes::NodeData; +using QtNodes::NodeDataType; +using QtNodes::NodeDataModel; +using QtNodes::NodeValidationState; + + +namespace noggit +{ + namespace Red::NodeEditor::Nodes + { + class RandomSeedNode : public LogicNodeBase + { + Q_OBJECT + + public: + RandomSeedNode(); + void compute() override; + + }; + + } + +} +#endif //NOGGIT_RANDOMSEEDNODE_HPP diff --git a/src/noggit/ui/SettingsPanel.cpp b/src/noggit/ui/SettingsPanel.cpp index 7cfca266..193d6411 100644 --- a/src/noggit/ui/SettingsPanel.cpp +++ b/src/noggit/ui/SettingsPanel.cpp @@ -149,7 +149,8 @@ namespace noggit ui->_theme->addItem(dir); } } - } else + } + else { LogError << "Failed to load themes. The \"themes/\" folder does not exist in Noggit directory. Using system theme."