1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

implement game_command_set_ride_name

This commit is contained in:
IntelOrca
2015-01-27 02:05:36 +00:00
parent 1aee1825d1
commit 1c18f80f07
8 changed files with 112 additions and 27 deletions

View File

@@ -869,7 +869,7 @@ static uint32 game_do_command_table[58] = {
0x006B49D9,
0x006B4EA6,
0x006B52D4,
0x006B578B, // 10
0, // 10
0x006B5559,
0x006660A8,
0x0066640B,
@@ -932,7 +932,7 @@ static GAME_COMMAND_POINTER* new_game_command_table[58] = {
game_command_emptysub,
game_command_emptysub,
game_command_emptysub,
game_command_emptysub, // 10
game_command_set_ride_name, // 10
game_command_emptysub,
game_command_emptysub,
game_command_emptysub,

View File

@@ -32,6 +32,7 @@ void error_string_quit(int error, rct_string_id format);
int get_string_length(char* buffer);
void user_string_clear_all();
rct_string_id user_string_allocate(int base, const char *text);
void user_string_free(rct_string_id id);
#define MAX_USER_STRINGS 1024

View File

@@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "../addresses.h"
#include "localisation.h"
char *gUserStrings = (char*)0x0135A8F4;
@@ -31,6 +32,21 @@ void user_string_clear_all()
memset(gUserStrings, 0, MAX_USER_STRINGS * USER_STRING_MAX_LENGTH);
}
/**
*
* rct2: 0x006C421D
*/
rct_string_id user_string_allocate(int base, const char *text)
{
int eax, ebx, ecx, edx, esi, edi, ebp;
ecx = base;
edi = (int)text;
RCT2_CALLFUNC_X(0x006C421D, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp);
return eax & 0xFFFF;
}
/**
*
* rct2: 0x006C42AC

View File

@@ -2680,3 +2680,80 @@ void ride_music_update_final()
}
#pragma endregion
void ride_set_name(int rideIndex, const char *name)
{
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = STR_CANT_RENAME_RIDE_ATTRACTION;
game_do_command(1, (rideIndex << 8) | 1, 0, *((int*)(name + 0)), GAME_COMMAND_SET_RIDE_NAME, *((int*)(name + 8)), *((int*)(name + 4)));
game_do_command(2, (rideIndex << 8) | 1, 0, *((int*)(name + 12)), GAME_COMMAND_SET_RIDE_NAME, *((int*)(name + 20)), *((int*)(name + 16)));
game_do_command(0, (rideIndex << 8) | 1, 0, *((int*)(name + 24)), GAME_COMMAND_SET_RIDE_NAME, *((int*)(name + 32)), *((int*)(name + 28)));
}
/**
*
* rct2: 0x006B578B
*/
void game_command_set_ride_name(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp)
{
rct_window *w;
rct_ride *ride;
rct_string_id newUserStringId;
char oldName[128];
static char newName[128];
int rideIndex = (*ebx >> 8) & 0xFF;
int nameChunkIndex = *eax & 0xFFFF;
RCT2_GLOBAL(0x0141F56C, uint8) = 4;
if (*ebx & GAME_COMMAND_FLAG_APPLY) {
int nameChunkOffset = nameChunkIndex - 1;
if (nameChunkOffset < 0)
nameChunkOffset = 2;
nameChunkOffset *= 12;
RCT2_GLOBAL(newName + nameChunkOffset + 0, uint32) = *edx;
RCT2_GLOBAL(newName + nameChunkOffset + 4, uint32) = *ebp;
RCT2_GLOBAL(newName + nameChunkOffset + 8, uint32) = *edi;
}
if (nameChunkIndex != 0) {
*ebx = 0;
return;
}
ride = GET_RIDE(rideIndex);
format_string(oldName, ride->name, &ride->name_arguments);
if (strcmp(oldName, newName) == 0) {
*ebx = 0;
return;
}
if (newName[0] == 0) {
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = STR_INVALID_RIDE_ATTRACTION_NAME;
*ebx = MONEY32_UNDEFINED;
return;
}
newUserStringId = user_string_allocate(4, newName);
if (newUserStringId == 0) {
*ebx = MONEY32_UNDEFINED;
return;
}
if (*ebx & GAME_COMMAND_FLAG_APPLY) {
// Free the old ride name
user_string_free(ride->name);
ride->name = newUserStringId;
gfx_invalidate_screen();
// Force ride list window refresh
w = window_find_by_class(WC_RIDE_LIST);
if (w != NULL)
w->no_list_items = 0;
} else {
user_string_free(newUserStringId);
}
*ebx = 0;
}

View File

@@ -637,4 +637,7 @@ void ride_set_map_tooltip(rct_map_element *mapElement);
int ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint16 sampleRate, uint32 position, uint8 *tuneId);
void ride_music_update_final();
void ride_set_name(int rideIndex, const char *name);
void game_command_set_ride_name(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp);
#endif

