get text rotating correctly, and add text to books

This commit is contained in:
darkrose 2015-03-20 16:25:18 +10:00
parent 315fe4e4bd
commit 0d9ce95e8b
5 changed files with 135 additions and 99 deletions

View File

@ -652,7 +652,7 @@ void content_mapnode_special(bool repeat)
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->solidness = 0; f->solidness = 0;
content_nodebox_book(f); content_nodebox_book(f);
//f->setFaceText(0,FaceText(0.05,0.175,0.9875,0.7375)); f->setFaceText(0,FaceText(0.45,0.3,0.9875,0.7375));
f->setInventoryTextureNodeBox(i, "book_cover.png", "book_end.png^[transformFX", "book_side.png^[transformFY"); f->setInventoryTextureNodeBox(i, "book_cover.png", "book_end.png^[transformFX", "book_side.png^[transformFY");
f->type = CMT_DIRT; f->type = CMT_DIRT;
f->hardness = 1.0; f->hardness = 1.0;
@ -747,6 +747,7 @@ void content_mapnode_special(bool repeat)
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->solidness = 0; f->solidness = 0;
content_nodebox_book(f); content_nodebox_book(f);
f->setFaceText(0,FaceText(0.45,0.3,0.9875,0.7375));
f->setInventoryTextureNodeBox(i, "book_diary_cover.png", "book_diary_end.png^[transformFX", "book_diary_side.png^[transformFY"); f->setInventoryTextureNodeBox(i, "book_diary_cover.png", "book_diary_end.png^[transformFX", "book_diary_side.png^[transformFY");
f->type = CMT_DIRT; f->type = CMT_DIRT;
f->hardness = 1.0; f->hardness = 1.0;
@ -816,6 +817,7 @@ void content_mapnode_special(bool repeat)
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_BOOK)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_BOOK)+" 1";
f->solidness = 0; f->solidness = 0;
content_nodebox_guide(f); content_nodebox_guide(f);
f->setFaceText(0,FaceText(0.15,0.35,0.85,0.85,FTT_BOOKCONTENT));
f->setInventoryTextureNodeBox(i, "guide_top.png", "guide_end.png", "guide_side.png"); f->setInventoryTextureNodeBox(i, "guide_top.png", "guide_end.png", "guide_side.png");
f->type = CMT_DIRT; f->type = CMT_DIRT;
f->hardness = 1.0; f->hardness = 1.0;
@ -900,6 +902,7 @@ void content_mapnode_special(bool repeat)
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_DIARY_BOOK)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_DIARY_BOOK)+" 1";
f->solidness = 0; f->solidness = 0;
content_nodebox_guide(f); content_nodebox_guide(f);
f->setFaceText(0,FaceText(0.15,0.35,0.85,0.85,FTT_BOOKCONTENT));
f->setInventoryTextureNodeBox(i, "guide_diary_top.png", "guide_diary_end.png", "guide_diary_side.png"); f->setInventoryTextureNodeBox(i, "guide_diary_top.png", "guide_diary_end.png", "guide_diary_side.png");
f->type = CMT_DIRT; f->type = CMT_DIRT;
f->hardness = 1.0; f->hardness = 1.0;

View File

