1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-24 21:55:42 +00:00

Ingredient name localisation somewhat works, not fully tested yet

This commit is contained in:
fgenesis 2012-06-18 18:54:41 +02:00
parent a55cbb64b8
commit 98c5cefed7
6 changed files with 70 additions and 38 deletions

View file

@ -168,6 +168,15 @@ IngredientType Continuity::getIngredientTypeFromName(const std::string &name) co
return IT_NONE;
}
std::string Continuity::getIngredientDisplayName(const std::string& name) const
{
IngredientNameMap::const_iterator it = ingredientDisplayNames.find(name);
if (it != ingredientDisplayNames.end())
return it->second;
return splitCamelCase(name);
}
IngredientData *Continuity::getIngredientHeldByIndex(int idx) const
{
if (idx < 0 || idx >= ingredients.size()) return 0;
@ -191,6 +200,7 @@ void Recipe::clear()
types.clear();
names.clear();
result = "";
resultDisplayName = "";
known = false;
}
@ -857,13 +867,6 @@ std::string Continuity::getIngredientAffectsString(IngredientData *data)
return getAllIEString(data);
}
std::string Continuity::getIngredientDescription(IngredientEffectType type)
{
int t = (int)type;
if (t < 0 || t >= ingredientDescriptions.size()) return "";
return ingredientDescriptions[t].text;
}
void Continuity::loadTreasureData()
{
treasureData.clear();
@ -900,20 +903,6 @@ void Continuity::loadIngredientData(const std::string &file)
{
std::string line, name, gfx, type, effects;
ingredientDescriptions.clear();
/*
int num;
InStream in2("data/ingredientdescriptions.txt");
while (std::getline(in2, line))
{
IngredientDescription desc;
std::istringstream inLine(line);
inLine >> num >> desc.text;
ingredientDescriptions.push_back(desc);
}
*/
clearIngredientData();
recipes.clear();
@ -1060,7 +1049,6 @@ void Continuity::loadIngredientData(const std::string &file)
Recipe r;
while (in >> name)
{
r.result = name;
if (name == "+")
{
continue;
@ -1073,10 +1061,13 @@ void Continuity::loadIngredientData(const std::string &file)
else
{
if (quitNext)
{
r.result = name;
r.resultDisplayName = getIngredientDisplayName(name);
}
else
{
IngredientType it = dsq->continuity.getIngredientTypeFromName(name);
IngredientType it = getIngredientTypeFromName(name);
if (it == IT_NONE)
{
r.addName(name);
@ -1101,6 +1092,24 @@ void Continuity::loadIngredientData(const std::string &file)
in.close();
}
void Continuity::loadIngredientDisplayNames(const std::string& file)
{
InStream in(file);
if (!in)
return;
std::string line, name, text;
while (std::getline(in, line))
{
size_t pos = line.find(' ');
if (pos == std::string::npos)
continue;
name = line.substr(0, pos);
text = line.substr(pos + 1);
ingredientDisplayNames[name] = text;
}
}
void Continuity::learnFormUpgrade(FormUpgradeType form)
{
formUpgrades[form] = true;
@ -3231,12 +3240,23 @@ void Continuity::reset()
//load ingredients
ingredientDisplayNames.clear();
loadIngredientDisplayNames("data/ingredientnames.txt");
std::string fname = dsq->user.localisePath("data/ingredientnames.txt");
loadIngredientDisplayNames(fname);
if(dsq->mod.isActive())
{
fname = dsq->user.localisePath(dsq->mod.getPath() + "ingredientnames.txt", dsq->mod.getPath());
loadIngredientDisplayNames(fname);
}
ingredientDescriptions.clear();
ingredientData.clear();
recipes.clear();
std::string fname;
if(dsq->mod.isActive())
{
//load mod ingredients

View file

@ -696,10 +696,10 @@ struct IngredientEffect
class IngredientData
{
public:
IngredientData(const std::string &name, const std::string &gfx, IngredientType type)
: name(name), gfx(gfx), amount(0), held(0), type(type), marked(0), sorted(false) {}
IngredientData(const std::string &name, const std::string &gfx, IngredientType type);
int getIndex() const;
const std::string name, gfx;
std::string displayName;
const IngredientType type;
int amount;
int held;
@ -747,6 +747,7 @@ public:
std::vector<RecipeType> types;
std::vector<RecipeName> names;
std::string result;
std::string resultDisplayName;
int index;
@ -1079,9 +1080,11 @@ public:
void applyIngredientEffects(IngredientData *data);
void loadIngredientData(const std::string &file);
void loadIngredientDisplayNames(const std::string& file);
bool hasIngredients() const { return !ingredients.empty(); }
IngredientDatas::size_type ingredientCount() const { return ingredients.size(); }
IngredientType getIngredientTypeFromName(const std::string &name) const;
std::string getIngredientDisplayName(const std::string& name) const;
void removeEmptyIngredients();
void spawnAllIngredients(const Vector &position);
@ -1130,7 +1133,6 @@ public:
IngredientDescriptions ingredientDescriptions;
std::string getIngredientAffectsString(IngredientData *data);
std::string getIngredientDescription(IngredientEffectType type);
WorldMap worldMap;
@ -1176,6 +1178,9 @@ private:
IngredientDatas ingredients; // held ingredients
IngredientDatas ingredientData; // all possible ingredients
typedef std::map<std::string,std::string> IngredientNameMap;
IngredientNameMap ingredientDisplayNames;
};
class Profile

View file

@ -635,7 +635,7 @@ void FoodSlot::onUpdate(float dt)
if ((core->mouse.position - getWorldPosition()).isLength2DIn(16))
//if (isCursorIn())
{
dsq->game->foodLabel->setText(splitCamelCase(ingredient->name));
dsq->game->foodLabel->setText(ingredient->displayName);
dsq->game->foodLabel->alpha.interpolateTo(1, 0.2);
dsq->game->foodDescription->setText(dsq->continuity.getIngredientAffectsString(ingredient));
@ -7946,7 +7946,7 @@ void Game::toggleHelpScreen(bool on, const std::string &label)
#endif
// !!! FIXME: this is such a hack.
data += "\n\n[Achievements]\n\n";
data += "\n\n" + dsq->continuity.stringBank.get(2032) + "\n\n";
dsq->continuity.statsAndAchievements->appendStringData(data);
helpBG = new Quad;
@ -11182,7 +11182,7 @@ void Game::learnedRecipe(Recipe *r, bool effects)
if (nocasecmp(dsq->getTopStateData()->name,"Game")==0 && !applyingState)
{
std::ostringstream os;
os << dsq->continuity.stringBank.get(23) << " " << splitCamelCase(r->result) << " " << dsq->continuity.stringBank.get(24);
os << dsq->continuity.stringBank.get(23) << " " << r->resultDisplayName << " " << dsq->continuity.stringBank.get(24);
IngredientData *data = dsq->continuity.getIngredientDataByName(r->result);
if (data)
{

View file

@ -21,6 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Game.h"
#include "Avatar.h"
IngredientData::IngredientData(const std::string &name, const std::string &gfx, IngredientType type)
: name(name), gfx(gfx), amount(0), held(0), type(type), marked(0), sorted(false)
, displayName(dsq->continuity.getIngredientDisplayName(name))
{
}
int IngredientData::getIndex() const
{

View file

@ -26,8 +26,7 @@ namespace RecipeMenuNamespace
std::string processFoodName(std::string name)
{
name = splitCamelCase(name);
int p = name.find(' ');
size_t p = name.find(' ');
if (p != std::string::npos)
{
name[p] = '\n';
@ -62,7 +61,7 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe
text->color = 0;
text->position = result->position + Vector(0, 18);
text->setText(processFoodName(data->name));
text->setText(processFoodName(data->displayName));
addChild(text, PM_POINTER);
}
@ -99,7 +98,7 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe
text->scale = Vector(0.7, 0.7);
text->color = 0;
text->position = ing[c]->position + Vector(0, 18);
text->setText(processFoodName(data->name));
text->setText(processFoodName(data->displayName));
addChild(text, PM_POINTER);
if (c < size)
@ -132,15 +131,16 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe
std::string typeName = recipe->types[i].typeName;
int loc = typeName.find("Type");
size_t loc = typeName.find("Type");
if (loc != std::string::npos)
{
typeName = typeName.substr(0, loc) + typeName.substr(loc+4, typeName.size());
}
typeName = dsq->continuity.getIngredientDisplayName(typeName);
if (typeName != "Anything")
typeName = std::string("Any\n") + typeName;
if (recipe->types[i].type != IT_ANYTHING)
typeName = dsq->continuity.stringBank.get(2031) + "\n" + typeName;
else
typeName = std::string("\n") + typeName;

View file

@ -204,3 +204,5 @@
2028 |Browse & enable/disable installed patches
2029 |Browse mods online
2030 |Return to title
2031 Any
2032 [Achievements]