From 0d9ce95e8bf13ae8414f7f4afc3ee30cd5ad4701 Mon Sep 17 00:00:00 2001 From: darkrose Date: Fri, 20 Mar 2015 16:25:18 +1000 Subject: [PATCH] get text rotating correctly, and add text to books --- src/content_mapnode_special.cpp | 5 +- src/mapblock_mesh.cpp | 101 +++++++++++++++++------------- src/mapnode.cpp | 105 +++++++++++++++++++------------- src/mapnode.h | 7 ++- src/tile.cpp | 16 ++--- 5 files changed, 135 insertions(+), 99 deletions(-) diff --git a/src/content_mapnode_special.cpp b/src/content_mapnode_special.cpp index 970c870..b22cb24 100644 --- a/src/content_mapnode_special.cpp +++ b/src/content_mapnode_special.cpp @@ -652,7 +652,7 @@ void content_mapnode_special(bool repeat) f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->solidness = 0; 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->type = CMT_DIRT; f->hardness = 1.0; @@ -747,6 +747,7 @@ void content_mapnode_special(bool repeat) f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->solidness = 0; 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->type = CMT_DIRT; 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->solidness = 0; 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->type = CMT_DIRT; 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->solidness = 0; 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->type = CMT_DIRT; f->hardness = 1.0; diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 4e6aad9..ad66f9e 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -33,6 +33,7 @@ #include "settings.h" #include "profiler.h" #include "mesh.h" +#include "base64.h" 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 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<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 @@ -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<getTextureId(os.str()); - - spec.texture = g_texturesource->getTexture(new_id); - } - } - } - return spec; } diff --git a/src/mapnode.cpp b/src/mapnode.cpp index b295a0f..8ca67d1 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -430,7 +430,7 @@ s16 MapNode::getRotationAngle() } #ifndef SERVER -TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6]) +TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6], bool rotate) { TileSpec spec; 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(f.param_type == CPT_MINERAL && g_texturesource) - { + if (f.param_type == CPT_MINERAL && g_texturesource) { u8 mineral = getMineral(); std::string mineral_texture_name = mineral_features(mineral).texture; - if(mineral_texture_name != "") - { + if (mineral_texture_name != "") { u32 orig_id = spec.texture.id; std::string texture_name = g_texturesource->getTextureName(orig_id); //texture_name += "^blit:"; @@ -479,46 +477,71 @@ TileSpec MapNode::getTileFrom(v3s16 dir, TileSpec raw_spec[6]) spec.texture = g_texturesource->getTexture(new_id); } } - if (f.rotate_tile_with_nodebox) { - u8 facedir = 0; - if (f.param_type == CPT_FACEDIR_SIMPLE) { - facedir = param1; - }else if (f.param2_type == CPT_FACEDIR_SIMPLE) { - facedir = (param2&0x0F); - } - if (dir_i == 0) { - if (facedir == 1) { // -90 - std::string name = g_texturesource->getTextureName(spec.texture.id); - name += "^[transformR270"; - spec.texture = g_texturesource->getTexture(name); - }else if (facedir == 2) { // 180 - std::string name = g_texturesource->getTextureName(spec.texture.id); - name += "^[transformR180"; - spec.texture = g_texturesource->getTexture(name); - }else if (facedir == 3) { // 90 - std::string name = g_texturesource->getTextureName(spec.texture.id); - name += "^[transformR90"; - spec.texture = g_texturesource->getTexture(name); - } - }else if (dir_i == 1) { - if (facedir == 1) { // -90 - std::string name = g_texturesource->getTextureName(spec.texture.id); - name += "^[transformR90"; - spec.texture = g_texturesource->getTexture(name); - }else if (facedir == 2) { // 180 - std::string name = g_texturesource->getTextureName(spec.texture.id); - name += "^[transformR180"; - spec.texture = g_texturesource->getTexture(name); - }else if (facedir == 3) { // 90 - std::string name = g_texturesource->getTextureName(spec.texture.id); - name += "^[transformR270"; - spec.texture = g_texturesource->getTexture(name); - } - } + 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; + if (f.param_type == CPT_FACEDIR_SIMPLE) { + facedir = param1; + }else if (f.param2_type == CPT_FACEDIR_SIMPLE) { + facedir = (param2&0x0F); + } + if (dir_i == 0) { + if (facedir == 1) { // -90 + return "^[transformR270"; + }else if (facedir == 2) { // 180 + return "^[transformR180"; + }else if (facedir == 3) { // 90 + return "^[transformR90"; + } + }else if (dir_i == 1) { + if (facedir == 1) { // -90 + return "^[transformR90"; + }else if (facedir == 2) { // 180 + return "^[transformR180"; + }else if (facedir == 3) { // 90 + return "^[transformR270"; + } + } + + return ""; +} #endif FaceText MapNode::getFaceText(v3s16 dir) { diff --git a/src/mapnode.h b/src/mapnode.h index 7d182d6..44d8e58 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -977,9 +977,10 @@ struct MapNode Returns: TileSpec. Can contain miscellaneous texture coordinates, which must be obeyed so that the texture atlas can be used. */ - TileSpec getTile(v3s16 dir) {return getTileFrom(dir,content_features(*this).tiles); } - TileSpec getMetaTile(v3s16 dir) {return getTileFrom(dir,content_features(*this).meta_tiles); } - TileSpec getTileFrom(v3s16 dir, TileSpec raw_spec[6]); + TileSpec getTile(v3s16 dir, bool rotate = true) {return getTileFrom(dir,content_features(*this).tiles,rotate); } + TileSpec getMetaTile(v3s16 dir, bool rotate = true) {return getTileFrom(dir,content_features(*this).meta_tiles,rotate); } + TileSpec getTileFrom(v3s16 dir, TileSpec raw_spec[6], bool rotate = true); + std::string getTileRotationString(v3s16 dir); #endif FaceText getFaceText(v3s16 dir); diff --git a/src/tile.cpp b/src/tile.cpp index 98877cf..f1e0872 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -38,6 +38,7 @@ #include "mapnode.h" // For texture atlas making #include "mineral.h" // For texture atlas making #include "path.h" +#include "base64.h" /* TextureSource @@ -218,16 +219,11 @@ u32 TextureSource::getTextureIdDirect(const std::string &name) // Find last meta separator in name 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--) { - if (name[i] == separator) { - last_separator_position = i; - break; - } + for (s32 i=name.size()-1; i>=0; i--) { + if (name[i] == separator) { + last_separator_position = i; + break; } - }else{ - last_separator_position = text_separator_position; } /* If separator was found, construct the base name and make the @@ -1686,7 +1682,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, std::string y = sf.next(","); std::string X = 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) { errorstream << "generateImagePart(): baseimg != NULL "