| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "UIDialogElement.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<Block*, Entity*> zTarget, Entity* zActor) const
- {
- Framework::XML::Element* result
- = UIContainerElement::toUIML(zTarget, zActor);
- result->setName("dialog");
- result->setAttribute("title", title);
- if (notifyOnClose)
- {
- result->setAttribute(
- "notifyOnClose", notifyOnClose->getReferenceId(zTarget, zActor));
- }
- return result;
- }
- UIDialogElementFactory::UIDialogElementFactory()
- : UIContainerElementFactory<UIDialogElement>()
- {}
- JSONObjectValidationBuilder* UIDialogElementFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return UIContainerElementFactory::addToValidator(builder)
- ->withRequiredString("title")
- ->finishString()
- ->withRequiredAttribute("notifyOnClose",
- Game::INSTANCE->zTypeRegistry()->getValidator<UIReference>(),
- 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<UIReference>(
- 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<UIReference>(
- zObject->zNotifyOnClose()));
- }
- return result;
- }
- UIDialogElement* UIDialogElementFactory::createElement(
- Framework::JSON::JSONObject* zJson) const
- {
- return new UIDialogElement();
- }
- const char* UIDialogElementFactory::getTypeToken() const
- {
- return "dialog";
- }
|