add extended info to inventory tooltips

This commit is contained in:
darkrose 2015-07-28 21:34:53 +10:00
parent 2823e22c30
commit 4ccbb18a73
10 changed files with 403 additions and 126 deletions

View File

@ -958,11 +958,11 @@ void giveCreative(Player *player)
for(u8 i=0; i<creativeinv.size(); i++) {
if ((creativeinv[(int)i]&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
assert(player->inventory.addItem("main", new CraftItem(creativeinv[i], 1)) == NULL) ;
assert(player->inventory.addItem("main", new CraftItem(creativeinv[i], 1,0)) == NULL) ;
}else if ((creativeinv.at(i)&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
assert(player->inventory.addItem("main", new ToolItem(creativeinv[i], 0)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(creativeinv[i], 0,0)) == NULL) ;
}else{
assert(player->inventory.addItem("main", new MaterialItem(creativeinv[i], 1)) == NULL) ;
assert(player->inventory.addItem("main", new MaterialItem(creativeinv[i], 1,0)) == NULL) ;
}
}
}
@ -970,13 +970,13 @@ void giveCreative(Player *player)
void giveInitial(Player *player)
{
player->resetInventory();
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELPICK, 0)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELAXE, 0)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELSHOVEL, 0)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELSHEARS, 0)) == NULL) ;
assert(player->inventory.addItem("main", new MaterialItem(CONTENT_TORCH, 99)) == NULL) ;
assert(player->inventory.addItem("main", new MaterialItem(CONTENT_ROUGHSTONEBRICK, 99)) == NULL) ;
assert(player->inventory.addItem("main", new MaterialItem(CONTENT_BORDERSTONE, 5)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELPICK, 0, 0)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELAXE, 0, 0)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELSHOVEL, 0, 0)) == NULL) ;
assert(player->inventory.addItem("main", new ToolItem(CONTENT_TOOLITEM_STEELSHEARS, 0, 0)) == NULL) ;
assert(player->inventory.addItem("main", new MaterialItem(CONTENT_TORCH, 99, 0)) == NULL) ;
assert(player->inventory.addItem("main", new MaterialItem(CONTENT_ROUGHSTONEBRICK, 99, 0)) == NULL) ;
assert(player->inventory.addItem("main", new MaterialItem(CONTENT_BORDERSTONE, 5, 0)) == NULL) ;
}
};

View File

@ -815,7 +815,7 @@ bool FurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
content_t c = fuel_item->getContent();
fuel_list->decrementMaterials(1);
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA) {
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0));
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
}
changed = true;
}else{
@ -1085,7 +1085,7 @@ bool LockingFurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment
content_t c = fuel_item->getContent();
fuel_list->decrementMaterials(1);
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA) {
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0));
fuel_list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
}
changed = true;
}else{
@ -2038,7 +2038,7 @@ NodeMetadata* DeCraftNodeMetadata::clone()
if (content_features(list[i]).dug_item == "" && content_features(list[i]).extra_dug_item == "")
continue;
t = new MaterialItem(list[i],1);
t = new MaterialItem(list[i],1,0);
l->addItem(t);
}
return d;
@ -2134,7 +2134,7 @@ bool DeCraftNodeMetadata::import(NodeMetadata *meta)
if (content_features(list[i]).dug_item == "" && content_features(list[i]).extra_dug_item == "")
continue;
t = new MaterialItem(list[i],1);
t = new MaterialItem(list[i],1,0);
l->addItem(t);
}
return true;
@ -2172,7 +2172,7 @@ bool DeCraftNodeMetadata::receiveFields(std::string formname, std::map<std::stri
if (content_features(list[i]).dug_item == "" && content_features(list[i]).extra_dug_item == "")
continue;
t = new MaterialItem(list[i],1);
t = new MaterialItem(list[i],1,0);
l->addItem(t);
}
return true;
@ -2824,7 +2824,7 @@ bool CauldronNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
content_t c = fitem->getContent();
list->decrementMaterials(1);
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA)
list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0));
list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
return true;
}
}

View File

