1
0
Fork 0

(svn r22627) -Codechange: Rename PrepareTextRefStackUsage() to StartTextRefStackUsage() to make it more obvious that you must call StopTextRefStackUsage() at some point. Also extent the documentation.

release/1.2
frosch 2011-07-03 13:49:29 +00:00
parent d29def43b0
commit f93c8ce5aa
7 changed files with 22 additions and 10 deletions

View File

@ -740,7 +740,7 @@ static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
/* STR_BLACK_STRING is used to start the string with {BLACK} */ /* STR_BLACK_STRING is used to start the string with {BLACK} */
SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback)); SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback));
PrepareTextRefStackUsage(0); StartTextRefStackUsage(0);
uint result = DrawStringMultiLine(left, right, y, INT32_MAX, STR_BLACK_STRING); uint result = DrawStringMultiLine(left, right, y, INT32_MAX, STR_BLACK_STRING);
StopTextRefStackUsage(); StopTextRefStackUsage();
return result; return result;

View File

@ -74,7 +74,7 @@ static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind,
if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) { if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, (cst != CST_FUND) ? ind->location.tile : INVALID_TILE); uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, (cst != CST_FUND) ? ind->location.tile : INVALID_TILE);
if (GB(callback, 0, 8) != 0xFF) { if (GB(callback, 0, 8) != 0xFF) {
PrepareTextRefStackUsage(6); StartTextRefStackUsage(6);
GetString(suffix, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), suffix_last); GetString(suffix, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), suffix_last);
StopTextRefStackUsage(); StopTextRefStackUsage();
} }
@ -458,7 +458,7 @@ public:
if (callback_res != CALLBACK_FAILED) { // Did it fail? if (callback_res != CALLBACK_FAILED) { // Did it fail?
str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
if (str != STR_UNDEFINED) { if (str != STR_UNDEFINED) {
PrepareTextRefStackUsage(6); StartTextRefStackUsage(6);
DrawStringMultiLine(left, right, y, bottom, str); DrawStringMultiLine(left, right, y, bottom, str);
StopTextRefStackUsage(); StopTextRefStackUsage();
} }
@ -788,7 +788,7 @@ public:
if (message != STR_NULL && message != STR_UNDEFINED) { if (message != STR_NULL && message != STR_UNDEFINED) {
y += WD_PAR_VSEP_WIDE; y += WD_PAR_VSEP_WIDE;
PrepareTextRefStackUsage(6); StartTextRefStackUsage(6);
/* Use all the available space left from where we stand up to the /* Use all the available space left from where we stand up to the
* end of the window. We ALSO enlarge the window if needed, so we * end of the window. We ALSO enlarge the window if needed, so we
* can 'go' wild with the bottom of the window. */ * can 'go' wild with the bottom of the window. */

View File

@ -551,7 +551,7 @@ CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uin
/* Copy some parameters from the registers to the error message text ref. stack */ /* Copy some parameters from the registers to the error message text ref. stack */
SwitchToErrorRefStack(); SwitchToErrorRefStack();
PrepareTextRefStackUsage(4); StartTextRefStackUsage(4);
SwitchToNormalRefStack(); SwitchToNormalRefStack();
switch (result) { switch (result) {

View File

@ -310,7 +310,7 @@ CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind
/* Copy some parameters from the registers to the error message text ref. stack */ /* Copy some parameters from the registers to the error message text ref. stack */
SwitchToErrorRefStack(); SwitchToErrorRefStack();
PrepareTextRefStackUsage(4); StartTextRefStackUsage(4);
SwitchToNormalRefStack(); SwitchToNormalRefStack();
switch (callback_res) { switch (callback_res) {

View File

@ -955,10 +955,22 @@ void RestoreTextRefStackBackup(struct TextRefStack *backup)
} }
/** /**
* Prepare the TTDP compatible string code parsing * Start using the TTDP compatible string code parsing.
*
* On start a number of values is copied on the #TextRefStack.
* You can then use #GetString() and the normal string drawing functions,
* and they will use the #TextRefStack for NewGRF string codes.
*
* However, when you want to draw a string multiple times using the same stack,
* you have to call #RewindTextRefStack() between draws.
*
* After you are done with drawing, you must disable usage of the #TextRefStack
* by calling #StopTextRefStackUsage(), so NewGRF string codes operate on the
* normal string parameters again.
*
* @param numEntries number of entries to copy from the registers * @param numEntries number of entries to copy from the registers
*/ */
void PrepareTextRefStackUsage(byte numEntries) void StartTextRefStackUsage(byte numEntries)
{ {
extern TemporaryStorageArray<int32, 0x110> _temp_store; extern TemporaryStorageArray<int32, 0x110> _temp_store;

View File

@ -34,7 +34,7 @@ void CleanUpGRFText(struct GRFText *grftext);
bool CheckGrfLangID(byte lang_id, byte grf_version); bool CheckGrfLangID(byte lang_id, byte grf_version);
void PrepareTextRefStackUsage(byte numEntries); void StartTextRefStackUsage(byte numEntries);
void StopTextRefStackUsage(); void StopTextRefStackUsage();
void SwitchToNormalRefStack(); void SwitchToNormalRefStack();
void SwitchToErrorRefStack(); void SwitchToErrorRefStack();

View File

@ -236,7 +236,7 @@ public:
if (callback_res != CALLBACK_FAILED) { if (callback_res != CALLBACK_FAILED) {
StringID message = GetGRFStringID(spec->grf_prop.grffile->grfid, 0xD000 + callback_res); StringID message = GetGRFStringID(spec->grf_prop.grffile->grfid, 0xD000 + callback_res);
if (message != STR_NULL && message != STR_UNDEFINED) { if (message != STR_NULL && message != STR_UNDEFINED) {
PrepareTextRefStackUsage(6); StartTextRefStackUsage(6);
/* Use all the available space left from where we stand up to the /* Use all the available space left from where we stand up to the
* end of the window. We ALSO enlarge the window if needed, so we * end of the window. We ALSO enlarge the window if needed, so we
* can 'go' wild with the bottom of the window. */ * can 'go' wild with the bottom of the window. */