mirror of https://github.com/OpenTTD/OpenTTD
(svn r26242) -Codechange: Use GRFFile that filled the TextRefStack to translate StringIDs from the TextRefStack, instead of passing stuff via global vars.
parent
ba1779b978
commit
4f419b8f84
|
@ -56,8 +56,8 @@ StringID TTDPStringIDToOTTDStringIDMapping(StringID str)
|
||||||
STR_TONS, STR_ITEMS, STR_LITERS, STR_ITEMS
|
STR_TONS, STR_ITEMS, STR_LITERS, STR_ITEMS
|
||||||
};
|
};
|
||||||
|
|
||||||
/* A string straight from a NewGRF; no need to remap this as it's already mapped. */
|
/* A string straight from a NewGRF; this was already translated by MapGRFStringID(). */
|
||||||
if (IsInsideMM(str, 0xD000, 0xD7FF)) return str;
|
assert(!IsInsideMM(str, 0xD000, 0xD7FF));
|
||||||
|
|
||||||
#define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \
|
#define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \
|
||||||
assert_compile(stringend - stringid == end - begin); \
|
assert_compile(stringend - stringid == end - begin); \
|
||||||
|
@ -754,20 +754,12 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
|
||||||
return (GRFTAB << TABSIZE) + id;
|
return (GRFTAB << TABSIZE) + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used to remember the grfid that the last retrieved string came from */
|
|
||||||
static uint32 _last_grfid = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index for this stringid associated with its grfID
|
* Returns the index for this stringid associated with its grfID
|
||||||
*/
|
*/
|
||||||
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
|
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
|
||||||
{
|
{
|
||||||
uint id;
|
for (uint id = 0; id < _num_grf_texts; id++) {
|
||||||
|
|
||||||
/* grfid is zero when we're being called via an include */
|
|
||||||
if (grfid == 0) grfid = _last_grfid;
|
|
||||||
|
|
||||||
for (id = 0; id < _num_grf_texts; id++) {
|
|
||||||
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
|
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
|
||||||
return (GRFTAB << TABSIZE) + id;
|
return (GRFTAB << TABSIZE) + id;
|
||||||
}
|
}
|
||||||
|
@ -809,9 +801,6 @@ const char *GetGRFStringPtr(uint16 stringid)
|
||||||
{
|
{
|
||||||
assert(_grf_text[stringid].grfid != 0);
|
assert(_grf_text[stringid].grfid != 0);
|
||||||
|
|
||||||
/* Remember this grfid in case the string has included text */
|
|
||||||
_last_grfid = _grf_text[stringid].grfid;
|
|
||||||
|
|
||||||
const char *str = GetGRFStringFromGRFText(_grf_text[stringid].textholder);
|
const char *str = GetGRFStringFromGRFText(_grf_text[stringid].textholder);
|
||||||
if (str != NULL) return str;
|
if (str != NULL) return str;
|
||||||
|
|
||||||
|
@ -1108,7 +1097,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const
|
||||||
case SCC_NEWGRF_UNPRINT: *buff = max(*buff - Utf8Consume(str), buf_start); break;
|
case SCC_NEWGRF_UNPRINT: *buff = max(*buff - Utf8Consume(str), buf_start); break;
|
||||||
|
|
||||||
case SCC_NEWGRF_PRINT_WORD_STRING_ID:
|
case SCC_NEWGRF_PRINT_WORD_STRING_ID:
|
||||||
*argv = TTDPStringIDToOTTDStringIDMapping(_newgrf_textrefstack.PopUnsignedWord());
|
*argv = MapGRFStringID(_newgrf_textrefstack.grffile->grfid, _newgrf_textrefstack.PopUnsignedWord());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,8 +192,8 @@ const char *GetStringPtr(StringID string)
|
||||||
{
|
{
|
||||||
switch (GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS)) {
|
switch (GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS)) {
|
||||||
case GAME_TEXT_TAB: return GetGameStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS));
|
case GAME_TEXT_TAB: return GetGameStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS));
|
||||||
/* GetGRFStringPtr doesn't handle 0xD4xx ids, we need to convert those to 0xD0xx. */
|
/* 0xD0xx and 0xD4xx IDs have been converted earlier. */
|
||||||
case 26: return GetStringPtr(GetGRFStringID(0, 0xD000 + GB(string, TAB_SIZE_OFFSET, 10)));
|
case 26: NOT_REACHED();
|
||||||
case 28: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS));
|
case 28: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS));
|
||||||
case 29: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x0800);
|
case 29: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x0800);
|
||||||
case 30: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x1000);
|
case 30: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x1000);
|
||||||
|
@ -242,12 +242,7 @@ char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, co
|
||||||
return FormatString(buffr, GetGameStringPtr(index), args, last, case_index, true);
|
return FormatString(buffr, GetGameStringPtr(index), args, last, case_index, true);
|
||||||
|
|
||||||
case 26:
|
case 26:
|
||||||
/* Include string within newgrf text (format code 81) */
|
NOT_REACHED();
|
||||||
if (HasBit(index, 10)) {
|
|
||||||
StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10));
|
|
||||||
return GetStringWithArgs(buffr, string, args, last, case_index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 28:
|
case 28:
|
||||||
return FormatString(buffr, GetGRFStringPtr(index), args, last, case_index);
|
return FormatString(buffr, GetGRFStringPtr(index), args, last, case_index);
|
||||||
|
|
Loading…
Reference in New Issue