Skip to content

Commit 00f9803

Browse files
committed
feat: callbacks working and ready
1 parent e6d889a commit 00f9803

4 files changed

Lines changed: 52 additions & 46 deletions

File tree

src/easy_dialog_editor.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,28 @@ namespace ede
157157
{
158158
int start_node_id = start_attr >> NodePartShift::EndPin;
159159
int end_node_id = end_attr >> NodePartShift::InputPin;
160+
Node* start_node = current_state.nodes[start_node_id];
161+
Node* end_node = current_state.nodes[end_node_id];
160162

161-
if (SpeechNode* start_speech_node = current_state.nodes[start_node_id]->AsSpeech()) {
162-
if (ResponseNode* end_response_node = current_state.nodes[end_node_id]->AsResponse()) {
163-
if (!start_speech_node->expectesResponse) {
163+
if (start_node->nodeType == NodeType::Speech) {
164+
if (end_node->nodeType == NodeType::Response) {
165+
if (!start_node->expectesResponse) {
164166
return;
165167
}
166168
else {
167-
start_speech_node->responses.push_back(end_node_id);
168-
end_response_node->prevNodeId = start_node_id;
169+
start_node->responses.push_back(end_node_id);
170+
end_node->prevNodeId = start_node_id;
169171
}
170172
}
171173
else {
172-
start_speech_node->nextNodeId = end_node_id;
174+
start_node->nextNodeId = end_node_id;
173175
}
174176
}
177+
178+
if (start_node->nodeType == NodeType::Response && end_node->nodeType == NodeType::Response) {
179+
return;
180+
}
181+
175182
Link* link = new Link{ ++current_state.next_link_id, start_attr, end_attr };
176183
current_state.links[link->id] = link;
177184

@@ -456,6 +463,14 @@ namespace ede
456463
void ToggleAboutWindow() {
457464
bShowAboutSection = !bShowAboutSection;
458465
}
466+
void NotifyCallbackDeletion(const std::string& deleted_callback) {
467+
for (auto& node_pair : current_state.nodes) {
468+
Node* node = node_pair.second;
469+
if (node) {
470+
node->selected_callbacks.erase(deleted_callback);
471+
}
472+
}
473+
}
459474

460475
/******************************************************************************
461476
******************************************************************************/
@@ -485,7 +500,7 @@ namespace ede
485500
style.PinHoverRadius = 10.0f;
486501

487502
style.NodePadding = ImVec2(8.0f, 8.0f);
488-
style.NodeCornerRounding = 4.0f;
503+
style.NodeCornerRounding = 6.0f;
489504
style.NodeBorderThickness = 1.0f;
490505
}
491506

@@ -543,4 +558,8 @@ namespace ede
543558
editor.ToggleAboutWindow();
544559
}
545560

561+
void NotifyCallbackDeletion(const std::string& deleted_callback) {
562+
editor.NotifyCallbackDeletion(deleted_callback);
563+
}
564+
546565
} // namespace storyteller

src/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
SDL_WindowFlags window_flags =
6767
(SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
6868
SDL_Window* window = SDL_CreateWindow(
69-
"EasyDialogueEditor v0.1.5 [beta]",
69+
"EasyDialogueEditor v0.2.0 [beta]",
7070
SDL_WINDOWPOS_CENTERED,
7171
SDL_WINDOWPOS_CENTERED,
7272
1440,
@@ -145,6 +145,7 @@ DockSpace ID=0x5F4274ED Window=0x1F1D7494 Pos=0,0 Size=1440,900 Split=X
145145
)INI";
146146

147147
ImGui::LoadIniSettingsFromMemory(DEFAULT_INI);
148+
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
148149

149150
// Main loop
150151
while (!done)
@@ -205,6 +206,7 @@ DockSpace ID=0x5F4274ED Window=0x1F1D7494 Pos=0,0 Size=1440,900 Split=X
205206
}
206207

207208
// Cleanup
209+
ImGui::PopStyleVar(1);
208210
ImGui_ImplOpenGL3_Shutdown();
209211
ImGui_ImplSDL2_Shutdown();
210212
ede::NodeEditorShutdown();

src/show_windows.cpp

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ namespace ede {
142142

143143
for (Node* node : nodes) {
144144
if (node) {
145+
std::set<std::string>& current_callbacks = node->selected_callbacks;
146+
std::ostringstream stream;
147+
std::copy(current_callbacks.begin(), current_callbacks.end(), std::ostream_iterator<std::string>(stream, " "));
148+
std::string result_str = stream.str();
145149
if (SpeechNode* speech_node = node->AsSpeech()) {
146150
std::stringstream ss;
147151
ss << "{";
@@ -151,21 +155,18 @@ namespace ede {
151155
if (speech_node->responses.empty())
152156
ss << " ";
153157
ss << "}";
154-
raw_info += std::format(R"([{{ "id": "{}" ; "type": "Speech" ; "next_node_id": "{}" ; "expected_responses": "{}" }} ; )",
155-
node->id, node->nextNodeId, ss.str());
156-
std::set<std::string>& current_callbacks = node->selected_callbacks;
157-
std::ostringstream stream;
158-
std::copy(current_callbacks.begin(), current_callbacks.end(), std::ostream_iterator<std::string>(stream, " "));
159-
std::string result_str = stream.str();
158+
raw_info += std::format(R"([{{ "id": "{}" ; "type": "Speech" ; "next_node_id": "{}" ; "expected_responses": "{}" }} ; "callbacks": "{}")",
159+
node->id, node->nextNodeId, ss.str(), result_str);
160+
160161
ImGui::Text(std::format("Node {}: {{\n \"id\": \"{}\",\n \"type\": \"Speech\",\n \"text\": \"{}\",\n \"next_node_id\": \"{}\",\n \"expected_responses\": \"{}\",\n \"callbacks\": \"{{ {}}}\"\n}}", node->id, node->id, node->text, node->nextNodeId, ss.str(), result_str).c_str());
161162

162163
}
163164
if (ResponseNode* response_node = node->AsResponse()) {
164165

165-
raw_info += std::format(R"([{{ "id": "{}" ; "type": "Response" ; "next_node_id": "{}" }} ; )",
166-
node->id, node->nextNodeId);
166+
raw_info += std::format(R"([{{ "id": "{}" ; "type": "Response" ; "next_node_id": "{}" ; "callbacks": "{}" }} ; )",
167+
node->id, node->nextNodeId, result_str);
167168

168-
ImGui::Text("Node %d: {\n \"id\": \"%d\",\n \"type\": \"Response\",\n \"next_node_id\": \"%d\"\n}", node->id, node->id, node->nextNodeId);
169+
ImGui::Text(std::format("Node {}: {{\n \"id\": \"{}\",\n \"type\": \"Response\",\n \"next_node_id\": \"{}\",\n \"callbacks\": \"{{ {}}}\"\n}}", node->id, node->id, node->nextNodeId, result_str).c_str());
169170

170171
}
171172
ImGui::Dummy(ImVec2(0.0f, 2.0f));
@@ -211,14 +212,20 @@ namespace ede {
211212
}
212213
std::set<std::string>& current_callbacks = ede::GetCallbacksMutable();
213214
ImGui::Indent();
214-
for (auto& callback : current_callbacks) {
215+
216+
// display current callback tags and delete buttons
217+
for (auto it = current_callbacks.begin(); it != current_callbacks.end();) {
218+
219+
const auto& callback = *it;
215220
TEXT_BULLET(">", callback.c_str());
216221
ImGui::SameLine();
217-
if (ImGui::Button("X")) {
218-
auto it = std::find(current_callbacks.begin(), current_callbacks.end(), callback);
219-
if (it != current_callbacks.end()) {
220-
current_callbacks.erase(it);
221-
}
222+
std::string button_label = "X##" + callback;
223+
if (ImGui::Button(button_label.c_str())) {
224+
ede::NotifyCallbackDeletion(callback);
225+
it = current_callbacks.erase(it);
226+
}
227+
else {
228+
++it;
222229
}
223230
}
224231
ImGui::Unindent();
@@ -244,27 +251,4 @@ namespace ede {
244251
ImGui::End();
245252
}
246253

247-
/*******************************************************
248-
* Helper methods
249-
*******************************************************/
250-
251-
void LinkCallback(ImGui::MarkdownLinkCallbackData data_);
252-
inline ImGui::MarkdownImageData ImageCallback(ImGui::MarkdownLinkCallbackData data_);
253-
254-
static ImFont* H1 = NULL;
255-
static ImFont* H2 = NULL;
256-
static ImFont* H3 = NULL;
257-
258-
static ImGui::MarkdownConfig mdConfig;
259-
260-
261-
void LinkCallback(ImGui::MarkdownLinkCallbackData data_)
262-
{
263-
std::string url(data_.link, data_.linkLength);
264-
if (!data_.isImage)
265-
{
266-
ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
267-
}
268-
}
269-
270254
}

vendors/imnodes/node_editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ namespace ede
2121
void ToggleDemoWindow();
2222
void ToggleAboutWindow();
2323
std::vector<Node> GetNodesData();
24+
void NotifyCallbackDeletion(const std::string& deleted_callback);
2425
} // namespace storyteller

0 commit comments

Comments
 (0)