#include "UIDialogElement.h" #include "Block.h" #include "Entity.h" #include "UIReference.h" UIDialogElement::UIDialogElement() : UIContainerElement(), notifyOnClose(0) {} UIDialogElement::~UIDialogElement() { if (notifyOnClose) { notifyOnClose->release(); } } void UIDialogElement::setTitle(const Framework::Text& title) { this->title = title; } const Framework::Text& UIDialogElement::getTitle() const { return title; } void UIDialogElement::setNotifyOnClose(UIReference* notifyOnClose) { if (this->notifyOnClose) { this->notifyOnClose->release(); } this->notifyOnClose = notifyOnClose; } UIReference* UIDialogElement::zNotifyOnClose() const { return notifyOnClose; } Framework::XML::Element* UIDialogElement::toUIML( Framework::Either zTarget, Entity* zActor) const { Framework::XML::Element* result = UIContainerElement::toUIML(zTarget, zActor); result->setName("dialog"); result->setAttribute("title", title); Framework::Text id = getId(); if (zTarget.isA()) { id.append() << "_" + zTarget.getA()->getDimensionId() << "," << zTarget.getA()->getPos().x << "," << zTarget.getA()->getPos().y << "," << zTarget.getA()->getPos().z << "_" << zActor->getId(); } else { id.append() << "_" << zTarget.getB()->getId() << "_" << zActor->getId(); } result->setAttribute("id", id); if (notifyOnClose) { result->setAttribute( "notifyOnClose", notifyOnClose->getReferenceId(zTarget, zActor)); } return result; } UIDialogElementFactory::UIDialogElementFactory() : UIContainerElementFactory() {} JSONObjectValidationBuilder* UIDialogElementFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return UIContainerElementFactory::addToValidator(builder) ->withRequiredString("title") ->finishString() ->withRequiredAttribute("notifyOnClose", Game::INSTANCE->zTypeRegistry()->getValidator(), false, true); } UIDialogElement* UIDialogElementFactory::fromJson( Framework::JSON::JSONObject* zJson) const { UIDialogElement* result = UIContainerElementFactory::fromJson(zJson); result->setTitle(zJson->zValue("title")->asString()->getString()); if (zJson->hasValue("notifyOnClose")) { result->setNotifyOnClose( Game::INSTANCE->zTypeRegistry()->fromJson( zJson->zValue("notifyOnClose"))); } return result; } Framework::JSON::JSONObject* UIDialogElementFactory::toJsonObject( UIDialogElement* zObject) const { Framework::JSON::JSONObject* result = UIContainerElementFactory::toJsonObject(zObject); result->addValue( "title", new Framework::JSON::JSONString(zObject->getTitle())); if (zObject->zNotifyOnClose()) { result->addValue("notifyOnClose", Game::INSTANCE->zTypeRegistry()->toJson( zObject->zNotifyOnClose())); } return result; } UIDialogElement* UIDialogElementFactory::createElement( Framework::JSON::JSONObject* zJson) const { return new UIDialogElement(); } const char* UIDialogElementFactory::getTypeToken() const { return "dialog"; }