@ -33,6 +33,7 @@
#include "settings.h" #include "settings.h"
#include "profiler.h" #include "profiler.h"
#include "mesh.h" #include "mesh.h"
#include "base64.h"
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block) void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{ {
@ -246,7 +247,62 @@ void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p,
TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, NodeModMap &temp_mods, NodeMetadata *meta) TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, NodeModMap &temp_mods, NodeMetadata *meta)
{ {
TileSpec spec; TileSpec spec;
spec = mn.getTile(face_dir); spec = mn.getTile(face_dir,false);
if (meta) {
FaceText ft = mn.getFaceText(face_dir);
if (ft.m_hastext) {
std::string txt("");
switch (ft.m_type) {
case FTT_BOOKCONTENT:
txt = ((BookNodeMetadata*)meta)->getContent();
break;
case FTT_OWNER:
txt = meta->getOwner();
break;
case FTT_INVOWNER:
txt = meta->getInventoryOwner();
break;
default:
txt = meta->getText();
break;
}
if (txt != "") {
// Get original texture name
u32 orig_id = spec.texture.id;
std::string orig_name = g_texturesource->getTextureName(orig_id);
// Create new texture name
std::ostringstream os;
os<<orig_name<<"^[text:";
os<<ft.m_pos.UpperLeftCorner.X;
os<<",";
os<<ft.m_pos.UpperLeftCorner.Y;
os<<",";
os<<ft.m_pos.LowerRightCorner.X;
os<<",";
os<<ft.m_pos.LowerRightCorner.Y;
os<<",";
os<<base64_encode((const unsigned char*)txt.c_str(),txt.size());
// Get new texture
u32 new_id = g_texturesource->getTextureId(os.str());
spec.texture = g_texturesource->getTexture(new_id);
}
}
}
std::string rot = mn.getTileRotationString(face_dir);
if (rot != "") {
// Get original texture name
u32 orig_id = spec.texture.id;
std::string orig_name = g_texturesource->getTextureName(orig_id);
// new name
std::string texture_name = orig_name + rot;
// Get new texture
u32 new_id = g_texturesource->getTextureId(texture_name);
spec.texture = g_texturesource->getTexture(new_id);
}
/* /*
Check temporary modifications on this node Check temporary modifications on this node
@ -288,49 +344,6 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, NodeModMap &temp_mods,
} }
} }
if (meta) {
FaceText ft = mn.getFaceText(face_dir);
if (ft.m_hastext) {
std::string txt("");
switch (ft.m_type) {
case FTT_BOOKCONTENT:
txt = ((BookNodeMetadata*)meta)->getContent();
break;
case FTT_OWNER:
txt = meta->getOwner();
break;
case FTT_INVOWNER:
txt = meta->getInventoryOwner();
break;
default:
txt = meta->getText();
break;
}
if (txt != "") {
// Get original texture name
u32 orig_id = spec.texture.id;
std::string orig_name = g_texturesource->getTextureName(orig_id);
// Create new texture name
std::ostringstream os;
os<<orig_name<<"^[text:";
os<<ft.m_pos.UpperLeftCorner.X;
os<<",";
os<<ft.m_pos.UpperLeftCorner.Y;
os<<",";
os<<ft.m_pos.LowerRightCorner.X;
os<<",";
os<<ft.m_pos.LowerRightCorner.Y;
os<<",";
os<<txt;
// Get new texture
u32 new_id = g_texturesource->getTextureId(os.str());
spec.texture = g_texturesource->getTexture(new_id);
}
}
}
return spec; return spec;
} }

View File

@ -430,7 +430,7 @@ s16 MapNode::getRotationAngle()
} }
#ifndef SERVER #ifndef SERVER
TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6]) TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6], bool rotate)
{ {
TileSpec spec; TileSpec spec;
s32 dir_i = 0; s32 dir_i = 0;
@ -464,12 +464,10 @@ TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6])
/* /*
If it contains some mineral, change texture id If it contains some mineral, change texture id
*/ */
if(f.param_type == CPT_MINERAL && g_texturesource) if (f.param_type == CPT_MINERAL && g_texturesource) {
{
u8 mineral = getMineral(); u8 mineral = getMineral();
std::string mineral_texture_name = mineral_features(mineral).texture; std::string mineral_texture_name = mineral_features(mineral).texture;
if(mineral_texture_name != "") if (mineral_texture_name != "") {
{
u32 orig_id = spec.texture.id; u32 orig_id = spec.texture.id;
std::string texture_name = g_texturesource->getTextureName(orig_id); std::string texture_name = g_texturesource->getTextureName(orig_id);
//texture_name += "^blit:"; //texture_name += "^blit:";
@ -479,7 +477,45 @@ TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6])
spec.texture = g_texturesource->getTexture(new_id); spec.texture = g_texturesource->getTexture(new_id);
} }
} }
if (f.rotate_tile_with_nodebox) { if (rotate && f.rotate_tile_with_nodebox) {
u32 orig_id = spec.texture.id;
std::string texture_name = g_texturesource->getTextureName(orig_id);
texture_name += getTileRotationString(dir);
u32 new_id = g_texturesource->getTextureId(texture_name);
spec.texture = g_texturesource->getTexture(new_id);
}
return spec;
}
std::string MapNode::getTileRotationString(v3s16 dir)
{
s32 dir_i = 0;
ContentFeatures &f = content_features(*this);
if (!f.rotate_tile_with_nodebox)
return "";
if (
f.param2_type == CPT_FACEDIR_SIMPLE
|| f.param2_type == CPT_FACEDIR_WALLMOUNT
) {
dir = facedir_rotate(param2&0x0F, dir);
}else if (
f.param_type == CPT_FACEDIR_SIMPLE
|| f.param_type == CPT_FACEDIR_WALLMOUNT
) {
dir = facedir_rotate(param1, dir);
}
if (dir == v3s16(0,-1,0)) {
dir_i = 1;
}else if(dir == v3s16(1,0,0)) {
dir_i = 2;
}else if(dir == v3s16(-1,0,0)) {
dir_i = 3;
}else if(dir == v3s16(0,0,1)) {
dir_i = 4;
}else if(dir == v3s16(0,0,-1)) {
dir_i = 5;
}
u8 facedir = 0; u8 facedir = 0;
if (f.param_type == CPT_FACEDIR_SIMPLE) { if (f.param_type == CPT_FACEDIR_SIMPLE) {
facedir = param1; facedir = param1;
@ -488,36 +524,23 @@ TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6])
} }
if (dir_i == 0) { if (dir_i == 0) {
if (facedir == 1) { // -90 if (facedir == 1) { // -90
std::string name = g_texturesource->getTextureName(spec.texture.id); return "^[transformR270";
name += "^[transformR270";
spec.texture = g_texturesource->getTexture(name);
}else if (facedir == 2) { // 180 }else if (facedir == 2) { // 180
std::string name = g_texturesource->getTextureName(spec.texture.id); return "^[transformR180";
name += "^[transformR180";
spec.texture = g_texturesource->getTexture(name);
}else if (facedir == 3) { // 90 }else if (facedir == 3) { // 90
std::string name = g_texturesource->getTextureName(spec.texture.id); return "^[transformR90";
name += "^[transformR90";
spec.texture = g_texturesource->getTexture(name);
} }
}else if (dir_i == 1) { }else if (dir_i == 1) {
if (facedir == 1) { // -90 if (facedir == 1) { // -90
std::string name = g_texturesource->getTextureName(spec.texture.id); return "^[transformR90";
name += "^[transformR90";
spec.texture = g_texturesource->getTexture(name);
}else if (facedir == 2) { // 180 }else if (facedir == 2) { // 180
std::string name = g_texturesource->getTextureName(spec.texture.id); return "^[transformR180";
name += "^[transformR180";
spec.texture = g_texturesource->getTexture(name);
}else if (facedir == 3) { // 90 }else if (facedir == 3) { // 90
std::string name = g_texturesource->getTextureName(spec.texture.id); return "^[transformR270";
name += "^[transformR270";
spec.texture = g_texturesource->getTexture(name);
}
} }
} }
return spec; return "";
} }
#endif #endif
FaceText MapNode::getFaceText(v3s16 dir) FaceText MapNode::getFaceText(v3s16 dir)

