New properties window (moved node parameters to this window)

This commit is contained in:
Anthony Rabine 2023-12-16 23:48:50 +01:00
parent 151d9fe457
commit 35a54ac94d
33 changed files with 486 additions and 85 deletions

View file

@ -119,6 +119,9 @@ set(SRCS
src/resources_window.cpp src/resources_window.cpp
src/resources_window.h src/resources_window.h
src/node_properties_window.cpp
src/node_properties_window.h
src/gui.h src/gui.h
src/gui.cpp src/gui.cpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 24 24"
version="1.1"
id="svg4"
sodipodi:docname="build.svg"
inkscape:export-filename="/mnt/data/git/OpenStoryTeller/software/ost_editor/assets/build.png"
inkscape:export-xdpi="599.172"
inkscape:export-ydpi="599.172"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs8" />
<sodipodi:namedview
id="namedview6"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="27.125401"
inkscape:cx="9.769441"
inkscape:cy="9.5298132"
inkscape:window-width="1920"
inkscape:window-height="1136"
inkscape:window-x="3840"
inkscape:window-y="40"
inkscape:window-maximized="1"
inkscape:current-layer="svg4" />
<g
id="g1850"
transform="translate(0.70835287,0.93011029)">
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 3.2156211,6.5613148 V 18.525394 H 19.075779 V 6.5677311"
id="path954" />
<path
sodipodi:type="star"
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:1.88976;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:4, 4;paint-order:fill markers stroke"
id="path1459"
inkscape:flatsided="true"
sodipodi:sides="3"
sodipodi:cx="11.1457"
sodipodi:cy="5.4293532"
sodipodi:r1="4.4335914"
sodipodi:r2="2.2167957"
sodipodi:arg1="1.5707963"
sodipodi:arg2="2.6179939"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 11.145701,9.8629446 -3.8396034,-6.6503869 7.6792054,-2e-7 z"
inkscape:transform-center-y="1.108398" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563"
width="1.2475514"
height="1.2941761"
x="6.0001993"
y="11.433697"
rx="0"
ry="0" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563-3"
width="1.2475514"
height="1.2941761"
x="10.620297"
y="11.629229"
rx="0"
ry="0" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563-6"
width="1.2475514"
height="1.2941761"
x="9.0350676"
y="14.689091"
rx="0"
ry="0" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563-7"
width="1.2475514"
height="1.2941761"
x="14.12255"
y="15.278944"
rx="0"
ry="0" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563-5"
width="1.2475514"
height="1.2941761"
x="15.634048"
y="11.481765"
rx="0"
ry="0" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563-35"
width="1.2475514"
height="1.2941761"
x="14.491208"
y="8.9748898"
rx="0"
ry="0" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563-62"
width="1.2475514"
height="1.2941761"
x="6.5650582"
y="14.504762"
rx="0"
ry="0" />
<rect
style="opacity:0.998;fill:#000000;stroke:none;stroke-width:0.781951;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1.65513, 1.65513;paint-order:fill markers stroke"
id="rect1563-9"
width="1.2475514"
height="1.2941761"
x="7.8922276"
y="9.9702663"
rx="0"
ry="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3,16.74L7.76,12L3,7.26L7.26,3L12,7.76L16.74,3L21,7.26L16.24,12L21,16.74L16.74,21L12,16.24L7.26,21L3,16.74M12,13.41L16.74,18.16L18.16,16.74L13.41,12L18.16,7.26L16.74,5.84L12,10.59L7.26,5.84L5.84,7.26L10.59,12L5.84,16.74L7.26,18.16L12,13.41Z" /></svg>

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 24 24"
version="1.1"
id="svg4"
sodipodi:docname="file-document-plus-outline.svg"
inkscape:export-filename="file-document-plus-outline.png"
inkscape:export-xdpi="599.172"
inkscape:export-ydpi="599.172"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs8" />
<sodipodi:namedview
id="namedview6"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="35.06856"
inkscape:cx="4.6908114"
inkscape:cy="10.707597"
inkscape:window-width="2112"
inkscape:window-height="1436"
inkscape:window-x="1352"
inkscape:window-y="380"
inkscape:window-maximized="0"
inkscape:current-layer="svg4" />
<path
d="M23 18H20V15H18V18H15V20H18V23H20V20H23M6 2C4.89 2 4 2.9 4 4V20C4 21.11 4.89 22 6 22H13.81C13.45 21.38 13.2 20.7 13.08 20H6V4H13V9H18V13.08C18.33 13.03 18.67 13 19 13C19.34 13 19.67 13.03 20 13.08V8L14 2M8 12V14H16V12M8 16V18H13V16Z"
id="path2" />
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5,3A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5.5L18.5,3H17V9A1,1 0 0,1 16,10H8A1,1 0 0,1 7,9V3H5M12,4V9H15V4H12M7,12H17A1,1 0 0,1 18,13V19H6V13A1,1 0 0,1 7,12Z" /></svg>

After

Width:  |  Height:  |  Size: 249 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6.1,10L4,18V8H21A2,2 0 0,0 19,6H12L10,4H4A2,2 0 0,0 2,6V18A2,2 0 0,0 4,20H19C19.9,20 20.7,19.4 20.9,18.5L23.2,10H6.1M19,18H6L7.6,12H20.6L19,18Z" /></svg>

After

Width:  |  Height:  |  Size: 223 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19,20H4C2.89,20 2,19.1 2,18V6C2,4.89 2.89,4 4,4H10L12,6H19A2,2 0 0,1 21,8H21L4,8V18L6.14,10H23.21L20.93,18.5C20.7,19.37 19.92,20 19,20Z" /></svg>

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 24 24"
version="1.1"
id="svg4"
sodipodi:docname="play-circle-green.svg"
inkscape:export-filename="play-circle-green.png"
inkscape:export-xdpi="599.172"
inkscape:export-ydpi="599.172"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs8" />
<sodipodi:namedview
id="namedview6"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="38.514415"
inkscape:cx="8.0619166"
inkscape:cy="14.708779"
inkscape:window-width="1920"
inkscape:window-height="1136"
inkscape:window-x="3840"
inkscape:window-y="40"
inkscape:window-maximized="1"
inkscape:current-layer="svg4"
inkscape:showpageshadow="2"
inkscape:deskcolor="#d1d1d1" />
<path
d="M10,16.5V7.5L16,12M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"
id="path2"
style="fill:#4e9a06" />
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 24 24"
version="1.1"
id="svg4"
sodipodi:docname="play-circle.svg"
inkscape:export-filename="/mnt/data/git/OpenStoryTeller/software/ost_editor/assets/play-circle.png"
inkscape:export-xdpi="599.172"
inkscape:export-ydpi="599.172"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs8" />
<sodipodi:namedview
id="namedview6"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="15.153839"
inkscape:cx="2.5406103"
inkscape:cy="15.738586"
inkscape:window-width="1920"
inkscape:window-height="1136"
inkscape:window-x="3840"
inkscape:window-y="40"
inkscape:window-maximized="1"
inkscape:current-layer="svg4" />
<path
d="M10,16.5V7.5L16,12M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"
id="path2" />
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7 KiB

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M14,3.23V5.29C16.89,6.15 19,8.83 19,12C19,15.17 16.89,17.84 14,18.7V20.77C18,19.86 21,16.28 21,12C21,7.72 18,4.14 14,3.23M16.5,12C16.5,10.23 15.5,8.71 14,7.97V16C15.5,15.29 16.5,13.76 16.5,12M3,9V15H7L12,20V4L7,9H3Z" /></svg>

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 24 24"
version="1.1"
id="svg4"
sodipodi:docname="volume-off.svg"
inkscape:export-filename="/mnt/data/git/open-story-teller/story-editor/assets/volume-off.png"
inkscape:export-xdpi="599.172"
inkscape:export-ydpi="599.172"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs8" />
<sodipodi:namedview
id="namedview6"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="36.375"
inkscape:cx="10.62543"
inkscape:cy="12"
inkscape:window-width="1920"
inkscape:window-height="1136"
inkscape:window-x="3840"
inkscape:window-y="40"
inkscape:window-maximized="1"
inkscape:current-layer="svg4" />
<path
d="M12,4L9.91,6.09L12,8.18M4.27,3L3,4.27L7.73,9H3V15H7L12,20V13.27L16.25,17.53C15.58,18.04 14.83,18.46 14,18.7V20.77C15.38,20.45 16.63,19.82 17.68,18.96L19.73,21L21,19.73L12,10.73M19,12C19,12.94 18.8,13.82 18.46,14.64L19.97,16.15C20.62,14.91 21,13.5 21,12C21,7.72 18,4.14 14,3.23V5.29C16.89,6.15 19,8.83 19,12M16.5,12C16.5,10.23 15.5,8.71 14,7.97V10.18L16.45,12.63C16.5,12.43 16.5,12.21 16.5,12Z"
id="path2" />
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 KiB

View file

@ -106,6 +106,8 @@ public:
virtual void Draw() = 0; virtual void Draw() = 0;
virtual void DrawProperties() = 0;
void SetPosition(int x, int y); void SetPosition(int x, int y);
void FrameStart(); void FrameStart();
@ -115,9 +117,19 @@ public:
uint32_t Outputs() const { return m_node->Outputs.size(); } uint32_t Outputs() const { return m_node->Outputs.size(); }
void SetType(const std::string &type)
{
m_type = type;
}
std::string GetType() const
{
return m_type;
}
void SetId(const int id) { m_id = id; } void SetId(const int id) { m_id = id; }
int GetId() const { return m_id; } int GetId() const { return m_id; }
int GetInternalId() const { return m_node->ID.Get(); } unsigned long GetInternalId() const { return m_node->ID.Get(); }
void seTitle(const std::string &title) { m_title = title; } void seTitle(const std::string &title) { m_title = title; }
std::string getTitle() const { return m_title; } std::string getTitle() const { return m_title; }

View file

@ -5,6 +5,7 @@ EmulatorWindow::EmulatorWindow()
: WindowBase("Emulator") : WindowBase("Emulator")
{ {
Gui::LoadRawImage("assets/play.png", m_playImage);
} }
void EmulatorWindow::Initialize() { void EmulatorWindow::Initialize() {
@ -21,16 +22,19 @@ void EmulatorWindow::Draw()
// return; // return;
// } // }
static ImVec2 size(320.0f, 240.0f);
WindowBase::BeginDraw(); WindowBase::BeginDraw();
ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver); ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver);
// ImGui::Image((void*)(intptr_t)my_image_texture, ImVec2(313, 367)); // ImGui::Image((void*)(intptr_t)my_image_texture, ImVec2(313, 367));
float sz = ImGui::GetTextLineHeight(); // float sz = ImGui::GetTextLineHeight();
ImVec2 p = ImGui::GetCursorScreenPos(); ImVec2 p = ImGui::GetCursorScreenPos();
ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + sz, p.y + sz), ImGui::GetColorU32(ImVec4(1.0, 1.0, 1.0, 1.0))); ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + 320, p.y + 240), ImGui::GetColorU32(ImVec4(1.0, 1.0, 1.0, 1.0)));
ImGui::SetCursorScreenPos(ImVec2(p.x, p.y + 240));
ImGui::ImageButton("play", m_playImage.texture, ImVec2(45, 45));
WindowBase::EndDraw(); WindowBase::EndDraw();
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "window_base.h" #include "window_base.h"
#include "gui.h"
class EmulatorWindow : public WindowBase class EmulatorWindow : public WindowBase
{ {
@ -11,6 +12,9 @@ public:
virtual void Draw() override; virtual void Draw() override;
private: private:
Gui::Image m_playImage;
Gui::Image m_pauseImage;
Gui::Image m_homeImage;
}; };

