mirror of https://github.com/OpenRCT2/OpenRCT2.git
fix object order and add object dat name to object selection window, closes #440
This commit is contained in:
parent
59eff1f572
commit
51802aac45
16
src/object.c
16
src/object.c
|
@ -535,3 +535,19 @@ rct_object_entry *object_get_next(rct_object_entry *entry)
|
|||
|
||||
return (rct_object_entry*)pos;
|
||||
}
|
||||
|
||||
char *object_get_name(rct_object_entry *entry)
|
||||
{
|
||||
uint8 *pos = (uint8*)entry;
|
||||
|
||||
// Skip sizeof(rct_object_entry)
|
||||
pos += 16;
|
||||
|
||||
// Skip filename
|
||||
while (*pos++);
|
||||
|
||||
// Skip
|
||||
pos += 4;
|
||||
|
||||
return pos;
|
||||
}
|
|
@ -92,4 +92,6 @@ int find_object_in_entry_group(rct_object_entry* entry, uint8* entry_type, uint8
|
|||
|
||||
rct_object_entry *object_list_find(rct_object_entry *entry);
|
||||
|
||||
char *object_get_name(rct_object_entry *entry);
|
||||
|
||||
#endif
|
|
@ -95,6 +95,56 @@ static void get_plugin_path(char *path)
|
|||
free(homePath);
|
||||
}
|
||||
|
||||
static void object_list_sort()
|
||||
{
|
||||
rct_object_entry **objectBuffer, *newBuffer, *entry, *destEntry, *lowestEntry;
|
||||
int numObjects, i, j, bufferSize, entrySize, lowestIndex;
|
||||
char *objectName, *lowestString;
|
||||
uint8 *copied;
|
||||
|
||||
objectBuffer = &RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*);
|
||||
numObjects = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, sint32);
|
||||
copied = calloc(numObjects, sizeof(uint8));
|
||||
|
||||
// Get buffer size
|
||||
entry = *objectBuffer;
|
||||
for (i = 0; i < numObjects; i++)
|
||||
entry = object_get_next(entry);
|
||||
bufferSize = (int)entry - (int)*objectBuffer;
|
||||
|
||||
// Create new buffer
|
||||
newBuffer = rct2_malloc(bufferSize);
|
||||
destEntry = newBuffer;
|
||||
|
||||
// Copy over sorted objects
|
||||
for (i = 0; i < numObjects; i++) {
|
||||
// Find next lowest string
|
||||
lowestString = NULL;
|
||||
entry = *objectBuffer;
|
||||
for (j = 0; j < numObjects; j++) {
|
||||
if (!copied[j]) {
|
||||
objectName = object_get_name(entry);
|
||||
if (lowestString == NULL || strcmp(objectName, lowestString) < 0) {
|
||||
lowestEntry = entry;
|
||||
lowestString = objectName;
|
||||
lowestIndex = j;
|
||||
}
|
||||
}
|
||||
entry = object_get_next(entry);
|
||||
}
|
||||
entrySize = object_get_length(lowestEntry);
|
||||
memcpy(destEntry, lowestEntry, entrySize);
|
||||
destEntry = (rct_object_entry*)((int)destEntry + entrySize);
|
||||
copied[lowestIndex] = 1;
|
||||
}
|
||||
|
||||
// Replace old buffer
|
||||
rct2_free(*objectBuffer);
|
||||
*objectBuffer = newBuffer;
|
||||
|
||||
free(copied);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006A93CD
|
||||
|
@ -111,6 +161,7 @@ static void object_list_examine()
|
|||
|
||||
object = object_get_next(object);
|
||||
}
|
||||
object_list_sort();
|
||||
|
||||
// Create a search index
|
||||
object_list_create_hash_table();
|
||||
|
@ -488,7 +539,7 @@ void object_list_create_hash_table()
|
|||
// Set hash table slot
|
||||
_installedObjectHashTable[index] = installedObject;
|
||||
|
||||
// Next installde object
|
||||
// Next installed object
|
||||
installedObject = object_get_next(installedObject);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -483,7 +483,7 @@ static void window_editor_object_selection_paint()
|
|||
rct_object_entry *highlightedEntry;
|
||||
rct_string_id stringId;
|
||||
uint8 *text;
|
||||
char *name, *stringBuffer;
|
||||
char *datName, *name, *stringBuffer;
|
||||
|
||||
window_paint_get_registers(w, dpi);
|
||||
|
||||
|
@ -545,6 +545,7 @@ static void window_editor_object_selection_paint()
|
|||
|
||||
// Skip object dat name
|
||||
text = (char*)(highlightedEntry + 1);
|
||||
datName = text;
|
||||
do {
|
||||
text++;
|
||||
} while (*(text - 1) != 0);
|
||||
|
@ -584,6 +585,10 @@ static void window_editor_object_selection_paint()
|
|||
x = w->x + w->widgets[WIDX_LIST].right + 4;
|
||||
y += 15;
|
||||
object_paint(type, 259, type, x, y, (int)w, (int)dpi, RCT2_GLOBAL(0x009ADAF8, sint32));
|
||||
|
||||
// Draw object dat name
|
||||
strcpy(stringBuffer, datName);
|
||||
gfx_draw_string_right(dpi, stringId, NULL, 0, w->x + w->width - 5, w->y + w->height - 3 - 12);
|
||||
}
|
||||
|
||||
static void window_editor_object_set_page(rct_window *w, int page)
|
||||
|
|
Loading…
Reference in New Issue