diff options
| author | Petr Mrázek | 2012-03-26 16:16:12 +0200 |
|---|---|---|
| committer | Petr Mrázek | 2012-03-26 16:16:12 +0200 |
| commit | f854810fb76a6c83a9ccd3a50f526963b5c85b90 (patch) | |
| tree | 53d4dc9001d65434a0de2f8a4b649772f9c3b63c | |
| parent | a0f6808254168063449b4f7e93afbd879bd1fafd (diff) | |
| parent | df37cc7e59b3cf5fadfa680a68793b91810a30ff (diff) | |
| download | stonesense-f854810fb76a6c83a9ccd3a50f526963b5c85b90.tar.gz stonesense-f854810fb76a6c83a9ccd3a50f526963b5c85b90.tar.bz2 stonesense-f854810fb76a6c83a9ccd3a50f526963b5c85b90.tar.xz | |
Merge https://github.com/JapaMala/stonesense
| -rw-r--r-- | Block.cpp | 21 | ||||
| -rw-r--r-- | Block.h | 1 | ||||
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | ContentLoader.cpp | 49 | ||||
| -rw-r--r-- | ContentLoader.h | 5 | ||||
| -rw-r--r-- | GUI.cpp | 11 | ||||
| -rw-r--r-- | ItemConfiguration.cpp | 119 | ||||
| -rw-r--r-- | ItemConfiguration.h | 27 | ||||
| -rw-r--r-- | MapLoading.cpp | 14 | ||||
| -rw-r--r-- | SpriteObjects.cpp | 4 | ||||
| -rw-r--r-- | commonTypes.h | 3 | ||||
| -rw-r--r-- | resources/index.txt | 1 | ||||
| -rw-r--r-- | resources/items/BARREL.xml | 5 | ||||
| -rw-r--r-- | resources/items/BIN.xml | 5 | ||||
| -rw-r--r-- | resources/items/WOOD.xml | 5 | ||||
| -rw-r--r-- | resources/items/index.txt | 3 | ||||
| -rw-r--r-- | resources/items/items.png | bin | 0 -> 10354 bytes |
17 files changed, 248 insertions, 26 deletions
@@ -64,7 +64,10 @@ Block::Block(WorldSegment* ownerSegment) engraving_character = 0;
visible = true;
- this->Item.item.type =-1;
+ Item.item.type =-1;
+ Item.dyed = 0;
+ Item.matt.type=-1;
+ Item.matt.index=-1;
}
@@ -286,7 +289,21 @@ void Block::Draw() //items
if(Item.item.type >= 0)
{
- DrawSpriteFromSheet( 350, IMGObjectSheet, lookupMaterialColor(Item.matt.type, Item.matt.index), drawx, (tileShapeBasic==tiletype_shape_basic::Ramp)?(drawy - ((WALLHEIGHT/2)*config.scale)):drawy , this);
+ if(
+ contentLoader->itemConfigs[Item.item.type] &&
+ (Item.item.type < contentLoader->itemConfigs[Item.item.type]->subItems.size()) &&
+ contentLoader->itemConfigs[Item.item.type]->subItems[Item.item.type])
+ {
+ contentLoader->itemConfigs[Item.item.type]->subItems[Item.item.type]->sprite.draw_world(x, y, z, this);
+ }
+ else if (
+ contentLoader->itemConfigs[Item.item.type] &&
+ contentLoader->itemConfigs[Item.item.type]->configured)
+ {
+ contentLoader->itemConfigs[Item.item.type]->default_sprite.draw_world(x, y, z, this);
+ }
+ else
+ DrawSpriteFromSheet( 350, IMGObjectSheet, lookupMaterialColor(Item.matt.type, Item.matt.index, Item.dyed), drawx, (tileShapeBasic==tiletype_shape_basic::Ramp)?(drawy - ((WALLHEIGHT/2)*config.scale)):drawy , this);
}
@@ -147,6 +147,7 @@ public: {
DFHack::t_matglossPair item;
DFHack::t_matglossPair matt;
+ bool dyed;
} Item;
//These are actually applied to the creature standing here, but there's only one creature shown, so it's okay.
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cc6b55..562c75d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ SET(PROJECT_SRCS GUI.cpp GameBuildings.cpp GroundMaterialConfiguration.cpp + ItemConfiguration.cpp MapLoading.cpp Occlusion_Test.cpp SpriteColors.cpp diff --git a/ContentLoader.cpp b/ContentLoader.cpp index 8997f75..eadb6f4 100644 --- a/ContentLoader.cpp +++ b/ContentLoader.cpp @@ -28,7 +28,8 @@ ContentLoader::~ContentLoader(void) //flush content on exit
flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
- flushTerrainConfig(terrainBlockConfigs);
+ flushTerrainConfig(terrainBlockConfigs);
+ flushItemConfig(itemConfigs);
flushCreatureConfig();
colorConfigs.clear();
}
@@ -96,6 +97,7 @@ bool ContentLoader::Load(){ flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
+ flushItemConfig(itemConfigs);
colorConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
@@ -219,6 +221,7 @@ bool ContentLoader::reload_configs() flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
+ flushItemConfig(itemConfigs);
colorConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
@@ -372,6 +375,8 @@ bool ContentLoader::parseContentXMLFile( const char* filepath ){ runningResult &= parseColorContent( elemRoot );
else if( elementType.compare( "fluids" ) == 0 )
runningResult &= parseFluidContent( elemRoot );
+ else if( elementType.compare( "item" ) == 0 )
+ runningResult &= parseItemContent( elemRoot );
else
contentError("Unrecognised root element",elemRoot);
@@ -414,6 +419,11 @@ bool ContentLoader::parseFluidContent(TiXmlElement* elemRoot ){ return addSingleFluidConfig( elemRoot );
}
+bool ContentLoader::parseItemContent(TiXmlElement* elemRoot ){
+ return addSingleItemConfig( elemRoot );
+}
+
+
const char* getDocument(TiXmlNode* element)
{
//walk up the tree to the root
@@ -736,7 +746,7 @@ void ContentLoader::flushCreatureConfig() // make big enough to hold all creatures
creatureConfigs.clear();
}
-ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex)
+ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex, bool dye)
{
if (matType < 0)
{
@@ -746,13 +756,7 @@ ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex) if (matType >= contentLoader->colorConfigs.size())
{
//if it's more than the size of our colorconfigs, then just make a guess based off what DF tells us.
- MaterialInfo mat;
- if(mat.decode(matType, matIndex))
- return al_map_rgb_f(
- contentLoader->Mats->color[mat.material->state_color[0]].red,
- contentLoader->Mats->color[mat.material->state_color[0]].green,
- contentLoader->Mats->color[mat.material->state_color[0]].blue);
- else return al_map_rgb(255,255,255);
+ goto DFColor;
}
if (matIndex < 0)
{
@@ -760,24 +764,27 @@ ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex) }
if (matIndex >= contentLoader->colorConfigs.at(matType).colorMaterials.size())
{
- MaterialInfo mat;
- if(mat.decode(matType, matIndex))
- return al_map_rgb_f(
- contentLoader->Mats->color[mat.material->state_color[0]].red,
- contentLoader->Mats->color[mat.material->state_color[0]].green,
- contentLoader->Mats->color[mat.material->state_color[0]].blue);
- else return al_map_rgb(255,255,255);
+ goto DFColor;
}
if (contentLoader->colorConfigs.at(matType).colorMaterials.at(matIndex).colorSet)
{
return contentLoader->colorConfigs.at(matType).colorMaterials.at(matIndex).color;
}
+ DFColor:
MaterialInfo mat;
if(mat.decode(matType, matIndex))
- return al_map_rgb_f(
- contentLoader->Mats->color[mat.material->state_color[0]].red,
- contentLoader->Mats->color[mat.material->state_color[0]].green,
- contentLoader->Mats->color[mat.material->state_color[0]].blue);
+ {
+ if(dye)
+ return al_map_rgb_f(
+ contentLoader->Mats->color[mat.material->powder_dye].red,
+ contentLoader->Mats->color[mat.material->powder_dye].green,
+ contentLoader->Mats->color[mat.material->powder_dye].blue);
+ else
+ return al_map_rgb_f(
+ contentLoader->Mats->color[mat.material->state_color[0]].red,
+ contentLoader->Mats->color[mat.material->state_color[0]].green,
+ contentLoader->Mats->color[mat.material->state_color[0]].blue);
+ }
else return al_map_rgb(255,255,255);
}
@@ -816,6 +823,8 @@ ShadeBy getShadeType(const char* Input) if( strcmp(Input, "grass") == 0)
return ShadeGrass;
if( strcmp(Input, "equipment") == 0)
+ return ShadeEquip;
+ if( strcmp(Input, "item") == 0)
return ShadeItem;
return ShadeNone;
}
\ No newline at end of file diff --git a/ContentLoader.h b/ContentLoader.h index ff5e50d..471ffdc 100644 --- a/ContentLoader.h +++ b/ContentLoader.h @@ -7,6 +7,7 @@ #include "ColorConfiguration.h"
#include "commonTypes.h"
#include "FluidConfiguration.h"
+#include "ItemConfiguration.h"
class ContentLoader{
private:
@@ -20,6 +21,7 @@ private: bool parseColorContent( TiXmlElement* elemRoot );
bool parseFluidContent( TiXmlElement* elemRoot );
bool parseGrassContent( TiXmlElement* elemRoot );
+ bool parseItemContent( TiXmlElement* elemRoot );
void flushCreatureConfig();
bool translationComplete;
@@ -39,6 +41,7 @@ public: vector<TerrainConfiguration*> terrainFloorConfigs;
vector<TerrainConfiguration*> terrainBlockConfigs;
vector<ColorConfiguration> colorConfigs;
+ vector<ItemConfiguration*> itemConfigs;
FluidConfiguration lava[8];
FluidConfiguration water[8];
@@ -105,6 +108,6 @@ uint8_t lookupMaterialFore(int matType,int matIndex); uint8_t lookupMaterialBack(int matType,int matIndex);
uint8_t lookupMaterialBright(int matType,int matIndex);
const char *lookupTreeName(int matIndex);
-ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex);
+ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex, bool dye = 0);
const char * lookupFormName(int formType);
ShadeBy getShadeType(const char* Input);
@@ -673,6 +673,17 @@ void drawDebugCursorAndInfo(WorldSegment * segment) draw_textf_border(font, al_map_rgb(255,255,255), 2, (i++*al_get_font_line_height(font)), 0,
"Snow: %d, Mud: %d, Blood: %d", b->snowlevel, b->mudlevel, b->bloodlevel);
}
+ if(b->Item.item.type >= 0)
+ {
+ MaterialInfo mat;
+ mat.decode(b->Item.matt.type, b->Item.matt.index);
+ ItemTypeInfo itemdef;
+ bool subtype = itemdef.decode((item_type::item_type)b->Item.item.type, b->Item.item.index);
+ draw_textf_border(font, al_map_rgb(255,255,255), 2, (i++*al_get_font_line_height(font)), 0,
+ "Item: %s - %s",
+ mat.getToken().c_str(),
+ subtype?itemdef.getToken().c_str():"");
+ }
//borders
/*
int dray = (i++*al_get_font_line_height(font));
diff --git a/ItemConfiguration.cpp b/ItemConfiguration.cpp new file mode 100644 index 0000000..49553c0 --- /dev/null +++ b/ItemConfiguration.cpp @@ -0,0 +1,119 @@ +#include "common.h" +#include "ItemConfiguration.h" +#include "tinyxml.h" +#include "GUI.h" +#include "ContentLoader.h" + +ItemConfiguration::ItemConfiguration() +{ + configured=0; +} + + + +ItemConfiguration::~ItemConfiguration() +{ + subItems.clear(); +} + + +bool addSingleItemConfig( TiXmlElement* elemRoot) +{ + const char* strGameID = elemRoot->Attribute("game_type"); + const char* strGameSub = elemRoot->Attribute("game_subtype"); + + if (strGameID == NULL || strGameID[0] == 0) + { + contentError("<item> node must game_type attribute",elemRoot); + return false; + } + item_type::item_type main_type = (item_type::item_type) INVALID_INDEX; + int subtype = INVALID_INDEX; + string game_type_s; + FOR_ENUM_ITEMS(item_type,i) + { + game_type_s = strGameID; + if (game_type_s == ENUM_KEY_STR(item_type,i)) + { + main_type = i; + break; + } + } + if(main_type == (item_type::item_type) INVALID_INDEX) + { + contentError("<item> unknown game_type value",elemRoot); + return false; + } + + if(strGameSub && strGameSub[0] != 0) + { + // get subtype string, if available + string sub; + if(strGameSub) + sub = strGameSub; + + //process subtypes + ItemTypeInfo itemdef; + if(!itemdef.find(sub)) + { + contentError("<item> unknown game_subtype value",elemRoot); + return false; + } + else subtype = itemdef.subtype; + } + + int basefile = -1; + + const char* filename = elemRoot->Attribute("file"); + if (filename != NULL && filename[0] != 0) + { + basefile = loadConfigImgFile((char*)filename, elemRoot); + if(basefile == -1) return false; + } + + + c_sprite sprite; + + sprite.set_by_xml(elemRoot, basefile); + + if(contentLoader->itemConfigs[main_type] == NULL) + contentLoader->itemConfigs[main_type] = new ItemConfiguration; + //check for an existing item there. + if(subtype == INVALID_INDEX) + { + if(!contentLoader->itemConfigs[main_type]->configured) + { + contentLoader->itemConfigs[main_type]->configured = true; + contentLoader->itemConfigs[main_type]->default_sprite = sprite; + } + } + else + { + if(contentLoader->itemConfigs[main_type]->subItems.size() <= subtype) + contentLoader->itemConfigs[main_type]->subItems.resize(subtype+1, NULL); + if(!contentLoader->itemConfigs[main_type]->subItems[subtype]->configured) + { + contentLoader->itemConfigs[main_type]->subItems[subtype]->configured = true; + contentLoader->itemConfigs[main_type]->subItems[subtype]->sprite = sprite; + } + } + return true; +} + + +void flushItemConfig(vector<ItemConfiguration *> &config) +{ + uint32_t currentsize = (uint32_t)config.size(); + for (uint32_t i=0;i<currentsize;i++) + { + if (config[i] != NULL) + { + delete(config[i]); + } + } + + config.clear(); + if (currentsize < ENUM_LAST_ITEM(item_type)) + currentsize = ENUM_LAST_ITEM(item_type); + config.resize(currentsize,NULL); +}
\ No newline at end of file diff --git a/ItemConfiguration.h b/ItemConfiguration.h new file mode 100644 index 0000000..3fd8b80 --- /dev/null +++ b/ItemConfiguration.h @@ -0,0 +1,27 @@ +#pragma once + +#include "SpriteObjects.h" + +class ItemSubConfiguration +{ +public: + c_sprite sprite; + + bool configured; +}; + +class ItemConfiguration +{ +public: + vector<ItemSubConfiguration*> subItems; + c_sprite default_sprite; + + bool configured; + + ItemConfiguration(); + ~ItemConfiguration(); +}; + +bool addSingleItemConfig( TiXmlElement* elemRoot); + +void flushItemConfig(vector<ItemConfiguration *> &config);
\ No newline at end of file diff --git a/MapLoading.cpp b/MapLoading.cpp index 751d016..19ab329 100644 --- a/MapLoading.cpp +++ b/MapLoading.cpp @@ -13,6 +13,7 @@ #include "df/item_constructed.h"
#include "df/itemimprovement.h"
#include "df/itemimprovement_threadst.h"
+#include "df/item_threadst.h"
/*
static DFHack::Core* pDFApiHandle = 0;
static DFHack::Process * DFProc = 0;
@@ -506,7 +507,7 @@ void ReadCellToSegment(DFHack::Core& DF, WorldSegment& segment, int CellX, int C b->Item.matt.type = found_item->getActualMaterial();
b->Item.matt.index = found_item->getActualMaterialIndex();
- if(found_item->isDyed())
+ if(1)//found_item->isDyed())
{
auto Constructed_Item = virtual_cast<df::item_constructed>(found_item);
if(Constructed_Item)
@@ -520,10 +521,21 @@ void ReadCellToSegment(DFHack::Core& DF, WorldSegment& segment, int CellX, int C auto Improvement_Thread = virtual_cast<df::itemimprovement_threadst>(Constructed_Item->improvements[idex]);
if(!Improvement_Thread)
continue;
+ if (Improvement_Thread->dye.mat_type < 0) break;
b->Item.matt.type = Improvement_Thread->dye.mat_type;
b->Item.matt.index = Improvement_Thread->dye.mat_index;
+ b->Item.dyed = 1;
}
}
+ else if (found_item->getType() == item_type::THREAD)
+ {
+ auto Thread_Item = virtual_cast<df::item_threadst>(found_item);
+ if(!Thread_Item) break;
+ if (Thread_Item->dye_mat_type < 0) break;
+ b->Item.matt.type = Thread_Item->dye_mat_type;
+ b->Item.matt.index = Thread_Item->dye_mat_index;
+ b->Item.dyed = 1;
+ }
}
}
diff --git a/SpriteObjects.cpp b/SpriteObjects.cpp index 963fb63..16273ba 100644 --- a/SpriteObjects.cpp +++ b/SpriteObjects.cpp @@ -1014,7 +1014,7 @@ ALLEGRO_COLOR c_sprite::get_color(void* block) else return al_map_rgb(255,255,255);
case ShadeBlood:
return b->bloodcolor;
- case ShadeItem:
+ case ShadeEquip:
if(itemsubtype >=0)
{
//FIXME: need a way to get a material for generic types.
@@ -1030,6 +1030,8 @@ ALLEGRO_COLOR c_sprite::get_color(void* block) return lookupMaterialColor(b->inv->item[itemtype][itemsubtype][0].matt.type, b->inv->item[itemtype][itemsubtype][0].matt.index);
}
else return al_map_rgb(255,255,255);
+ case ShadeItem:
+ return lookupMaterialColor(b->Item.matt.type, b->Item.matt.index);
default:
return al_map_rgb(255, 255, 255);
} ;
diff --git a/commonTypes.h b/commonTypes.h index 630be63..1b804b1 100644 --- a/commonTypes.h +++ b/commonTypes.h @@ -21,7 +21,8 @@ enum ShadeBy ShadeBlood,
ShadeBuilding,
ShadeGrass,
- ShadeItem
+ ShadeItem,
+ ShadeEquip
} ;
struct t_subSprite
{
diff --git a/resources/index.txt b/resources/index.txt index 7f24416..685976a 100644 --- a/resources/index.txt +++ b/resources/index.txt @@ -9,3 +9,4 @@ vegetation/index.txt colors/index.txt
Colors.xml
Fluids/index.txt
+items/index.txt
diff --git a/resources/items/BARREL.xml b/resources/items/BARREL.xml new file mode 100644 index 0000000..01a7c6e --- /dev/null +++ b/resources/items/BARREL.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" ?> + + +<item file="items.png" game_type="BARREL" index = "69" color="item"> +</item> diff --git a/resources/items/BIN.xml b/resources/items/BIN.xml new file mode 100644 index 0000000..fa564a9 --- /dev/null +++ b/resources/items/BIN.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" ?> + + +<item file="items.png" game_type="BIN" index = "70" color="item"> +</item> diff --git a/resources/items/WOOD.xml b/resources/items/WOOD.xml new file mode 100644 index 0000000..73084d4 --- /dev/null +++ b/resources/items/WOOD.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" ?> + + +<item file="items.png" game_type="WOOD" index = "0" color="item"> +</item> diff --git a/resources/items/index.txt b/resources/items/index.txt new file mode 100644 index 0000000..202f1c9 --- /dev/null +++ b/resources/items/index.txt @@ -0,0 +1,3 @@ +BARREL.xml +BIN.xml +WOOD.xml diff --git a/resources/items/items.png b/resources/items/items.png Binary files differnew file mode 100644 index 0000000..a8b878d --- /dev/null +++ b/resources/items/items.png |