View File

@ -977,9 +977,10 @@ struct MapNode
Returns: TileSpec. Can contain miscellaneous texture coordinates, Returns: TileSpec. Can contain miscellaneous texture coordinates,
which must be obeyed so that the texture atlas can be used. which must be obeyed so that the texture atlas can be used.
*/ */
TileSpec getTile(v3s16 dir) {return getTileFrom(dir,content_features(*this).tiles); } TileSpec getTile(v3s16 dir, bool rotate = true) {return getTileFrom(dir,content_features(*this).tiles,rotate); }
TileSpec getMetaTile(v3s16 dir) {return getTileFrom(dir,content_features(*this).meta_tiles); } TileSpec getMetaTile(v3s16 dir, bool rotate = true) {return getTileFrom(dir,content_features(*this).meta_tiles,rotate); }
TileSpec getTileFrom(v3s16 dir, TileSpec raw_spec[6]); TileSpec getTileFrom(v3s16 dir, TileSpec raw_spec[6], bool rotate = true);
std::string getTileRotationString(v3s16 dir);
#endif #endif
FaceText getFaceText(v3s16 dir); FaceText getFaceText(v3s16 dir);

View File

@ -38,6 +38,7 @@
#include "mapnode.h" // For texture atlas making #include "mapnode.h" // For texture atlas making
#include "mineral.h" // For texture atlas making #include "mineral.h" // For texture atlas making
#include "path.h" #include "path.h"
#include "base64.h"
/* /*
TextureSource TextureSource
@ -218,17 +219,12 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
// Find last meta separator in name // Find last meta separator in name
s32 last_separator_position = -1; s32 last_separator_position = -1;
size_t text_separator_position = name.find("^[text:");
if (text_separator_position == std::string::npos) {
for (s32 i=name.size()-1; i>=0; i--) { for (s32 i=name.size()-1; i>=0; i--) {
if (name[i] == separator) { if (name[i] == separator) {
last_separator_position = i; last_separator_position = i;
break; break;
} }
} }
}else{
last_separator_position = text_separator_position;
}
/* /*
If separator was found, construct the base name and make the If separator was found, construct the base name and make the
base image using a recursive call base image using a recursive call
@ -1686,7 +1682,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
std::string y = sf.next(","); std::string y = sf.next(",");
std::string X = sf.next(","); std::string X = sf.next(",");
std::string Y = sf.next(","); std::string Y = sf.next(",");
std::wstring text = narrow_to_wide(sf.end()); std::wstring text = narrow_to_wide(base64_decode(sf.end()));
if (baseimg == NULL) { if (baseimg == NULL) {
errorstream << "generateImagePart(): baseimg != NULL " errorstream << "generateImagePart(): baseimg != NULL "