customLen

for formatting text on booster shop, we pass the desired length from
getformatted text with noremove(no removal of {}) enabled, if its not
enabled then default the value to zero(passing zero means use the
default values)
This commit is contained in:
Anthony Calosa
2017-02-25 07:27:57 +08:00
parent ec730a4383
commit ec078b6ccc
3 changed files with 13 additions and 10 deletions

View File

@@ -52,7 +52,7 @@ public:
// Set Base for the character set to use.
virtual void SetBase(int base) = 0;
// Format text.
virtual void FormatText(string &s, vector<string>& output) = 0;
virtual void FormatText(string &s, vector<string>& output, int customLen = 0) = 0;
WFont(int inID) : mFontID(inID) {};
virtual ~WFont() {};
};
@@ -117,7 +117,7 @@ public:
it->SetBase(base);
}
;
void FormatText(string &s, vector<string>& output);
void FormatText(string &s, vector<string>& output, int customLen = 0);
private:
JLBFont * it;
@@ -143,7 +143,7 @@ public:
virtual float GetStringWidth(const char *s) const;
void SetTracking(float) {};
void SetBase(int) {};
void FormatText(string &, vector<string>&) {};
void FormatText(string &, vector<string>&, int customLen = 0) {};
virtual void DrawString(const char *s, float x, float y, int align = JGETEXT_LEFT, float leftOffset = 0, float width = 0);
virtual int GetCode(const u8 *ch, int *charLength) const = 0;
@@ -187,7 +187,7 @@ public:
void DrawString(const char *s, float x, float y, int align = JGETEXT_LEFT, float leftOffset = 0, float width = 0);
int GetCode(const u8 *ch, int *charLength) const;
int GetMana(const u8 *ch) const;
void FormatText(string &s, vector<string>& output);
void FormatText(string &s, vector<string>& output, int customLen = 0);
};
class WUFont: public WFBFont
@@ -198,7 +198,7 @@ public:
int GetCode(const u8 *ch, int *charLength) const;
int GetMana(const u8 *ch) const;
void FormatText(string &s, vector<string>& output);
void FormatText(string &s, vector<string>& output, int customLen = 0);
};
#endif

View File

@@ -312,8 +312,9 @@ const vector<string>& CardPrimitive::getFormattedText(bool noremove)
found = text.find_first_of("{}", found + 1);
}
}
int defL = noremove?44:0;
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
mFont->FormatText(text, formattedText);
mFont->FormatText(text, formattedText, defL);
text = "";

View File

@@ -115,10 +115,12 @@ WLBFont::WLBFont(int inFontID, const char *fontname, int lineheight, bool useVid
it = NEW JLBFont(path.c_str(), lineheight, useVideoRAM);
}
void WLBFont::FormatText(string &s, vector<string>& output)
void WLBFont::FormatText(string &s, vector<string>& output, int customLen)
{
int defL = (customLen>0)?customLen:30;
// The way of CardPrimitive::formattedText() in r2081.
std::string::size_type len = 30;
//std::string::size_type len = 30;
std::string::size_type len = defL;
while (s.length() > 0)
{
std::string::size_type cut = s.find_first_of("., \t)", 0);
@@ -1055,7 +1057,7 @@ int WGBKFont::GetMana(const u8 *ch) const
return mana;
}
void WGBKFont::FormatText(string &s, vector<string>& output)
void WGBKFont::FormatText(string &s, vector<string>& output, int customLen)
{
while (s.length() > 0)
{
@@ -1196,7 +1198,7 @@ int WUFont::GetMana(const u8 *ch) const
return -1;
}
void WUFont::FormatText(string &s, vector<string>& output)
void WUFont::FormatText(string &s, vector<string>& output, int customLen)
{
std::string::size_type limit = 22; //28
string delim("., \t)");