View file

@ -165,6 +165,7 @@ void MainWindow::Initialize()
editor.Initialize(); editor.Initialize();
m_emulatorWindow.Initialize(); m_emulatorWindow.Initialize();
m_nodeEditorWindow.Initialize(); m_nodeEditorWindow.Initialize();
m_nodePropertiesWindow.Initialize();
LoadParams(); LoadParams();
} }
@ -596,6 +597,8 @@ void MainWindow::Loop()
m_resourcesWindow.Draw(); m_resourcesWindow.Draw();
m_nodeEditorWindow.Draw(); m_nodeEditorWindow.Draw();
m_nodePropertiesWindow.SetSelectedNode(m_nodeEditorWindow.GetSelectedNode());
m_nodePropertiesWindow.Draw();
ShowOptionsWindow(); ShowOptionsWindow();

View file

@ -8,6 +8,7 @@
#include "emulator_window.h" #include "emulator_window.h"
#include "resources_window.h" #include "resources_window.h"
#include "node_editor_window.h" #include "node_editor_window.h"
#include "node_properties_window.h"
#include "chip32_assembler.h" #include "chip32_assembler.h"
#include "chip32_vm.h" #include "chip32_vm.h"
@ -106,6 +107,9 @@ private:
NodeEditorWindow m_nodeEditorWindow; NodeEditorWindow m_nodeEditorWindow;
NodePropertiesWindow m_nodePropertiesWindow;
char mBufAddress[200]; char mBufAddress[200];
char mBufReceivePath[200]; char mBufReceivePath[200];
char mBufSendPath[200]; char mBufSendPath[200];

