Added default font editing to VN
This commit is contained in:
@ -9,7 +9,8 @@
|
||||
using namespace Dawn;
|
||||
|
||||
VNManager::VNManager(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
SceneItemComponent(item),
|
||||
defaultFont("<font font=\"font_main\">{{ text }}</font>")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace Dawn {
|
||||
std::map<std::string, std::string> flags;
|
||||
|
||||
public:
|
||||
// @optional
|
||||
std::string defaultFont;
|
||||
|
||||
/**
|
||||
* Constructs a visual novel manager, scene item component.
|
||||
*
|
||||
|
20
src/dawn/games/vn/events/VNSetDefaultFontEvent.hpp
Normal file
20
src/dawn/games/vn/events/VNSetDefaultFontEvent.hpp
Normal file
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
@ -20,7 +20,8 @@ namespace Dawn {
|
||||
scroller = this->getScene()->findComponent<VNTextboxScroller>();
|
||||
assertNotNull(scroller);
|
||||
|
||||
scroller->label->richText = "<font font=\"font_main\" size=\"32\">" + text + "</font>";
|
||||
auto richText = stringReplaceAll(this->manager->defaultFont, "{{ text }}", this->text);
|
||||
scroller->label->richText = richText;
|
||||
|
||||
useEvent([&](inputbind_t bind){
|
||||
if(bind != INPUT_BIND_ACCEPT) return;
|
||||
|
@ -79,7 +79,7 @@ void UIRichTextLabel::onStart() {
|
||||
}
|
||||
};
|
||||
|
||||
auto root = Xml::load("<root><font font=\"font_main\">" + ((std::string)this->richText) + "</font></root>");
|
||||
auto root = Xml::load("<root>" + ((std::string)this->richText) + "</root>");
|
||||
parseChildren(&root);
|
||||
this->rebufferQuads(bufferTexts);
|
||||
}, this->richText)();
|
||||
|
@ -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 = "<font ";
|
||||
auto sdf = event->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 }}</font>";
|
||||
line(&eventInitAfter, eventName + "->font = " + stringParser(strFont, NULL) + ";", "");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
std::cout << "Unknown event type: " << event->type << std::endl;
|
||||
|
@ -18,4 +18,5 @@ target_sources(vnscenetool
|
||||
VNChoiceSetEventParser.cpp
|
||||
VNIfEventParser.cpp
|
||||
VNSceneChangeEventParser.cpp
|
||||
VNSetDefaultFontEventParser.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;
|
||||
|
@ -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<struct VNSceneEventList> {
|
||||
|
@ -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<std::string, std::string> VNSetDefaultFontEventParser::getOptionalAttributes() {
|
||||
return {
|
||||
{ "font", "font_main" },
|
||||
{ "style", "" },
|
||||
{ "size", "" },
|
||||
{ "color", "" }
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<std::string> VNSetDefaultFontEventParser::getRequiredAttributes() {
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t VNSetDefaultFontEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> 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;
|
||||
}
|
@ -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<struct VNSetFont> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSetFont *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
@ -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;
|
||||
|
Reference in New Issue
Block a user