| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "OpenDialogInteractionConfig.h"
- #include <XML.h>
- #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<Block*, Entity*> 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<OpenDialogInteractionConfig>()
- {}
- JSONObjectValidationBuilder* OpenDialogInteractionConfigFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return InteractionConfigFactory<
- OpenDialogInteractionConfig>::addToValidator(builder)
- ->withRequiredAttribute("dialogElement",
- Game::INSTANCE->zTypeRegistry()->getValidator<UIDialogElement>());
- }
- OpenDialogInteractionConfig* OpenDialogInteractionConfigFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- OpenDialogInteractionConfig* result
- = InteractionConfigFactory<OpenDialogInteractionConfig>::fromJson(
- zJson);
- result->setDialogElement(
- Game::INSTANCE->zTypeRegistry()->fromJson<UIDialogElement>(
- zJson->zValue("dialogElement")));
- return result;
- }
- Framework::JSON::JSONObject* OpenDialogInteractionConfigFactory::toJsonObject(
- OpenDialogInteractionConfig* zObject) const
- {
- Framework::JSON::JSONObject* result
- = InteractionConfigFactory<OpenDialogInteractionConfig>::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();
- }
|