View file

@ -57,40 +57,9 @@ void MediaNode::Draw()
ImGui::AlignTextToFramePadding();
ImGui::Text("Image");
ImGui::SameLine();
ImGui::Text("%s", m_image.name.c_str());
ImGui::SameLine();
bool do_popup = false;
std::string type = "sound";
if (ImGui::Button("Select...")) {
do_popup = true; // Instead of saying OpenPopup() here, we set this bool, which is used later in the Deferred Pop-up Section
type = "image";
}
// Use AlignTextToFramePadding() to align text baseline to the baseline of framed elements // Use AlignTextToFramePadding() to align text baseline to the baseline of framed elements
// (otherwise a Text+SameLine+Button sequence will have the text a little too high by default) // (otherwise a Text+SameLine+Button sequence will have the text a little too high by default)
ImGui::AlignTextToFramePadding();
ImGui::Text("Sound");
ImGui::SameLine();
ImGui::Text("%s", m_soundName.c_str());
ImGui::SameLine();
if (ImGui::Button(m_buttonUniqueName.c_str()))
{
m_project.PlaySoundFile(m_soundPath);
}
if (ImGui::Button("Select...")) {
do_popup = true; // Instead of saying OpenPopup() here, we set this bool, which is used later in the Deferred Pop-up Section
}
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
ImGui::Text("Outputs:"); ImGui::Text("Outputs:");
@ -119,47 +88,9 @@ void MediaNode::Draw()
DrawPins(); DrawPins();
if (do_popup) {
ImGui::OpenPopup("popup_button"); // Cause openpopup to stick open.
do_popup = false; // disable bool so that if we click off the popup, it doesn't open the next frame.
}
// This is the actual popup Gui drawing section.
if (ImGui::BeginPopup("popup_button")) {
// Note: if it weren't for the child window, we would have to PushItemWidth() here to avoid a crash!
ImGui::TextDisabled("Choose media file:");
static int item_current_idx = 0; // Here we store our selection data as an index.
if (ImGui::BeginListBox("listbox media"))
{
auto [filtreDebut, filtreFin] = m_project.Sounds();
int n = 0;
for (auto it = filtreDebut; it != filtreFin; ++it, n++)
{
const bool is_selected = (item_current_idx == n);
if (ImGui::Selectable((*it)->file.c_str(), is_selected))
item_current_idx = n;
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndListBox();
}
if (ImGui::Button("Ok")) {
ImGui::CloseCurrentPopup(); // These calls revoke the popup open state, which was set by OpenPopup above.
}
ImGui::EndChild();
ImGui::EndPopup(); // Note this does not do anything to the popup open/close state. It just terminates the content declaration.
}
BaseNode::FrameEnd(); BaseNode::FrameEnd();
} }
/* /*
@ -179,3 +110,57 @@ void MediaNode::FromJson(nlohmann::json &j)
m_soundName = j["sound"].get<std::string>(); m_soundName = j["sound"].get<std::string>();
m_soundPath = m_project.BuildFullAssetsPath(m_soundName); m_soundPath = m_project.BuildFullAssetsPath(m_soundName);
} }
void MediaNode::DrawProperties()
{
ImGui::AlignTextToFramePadding();
ImGui::Text("Image");
ImGui::SameLine();
ImGui::Text("%s", m_image.name.c_str());
ImGui::SameLine();
std::string type = "sound";
if (ImGui::Button("Select...##image")) {
type = "image";
ImGui::OpenPopup("popup_button");
}
ImGui::AlignTextToFramePadding();
ImGui::Text("Sound");
ImGui::SameLine();
ImGui::Text("%s", m_soundName.c_str());
ImGui::SameLine();
if (ImGui::Button(m_buttonUniqueName.c_str()))
{
m_project.PlaySoundFile(m_soundPath);
}
if (ImGui::Button("Select...##sound")) {
ImGui::OpenPopup("popup_button");
}
// This is the actual popup Gui drawing section.
if (ImGui::BeginPopup("popup_button")) {
ImGui::SeparatorText("Sounds");
static int item_current_idx = 0; // Here we store our selection data as an index.
auto [filtreDebut, filtreFin] = m_project.Sounds();
int n = 0;
for (auto it = filtreDebut; it != filtreFin; ++it, n++)
{
if (ImGui::Selectable((*it)->file.c_str()), n == item_current_idx)
item_current_idx = n;
}
ImGui::EndPopup(); // Note this does not do anything to the popup open/close state. It just terminates the content declaration.
}
}

View file

@ -20,11 +20,15 @@ public:
virtual void FromJson(nlohmann::json &j) override; virtual void FromJson(nlohmann::json &j) override;
virtual void DrawProperties() override;
private: private:
IStoryProject &m_project; IStoryProject &m_project;
Gui::Image m_image; Gui::Image m_image;
std::string m_soundName; std::string m_soundName;
std::string m_soundPath; std::string m_soundPath;
std::string m_id;
std::string m_buttonUniqueName; std::string m_buttonUniqueName;
}; };

View file

@ -50,13 +50,14 @@ void NodeEditorWindow::LoadNode(const nlohmann::json &nodeJson)
auto n = createNode(type, "", m_project); auto n = createNode(type, "", m_project);
if (n) if (n)
{ {
n->SetType(type); // FIXME: set type in createNode factory?
n->SetId(restoredNodeId); n->SetId(restoredNodeId);
nlohmann::json posJson = nodeJson["position"]; nlohmann::json posJson = nodeJson["position"];
n->SetOutputs(nodeJson["outPortCount"].get<int>()); n->SetOutputs(nodeJson["outPortCount"].get<int>());
n->SetPosition(posJson["x"].get<int>(), posJson["y"].get<int>()); n->SetPosition(posJson["x"].get<int>(), posJson["y"].get<int>());
n->FromJson(internalDataJson); n->FromJson(internalDataJson);
m_nodes[restoredNodeId] = n; m_nodes[n->GetInternalId()] = n;
} }
else else
{ {
@ -71,7 +72,7 @@ void NodeEditorWindow::LoadNode(const nlohmann::json &nodeJson)
} }
ed::PinId NodeEditorWindow::GetInputPin(int modelNodeId, int pinIndex) ed::PinId NodeEditorWindow::GetInputPin(unsigned long modelNodeId, int pinIndex)
{ {
ed::PinId id = -1; ed::PinId id = -1;
@ -86,7 +87,7 @@ ed::PinId NodeEditorWindow::GetInputPin(int modelNodeId, int pinIndex)
return id; return id;
} }
ed::PinId NodeEditorWindow::GetOutputPin(int modelNodeId, int pinIndex) ed::PinId NodeEditorWindow::GetOutputPin(unsigned long modelNodeId, int pinIndex)
{ {
ed::PinId id = -1; ed::PinId id = -1;
@ -126,17 +127,39 @@ void NodeEditorWindow::Load(const nlohmann::json &model)
// ImGui stuff for links // ImGui stuff for links
conn->Id = 100000 + BaseNode::GetNextId(); conn->Id = BaseNode::GetNextId();
conn->InputId = GetInputPin(conn->model.inNodeId, conn->model.inPortIndex); conn->InputId = GetInputPin(conn->model.inNodeId, conn->model.inPortIndex);
conn->OutputId = GetOutputPin(conn->model.outNodeId, conn->model.outPortIndex); conn->OutputId = GetOutputPin(conn->model.outNodeId, conn->model.outPortIndex);
// Since we accepted new link, lets add one to our list of links. // Since we accepted new link, lets add one to our list of links.
m_links.push_back(conn); m_links.push_back(conn);
} }
} }
std::shared_ptr<BaseNode> NodeEditorWindow::GetSelectedNode()
{
std::shared_ptr<BaseNode> selected;
ed::SetCurrentEditor(m_context);
if (ed::GetSelectedObjectCount() > 0)
{
ed::NodeId nId;
int nodeCount = ed::GetSelectedNodes(&nId, 1);
if (nodeCount > 0)
{
if (m_nodes.contains(nId.Get()))
{
selected = m_nodes[nId.Get()];
}
}
}
ed::SetCurrentEditor(nullptr);
return selected;
}
void NodeEditorWindow::Draw() void NodeEditorWindow::Draw()
{ {
if (WindowBase::BeginDraw()) if (WindowBase::BeginDraw())
@ -148,7 +171,9 @@ void NodeEditorWindow::Draw()
for (const auto & n : m_nodes) for (const auto & n : m_nodes)
{ {
ImGui::PushID(n.first);
n.second->Draw(); n.second->Draw();
ImGui::PopID();
} }
for (const auto& linkInfo : m_links) for (const auto& linkInfo : m_links)
@ -180,10 +205,10 @@ void NodeEditorWindow::Draw()
if (ed::AcceptNewItem()) if (ed::AcceptNewItem())
{ {
// Since we accepted new link, lets add one to our list of links. // Since we accepted new link, lets add one to our list of links.
// m_Links.push_back({ ed::LinkId(BaseNode::GetNextId()), inputPinId, outputPinId }); // m_Links.push_back({ ed::LinkId(BaseNode::GetNextId()), inputPinId, outputPinId });
// Draw new link. // Draw new link.
// ed::Link(m_Links.back().Id, m_Links.back().InputId, m_Links.back().OutputId); // ed::Link(m_Links.back().Id, m_Links.back().InputId, m_Links.back().OutputId);
} }
// You may choose to reject connection between these nodes // You may choose to reject connection between these nodes

View file

@ -47,13 +47,14 @@ public:
void Clear(); void Clear();
void Load(const nlohmann::json &model); void Load(const nlohmann::json &model);
std::shared_ptr<BaseNode> GetSelectedNode();
private: private:
IStoryProject &m_project; IStoryProject &m_project;
ed::EditorContext* m_context = nullptr; ed::EditorContext* m_context = nullptr;
// key: Id // key: Id
std::map<int, std::shared_ptr<BaseNode>> m_nodes; std::map<unsigned long, std::shared_ptr<BaseNode>> m_nodes;
std::vector<std::shared_ptr<LinkInfo>> m_links; // List of live links. It is dynamic unless you want to create read-only view over nodes. std::vector<std::shared_ptr<LinkInfo>> m_links; // List of live links. It is dynamic unless you want to create read-only view over nodes.
void ToolbarUI(); void ToolbarUI();
@ -99,7 +100,7 @@ private:
} }
void LoadNode(const nlohmann::json &nodeJson); void LoadNode(const nlohmann::json &nodeJson);
ed::PinId GetInputPin(int modelNodeId, int pinIndex); ed::PinId GetInputPin(unsigned long modelNodeId, int pinIndex);
ed::PinId GetOutputPin(int modelNodeId, int pinIndex); ed::PinId GetOutputPin(unsigned long modelNodeId, int pinIndex);
}; };

View file

@ -0,0 +1,42 @@
#include "node_properties_window.h"
#include "gui.h"
NodePropertiesWindow::NodePropertiesWindow()
: WindowBase("Properties")
{
}
void NodePropertiesWindow::Initialize() {
int my_image_width = 0;
int my_image_height = 0;
}
void NodePropertiesWindow::Draw()
{
// if (!IsVisible())
// {
// return;
// }
WindowBase::BeginDraw();
ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver);
static char buf1[32] = ""; ImGui::InputText("Title", buf1, 32);
if (m_selectedNode)
{
m_selectedNode->DrawProperties();
}
WindowBase::EndDraw();
}
void NodePropertiesWindow::SetSelectedNode(std::shared_ptr<BaseNode> node)
{
m_selectedNode = node;
}

View file

@ -0,0 +1,22 @@
#pragma once
#include "window_base.h"
#include "gui.h"
#include "base_node.h"
class NodePropertiesWindow : public WindowBase
{
public:
NodePropertiesWindow();
void Initialize();
virtual void Draw() override;
void SetSelectedNode(std::shared_ptr<BaseNode> node);
private:
std::shared_ptr<BaseNode> m_selectedNode;
};