@ -50,6 +50,8 @@ struct ToolItemFeatures {
f32 hardness;
// the dig time of this tool
f32 dig_time;
// the level of the tool, this affects the amount of minerals etc.
u8 level;
// used for eg. bows throwing an arrow
content_t thrown_item;
// when this item is placed, it should be replaced by this in inventory
@ -75,6 +77,7 @@ struct ToolItemFeatures {
type(TT_NONE),
hardness(0.),
dig_time(3.),
level(1),
thrown_item(CONTENT_IGNORE),
onplace_replace_item(CONTENT_IGNORE),
onplace_node(CONTENT_IGNORE)

View File

@ -455,14 +455,14 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
// Add tooltip
{
// Note: parent != this so that the tooltip isn't clipped by the menu rectangle
m_tooltip_element = Environment->addStaticText(L"",core::rect<s32>(0,0,110,18));
m_tooltip_element = Environment->addStaticText(L"",core::rect<s32>(0,0,1000,18));
m_tooltip_element->enableOverrideColor(true);
m_tooltip_element->setBackgroundColor(GUI_BG_TT);
m_tooltip_element->setDrawBackground(true);
m_tooltip_element->setDrawBorder(true);
m_tooltip_element->setOverrideColor(GUI_TT_TEXT);
m_tooltip_element->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
m_tooltip_element->setWordWrap(false);
m_tooltip_element->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
m_tooltip_element->setWordWrap(true);
}
}
@ -532,13 +532,20 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase)
if (item) {
draw_inv_item(driver, font, item, rect, &AbsoluteClippingRect);
if (rect.isPointInside(m_pointer)) {
std::wstring name = item->getGuiName();
std::wstring name = item->getGuiText();
if (name != L"") {
m_tooltip_element->setVisible(true);
this->bringToFront(m_tooltip_element);
m_tooltip_element->setText(name.c_str());
s32 tooltip_x = m_pointer.X + 15;
s32 tooltip_y = m_pointer.Y + 15;
// this prevents forced word-wrap when we don't want it
m_tooltip_element->setRelativePosition(
core::rect<s32>(
core::position2d<s32>(tooltip_x, tooltip_y),
core::dimension2d<s32>(1000,18)
)
);
s32 tooltip_width = m_tooltip_element->getTextWidth() + 14;
s32 tooltip_height = m_tooltip_element->getTextHeight() + 4;
m_tooltip_element->setRelativePosition(

View File

@ -9,7 +9,7 @@
#define GUI_BG_DEATH video::SColor(180,50,0,0)
#define GUI_BG_TT video::SColor(140,30,30,50)
#define GUI_BG_TT video::SColor(200,30,30,50)
#define GUI_TT_TEXT video::SColor(255,255,255,255)
#define GUI_INV_BORDER video::SColor(245,60,60,80)

View File

@ -36,28 +36,31 @@
#include "content_mob.h"
#include "player.h"
#include "log.h"
#include "intl.h"
/*
InventoryItem
*/
InventoryItem::InventoryItem(u16 count)
InventoryItem::InventoryItem(u16 count, u16 data)
{
m_content = CONTENT_IGNORE;
m_count = count;
m_data = data;
}
InventoryItem::~InventoryItem()
{
}
content_t InventoryItem::info(std::istream &is, u16 *count, u16 *wear)
content_t InventoryItem::info(std::istream &is, u16 *count, u16 *wear, u16 *data)
{
DSTACK(__FUNCTION_NAME);
content_t c = CONTENT_IGNORE;
*count = 0;
*wear = 0;
*data = 0;
//is.imbue(std::locale("C"));
// Read name
@ -79,33 +82,59 @@ content_t InventoryItem::info(std::istream &is, u16 *count, u16 *wear)
if (material > MAX_CONTENT)
throw SerializationError("Too large material number");
c = material;
}else if(name == "MaterialItem3") {
u16 material;
is>>material;
is>>(*count);
is>>(*data);
if (material > MAX_CONTENT)
throw SerializationError("Too large material number");
c = material;
}else if(name == "CraftItem") {
std::string subname;
std::getline(is, subname, ' ');
is>>(*count);
CraftItem itm(subname, *count);
CraftItem itm(subname, *count, 0);
c = itm.getContent();
}else if(name == "CraftItem2") {
u16 material;
is>>material;
is>>(*count);
c = material;
}else if(name == "CraftItem3") {
u16 material;
is>>material;
is>>(*count);
is>>(*data);
c = material;
}else if(name == "ToolItem") {
std::string toolname;
std::getline(is, toolname, ' ');
is>>(*wear);
ToolItem itm(toolname, *wear);
ToolItem itm(toolname, *wear, 0);
c = itm.getContent();
}else if(name == "ToolItem2") {
u16 material;
is>>material;
is>>(*wear);
c = material;
}else if(name == "ToolItem3") {
u16 material;
is>>material;
is>>(*wear);
is>>(*data);
c = material;
}else if(name == "ClothesItem") {
u16 material;
is>>material;
is>>(*wear);
c = material;
}else if(name == "ClothesItem2") {
u16 material;
is>>material;
is>>(*wear);
is>>(*data);
c = material;
}else if (name != "") {
infostream<<"Unknown InventoryItem name=\""<<name<<"\""<<std::endl;
throw SerializationError("Unknown InventoryItem name");
@ -119,24 +148,25 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
content_t c;
u16 count;
u16 wear;
u16 data;
c = InventoryItem::info(is,&count,&wear);
c = InventoryItem::info(is,&count,&wear,&data);
if (c == CONTENT_IGNORE)
return NULL;
return InventoryItem::create(c,count,wear);
return InventoryItem::create(c,count,wear,data);
}
InventoryItem* InventoryItem::create(content_t c, u16 count, u16 wear)
InventoryItem* InventoryItem::create(content_t c, u16 count, u16 wear, u16 data)
{
if ((c&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
return new CraftItem(c,count);
return new CraftItem(c,count,data);
}else if ((c&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
return new ToolItem(c,wear);
return new ToolItem(c,wear,data);
}else if ((c&CONTENT_CLOTHESITEM_MASK) == CONTENT_CLOTHESITEM_MASK) {
return new ClothesItem(c,wear);
return new ClothesItem(c,wear,data);
}
return new MaterialItem(c,count);
return new MaterialItem(c,count,data);
}
std::string InventoryItem::getItemString() {
@ -159,6 +189,29 @@ ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f
/*
MaterialItem
*/
std::wstring MaterialItem::getGuiText()
{
std::wstring txt(L" ");
ContentFeatures *f = &content_features(m_content);
txt += f->description;
if (f->cook_result != "" || f->fuel_time != 0.0)
txt += L"\n";
if (f->cook_result != "") {
txt += L"\n";
txt += wgettext("Cookable: Yes");
}
if (f->fuel_time != 0.0) {
char buff[20];
txt += L"\n";
txt += wgettext("Fuel Burn Time: ");
txt += itows((int)f->fuel_time/60);
txt += L":";
sprintf(buff,"%02d",(int)f->fuel_time%60);
txt += narrow_to_wide(buff);
}
return txt;
}
bool MaterialItem::isCookable() const
{
@ -210,6 +263,61 @@ std::wstring CraftItem::getGuiName()
{
return content_craftitem_features(m_content).description;
}
std::wstring CraftItem::getGuiText()
{
std::wstring txt(L" ");
CraftItemFeatures *f = &content_craftitem_features(m_content);
txt += f->description;
if (f->consumable || f->cook_result != "" || f->fuel_time != 0.0)
txt += L"\n";
if (f->consumable) {
if (f->hunger_effect) {
txt += L"\n";
txt += wgettext("Hunger: ");
txt += itows(f->hunger_effect*5);
txt += L"%";
}
if (f->health_effect) {
txt += L"\n";
txt += wgettext("Health: ");
txt += itows(f->health_effect*5);
txt += L"%";
}
if (f->cold_effect) {
char buff[20];
txt += L"\n";
txt += wgettext("Cold Protection: ");
txt += itows(f->cold_effect/60);
txt += L":";
sprintf(buff,"%02d",f->cold_effect%60);
txt += narrow_to_wide(buff);
}
if (f->energy_effect) {
char buff[20];
txt += L"\n";
txt += wgettext("Energy Boost: ");
txt += itows(f->energy_effect/60);
txt += L":";
sprintf(buff,"%02d",f->energy_effect%60);
txt += narrow_to_wide(buff);
}
}
if (f->cook_result != "") {
txt += L"\n";
txt += wgettext("Cookable: Yes");
}
if (f->fuel_time != 0.0) {
char buff[20];
txt += L"\n";
txt += wgettext("Fuel Burn Time: ");
txt += itows((int)f->fuel_time/60);
txt += L":";
sprintf(buff,"%02d",(int)f->fuel_time%60);
txt += narrow_to_wide(buff);
}
return txt;
}
ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos)
{
@ -298,6 +406,60 @@ bool CraftItem::use(ServerEnvironment *env, Player *player)
return false;
}
/*
ToolItem
*/
#ifndef SERVER
video::ITexture *ToolItem::getImage() const
{
if(g_texturesource == NULL)
return NULL;
std::string basename = getBasename();
/*
Calculate a progress value with sane amount of
maximum states
*/
u32 maxprogress = 30;
u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
float value_f = (float)toolprogress / (float)maxprogress;
std::ostringstream os;
os<<basename<<"^[progressbar"<<value_f;
return g_texturesource->getTextureRaw(os.str());
}
#endif
std::wstring ToolItem::getGuiText()
{
std::wstring txt(L" ");
ToolItemFeatures *f = &content_toolitem_features(m_content);
txt += f->description;
txt += L"\n\n";
txt += wgettext("Strength: ");
txt += ftows(f->hardness);
txt += L"\n";
txt += wgettext("Speed: ");
txt += ftows(f->dig_time);
txt += L"\n";
txt += wgettext("Level: ");
txt += itows(f->level);
if (f->fuel_time != 0.0) {
char buff[20];
txt += L"\n";
txt += wgettext("Fuel Burn Time: ");
txt += itows((int)f->fuel_time/60);
txt += L":";
sprintf(buff,"%02d",(int)f->fuel_time%60);
txt += narrow_to_wide(buff);
}
return txt;
}
bool ToolItem::isCookable() const
{
return content_toolitem_features(m_content).cook_result != "";
@ -319,6 +481,79 @@ float ToolItem::getFuelTime() const
return content_toolitem_features(m_content).fuel_time;
}
/*
ClothesItem
*/
#ifndef SERVER
video::ITexture *ClothesItem::getImage() const
{
if (g_texturesource == NULL)
return NULL;
std::string basename = getBasename();
/*
Calculate a progress value with sane amount of
maximum states
*/
u32 maxprogress = 30;
u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
float value_f = (float)toolprogress / (float)maxprogress;
std::ostringstream os;
os<<basename<<"^[progressbar"<<value_f;
return g_texturesource->getTextureRaw(os.str());
}
#endif
std::wstring ClothesItem::getGuiText()
{
std::wstring txt(L" ");
ClothesItemFeatures *f = &content_clothesitem_features(m_content);
txt += f->description;
if (f->armour > 0.0 || f->warmth > 0.0 || f->vacuum > 0.0 || f->suffocate > 0.0 || f->durability > 0.0 || f->effect > 1.0)
txt += L"\n";
if (f->armour > 0.0) {
txt += L"\n";
txt += wgettext("Armour: ");
txt += itows(f->armour*100.0);
txt += L"%";
}
if (f->warmth > 0.0) {
txt += L"\n";
txt += wgettext("Warmth: ");
txt += itows(f->warmth*100.0);
txt += L"%";
}
if (f->vacuum > 0.0) {
txt += L"\n";
txt += wgettext("Pressure: ");
txt += itows(f->vacuum*100.0);
txt += L"%";
}
if (f->suffocate > 0.0) {
txt += L"\n";
txt += wgettext("Suffocation: ");
txt += itows(f->suffocate*100.0);
txt += L"%";
}
if (f->durability > 0.0) {
txt += L"\n";
txt += wgettext("Durability: ");
txt += itows(f->durability);
}
if (f->effect != 1.0) {
txt += L"\n";
txt += wgettext("Effect Boost: ");
txt += itows(f->effect*100.0);
txt += L"%";
}
return txt;
}
/*
Inventory
*/
@ -356,13 +591,11 @@ void InventoryList::clearItems()
for (u32 i=0; i<m_size; i++) {
m_items.push_back(NULL);
}
//setDirty(true);
}
void InventoryList::serialize(std::ostream &os) const
{
//os.imbue(std::locale("C"));
writeU8(os,1); // version
for (u32 i=0; i<m_items.size(); i++) {
InventoryItem *item = m_items[i];
@ -374,6 +607,7 @@ void InventoryList::serialize(std::ostream &os) const
}else{
writeU16(os,item->getCount());
}
writeU16(os,item->getData());
}else{
writeU16(os,CONTENT_IGNORE);
}
@ -385,6 +619,44 @@ void InventoryList::deSerialize(std::istream &is)
u32 item_i = 0;
char f;
is.get(f);
if (f == '\1') {
char v;
is.get(v);
switch (v) {
case 1:
{
for (item_i=0; item_i<getSize(); item_i++) {
content_t c = readU16(is);
if (c == CONTENT_IGNORE) {
if (m_items[item_i] != NULL)
delete m_items[item_i];
m_items[item_i] = NULL;
continue;
}
u16 wc = readU16(is);
u16 d = readU16(is);
if (m_items[item_i] != NULL) {
if (m_items[item_i]->getContent() == c) {
m_items[item_i]->setWear(wc);
m_items[item_i]->setCount(wc);
m_items[item_i]->setData(d);
continue;
}
delete m_items[item_i];
}
m_items[item_i] = InventoryItem::create(c,wc,wc,d);
}
}
break;
default:
throw SerializationError("Unknown inventory format");
}
if (readU8(is) != 3)
throw SerializationError("Unknown inventory identifier");
return;
}
if (f == '\2') {
for (item_i=0; item_i<getSize(); item_i++) {
content_t c = readU16(is);
@ -443,8 +715,9 @@ void InventoryList::deSerialize(std::istream &is)
content_t c;
u16 count;
u16 wear;
u16 data;
c = InventoryItem::info(iss,&count,&wear);
c = InventoryItem::info(iss,&count,&wear,&data);
if (c == CONTENT_IGNORE) {
if (m_items[item_i] != NULL)
delete m_items[item_i];
@ -455,6 +728,7 @@ void InventoryList::deSerialize(std::istream &is)
if (m_items[item_i]->getContent() == c) {
m_items[item_i]->setWear(wear);
m_items[item_i++]->setCount(count);
m_items[item_i++]->setData(data);
continue;
}
delete m_items[item_i];
@ -824,8 +1098,8 @@ void Inventory::serialize(std::ostream &os) const
InventoryList *list = m_lists[i];
os<<list->getName()<<" ";
writeU16(os,list->getSize());
// start text
writeU8(os,2);
// start header
writeU8(os,1);
list->serialize(os);
// end text
writeU8(os,3);

View File

@ -50,12 +50,12 @@ class Player;
class InventoryItem
{
public:
InventoryItem(u16 count);
InventoryItem(u16 count, u16 data);
virtual ~InventoryItem();
static content_t info(std::istream &is, u16 *count, u16 *wear);
static content_t info(std::istream &is, u16 *count, u16 *wear, u16 *data);
static InventoryItem* deSerialize(std::istream &is);
static InventoryItem* create(content_t c, u16 count, u16 wear=0);
static InventoryItem* create(content_t c, u16 count, u16 wear=0, u16 data=0);
virtual const char* getName() const = 0;
// Shall write the name and the parameters
@ -74,6 +74,8 @@ public:
content_t getContent() {return m_content;}
// this is used for tool tips
virtual std::wstring getGuiName() { return L""; }
// this is used for hover data / extended tool tips
virtual std::wstring getGuiText() { return L""; }
// Shall return a text to show in the GUI
virtual std::string getText() { return ""; }
// Returns the string used for inventory
@ -114,12 +116,19 @@ public:
}
void remove(u16 count)
{
assert(m_count >= count);
if (m_count < count) {
m_count = 0;
}else{
m_count -= count;
}
}
virtual void setWear(u16 wear) {}
virtual u16 getWear() {return 0;}
void setData(u16 data) { m_data = data; }
void addData(u16 data) { m_data |= data; }
u16 getData() { return m_data; }
/*
Other properties
*/
@ -144,13 +153,14 @@ public:
protected:
u16 m_count;
content_t m_content;
u16 m_data;
};
class MaterialItem : public InventoryItem
{
public:
MaterialItem(content_t content, u16 count):
InventoryItem(count)
MaterialItem(content_t content, u16 count, u16 data):
InventoryItem(count,data)
{
MapNode n(content);
n = mapnode_translate_to_internal(n,SER_FMT_VER_HIGHEST);
@ -166,15 +176,17 @@ public:
virtual void serialize(std::ostream &os) const
{
//os.imbue(std::locale("C"));
os<<"MaterialItem2";
os<<"MaterialItem3";
os<<" ";
os<<(unsigned int)m_content;
os<<" ";
os<<m_count;
os<<" ";
os<<m_data;
}
virtual InventoryItem* clone()
{
return new MaterialItem(m_content, m_count);
return new MaterialItem(m_content, m_count, m_data);
}
#ifndef SERVER
video::ITexture * getImage() const
@ -187,6 +199,8 @@ public:
return content_features(m_content).description;
}
std::wstring getGuiText();
std::string getText()
{
std::ostringstream os;
@ -197,8 +211,11 @@ public:
virtual bool addableTo(const InventoryItem *other) const
{
content_t c = ((InventoryItem*)other)->getContent();
u16 d = ((InventoryItem*)other)->getData();
if (c != m_content)
return false;
if (m_data != d)
return false;
return true;
}
u16 freeSpace() const
@ -235,14 +252,14 @@ private:
class CraftItem : public InventoryItem
{
public:
CraftItem(std::string subname, u16 count):
InventoryItem(count)
CraftItem(std::string subname, u16 count, u16 data):
InventoryItem(count,data)
{
m_subname = content_craftitem_features(subname).name;
m_content = content_craftitem_features(subname).content;
}
CraftItem(content_t content, u16 count):
InventoryItem(count)
CraftItem(content_t content, u16 count, u16 data):
InventoryItem(count,data)
{
m_subname = content_craftitem_features(content).name;
m_content = content_craftitem_features(content).content;
@ -256,21 +273,24 @@ public:
}
virtual void serialize(std::ostream &os) const
{
os<<"CraftItem2";
os<<"CraftItem3";
os<<" ";
os<<(unsigned int)m_content;
os<<" ";
os<<m_count;
os<<" ";
os<<m_data;
}
virtual InventoryItem* clone()
{
return new CraftItem(m_content, m_count);
return new CraftItem(m_content, m_count, m_data);
}
#ifndef SERVER
video::ITexture * getImage() const;
#endif
std::wstring getGuiName();
std::wstring getGuiText();
std::string getText()
{
@ -285,8 +305,11 @@ public:
virtual bool addableTo(const InventoryItem *other) const
{
content_t c = ((InventoryItem*)other)->getContent();
u16 d = ((InventoryItem*)other)->getData();
if (c != m_content)
return false;
if (m_data != d)
return false;
return true;
}
u16 freeSpace() const
@ -323,15 +346,15 @@ private:
class ToolItem : public InventoryItem
{
public:
ToolItem(std::string toolname, u16 wear):
InventoryItem(1)
ToolItem(std::string toolname, u16 wear, u16 data):
InventoryItem(1,data)
{
m_wear = wear;
m_toolname = content_toolitem_features(toolname).name;
m_content = content_toolitem_features(toolname).content;
}
ToolItem(content_t content, u16 wear):
InventoryItem(1)
ToolItem(content_t content, u16 wear, u16 data):
InventoryItem(1,data)
{
m_wear = wear;
m_toolname = content_toolitem_features(content).name;
@ -346,41 +369,24 @@ public:
}
virtual void serialize(std::ostream &os) const
{
os<<"ToolItem2";
os<<"ToolItem3";
os<<" ";
os<<(unsigned int)m_content;
os<<" ";
os<<m_wear;
os<<" ";
os<<m_data;
}
virtual InventoryItem* clone()
{
return new ToolItem(m_content, m_wear);
return new ToolItem(m_content, m_wear, m_data);
}
#ifndef SERVER
std::string getBasename() const {
return content_toolitem_features(m_content).texture;
}
video::ITexture * getImage() const
{
if(g_texturesource == NULL)
return NULL;
std::string basename = getBasename();
/*
Calculate a progress value with sane amount of
maximum states
*/
u32 maxprogress = 30;
u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
float value_f = (float)toolprogress / (float)maxprogress;
std::ostringstream os;
os<<basename<<"^[progressbar"<<value_f;
return g_texturesource->getTextureRaw(os.str());
}
video::ITexture * getImage() const;
video::ITexture * getImageRaw() const
{
@ -390,9 +396,11 @@ public:
return g_texturesource->getTextureRaw(getBasename());
}
#endif
std::wstring getGuiName() {
std::wstring getGuiName()
{
return content_toolitem_features(m_content).description;
}
std::wstring getGuiText();
std::string getText()
{
return "";
@ -435,8 +443,8 @@ private:
class ClothesItem : public InventoryItem
{
public:
ClothesItem(content_t content, u16 wear):
InventoryItem(1)
ClothesItem(content_t content, u16 wear, u16 data):
InventoryItem(1,data)
{
m_wear = wear;
m_content = content_clothesitem_features(content).content;
@ -450,41 +458,24 @@ public:
}
virtual void serialize(std::ostream &os) const
{
os<<"ClothesItem";
os<<"ClothesItem2";
os<<" ";
os<<(unsigned int)m_content;
os<<" ";
os<<m_wear;
os<<" ";
os<<m_data;
}
virtual InventoryItem* clone()
{
return new ClothesItem(m_content, m_wear);
return new ClothesItem(m_content, m_wear, m_data);
}
#ifndef SERVER
std::string getBasename() const {
return content_clothesitem_features(m_content).texture;
}
video::ITexture * getImage() const
{
if (g_texturesource == NULL)
return NULL;
std::string basename = getBasename();
/*
Calculate a progress value with sane amount of
maximum states
*/
u32 maxprogress = 30;
u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
float value_f = (float)toolprogress / (float)maxprogress;
std::ostringstream os;
os<<basename<<"^[progressbar"<<value_f;
return g_texturesource->getTextureRaw(os.str());
}
video::ITexture * getImage() const;
video::ITexture * getImageRaw() const
{
@ -494,9 +485,11 @@ public:
return g_texturesource->getTextureRaw(getBasename());
}
#endif
std::wstring getGuiName() {
std::wstring getGuiName()
{
return content_clothesitem_features(m_content).description;
}
std::wstring getGuiText();
std::string getText()
{
return "";

View File

@ -70,7 +70,7 @@ inline CraftItem * getDiggedMineralItem(u8 mineral)
if (m.dug_item == CONTENT_IGNORE)
return NULL;
return new CraftItem(content_craftitem_features(m.dug_item).name,m.dug_count);
return new CraftItem(content_craftitem_features(m.dug_item).name,m.dug_count, 0);
}
#endif

View File

@ -434,22 +434,22 @@ void ServerRemotePlayer::setCharDef(std::string d)
return;
InventoryItem *item = NULL;
if (shirt == "white") {
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT,0,0);
}else if (shirt == "blue") {
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_BLUE,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_BLUE,0,0);
}else if (shirt == "orange") {
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_ORANGE,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_ORANGE,0,0);
}else if (shirt == "purple") {
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_PURPLE,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_PURPLE,0,0);
}else if (shirt == "red") {
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_RED,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_RED,0,0);
}else if (shirt == "yellow") {
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_YELLOW,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_YELLOW,0,0);
}else if (shirt == "black") {
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_BLACK,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_BLACK,0,0);
}
if (item == NULL)
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_GREEN,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_COTTON_TSHIRT_GREEN,0,0);
l->addItem(0,item);
}
{
@ -458,22 +458,22 @@ void ServerRemotePlayer::setCharDef(std::string d)
return;
InventoryItem *item = NULL;
if (pants == "white") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS,0,0);
}else if (pants == "green") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_GREEN,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_GREEN,0,0);
}else if (pants == "orange") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_ORANGE,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_ORANGE,0,0);
}else if (pants == "purple") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_PURPLE,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_PURPLE,0,0);
}else if (pants == "red") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_RED,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_RED,0,0);
}else if (pants == "yellow") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_YELLOW,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_YELLOW,0,0);
}else if (pants == "black") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_BLACK,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_BLACK,0,0);
}
if (item == NULL)
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_BLUE,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_PANTS_BLUE,0,0);
l->addItem(0,item);
}
{
@ -482,12 +482,12 @@ void ServerRemotePlayer::setCharDef(std::string d)
return;
InventoryItem *item = NULL;
if (shirt == "fur") {
item = new ClothesItem(CONTENT_CLOTHESITEM_FUR_SHOES,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_FUR_SHOES,0,0);
}else if (shirt == "canvas") {
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_SHOES,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_CANVAS_SHOES,0,0);
}
if (item == NULL)
item = new ClothesItem(CONTENT_CLOTHESITEM_LEATHER_SHOES,0);
item = new ClothesItem(CONTENT_CLOTHESITEM_LEATHER_SHOES,0,0);
l->addItem(0,item);
}

View File

@ -2894,7 +2894,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
content_t c = fitem->getContent();
ilist->deleteItem(0);
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA)
ilist->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0));
ilist->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0,0));
}else{
fitem->remove(1);
}