diff --git a/src/dawn/games/vn/components/VNManager.cpp b/src/dawn/games/vn/components/VNManager.cpp
index 8aacf0a9..569bc1aa 100644
--- a/src/dawn/games/vn/components/VNManager.cpp
+++ b/src/dawn/games/vn/components/VNManager.cpp
@@ -9,7 +9,8 @@
using namespace Dawn;
VNManager::VNManager(SceneItem *item) :
- SceneItemComponent(item)
+ SceneItemComponent(item),
+ defaultFont("{{ text }}")
{
}
diff --git a/src/dawn/games/vn/components/VNManager.hpp b/src/dawn/games/vn/components/VNManager.hpp
index b000bb1d..2b5e1009 100644
--- a/src/dawn/games/vn/components/VNManager.hpp
+++ b/src/dawn/games/vn/components/VNManager.hpp
@@ -23,6 +23,9 @@ namespace Dawn {
std::map flags;
public:
+ // @optional
+ std::string defaultFont;
+
/**
* Constructs a visual novel manager, scene item component.
*
diff --git a/src/dawn/games/vn/events/VNSetDefaultFontEvent.hpp b/src/dawn/games/vn/events/VNSetDefaultFontEvent.hpp
new file mode 100644
index 00000000..fa90efaf
--- /dev/null
+++ b/src/dawn/games/vn/events/VNSetDefaultFontEvent.hpp
@@ -0,0 +1,20 @@
+// Copyright (c) 2023 Dominic Masters
+//
+// This software is released under the MIT License.
+// https://opensource.org/licenses/MIT
+
+#pragma once
+#include "VNEvent.hpp"
+
+namespace Dawn {
+ class VNSetDefaultFontEvent : public VNEvent {
+ public:
+ std::string font;
+
+ protected:
+ void onStart() override {
+ this->manager->defaultFont = this->font;
+ this->next();
+ }
+ };
+}
\ No newline at end of file
diff --git a/src/dawn/games/vn/events/VNTextEvent.hpp b/src/dawn/games/vn/events/VNTextEvent.hpp
index c6e30fec..29d57048 100644
--- a/src/dawn/games/vn/events/VNTextEvent.hpp
+++ b/src/dawn/games/vn/events/VNTextEvent.hpp
@@ -20,7 +20,8 @@ namespace Dawn {
scroller = this->getScene()->findComponent();
assertNotNull(scroller);
- scroller->label->richText = "" + text + "";
+ auto richText = stringReplaceAll(this->manager->defaultFont, "{{ text }}", this->text);
+ scroller->label->richText = richText;
useEvent([&](inputbind_t bind){
if(bind != INPUT_BIND_ACCEPT) return;
diff --git a/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp b/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp
index 04986758..8cddc32b 100644
--- a/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp
+++ b/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp
@@ -79,7 +79,7 @@ void UIRichTextLabel::onStart() {
}
};
- auto root = Xml::load("" + ((std::string)this->richText) + "");
+ auto root = Xml::load("" + ((std::string)this->richText) + "");
parseChildren(&root);
this->rebufferQuads(bufferTexts);
}, this->richText)();
diff --git a/src/dawntools/vnscenetool/VNSceneGen.cpp b/src/dawntools/vnscenetool/VNSceneGen.cpp
index fa061a6d..e608d161 100644
--- a/src/dawntools/vnscenetool/VNSceneGen.cpp
+++ b/src/dawntools/vnscenetool/VNSceneGen.cpp
@@ -140,11 +140,27 @@ void VNSceneGen::test(
break;
}
- case VN_SCENE_EVENT_TYPE_SCENE_CHANGE:
+ case VN_SCENE_EVENT_TYPE_SCENE_CHANGE: {
initType = "VNSceneChangeEvent<" + event->sceneChange.scene + ">";
toInclude = "games/vn/events/VNSceneChangeEvent.hpp";
includes->push_back(event->sceneChange.include);
break;
+ }
+
+ case VN_SCENE_EVENT_SET_DEFAULT_FONT: {
+ initType = "VNSetDefaultFontEvent";
+ toInclude = "games/vn/events/VNSetDefaultFontEvent.hpp";
+ printf("GENERATING\n\n\n");
+ std::string strFont = "setDefaultFont;
+ if(!sdf.font.empty()) strFont += "font=" + stringParser(sdf.font, NULL);
+ if(!sdf.fontSize.empty()) strFont += " size=\"" + floatParser(sdf.fontSize, NULL) + "\"";
+ if(!sdf.color.empty()) strFont += " color=\"" + colorParser(sdf.color, NULL) + "\"";
+ if(!sdf.style.empty()) strFont += " style=" + stringParser(sdf.style, NULL);
+ strFont += ">{{ text }}";
+ line(&eventInitAfter, eventName + "->font = " + stringParser(strFont, NULL) + ";", "");
+ break;
+ }
default:
std::cout << "Unknown event type: " << event->type << std::endl;
diff --git a/src/dawntools/vnscenetool/events/CMakeLists.txt b/src/dawntools/vnscenetool/events/CMakeLists.txt
index 04e13042..99f79dcb 100644
--- a/src/dawntools/vnscenetool/events/CMakeLists.txt
+++ b/src/dawntools/vnscenetool/events/CMakeLists.txt
@@ -18,4 +18,5 @@ target_sources(vnscenetool
VNChoiceSetEventParser.cpp
VNIfEventParser.cpp
VNSceneChangeEventParser.cpp
+ VNSetDefaultFontEventParser.cpp
)
\ No newline at end of file
diff --git a/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp b/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp
index 7ef5c08b..e6ffdfc4 100644
--- a/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp
+++ b/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp
@@ -90,6 +90,11 @@ int32_t VNSceneEventsParser::onParse(
ret = (VNSceneChangeEventParser()).parse(child, &event.sceneChange, error);
if(ret != 0) return ret;
+ } else if(child->node == "set-default-font" || child->node == "set-font") {
+ event.type = VN_SCENE_EVENT_SET_DEFAULT_FONT;
+ ret = (VNSetDefaultFontEventParser()).parse(child, &event.setDefaultFont, error);
+ if(ret != 0) return ret;
+
} else {
*error = "Unknown child node '" + child->node + "'";
return -1;
diff --git a/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp b/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp
index 76bba0f5..4185f708 100644
--- a/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp
+++ b/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp
@@ -15,6 +15,7 @@
#include "VNChoiceSetEventParser.hpp"
#include "VNIfEventParser.hpp"
#include "VNSceneChangeEventParser.hpp"
+#include "VNSetDefaultFontEventParser.hpp"
namespace Dawn {
struct VNSceneEvent;
@@ -34,7 +35,8 @@ namespace Dawn {
VN_SCENE_EVENT_TYPE_CHOICES,
VN_SCENE_EVENT_TYPE_CHOICE_SET,
VN_SCENE_EVENT_TYPE_IF,
- VN_SCENE_EVENT_TYPE_SCENE_CHANGE
+ VN_SCENE_EVENT_TYPE_SCENE_CHANGE,
+ VN_SCENE_EVENT_SET_DEFAULT_FONT
};
struct VNParallelEvent {
@@ -61,6 +63,7 @@ namespace Dawn {
struct VNChoiceSetEvent choiceSet;
struct VNIfEvent ifEvent;
struct VNSceneChangeEvent sceneChange;
+ struct VNSetFont setDefaultFont;
};
class VNSceneEventsParser : public XmlParser {
diff --git a/src/dawntools/vnscenetool/events/VNSetDefaultFontEventParser.cpp b/src/dawntools/vnscenetool/events/VNSetDefaultFontEventParser.cpp
new file mode 100644
index 00000000..28cae84d
--- /dev/null
+++ b/src/dawntools/vnscenetool/events/VNSetDefaultFontEventParser.cpp
@@ -0,0 +1,46 @@
+// Copyright (c) 2023 Dominic Masters
+//
+// This software is released under the MIT License.
+// https://opensource.org/licenses/MIT
+
+#include "VNSetDefaultFontEventParser.hpp"
+
+using namespace Dawn;
+
+std::map VNSetDefaultFontEventParser::getOptionalAttributes() {
+ return {
+ { "font", "font_main" },
+ { "style", "" },
+ { "size", "" },
+ { "color", "" }
+ };
+}
+
+std::vector VNSetDefaultFontEventParser::getRequiredAttributes() {
+ return {};
+}
+
+int32_t VNSetDefaultFontEventParser::onParse(
+ Xml *node,
+ std::map values,
+ struct VNSetFont *out,
+ std::string *error
+) {
+ //Get the font
+ out->font = values["font"];
+ if(out->font.empty()) {
+ *error = "Font is required.";
+ return 1;
+ }
+
+ //Get the style
+ out->style = values["style"];
+
+ //Get the size
+ out->fontSize = values["size"];
+
+ //Get the color
+ out->color = values["color"];
+
+ return 0;
+}
\ No newline at end of file
diff --git a/src/dawntools/vnscenetool/events/VNSetDefaultFontEventParser.hpp b/src/dawntools/vnscenetool/events/VNSetDefaultFontEventParser.hpp
new file mode 100644
index 00000000..f2d525e9
--- /dev/null
+++ b/src/dawntools/vnscenetool/events/VNSetDefaultFontEventParser.hpp
@@ -0,0 +1,28 @@
+// Copyright (c) 2023 Dominic Masters
+//
+// This software is released under the MIT License.
+// https://opensource.org/licenses/MIT
+
+#pragma once
+#include "util/XmlParser.hpp"
+
+namespace Dawn {
+ struct VNSetFont {
+ std::string font;
+ std::string style;
+ std::string fontSize;
+ std::string color;
+ };
+
+ class VNSetDefaultFontEventParser : public XmlParser {
+ protected:
+ std::vector getRequiredAttributes() override;
+ std::map getOptionalAttributes() override;
+ int32_t onParse(
+ Xml *node,
+ std::map values,
+ struct VNSetFont *out,
+ std::string *error
+ ) override;
+ };
+}
\ No newline at end of file
diff --git a/src/dawntools/vnscenetool/events/VNTextEventParser.cpp b/src/dawntools/vnscenetool/events/VNTextEventParser.cpp
index 203bfdd2..67e90e59 100644
--- a/src/dawntools/vnscenetool/events/VNTextEventParser.cpp
+++ b/src/dawntools/vnscenetool/events/VNTextEventParser.cpp
@@ -22,9 +22,6 @@ int32_t VNTextParser::onParse(
struct VNText *out,
std::string *error
) {
-
- std::cout << "TEST" << node->innerXml << std::endl;
-
out->language = values["lang"];
out->text = stringParser(node->innerXml, error);
return error->length() == 0 ? 0 : -1;