123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include "QuestRequirement.h"
- #include <Fenster.h>
- #include "Quest.h"
- QuestRequirement::QuestRequirement(
- Framework::Text id, Framework::Text description)
- : ReferenceCounter(),
- id(id),
- description(description)
- {}
- void QuestRequirement::api(Framework::StreamReader* message,
- Framework::XML::Element* zParent,
- QuestStorage* zStorage)
- {}
- const Framework::Text& QuestRequirement::getRequirementId() const
- {
- return id;
- }
- const Framework::Text& QuestRequirement::getDescription() const
- {
- return description;
- }
- QuestRequirementOpenDialog::QuestRequirementOpenDialog(
- Framework::Text id, Framework::Text description, Framework::Text dialogId)
- : QuestRequirement(id, description),
- dialogId(dialogId)
- {}
- void QuestRequirementOpenDialog::processEvent(
- QuestEvent* zEvent, QuestStorage* zStorage)
- {
- QuestRequirementStorage* zRequirementStorage
- = zStorage->zStorage(getRequirementId());
- QuestEventOpenDialog* event = dynamic_cast<QuestEventOpenDialog*>(zEvent);
- if (event)
- {
- if (event->getDialogId() == dialogId)
- {
- zRequirementStorage->setFullfilled(true);
- }
- }
- }
- void QuestRequirementOpenDialog::addRequirementUIML(QuestStorage* zStorage,
- Framework::XML::Element* zParent,
- Framework::Text onClickPrefix)
- {
- Framework::XML::Element* container = new Framework::XML::Element(
- "<frame width=\"100%\" height=\"50\" display=\"row\" gap=\"10\"/>");
- container->setAttribute("style",
- Framework::Text() += (Framework::Fenster::Style::Sichtbar
- | Framework::Fenster::Style::Erlaubt));
- container->setAttribute(
- "id", Framework::Text("requirement_") += getRequirementId());
- // TODO: add icon of dialog
- auto text
- = new Framework::XML::Element("<text width=\"auto\" height=\"auto\"/>");
- text->setAttribute("id",
- Framework::Text("requirement_description_") += getRequirementId());
- text->setText(description);
- container->addChild(text);
- auto status = new Framework::XML::Element(
- "<text margin-top=\"10\" width=\"auto\" height=\"auto\"/>");
- status->setAttribute("align-top", text->getAttributeValue("id"));
- status->setAttribute("align-x", text->getAttributeValue("id"));
- if (zStorage->zStorage(getRequirementId())->isFullfilled())
- {
- status->setText("Completed");
- status->setAttribute("text-color", "0xFF00FF00");
- }
- else
- {
- status->setText("Not completed");
- status->setAttribute("text-color", "0xFFFF0000");
- }
- container->addChild(status);
- zParent->addChild(container);
- }
- QuestRequirementOpenDialogType::QuestRequirementOpenDialogType()
- : SubTypeFactory()
- {}
- QuestRequirementOpenDialog* QuestRequirementOpenDialogType::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- return new QuestRequirementOpenDialog(
- zJson->zValue("id")->asString()->getString(),
- zJson->zValue("description")->asString()->getString(),
- zJson->zValue("dialogId")->asString()->getString());
- }
- Framework::JSON::JSONObject* QuestRequirementOpenDialogType::toJson(
- QuestRequirementOpenDialog* zObject) const
- {
- Framework::JSON::JSONObject* json = new Framework::JSON::JSONObject();
- json->addValue(
- "id", new Framework::JSON::JSONString(zObject->getRequirementId()));
- json->addValue("description",
- new Framework::JSON::JSONString(zObject->getDescription()));
- json->addValue(
- "dialogId", new Framework::JSON::JSONString(zObject->dialogId));
- return json;
- }
- Framework::JSON::Validator::JSONValidator*
- QuestRequirementOpenDialogType::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder->withRequiredString("id")
- ->finishString()
- ->withRequiredString("description")
- ->finishString()
- ->withRequiredString("dialogId")
- ->finishString()
- ->finishObject();
- }
- Framework::Text QuestRequirementOpenDialogType::getTypeToken() const
- {
- return "open_dialog";
- }
|