forked from oerkki/voxelands
new fromspec-based craft guide pt3
This commit is contained in:
parent
e06056ef82
commit
d8a44e1cee
|
@ -552,7 +552,6 @@ InventoryItem *getResult(InventoryItem **items)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// TODO: return recipe from result
|
||||
content_t *getRecipe(InventoryItem *item)
|
||||
{
|
||||
content_t r = item->getContent();
|
||||
|
@ -580,6 +579,22 @@ content_t *getRecipe(InventoryItem *item)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int getResultCount(InventoryItem *item)
|
||||
{
|
||||
content_t r = item->getContent();
|
||||
for (std::vector<CraftDef>::iterator i=shaped_recipes.begin(); i!=shaped_recipes.end(); i++) {
|
||||
CraftDef d = *i;
|
||||
if (d.result == r)
|
||||
return d.result_count;
|
||||
}
|
||||
for (std::vector<CraftDefShapeless>::iterator i=shapeless_recipes.begin(); i!=shapeless_recipes.end(); i++) {
|
||||
CraftDefShapeless d = *i;
|
||||
if (d.result == r)
|
||||
return d.result_count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: creative inventory needs redoing
|
||||
void giveCreative(Player *player)
|
||||
{
|
||||
|
|
|
@ -231,6 +231,7 @@ namespace crafting {
|
|||
|
||||
InventoryItem *getResult(InventoryItem **items);
|
||||
content_t *getRecipe(InventoryItem *item);
|
||||
int getResultCount(InventoryItem *item);
|
||||
|
||||
void giveCreative(Player *player);
|
||||
void giveInitial(Player *player);
|
||||
|
|
|
@ -1079,9 +1079,12 @@ bool CraftGuideNodeMetadata::receiveFields(std::string formname, std::map<std::s
|
|||
}
|
||||
std::string CraftGuideNodeMetadata::getDrawSpecString()
|
||||
{
|
||||
InventoryList *l = m_inventory->getList("result");
|
||||
InventoryItem *q = l->getItem(0);
|
||||
InventoryItem *t;
|
||||
content_t *r;
|
||||
if (m_count == 0) {
|
||||
int tr = 0;
|
||||
m_count = 0;
|
||||
for (int i=0; g_contents[i] != CONTENT_IGNORE; i++) {
|
||||
if ((g_contents[i]&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
t = new CraftItem(g_contents[i],1);
|
||||
|
@ -1091,15 +1094,27 @@ std::string CraftGuideNodeMetadata::getDrawSpecString()
|
|||
t = new MaterialItem(g_contents[i],1);
|
||||
}
|
||||
r = crafting::getRecipe(t);
|
||||
if (!r) {
|
||||
delete t;
|
||||
if (!r)
|
||||
continue;
|
||||
}
|
||||
if (q && q->getContent() == g_contents[i])
|
||||
tr = crafting::getResultCount(t);
|
||||
delete t;
|
||||
m_count++;
|
||||
}
|
||||
}
|
||||
|
||||
std::string spec("size[8,9]");
|
||||
spec += "label[0.5,0.75;Add item here to see recipe]";
|
||||
spec += "list[current_name;result;2,1;1,1;]";
|
||||
// this overflows into the craft grid... but could be cool
|
||||
//if (q && tr) {
|
||||
//spec += "label[0.5,2.5;Gives ";
|
||||
//spec += itos(tr);
|
||||
//spec += " ";
|
||||
//spec += q->getGuiName();
|
||||
//spec += "]";
|
||||
//}
|
||||
spec += "list[current_name;recipe;4,0;3,3;]";
|
||||
spec += "button[0.25,3.5;2.5,0.75;prev;<< Previous Page]";
|
||||
spec += "label[3.5,3.5;Page ";
|
||||
|
|
Loading…
Reference in New Issue