View File

@@ -287,17 +287,13 @@ static void window_banner_dropdown()
text_buffer[0] = banner->text_colour + FORMAT_COLOUR_CODE_START;
int string_id = 0, ebx = 0, ecx = 128, edx = 0, ebp = 0, esi = 0;
// Allocate text_buffer to a new string_id?
RCT2_CALLFUNC_X(0x6C421D, &string_id, &ebx, &ecx, &edx, &esi, (int*)&text_buffer, &ebp);
if (string_id){
rct_string_id stringId = user_string_allocate(128, text_buffer);
if (stringId != 0) {
rct_string_id prev_string_id = banner->string_idx;
banner->string_idx = string_id;
banner->string_idx = stringId;
user_string_free(prev_string_id);
window_invalidate(w);
}
else{
} else {
window_error_open(2984, RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id));
}
break;
@@ -324,16 +320,13 @@ static void window_banner_textinput()
text_buffer[0] = banner->text_colour + FORMAT_COLOUR_CODE_START;
strncpy(text_buffer + 1, text, 32);
int string_id = 0, ebx = 0, ecx = 128, edx = 0, ebp = 0, esi = 0;
RCT2_CALLFUNC_X(0x6C421D, &string_id, &ebx, &ecx, &edx, &esi, (int*)&text_buffer, &ebp);
if (string_id){
rct_string_id stringId = user_string_allocate(128, text_buffer);
if (stringId) {
rct_string_id prev_string_id = banner->string_idx;
banner->string_idx = string_id;
banner->string_idx = stringId;
user_string_free(prev_string_id);
window_invalidate(w);
}
else{
} else {
window_error_open(2984, RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id));
}
}

View File

@@ -1899,10 +1899,7 @@ static void window_ride_main_textinput()
if (widgetIndex != WIDX_RENAME || !result)
return;
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = STR_CANT_RENAME_RIDE_ATTRACTION;
game_do_command(1, (w->number << 8) | 1, 0, *((int*)(text + 0)), GAME_COMMAND_SET_RIDE_NAME, *((int*)(text + 8)), *((int*)(text + 4)));
game_do_command(2, (w->number << 8) | 1, 0, *((int*)(text + 12)), GAME_COMMAND_SET_RIDE_NAME, *((int*)(text + 20)), *((int*)(text + 16)));
game_do_command(0, (w->number << 8) | 1, 0, *((int*)(text + 24)), GAME_COMMAND_SET_RIDE_NAME, *((int*)(text + 32)), *((int*)(text + 28)));
ride_set_name(w->number, text);
}
/**

View File

@@ -360,17 +360,15 @@ static void window_sign_textinput()
if (widgetIndex == WIDX_SIGN_TEXT && result) {
if (*text != 0){
int string_id = 0, ebx = 0, ecx = 128, edx = 0, ebp = 0, esi = 0;
RCT2_CALLFUNC_X(0x6C421D, &string_id, &ebx, &ecx, &edx, &esi, (int*)&text, &ebp);
if (string_id){
rct_string_id string_id = user_string_allocate(128, text);
if (string_id != 0) {
rct_string_id prev_string_id = banner->string_idx;
banner->string_idx = string_id;
user_string_free(prev_string_id);
banner->flags &= ~(BANNER_FLAG_2);
gfx_invalidate_screen();
}
else{
} else {
window_error_open(2984, RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id));
}
}