#include "UIFuelState.h" #include "UIReference.h" UIFuelState::UIFuelState() : UIElement(), reference(0) {} UIFuelState::~UIFuelState() { if (reference) { reference->release(); } } void UIFuelState::setReference(UIReference* reference) { if (this->reference) { this->reference->release(); } this->reference = reference; } UIReference* UIFuelState::zReference() const { return reference; } void UIFuelState::setBackgroundImagePath( const Framework::Text& backgroundImagePath) { this->backgroundImagePath = backgroundImagePath; } const Framework::Text& UIFuelState::getBackgroundImagePath() const { return backgroundImagePath; } void UIFuelState::setForegroundImagePath( const Framework::Text& foregroundImagePath) { this->foregroundImagePath = foregroundImagePath; } const Framework::Text& UIFuelState::getForegroundImagePath() const { return foregroundImagePath; } void UIFuelState::setDirection(const Framework::Text& direction) { this->direction = direction; } const Framework::Text& UIFuelState::getDirection() const { return direction; } Framework::XML::Element* UIFuelState::toUIML( Framework::Either zTarget, Entity* zActor) const { Framework::XML::Element* element = UIElement::toUIML(zTarget, zActor); element->setName("fuelState"); element->setAttribute("target", reference->getReferenceId(zTarget, zActor)); element->setAttribute("backgroundImagePath", backgroundImagePath); element->setAttribute("foregroundImagePath", foregroundImagePath); element->setAttribute("direction", direction); return element; } UIFuelStateFactory::UIFuelStateFactory() : UIElementFactory() {} JSONObjectValidationBuilder* UIFuelStateFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return UIElementFactory::addToValidator(builder) ->withRequiredAttribute("reference", Game::INSTANCE->zTypeRegistry()->getValidator()) ->withRequiredString("backgroundImagePath") ->finishString() ->withRequiredString("foregroundImagePath") ->finishString() ->withRequiredString("direction") ->whichIsOneOf({"TOP", "LEFT", "BOTTOM", "RIGHT"}) ->finishString(); } UIFuelState* UIFuelStateFactory::fromJson( Framework::JSON::JSONObject* zJson) const { UIFuelState* result = UIElementFactory::fromJson(zJson); result->setReference(Game::INSTANCE->zTypeRegistry()->fromJson( zJson->zValue("reference"))); result->setBackgroundImagePath( zJson->zValue("backgroundImagePath")->asString()->getString()); result->setForegroundImagePath( zJson->zValue("foregroundImagePath")->asString()->getString()); result->setDirection(zJson->zValue("direction")->asString()->getString()); return result; } Framework::JSON::JSONObject* UIFuelStateFactory::toJsonObject( UIFuelState* zObject) const { Framework::JSON::JSONObject* result = UIElementFactory::toJsonObject(zObject); result->addValue("reference", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zReference())); result->addValue("backgroundImagePath", new Framework::JSON::JSONString(zObject->getBackgroundImagePath())); result->addValue("foregroundImagePath", new Framework::JSON::JSONString(zObject->getForegroundImagePath())); result->addValue( "direction", new Framework::JSON::JSONString(zObject->getDirection())); return result; } UIFuelState* UIFuelStateFactory::createElement( Framework::JSON::JSONObject* zJson) const { return new UIFuelState(); } const char* UIFuelStateFactory::getTypeToken() const { return "fuelState"; }