#include "OpenDialogInteractionConfig.h" #include #include "Entity.h" #include "UIController.h" #include "UIDialog.h" #include "UIDialogElement.h" OpenDialogInteractionConfig::OpenDialogInteractionConfig() : InteractionConfig(), dialogElement(0) {} OpenDialogInteractionConfig::~OpenDialogInteractionConfig() { if (dialogElement) { dialogElement->release(); } } void OpenDialogInteractionConfig::setDialogElement( UIDialogElement* dialogElement) { if (this->dialogElement) { this->dialogElement->release(); } this->dialogElement = dialogElement; } UIDialogElement* OpenDialogInteractionConfig::zDialogElement() const { return dialogElement; } bool OpenDialogInteractionConfig::onInteraction( Framework::Either target, Item* zItem, Entity* actor, bool& itemChanged) { Framework::XML::Element* uiml = dialogElement->toUIML(target, actor); Game::INSTANCE->zUIController()->addDialog( new UIDialog(uiml->getAttributeValue("id"), actor->getId(), uiml)); return true; } OpenDialogInteractionConfigFactory::OpenDialogInteractionConfigFactory() : InteractionConfigFactory() {} JSONObjectValidationBuilder* OpenDialogInteractionConfigFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return InteractionConfigFactory< OpenDialogInteractionConfig>::addToValidator(builder) ->withRequiredAttribute("dialogElement", Game::INSTANCE->zTypeRegistry()->getValidator()); } OpenDialogInteractionConfig* OpenDialogInteractionConfigFactory::fromJson( Framework::JSON::JSONObject* zJson) const { OpenDialogInteractionConfig* result = InteractionConfigFactory::fromJson( zJson); result->setDialogElement( Game::INSTANCE->zTypeRegistry()->fromJson( zJson->zValue("dialogElement"))); return result; } Framework::JSON::JSONObject* OpenDialogInteractionConfigFactory::toJsonObject( OpenDialogInteractionConfig* zObject) const { Framework::JSON::JSONObject* result = InteractionConfigFactory::toJsonObject( zObject); result->addValue("dialogElement", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zDialogElement())); return result; } const char* OpenDialogInteractionConfigFactory::getTypeToken() const { return "OpenDialogInteractionConfig"; } OpenDialogInteractionConfig* OpenDialogInteractionConfigFactory::createValue( Framework::JSON::JSONObject* zJson) const { return new OpenDialogInteractionConfig(); }