mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-24 20:54:08 +01:00
(svn r22654) [1.1] -Backport from trunk:
- Fix: Switching from a red to a white highlight (by switching to another tool) without switching the highlight mode (HT_RECT etc.) did not mark the selection dirty [FS#4670] (r22649) - Fix: [NewGRF] Parameters from NewGRFs were not properly parsed in all cases [FS#4599] (r22648, r22630, r22629, r22628, r22627) - Fix: GetSection() does not return a LockPart [FS#4678] (r22645) - Fix: [NewGRF] Disallow building NewObjects on water tiles owned by another company (r22643)
This commit is contained in:
@@ -920,11 +920,8 @@ struct TextRefStack {
|
||||
void RewindStack() { this->position = 0; }
|
||||
};
|
||||
|
||||
static TextRefStack _newgrf_normal_textrefstack;
|
||||
static TextRefStack _newgrf_error_textrefstack;
|
||||
|
||||
/** The stack that is used for TTDP compatible string code parsing */
|
||||
static TextRefStack *_newgrf_textrefstack = &_newgrf_normal_textrefstack;
|
||||
static TextRefStack _newgrf_textrefstack;
|
||||
|
||||
/**
|
||||
* Check whether the NewGRF text stack is in use.
|
||||
@@ -932,7 +929,7 @@ static TextRefStack *_newgrf_textrefstack = &_newgrf_normal_textrefstack;
|
||||
*/
|
||||
bool UsingNewGRFTextStack()
|
||||
{
|
||||
return _newgrf_textrefstack->used;
|
||||
return _newgrf_textrefstack.used;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -941,7 +938,7 @@ bool UsingNewGRFTextStack()
|
||||
*/
|
||||
struct TextRefStack *CreateTextRefStackBackup()
|
||||
{
|
||||
return new TextRefStack(*_newgrf_textrefstack);
|
||||
return new TextRefStack(_newgrf_textrefstack);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -950,24 +947,38 @@ struct TextRefStack *CreateTextRefStackBackup()
|
||||
*/
|
||||
void RestoreTextRefStackBackup(struct TextRefStack *backup)
|
||||
{
|
||||
*_newgrf_textrefstack = *backup;
|
||||
_newgrf_textrefstack = *backup;
|
||||
delete 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 values values to copy onto the stack; if NULL the temporary NewGRF registers will be used instead
|
||||
*/
|
||||
void PrepareTextRefStackUsage(byte numEntries)
|
||||
void StartTextRefStackUsage(byte numEntries, const uint32 *values)
|
||||
{
|
||||
extern TemporaryStorageArray<int32, 0x110> _temp_store;
|
||||
|
||||
_newgrf_textrefstack->ResetStack();
|
||||
_newgrf_textrefstack.ResetStack();
|
||||
|
||||
byte *p = _newgrf_textrefstack->stack;
|
||||
byte *p = _newgrf_textrefstack.stack;
|
||||
for (uint i = 0; i < numEntries; i++) {
|
||||
uint32 value = values != NULL ? values[i] : _temp_store.Get(0x100 + i);
|
||||
for (uint j = 0; j < 32; j += 8) {
|
||||
*p = GB(_temp_store.Get(0x100 + i), j, 8);
|
||||
*p = GB(value, j, 8);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
@@ -976,22 +987,12 @@ void PrepareTextRefStackUsage(byte numEntries)
|
||||
/** Stop using the TTDP compatible string code parsing */
|
||||
void StopTextRefStackUsage()
|
||||
{
|
||||
_newgrf_textrefstack->used = false;
|
||||
}
|
||||
|
||||
void SwitchToNormalRefStack()
|
||||
{
|
||||
_newgrf_textrefstack = &_newgrf_normal_textrefstack;
|
||||
}
|
||||
|
||||
void SwitchToErrorRefStack()
|
||||
{
|
||||
_newgrf_textrefstack = &_newgrf_error_textrefstack;
|
||||
_newgrf_textrefstack.used = false;
|
||||
}
|
||||
|
||||
void RewindTextRefStack()
|
||||
{
|
||||
_newgrf_textrefstack->RewindStack();
|
||||
_newgrf_textrefstack.RewindStack();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1004,38 +1005,38 @@ void RewindTextRefStack()
|
||||
*/
|
||||
uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const char **str, int64 *argv)
|
||||
{
|
||||
if (_newgrf_textrefstack->used) {
|
||||
if (_newgrf_textrefstack.used) {
|
||||
switch (scc) {
|
||||
default: NOT_REACHED();
|
||||
case SCC_NEWGRF_PRINT_SIGNED_BYTE: *argv = _newgrf_textrefstack->PopSignedByte(); break;
|
||||
case SCC_NEWGRF_PRINT_SIGNED_WORD: *argv = _newgrf_textrefstack->PopSignedWord(); break;
|
||||
case SCC_NEWGRF_PRINT_QWORD_CURRENCY: *argv = _newgrf_textrefstack->PopUnsignedQWord(); break;
|
||||
case SCC_NEWGRF_PRINT_SIGNED_BYTE: *argv = _newgrf_textrefstack.PopSignedByte(); break;
|
||||
case SCC_NEWGRF_PRINT_SIGNED_WORD: *argv = _newgrf_textrefstack.PopSignedWord(); break;
|
||||
case SCC_NEWGRF_PRINT_QWORD_CURRENCY: *argv = _newgrf_textrefstack.PopUnsignedQWord(); break;
|
||||
|
||||
case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
|
||||
case SCC_NEWGRF_PRINT_DWORD: *argv = _newgrf_textrefstack->PopSignedDWord(); break;
|
||||
case SCC_NEWGRF_PRINT_DWORD: *argv = _newgrf_textrefstack.PopSignedDWord(); break;
|
||||
|
||||
case SCC_NEWGRF_PRINT_HEX_BYTE: *argv = _newgrf_textrefstack->PopUnsignedByte(); break;
|
||||
case SCC_NEWGRF_PRINT_HEX_DWORD: *argv = _newgrf_textrefstack->PopUnsignedDWord(); break;
|
||||
case SCC_NEWGRF_PRINT_HEX_QWORD: *argv = _newgrf_textrefstack->PopSignedQWord(); break;
|
||||
case SCC_NEWGRF_PRINT_HEX_BYTE: *argv = _newgrf_textrefstack.PopUnsignedByte(); break;
|
||||
case SCC_NEWGRF_PRINT_HEX_DWORD: *argv = _newgrf_textrefstack.PopUnsignedDWord(); break;
|
||||
case SCC_NEWGRF_PRINT_HEX_QWORD: *argv = _newgrf_textrefstack.PopSignedQWord(); break;
|
||||
|
||||
case SCC_NEWGRF_PRINT_HEX_WORD:
|
||||
case SCC_NEWGRF_PRINT_WORD_SPEED:
|
||||
case SCC_NEWGRF_PRINT_WORD_VOLUME:
|
||||
case SCC_NEWGRF_PRINT_WORD_WEIGHT:
|
||||
case SCC_NEWGRF_PRINT_WORD_STATION_NAME:
|
||||
case SCC_NEWGRF_PRINT_UNSIGNED_WORD: *argv = _newgrf_textrefstack->PopUnsignedWord(); break;
|
||||
case SCC_NEWGRF_PRINT_UNSIGNED_WORD: *argv = _newgrf_textrefstack.PopUnsignedWord(); break;
|
||||
|
||||
case SCC_NEWGRF_PRINT_DATE:
|
||||
case SCC_NEWGRF_PRINT_MONTH_YEAR: *argv = _newgrf_textrefstack->PopSignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; break;
|
||||
case SCC_NEWGRF_PRINT_MONTH_YEAR: *argv = _newgrf_textrefstack.PopSignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; break;
|
||||
|
||||
case SCC_NEWGRF_DISCARD_WORD: _newgrf_textrefstack->PopUnsignedWord(); break;
|
||||
case SCC_NEWGRF_DISCARD_WORD: _newgrf_textrefstack.PopUnsignedWord(); break;
|
||||
|
||||
case SCC_NEWGRF_ROTATE_TOP_4_WORDS: _newgrf_textrefstack->RotateTop4Words(); break;
|
||||
case SCC_NEWGRF_PUSH_WORD: _newgrf_textrefstack->PushWord(Utf8Consume(str)); break;
|
||||
case SCC_NEWGRF_ROTATE_TOP_4_WORDS: _newgrf_textrefstack.RotateTop4Words(); break;
|
||||
case SCC_NEWGRF_PUSH_WORD: _newgrf_textrefstack.PushWord(Utf8Consume(str)); break;
|
||||
case SCC_NEWGRF_UNPRINT: *buff = max(*buff - Utf8Consume(str), buf_start); break;
|
||||
|
||||
case SCC_NEWGRF_PRINT_STRING_ID:
|
||||
*argv = TTDPStringIDToOTTDStringIDMapping(_newgrf_textrefstack->PopUnsignedWord());
|
||||
*argv = TTDPStringIDToOTTDStringIDMapping(_newgrf_textrefstack.PopUnsignedWord());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user