| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018 |
- #include "RecipieIngredient.h"
- #include <FileSystem.h>
- #include <ToolTip.h>
- #include <XML.h>
- #include "Globals.h"
- RecipieIngredientElement::RecipieIngredientElement()
- : Framework::UIMLElement()
- {}
- LogicTree* RecipieIngredientElement::parse(Framework::XML::Element* zElement)
- {
- if (zElement->getName().isEqual("anyItem"))
- {
- return new LogicTree(LogicalOperator::OR, new RequirementSet());
- }
- else if (zElement->getName().isEqual("attribute"))
- {
- AttributeOperator op = AttributeOperator::Equals;
- if (zElement->getAttributeValue("operator").isEqual("!="))
- {
- op = AttributeOperator::NotEquals;
- }
- else if (zElement->getAttributeValue("operator").isEqual(">"))
- {
- op = AttributeOperator::GreaterThan;
- }
- else if (zElement->getAttributeValue("operator").isEqual(">="))
- {
- op = AttributeOperator::GreaterThanOrEquals;
- }
- else if (zElement->getAttributeValue("operator").isEqual("<"))
- {
- op = AttributeOperator::LessThan;
- }
- else if (zElement->getAttributeValue("operator").isEqual("<="))
- {
- op = AttributeOperator::LessThanOrEquals;
- }
- Requirement* req = new Requirement(zElement->getAttributeValue("name"),
- zElement->getAttributeValue("value"),
- op);
- RequirementSet* set = new RequirementSet();
- set->addRequirement(req);
- req->release();
- return new LogicTree(LogicalOperator::OR, set);
- }
- else if (zElement->getName().isEqual("operator"))
- {
- bool result0_0 = (bool)(int)zElement->getAttributeValue("result_0_0");
- bool result0_1 = (bool)(int)zElement->getAttributeValue("result_0_1");
- bool result1_0 = (bool)(int)zElement->getAttributeValue("result_1_0");
- bool result1_1 = (bool)(int)zElement->getAttributeValue("result_1_1");
- if (!result0_0 && !result0_1 && !result1_0 && !result1_1)
- { // none match
- RequirementSet* set = new RequirementSet();
- Requirement* req
- = new Requirement("_x", "0", AttributeOperator::Equals);
- set->addRequirement(req);
- req->release();
- req = new Requirement("_x", "1", AttributeOperator::Equals);
- set->addRequirement(req);
- req->release();
- return new LogicTree(LogicalOperator::OR, set);
- }
- if (result0_0 && result0_1 && result1_0 && result1_1)
- { // any match
- return new LogicTree(LogicalOperator::OR, new RequirementSet());
- }
- auto iterator = zElement->getChilds();
- LogicTree* left = parse(iterator.val());
- if (!result0_0 && !result0_1 && result1_0 && result1_1)
- {
- return left;
- }
- if (result0_0 && result0_1 && !result1_0 && !result1_1)
- {
- left->negate();
- return left;
- }
- LogicTree* right = 0;
- iterator++;
- right = parse(iterator.val());
- if (!result0_0 && result0_1 && !result1_0 && result1_1)
- {
- left->release();
- return right;
- }
- if (result0_0 && !result0_1 && result1_0 && !result1_1)
- {
- left->release();
- right->negate();
- return right;
- }
- if (!result0_0 && !result0_1 && !result1_0 && result1_1)
- {
- LogicTree* result = new LogicTree(LogicalOperator::AND, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- if (!result0_0 && result0_1 && result1_0 && result1_1)
- {
- LogicTree* result = new LogicTree(LogicalOperator::OR, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- if (result0_0 && result0_1 && result1_0 && !result1_1)
- {
- left->negate();
- right->negate();
- LogicTree* result = new LogicTree(LogicalOperator::OR, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- if (result0_0 && !result0_1 && !result1_0 && !result1_1)
- {
- left->negate();
- right->negate();
- LogicTree* result = new LogicTree(LogicalOperator::AND, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- if (!result0_0 && !result0_1 && result1_0 && !result1_1)
- {
- right->negate();
- LogicTree* result = new LogicTree(LogicalOperator::AND, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- if (!result0_0 && result0_1 && !result1_0 && !result1_1)
- {
- left->negate();
- LogicTree* result = new LogicTree(LogicalOperator::AND, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- if (!result0_0 && result0_1 && result1_0 && !result1_1)
- {
- LogicTree* orT = new LogicTree(LogicalOperator::OR, 0);
- orT->addChildren(left);
- orT->addChildren(right);
- LogicTree* notLeft = left->clone();
- notLeft->negate();
- LogicTree* notRight = right->clone();
- notRight->negate();
- LogicTree* notOr = new LogicTree(LogicalOperator::OR, 0);
- notOr->addChildren(notLeft);
- notOr->addChildren(notRight);
- LogicTree* result = new LogicTree(LogicalOperator::AND, 0);
- result->addChildren(orT);
- result->addChildren(notOr);
- return result;
- }
- if (result0_0 && !result0_1 && !result1_0 && result1_1)
- {
- LogicTree* andT = new LogicTree(LogicalOperator::AND, 0);
- andT->addChildren(left);
- andT->addChildren(right);
- LogicTree* notLeft = left->clone();
- notLeft->negate();
- LogicTree* notRight = right->clone();
- notRight->negate();
- LogicTree* notAnd = new LogicTree(LogicalOperator::AND, 0);
- notAnd->addChildren(notLeft);
- notAnd->addChildren(notRight);
- LogicTree* result = new LogicTree(LogicalOperator::OR, 0);
- result->addChildren(andT);
- result->addChildren(notAnd);
- return result;
- }
- if (result0_0 && !result0_1 && result1_0 && result1_1)
- {
- right->negate();
- LogicTree* result = new LogicTree(LogicalOperator::OR, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- if (result0_0 && result0_1 && !result1_0 && result1_1)
- {
- left->negate();
- LogicTree* result = new LogicTree(LogicalOperator::OR, 0);
- result->addChildren(left);
- result->addChildren(right);
- return result;
- }
- }
- return 0;
- }
- //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
- //! ist
- bool RecipieIngredientElement::isApplicableFor(Framework::XML::Element& element)
- {
- return element.getName().isEqual("ingredient");
- }
- //! erstellt eine neue Drawable zu einem gegebenen xml Element
- Framework::Drawable* RecipieIngredientElement::parseElement(
- Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
- {
- int amount = (int)element.getAttributeValue("amount");
- RecipieIngredient* result = new RecipieIngredient(amount);
- Framework::XML::Editor logicSelector = element.selectChildsByName("logic");
- if (logicSelector.exists())
- {
- LogicTree* logic = new LogicTree(LogicalOperator::OR, 0);
- logicSelector.selectChildren().forEach(
- [this, logic](Framework::XML::Element* zElement) {
- logic->addChildren(parse(zElement));
- });
- Framework::RCArray<RequirementSet>* requirements = logic->resolve();
- logic->release();
- for (RequirementSet* set : *requirements)
- {
- result->addPossibleItem(set->getIcon(),
- new Text(set->renderToTooltip()),
- set->getItemType());
- }
- requirements->release();
- }
- return result;
- }
- bool RecipieIngredientElement::updateElement(Framework::XML::Element& element,
- Framework::Drawable& z,
- Framework::UIMLContainer& generalFactory)
- {
- return false;
- }
- //! wendet die layout parameter zu einer Drawable an
- void RecipieIngredientElement::layout(Framework::XML::Element& element,
- Framework::Drawable& z,
- int pWidth,
- int pHeight,
- Framework::UIMLContainer& generalLayouter)
- {
- UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
- z.setWidth(50);
- z.setHeight(50);
- }
- RecipieIngredient::RecipieIngredient(int amount)
- : Framework::DrawableBackground(),
- currentIconIndex(0),
- timtUntilNextIcon(2.0),
- amount(amount)
- {
- setStyle(Framework::Drawable::Style::Allowed
- | Framework::Drawable::Style::Visible);
- Framework::ToolTip* tip = new Framework::ToolTip(window->zScreen());
- tip->addStyle(Framework::DrawableBackground::Style::Background
- | Framework::DrawableBackground::Style::BAlpha
- | Framework::DrawableBackground::Style::Border
- | Framework::DrawableBackground::Style::Visible);
- tip->setBackgroundColor(0xA0000000);
- tip->setBorderColor(0xFFFFFFFF);
- tip->setBorderWidth(1);
- toolTip = uiFactory.createTextField(uiFactory.initParam);
- toolTip->setText("");
- toolTip->setSize(0, 0);
- toolTip->addStyle(Framework::TextField::Style::Multiline);
- tip->addMember(toolTip);
- tip->setWarten(0.5);
- setToolTipZ(tip);
- }
- void RecipieIngredient::addPossibleItem(
- Framework::Image* icon, Framework::Text* toolTip, int typeId)
- {
- icons.add(icon);
- toolTips.add(toolTip);
- itemTypes.add(typeId);
- if (toolTips.getEntryCount() == 1)
- {
- this->toolTip->setText(toolTips.z(0)->getText());
- this->toolTip->setSize(
- this->toolTip->getNeededWidth(), this->toolTip->getNeededHeight());
- }
- }
- bool RecipieIngredient::tick(double tickVal)
- {
- if (!zToolTip()->isVisible())
- {
- timtUntilNextIcon -= tickVal;
- if (timtUntilNextIcon <= 0)
- {
- timtUntilNextIcon = 2.0;
- currentIconIndex++;
- if (currentIconIndex >= icons.getEntryCount())
- {
- currentIconIndex = 0;
- }
- if (toolTips.getEntryCount() > 0)
- {
- toolTip->setText(toolTips.z(currentIconIndex)->getText());
- toolTip->setSize(
- toolTip->getNeededWidth(), toolTip->getNeededHeight());
- rend = 1;
- }
- }
- }
- return DrawableBackground::tick(tickVal);
- }
- void RecipieIngredient::render(Framework::Image& rObj)
- {
- DrawableBackground::render(rObj);
- if (!rObj.setDrawOptions(pos.x, pos.y, gr.x, gr.y)) return;
- TextRenderer tr;
- tr.setFontZ(dynamic_cast<Font*>(uiFactory.initParam.font->getThis()));
- tr.setFontSize(12);
- rObj.fillRegion(0, 0, 50, 50, 0xFF222222);
- if (icons.getEntryCount() > 0)
- rObj.alphaImage(0, 0, 50, 50, *icons.z(currentIconIndex));
- const char* units[] = {"", "K", "M", "G", "T", "P"};
- int i = 0;
- int tmpCount = amount;
- for (; i < 6 && tmpCount > 1024; i++)
- tmpCount = tmpCount / 1024;
- Text count = tmpCount;
- count += units[i];
- tr.renderText(45 - tr.getTextWidth(count),
- 45 - tr.getTextHeight(count),
- count,
- rObj,
- 0xFFFFFFFF);
- rObj.releaseDrawOptions();
- }
- void RecipieIngredient::doMouseEvent(Framework::MouseEvent& me, bool userRet)
- {
- if (me.id == ME_RLeft)
- {
- if (itemTypes.getEntryCount() > currentIconIndex)
- {
- World::INSTANCE->zClient()->craftingUIMLRequest(
- itemTypes.get(currentIconIndex));
- }
- }
- DrawableBackground::doMouseEvent(me, userRet);
- }
- Requirement::Requirement(
- Framework::Text attribute, Framework::Text value, AttributeOperator op)
- : Framework::ReferenceCounter(),
- attribute(attribute),
- value(value),
- op(op)
- {}
- void Requirement::negate()
- {
- switch (op)
- {
- case AttributeOperator::Equals:
- op = AttributeOperator::NotEquals;
- break;
- case AttributeOperator::NotEquals:
- op = AttributeOperator::Equals;
- break;
- case AttributeOperator::GreaterThan:
- op = AttributeOperator::LessThanOrEquals;
- break;
- case AttributeOperator::GreaterThanOrEquals:
- op = AttributeOperator::LessThan;
- break;
- case AttributeOperator::LessThan:
- op = AttributeOperator::GreaterThanOrEquals;
- break;
- case AttributeOperator::LessThanOrEquals:
- op = AttributeOperator::GreaterThan;
- break;
- }
- }
- Requirement* Requirement::clone()
- {
- return new Requirement(attribute, value, op);
- }
- bool Requirement::contradicts(Requirement* zOther)
- {
- if (zOther->attribute.isEqual(attribute.getText()))
- {
- if (zOther->value.isEqual(value))
- {
- if (op == AttributeOperator::Equals
- && zOther->op == AttributeOperator::NotEquals)
- {
- return 1;
- }
- if (op == AttributeOperator::NotEquals
- && zOther->op == AttributeOperator::Equals)
- {
- return 1;
- }
- if (op == AttributeOperator::GreaterThan
- && zOther->op == AttributeOperator::LessThan)
- {
- return 1;
- }
- if (op == AttributeOperator::LessThan
- && zOther->op == AttributeOperator::GreaterThan)
- {
- return 1;
- }
- }
- if (op == AttributeOperator::LessThan
- || op == AttributeOperator::LessThanOrEquals
- || op == AttributeOperator::GreaterThan
- || op == AttributeOperator::GreaterThanOrEquals)
- {
- double v1 = (double)value;
- double v2 = (double)zOther->value;
- if (op == AttributeOperator::LessThan
- || op == AttributeOperator::LessThanOrEquals)
- {
- if (v1 < v2)
- {
- if (zOther->op == AttributeOperator::GreaterThan
- || zOther->op == AttributeOperator::GreaterThanOrEquals
- || zOther->op == AttributeOperator::Equals)
- {
- return 1;
- }
- }
- }
- else if (op == AttributeOperator::GreaterThan
- || op == AttributeOperator::GreaterThanOrEquals)
- {
- if (v1 > v2)
- {
- if (zOther->op == AttributeOperator::LessThan
- || zOther->op == AttributeOperator::LessThanOrEquals
- || zOther->op == AttributeOperator::Equals)
- {
- return 1;
- }
- }
- }
- }
- if (zOther->op == AttributeOperator::LessThan
- || zOther->op == AttributeOperator::LessThanOrEquals
- || zOther->op == AttributeOperator::GreaterThan
- || zOther->op == AttributeOperator::GreaterThanOrEquals)
- {
- double v1 = (double)zOther->value;
- double v2 = (double)value;
- if (zOther->op == AttributeOperator::LessThan
- || zOther->op == AttributeOperator::LessThanOrEquals)
- {
- if (v1 < v2)
- {
- if (op == AttributeOperator::GreaterThan
- || op == AttributeOperator::GreaterThanOrEquals
- || op == AttributeOperator::Equals)
- {
- return 1;
- }
- }
- }
- else if (zOther->op == AttributeOperator::GreaterThan
- || zOther->op == AttributeOperator::GreaterThanOrEquals)
- {
- if (v1 > v2)
- {
- if (op == AttributeOperator::LessThan
- || op == AttributeOperator::LessThanOrEquals
- || op == AttributeOperator::Equals)
- {
- return 1;
- }
- }
- }
- }
- }
- return 0;
- }
- bool Requirement::merge(Requirement* zOther)
- {
- if (zOther->attribute.isEqual(attribute.getText()))
- {
- if (zOther->value.isEqual(value))
- {
- if (op == zOther->op)
- {
- return 1;
- }
- }
- else
- {
- if (op == AttributeOperator::Equals
- && zOther->op == AttributeOperator::NotEquals)
- {
- return 1;
- }
- if (op == AttributeOperator::NotEquals
- && zOther->op == AttributeOperator::Equals)
- {
- op = AttributeOperator::Equals;
- value = zOther->value;
- return 1;
- }
- }
- if (op == AttributeOperator::LessThan
- || op == AttributeOperator::LessThanOrEquals
- || op == AttributeOperator::GreaterThan
- || op == AttributeOperator::GreaterThanOrEquals)
- {
- double v1 = (double)value;
- double v2 = (double)zOther->value;
- if (op == AttributeOperator::LessThan
- || op == AttributeOperator::LessThanOrEquals)
- {
- if (zOther->op == AttributeOperator::LessThan
- || zOther->op == AttributeOperator::LessThanOrEquals)
- {
- if (v1 > v2
- || (v1 == v2
- && op == AttributeOperator::LessThanOrEquals))
- {
- op = zOther->op;
- value = zOther->value;
- }
- return 1;
- }
- if (zOther->op == AttributeOperator::Equals)
- {
- if (v2 < v1
- || (v2 == v1
- && op == AttributeOperator::LessThanOrEquals))
- {
- op = zOther->op;
- value = zOther->value;
- return 1;
- }
- }
- if (zOther->op == AttributeOperator::NotEquals)
- {
- if (v2 > v1
- || (v2 == v1 && op == AttributeOperator::LessThan))
- {
- return 1;
- }
- }
- }
- else if (op == AttributeOperator::GreaterThan
- || op == AttributeOperator::GreaterThanOrEquals)
- {
- if (zOther->op == AttributeOperator::GreaterThan
- || zOther->op == AttributeOperator::GreaterThanOrEquals)
- {
- if (v1 < v2
- || (v1 == v2
- && op == AttributeOperator::GreaterThanOrEquals))
- {
- op = zOther->op;
- value = zOther->value;
- }
- return 1;
- }
- if (zOther->op == AttributeOperator::Equals)
- {
- if (v2 > v1
- || (v2 == v1
- && op == AttributeOperator::GreaterThanOrEquals))
- {
- op = zOther->op;
- value = zOther->value;
- return 1;
- }
- }
- if (zOther->op == AttributeOperator::NotEquals)
- {
- if (v2 < v1
- || (v2 == v1 && op == AttributeOperator::GreaterThan))
- {
- return 1;
- }
- }
- }
- }
- if (zOther->op == AttributeOperator::LessThan
- || zOther->op == AttributeOperator::LessThanOrEquals
- || zOther->op == AttributeOperator::GreaterThan
- || zOther->op == AttributeOperator::GreaterThanOrEquals)
- {
- double v1 = (double)zOther->value;
- double v2 = (double)value;
- if (zOther->op == AttributeOperator::LessThan
- || zOther->op == AttributeOperator::LessThanOrEquals)
- {
- if (op == AttributeOperator::Equals)
- {
- if (v2 < v1
- || (v2 == v1
- && zOther->op
- == AttributeOperator::LessThanOrEquals))
- {
- return 1;
- }
- }
- if (op == AttributeOperator::NotEquals)
- {
- if (v2 > v1
- || (v2 == v1
- && zOther->op == AttributeOperator::LessThan))
- {
- op = zOther->op;
- value = zOther->value;
- return 1;
- }
- }
- }
- else if (zOther->op == AttributeOperator::GreaterThan
- || zOther->op == AttributeOperator::GreaterThanOrEquals)
- {
- if (op == AttributeOperator::Equals)
- {
- if (v2 > v1
- || (v2 == v1
- && zOther->op
- == AttributeOperator::GreaterThanOrEquals))
- {
- return 1;
- }
- }
- if (op == AttributeOperator::NotEquals)
- {
- if (v2 < v1
- || (v2 == v1
- && zOther->op == AttributeOperator::GreaterThan))
- {
- op = zOther->op;
- value = zOther->value;
- return 1;
- }
- }
- }
- }
- }
- return 0;
- }
- int Requirement::getItemType()
- {
- if (attribute.isEqual("Type") && op == AttributeOperator::Equals)
- {
- return (int)value;
- }
- return -1;
- }
- Framework::Text Requirement::getDescription()
- {
- Framework::Text result = attribute;
- result += " ";
- switch (op)
- {
- case AttributeOperator::Equals:
- result += "is";
- break;
- case AttributeOperator::NotEquals:
- result += "is not";
- break;
- case AttributeOperator::LessThan:
- result += "is less than";
- break;
- case AttributeOperator::LessThanOrEquals:
- result += "is less than or equal to";
- break;
- case AttributeOperator::GreaterThan:
- result += "is greater than";
- break;
- case AttributeOperator::GreaterThanOrEquals:
- result += "is greater than or equal to";
- break;
- }
- result += " ";
- result += value;
- return result;
- }
- RequirementSet::RequirementSet()
- : Framework::ReferenceCounter()
- {}
- void RequirementSet::addRequirement(Requirement* zReq)
- {
- for (Requirement* req : requirements)
- {
- if (req->merge(zReq)) return;
- }
- requirements.add(zReq->clone());
- }
- RequirementSet* RequirementSet::clone()
- {
- RequirementSet* result = new RequirementSet();
- for (Requirement* req : requirements)
- {
- result->requirements.add(req->clone());
- }
- return result;
- }
- void RequirementSet::addRequirements(RequirementSet* zOther)
- {
- for (Requirement* req : zOther->requirements)
- {
- addRequirement(req);
- }
- }
- void RequirementSet::negate(LogicTree* zNode)
- {
- for (Requirement* req : requirements)
- {
- Requirement* negate = req->clone();
- negate->negate();
- RequirementSet* set = new RequirementSet();
- set->addRequirement(negate);
- negate->release();
- zNode->addChildren(new LogicTree(LogicalOperator::OR, set));
- }
- }
- bool RequirementSet::isNoneMatch() const
- {
- for (Requirement* req : requirements)
- {
- for (Requirement* req2 : requirements)
- {
- if (req != req2)
- {
- if (req->contradicts(req2))
- {
- return 1;
- }
- }
- }
- }
- return 0;
- }
- bool RequirementSet::isAnyMatch() const
- {
- return requirements.getEntryCount() == 0;
- }
- Framework::Text RequirementSet::renderToTooltip() const
- {
- int itemType = -1;
- for (Requirement* req : requirements)
- {
- int rT = req->getItemType();
- if (rT != -1)
- {
- if (itemType == -1)
- {
- itemType = rT;
- }
- else if (itemType != rT)
- {
- itemType = -2;
- }
- }
- }
- Framework::Text result = "";
- if (itemType == -2)
- {
- return "No Item matches this filter";
- }
- else if (itemType == -1)
- {
- result += "Any Item";
- }
- else
- {
- result += zItemType(itemType)->getName();
- }
- if (requirements.getEntryCount() > 0)
- {
- bool first = 1;
- for (Requirement* req : requirements)
- {
- if (req->getItemType() == -1)
- {
- if (first)
- {
- result += ":\n";
- first = 0;
- }
- result += " ";
- result += req->getDescription();
- result += "\n";
- }
- }
- }
- return result;
- }
- Framework::Image* RequirementSet::getIcon() const
- {
- int itemType = -1;
- for (Requirement* req : requirements)
- {
- int rT = req->getItemType();
- if (rT != -1)
- {
- if (itemType == -1)
- {
- itemType = rT;
- }
- else if (itemType != rT)
- {
- itemType = -2;
- }
- }
- }
- if (itemType == -2)
- {
- LTDBFile dat;
- dat.setFile(new Text("data/images/gui_icons.ltdb"));
- dat.readData(0);
- return dat.load(0, new Text("noitem.png"));
- }
- else if (itemType == -1)
- {
- LTDBFile dat;
- dat.setFile(new Text("data/images/gui_icons.ltdb"));
- dat.readData(0);
- return dat.load(0, new Text("anyitem.png"));
- }
- else
- {
- return dynamic_cast<Framework::Image*>(
- zItemType(itemType)->zIcon()->getThis());
- }
- }
- int RequirementSet::getItemType() const
- {
- int itemType = -1;
- for (Requirement* req : requirements)
- {
- int rT = req->getItemType();
- if (rT != -1)
- {
- if (itemType == -1)
- {
- itemType = rT;
- }
- else if (itemType != rT)
- {
- itemType = -2;
- }
- }
- }
- return itemType;
- }
- LogicTree::LogicTree(LogicalOperator op, RequirementSet* set)
- : Framework::ReferenceCounter(),
- op(op),
- requirementSet(set)
- {}
- LogicTree::~LogicTree()
- {
- if (requirementSet) requirementSet->release();
- }
- Framework::RCArray<RequirementSet>* LogicTree::multiply(
- Framework::RCArray<RequirementSet>* a,
- Framework::RCArray<RequirementSet>* b)
- {
- Framework::RCArray<RequirementSet>* result
- = new Framework::RCArray<RequirementSet>();
- for (RequirementSet* aSet : *a)
- {
- for (RequirementSet* bSet : *b)
- {
- RequirementSet* set = aSet->clone();
- set->addRequirements(bSet);
- if (!set->isNoneMatch())
- {
- if (set->isAnyMatch())
- {
- result->clear();
- result->add(set);
- a->release();
- b->release();
- return result;
- }
- else
- {
- result->add(set);
- }
- }
- else
- {
- set->release();
- }
- }
- }
- return result;
- }
- void LogicTree::addChildren(LogicTree* tree)
- {
- children.add(tree);
- }
- LogicTree* LogicTree::clone()
- {
- LogicTree* result = new LogicTree(op, requirementSet->clone());
- for (LogicTree* child : children)
- {
- result->children.add(child->clone());
- }
- return result;
- }
- void LogicTree::negate()
- {
- if (requirementSet != 0)
- {
- requirementSet->negate(this);
- requirementSet->release();
- requirementSet = 0;
- }
- else
- {
- if (op == LogicalOperator::AND)
- {
- op = LogicalOperator::OR;
- }
- else if (op == LogicalOperator::OR)
- {
- op = LogicalOperator::AND;
- }
- for (LogicTree* child : children)
- {
- child->negate();
- }
- }
- }
- Framework::RCArray<RequirementSet>* LogicTree::resolve()
- {
- if (requirementSet != 0)
- {
- Framework::RCArray<RequirementSet>* result
- = new Framework::RCArray<RequirementSet>();
- result->add(dynamic_cast<RequirementSet*>(requirementSet->getThis()));
- return result;
- }
- else
- {
- Framework::RCArray<RequirementSet>* result = 0;
- if (op == LogicalOperator::OR)
- {
- result = new Framework::RCArray<RequirementSet>();
- for (LogicTree* child : children)
- {
- Framework::RCArray<RequirementSet>* childSet = child->resolve();
- for (RequirementSet* set : *childSet)
- {
- result->add(dynamic_cast<RequirementSet*>(set->getThis()));
- }
- childSet->release();
- }
- }
- else if (op == LogicalOperator::AND)
- {
- result = children.z(0)->resolve();
- for (int i = 1; i < children.getEntryCount(); i++)
- {
- Framework::RCArray<RequirementSet>* childSet
- = children.z(i)->resolve();
- result = multiply(result, childSet);
- }
- }
- if (result != 0)
- {
- for (int i = 0; i < result->getEntryCount(); i++)
- {
- if (result->z(i)->isNoneMatch())
- {
- result->remove(i);
- i--;
- }
- else if (result->z(i)->isAnyMatch())
- {
- Framework::RCArray<RequirementSet>* anyMatch
- = new Framework::RCArray<RequirementSet>();
- anyMatch->add(result->get(i));
- result->release();
- return anyMatch;
- }
- }
- }
- return result;
- }
- }
|