|
|
@@ -0,0 +1,135 @@
|
|
|
+#include "UICraftingProgress.h"
|
|
|
+
|
|
|
+#include "UIReference.h"
|
|
|
+
|
|
|
+UICraftingProgress::UICraftingProgress()
|
|
|
+ : UIElement(),
|
|
|
+ reference(0)
|
|
|
+{}
|
|
|
+
|
|
|
+UICraftingProgress::~UICraftingProgress()
|
|
|
+{
|
|
|
+ if (reference)
|
|
|
+ {
|
|
|
+ reference->release();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void UICraftingProgress::setReference(UIReference* reference)
|
|
|
+{
|
|
|
+ if (this->reference)
|
|
|
+ {
|
|
|
+ this->reference->release();
|
|
|
+ }
|
|
|
+ this->reference = reference;
|
|
|
+}
|
|
|
+
|
|
|
+UIReference* UICraftingProgress::zReference() const
|
|
|
+{
|
|
|
+ return reference;
|
|
|
+}
|
|
|
+
|
|
|
+void UICraftingProgress::setBackgroundImagePath(
|
|
|
+ const Framework::Text& backgroundImagePath)
|
|
|
+{
|
|
|
+ this->backgroundImagePath = backgroundImagePath;
|
|
|
+}
|
|
|
+
|
|
|
+const Framework::Text& UICraftingProgress::getBackgroundImagePath() const
|
|
|
+{
|
|
|
+ return backgroundImagePath;
|
|
|
+}
|
|
|
+
|
|
|
+void UICraftingProgress::setForegroundImagePath(
|
|
|
+ const Framework::Text& foregroundImagePath)
|
|
|
+{
|
|
|
+ this->foregroundImagePath = foregroundImagePath;
|
|
|
+}
|
|
|
+
|
|
|
+const Framework::Text& UICraftingProgress::getForegroundImagePath() const
|
|
|
+{
|
|
|
+ return foregroundImagePath;
|
|
|
+}
|
|
|
+
|
|
|
+void UICraftingProgress::setDirection(const Framework::Text& direction)
|
|
|
+{
|
|
|
+ this->direction = direction;
|
|
|
+}
|
|
|
+
|
|
|
+const Framework::Text& UICraftingProgress::getDirection() const
|
|
|
+{
|
|
|
+ return direction;
|
|
|
+}
|
|
|
+
|
|
|
+Framework::XML::Element* UICraftingProgress::toUIML(
|
|
|
+ Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
|
|
|
+{
|
|
|
+ Framework::XML::Element* element = UIElement::toUIML(zTarget, zActor);
|
|
|
+ element->setName("craftingProgress");
|
|
|
+ element->setAttribute("target", reference->getReferenceId(zTarget, zActor));
|
|
|
+ element->setAttribute("backgroundImagePath", backgroundImagePath);
|
|
|
+ element->setAttribute("foregroundImagePath", foregroundImagePath);
|
|
|
+ element->setAttribute("direction", direction);
|
|
|
+ return element;
|
|
|
+}
|
|
|
+
|
|
|
+UICraftingProgressFactory::UICraftingProgressFactory()
|
|
|
+ : UIElementFactory()
|
|
|
+{}
|
|
|
+
|
|
|
+JSONObjectValidationBuilder* UICraftingProgressFactory::addToValidator(
|
|
|
+ JSONObjectValidationBuilder* builder) const
|
|
|
+{
|
|
|
+ return UIElementFactory::addToValidator(builder)
|
|
|
+ ->withRequiredAttribute("reference",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<UIReference>())
|
|
|
+ ->withRequiredString("backgroundImagePath")
|
|
|
+ ->finishString()
|
|
|
+ ->withRequiredString("foregroundImagePath")
|
|
|
+ ->finishString()
|
|
|
+ ->withRequiredString("direction")
|
|
|
+ ->whichIsOneOf({"TOP", "LEFT", "BOTTOM", "RIGHT"})
|
|
|
+ ->finishString();
|
|
|
+}
|
|
|
+
|
|
|
+UICraftingProgress* UICraftingProgressFactory::fromJson(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ UICraftingProgress* result = UIElementFactory::fromJson(zJson);
|
|
|
+ result->setReference(Game::INSTANCE->zTypeRegistry()->fromJson<UIReference>(
|
|
|
+ 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* UICraftingProgressFactory::toJsonObject(
|
|
|
+ UICraftingProgress* 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;
|
|
|
+}
|
|
|
+
|
|
|
+UICraftingProgress* UICraftingProgressFactory::createElement(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ return new UICraftingProgress();
|
|
|
+}
|
|
|
+
|
|
|
+const char* UICraftingProgressFactory::getTypeToken() const
|
|
|
+{
|
|
|
+ return "craftingProgress";
|
|
|
+}
|