Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed Mar 26, 2012
2 parents a0f6808 + df37cc7 commit f854810
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 26 deletions.
21 changes: 19 additions & 2 deletions Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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);
}


Expand Down
1 change: 1 addition & 0 deletions Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Block
{
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.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SET(PROJECT_SRCS
GUI.cpp
GameBuildings.cpp
GroundMaterialConfiguration.cpp
ItemConfiguration.cpp
MapLoading.cpp
Occlusion_Test.cpp
SpriteColors.cpp
Expand Down
49 changes: 29 additions & 20 deletions ContentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ ContentLoader::~ContentLoader(void)
//flush content on exit
flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
flushTerrainConfig(terrainBlockConfigs);
flushItemConfig(itemConfigs);
flushCreatureConfig();
colorConfigs.clear();
}
Expand Down Expand Up @@ -96,6 +97,7 @@ bool ContentLoader::Load(){
flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
flushItemConfig(itemConfigs);
colorConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
Expand Down Expand Up @@ -219,6 +221,7 @@ bool ContentLoader::reload_configs()
flushBuildingConfig(&buildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
flushItemConfig(itemConfigs);
colorConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -746,38 +756,35 @@ 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)
{
return contentLoader->colorConfigs.at(matType).color;
}
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);
}

Expand Down Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion ContentLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ColorConfiguration.h"
#include "commonTypes.h"
#include "FluidConfiguration.h"
#include "ItemConfiguration.h"

class ContentLoader{
private:
Expand All @@ -20,6 +21,7 @@ class ContentLoader{
bool parseColorContent( TiXmlElement* elemRoot );
bool parseFluidContent( TiXmlElement* elemRoot );
bool parseGrassContent( TiXmlElement* elemRoot );
bool parseItemContent( TiXmlElement* elemRoot );
void flushCreatureConfig();

bool translationComplete;
Expand All @@ -39,6 +41,7 @@ class ContentLoader{
vector<TerrainConfiguration*> terrainFloorConfigs;
vector<TerrainConfiguration*> terrainBlockConfigs;
vector<ColorConfiguration> colorConfigs;
vector<ItemConfiguration*> itemConfigs;
FluidConfiguration lava[8];
FluidConfiguration water[8];

Expand Down Expand Up @@ -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);
11 changes: 11 additions & 0 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
119 changes: 119 additions & 0 deletions ItemConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
27 changes: 27 additions & 0 deletions ItemConfiguration.h
Original file line number Diff line number Diff line change
@@ -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);
Loading

0 comments on commit f854810

Please sign in to comment.