1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-25 22:25:46 +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; 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 IngredientData *Continuity::getIngredientHeldByIndex(int idx) const
{ {
if (idx < 0 || idx >= ingredients.size()) return 0; if (idx < 0 || idx >= ingredients.size()) return 0;
@ -191,6 +200,7 @@ void Recipe::clear()
types.clear(); types.clear();
names.clear(); names.clear();
result = ""; result = "";
resultDisplayName = "";
known = false; known = false;
} }
@ -857,13 +867,6 @@ std::string Continuity::getIngredientAffectsString(IngredientData *data)
return getAllIEString(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() void Continuity::loadTreasureData()
{ {
treasureData.clear(); treasureData.clear();
@ -900,20 +903,6 @@ void Continuity::loadIngredientData(const std::string &file)
{ {
std::string line, name, gfx, type, effects; 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(); clearIngredientData();
recipes.clear(); recipes.clear();
@ -1060,7 +1049,6 @@ void Continuity::loadIngredientData(const std::string &file)
Recipe r; Recipe r;
while (in >> name) while (in >> name)
{ {
r.result = name;
if (name == "+") if (name == "+")
{ {
continue; continue;
@ -1073,10 +1061,13 @@ void Continuity::loadIngredientData(const std::string &file)
else else
{ {
if (quitNext) if (quitNext)
{
r.result = name; r.result = name;
r.resultDisplayName = getIngredientDisplayName(name);
}
else else
{ {
IngredientType it = dsq->continuity.getIngredientTypeFromName(name); IngredientType it = getIngredientTypeFromName(name);
if (it == IT_NONE) if (it == IT_NONE)
{ {
r.addName(name); r.addName(name);
@ -1101,6 +1092,24 @@ void Continuity::loadIngredientData(const std::string &file)
in.close(); 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) void Continuity::learnFormUpgrade(FormUpgradeType form)
{ {
formUpgrades[form] = true; formUpgrades[form] = true;
@ -3231,12 +3240,23 @@ void Continuity::reset()
//load ingredients //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(); ingredientDescriptions.clear();
ingredientData.clear(); ingredientData.clear();
recipes.clear(); recipes.clear();
std::string fname;
if(dsq->mod.isActive()) if(dsq->mod.isActive())
{ {
//load mod ingredients //load mod ingredients

View file

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

View file

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

View file

@ -21,6 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Game.h" #include "Game.h"
#include "Avatar.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 int IngredientData::getIndex() const
{ {

View file

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

View file

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