2017-06-01 21:55:10 +02:00
|
|
|
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
|
2014-11-25 00:05:35 +01:00
|
|
|
/*****************************************************************************
|
2016-05-04 19:24:41 +02:00
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
|
|
|
*****************************************************************************/
|
|
|
|
#pragma endregion
|
2014-11-25 00:05:35 +01:00
|
|
|
|
2017-08-12 23:06:12 +02:00
|
|
|
#include <openrct2/interface/Cursors.h>
|
|
|
|
#include <openrct2/object/ObjectManager.h>
|
|
|
|
#include <openrct2/object/ObjectRepository.h>
|
|
|
|
#include <openrct2/OpenRCT2.h>
|
|
|
|
#include <openrct2/core/Util.hpp>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2017-08-02 00:20:32 +02:00
|
|
|
|
2017-09-22 07:56:24 +02:00
|
|
|
#include <openrct2/Editor.h>
|
2017-09-18 17:05:28 +02:00
|
|
|
#include <openrct2/input.h>
|
|
|
|
#include <openrct2/interface/widget.h>
|
|
|
|
#include <openrct2/localisation/localisation.h>
|
2017-10-05 16:22:37 +02:00
|
|
|
#include <openrct2/management/Research.h>
|
2017-09-18 17:05:28 +02:00
|
|
|
#include <openrct2/sprites.h>
|
|
|
|
#include <openrct2/util/util.h>
|
|
|
|
#include <openrct2/world/scenery.h>
|
|
|
|
#include <openrct2/windows/_legacy.h>
|
2014-12-16 02:24:13 +01:00
|
|
|
|
|
|
|
#pragma region Widgets
|
|
|
|
|
|
|
|
enum {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_PAGE_BACKGROUND,
|
|
|
|
WIDX_TAB_1,
|
|
|
|
WIDX_PRE_RESEARCHED_SCROLL,
|
|
|
|
WIDX_RESEARCH_ORDER_SCROLL,
|
|
|
|
WIDX_PREVIEW,
|
|
|
|
WIDX_RANDOM_SHUFFLE,
|
|
|
|
WIDX_MOVE_ITEMS_TO_BOTTOM,
|
|
|
|
WIDX_MOVE_ITEMS_TO_TOP
|
2014-12-16 02:24:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_editor_inventions_list_widgets[] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WWT_FRAME, 0, 0, 599, 0, 399, STR_NONE, STR_NONE },
|
|
|
|
{ WWT_CAPTION, 0, 1, 598, 1, 14, STR_INVENTION_LIST, STR_WINDOW_TITLE_TIP },
|
|
|
|
{ WWT_CLOSEBOX, 0, 587, 597, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP },
|
|
|
|
{ WWT_RESIZE, 1, 0, 599, 43, 399, STR_NONE, STR_NONE },
|
2017-07-20 20:56:29 +02:00
|
|
|
{ WWT_TAB, 1, 3, 33, 17, 43, IMAGE_TYPE_REMAP | SPR_TAB, STR_NONE },
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WWT_SCROLL, 1, 4, 371, 56, 175, SCROLL_VERTICAL, STR_NONE },
|
|
|
|
{ WWT_SCROLL, 1, 4, 371, 189, 396, SCROLL_VERTICAL, STR_NONE },
|
|
|
|
{ WWT_FLATBTN, 1, 431, 544, 106, 219, 0xFFFFFFFF, STR_NONE },
|
2017-10-21 00:21:01 +02:00
|
|
|
{ WWT_DROPDOWN_BUTTON, 1, 375, 594, 383, 396, STR_RANDOM_SHUFFLE, STR_RANDOM_SHUFFLE_TIP },
|
|
|
|
{ WWT_DROPDOWN_BUTTON, 1, 375, 594, 368, 381, STR_MOVE_ALL_BOTTOM, STR_NONE },
|
|
|
|
{ WWT_DROPDOWN_BUTTON, 1, 375, 594, 353, 366, STR_MOVE_ALL_TOP, STR_NONE },
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END }
|
2014-12-16 02:24:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_editor_inventions_list_drag_widgets[] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WWT_IMGBTN, 0, 0, 149, 0, 13, STR_NONE, STR_NONE },
|
|
|
|
{ WIDGETS_END }
|
2014-12-16 02:24:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region Events
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_editor_inventions_list_close(rct_window *w);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_editor_inventions_list_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2014-12-16 02:24:13 +01:00
|
|
|
static void window_editor_inventions_list_update(rct_window *w);
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_scrollgetheight(rct_window *w, sint32 scrollIndex, sint32 *width, sint32 *height);
|
|
|
|
static void window_editor_inventions_list_scrollmousedown(rct_window *w, sint32 scrollIndex, sint32 x, sint32 y);
|
|
|
|
static void window_editor_inventions_list_scrollmouseover(rct_window *w, sint32 scrollIndex, sint32 x, sint32 y);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_editor_inventions_list_tooltip(rct_window* w, rct_widgetindex widgetIndex, rct_string_id *stringId);
|
|
|
|
static void window_editor_inventions_list_cursor(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y, sint32 *cursorId);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_editor_inventions_list_invalidate(rct_window *w);
|
|
|
|
static void window_editor_inventions_list_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, sint32 scrollIndex);
|
2015-07-10 02:39:16 +02:00
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_editor_inventions_list_drag_cursor(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y, sint32 *cursorId);
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_drag_moved(rct_window* w, sint32 x, sint32 y);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_editor_inventions_list_drag_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2014-12-16 02:24:13 +01:00
|
|
|
|
|
|
|
// 0x0098177C
|
2015-07-10 02:39:16 +02:00
|
|
|
static rct_window_event_list window_editor_inventions_list_events = {
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_close,
|
|
|
|
window_editor_inventions_list_mouseup,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_update,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_scrollgetheight,
|
|
|
|
window_editor_inventions_list_scrollmousedown,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_scrollmouseover,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_tooltip,
|
|
|
|
window_editor_inventions_list_cursor,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_invalidate,
|
|
|
|
window_editor_inventions_list_paint,
|
|
|
|
window_editor_inventions_list_scrollpaint
|
2014-12-16 02:24:13 +01:00
|
|
|
};
|
|
|
|
|
2015-06-03 21:54:28 +02:00
|
|
|
// 0x009817EC
|
2015-07-10 02:39:16 +02:00
|
|
|
static rct_window_event_list window_editor_inventions_list_drag_events = {
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_drag_cursor,
|
|
|
|
window_editor_inventions_list_drag_moved,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_editor_inventions_list_drag_paint,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr
|
2014-12-16 02:24:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2017-08-06 14:41:13 +02:00
|
|
|
static rct_research_item *_editorInventionsListDraggedItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2016-07-14 14:07:49 +02:00
|
|
|
static const rct_string_id EditorInventionsResearchCategories[] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
STR_RESEARCH_NEW_TRANSPORT_RIDES,
|
|
|
|
STR_RESEARCH_NEW_GENTLE_RIDES,
|
|
|
|
STR_RESEARCH_NEW_ROLLER_COASTERS,
|
|
|
|
STR_RESEARCH_NEW_THRILL_RIDES,
|
|
|
|
STR_RESEARCH_NEW_WATER_RIDES,
|
|
|
|
STR_RESEARCH_NEW_SHOPS_AND_STALLS,
|
|
|
|
STR_RESEARCH_NEW_SCENERY_AND_THEMING,
|
2016-07-14 14:07:49 +02:00
|
|
|
};
|
|
|
|
|
2014-12-16 02:24:13 +01:00
|
|
|
static void window_editor_inventions_list_drag_open(rct_research_item *researchItem);
|
2015-06-04 22:15:00 +02:00
|
|
|
static void move_research_item(rct_research_item *beforeItem);
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-01-04 22:17:08 +01:00
|
|
|
static sint32 research_item_is_always_researched(rct_research_item *researchItem)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return (researchItem->entryIndex & (RESEARCH_ENTRY_FLAG_RIDE_ALWAYS_RESEARCHED | RESEARCH_ENTRY_FLAG_SCENERY_SET_ALWAYS_RESEARCHED)) != 0;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
2015-12-11 16:38:37 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068596F
|
2015-06-06 10:46:01 +02:00
|
|
|
* Sets rides that are in use to be always researched
|
|
|
|
*/
|
|
|
|
static void research_rides_setup(){
|
2017-06-06 23:24:18 +02:00
|
|
|
// Reset all objects to not required
|
|
|
|
for (uint8 object_type = OBJECT_TYPE_RIDE; object_type < 11; object_type++){
|
2017-09-22 07:56:24 +02:00
|
|
|
uint8* in_use = Editor::SelectedObjects[object_type];
|
2017-06-06 23:24:18 +02:00
|
|
|
for (uint8 num_objects = object_entry_group_counts[object_type]; num_objects != 0; num_objects--){
|
|
|
|
*in_use++ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set research required for rides in use
|
|
|
|
for (uint16 rideIndex = 0; rideIndex < 255; rideIndex++){
|
2017-09-12 11:16:57 +02:00
|
|
|
Ride * ride = get_ride(rideIndex);
|
2017-06-06 23:24:18 +02:00
|
|
|
if (ride->type == RIDE_TYPE_NULL)continue;
|
2017-09-22 07:56:24 +02:00
|
|
|
Editor::SelectedObjects[OBJECT_TYPE_RIDE][ride->subtype] |= 1;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 12:18:17 +02:00
|
|
|
for (rct_research_item* research = gResearchItems; research->entryIndex != RESEARCHED_ITEMS_END; research++)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
if (research->entryIndex & RESEARCH_ENTRY_FLAG_RIDE_ALWAYS_RESEARCHED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If not a ride
|
|
|
|
if ((research->entryIndex & 0xFFFFFF) < 0x10000)
|
|
|
|
continue;
|
|
|
|
|
2017-09-19 12:18:17 +02:00
|
|
|
uint8 ride_base_type = research_get_ride_base_type(research->entryIndex);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
uint8 object_index = research->entryIndex & 0xFF;
|
|
|
|
rct_ride_entry* ride_entry = get_ride_entry(object_index);
|
|
|
|
|
|
|
|
bool master_found = false;
|
2017-09-19 12:18:17 +02:00
|
|
|
if (!(ride_entry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE))
|
|
|
|
{
|
|
|
|
for (uint8 rideType = 0; rideType < object_entry_group_counts[OBJECT_TYPE_RIDE]; rideType++)
|
|
|
|
{
|
2017-10-12 21:07:35 +02:00
|
|
|
rct_ride_entry * master_ride = get_ride_entry(rideType);
|
|
|
|
if (master_ride == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (master_ride->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If master ride not in use
|
2017-09-22 07:56:24 +02:00
|
|
|
if (!(Editor::SelectedObjects[OBJECT_TYPE_RIDE][rideType] & (1 << 0)))
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
|
|
|
|
2017-09-19 12:18:17 +02:00
|
|
|
for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++)
|
|
|
|
{
|
|
|
|
if (master_ride->ride_type[j] == ride_base_type)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
master_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-19 12:18:17 +02:00
|
|
|
if (master_found)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!master_found){
|
|
|
|
// If not in use
|
2017-09-22 07:56:24 +02:00
|
|
|
if (!(Editor::SelectedObjects[OBJECT_TYPE_RIDE][object_index] & (1 << 0))) {
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool foundBaseType = false;
|
|
|
|
for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) {
|
|
|
|
if (ride_entry->ride_type[j] == ride_base_type) {
|
|
|
|
foundBaseType = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundBaseType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
research->entryIndex |= RESEARCH_ENTRY_FLAG_RIDE_ALWAYS_RESEARCHED;
|
|
|
|
_editorInventionsListDraggedItem = research;
|
|
|
|
move_research_item(gResearchItems);
|
2017-08-15 10:07:44 +02:00
|
|
|
_editorInventionsListDraggedItem = nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
research--;
|
|
|
|
}
|
2015-06-04 22:15:00 +02:00
|
|
|
}
|
|
|
|
|
2015-12-11 16:38:37 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068590C
|
2015-06-06 10:46:01 +02:00
|
|
|
* Sets the critical scenery sets to always researched
|
|
|
|
*/
|
|
|
|
static void research_scenery_sets_setup(){
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2017-08-03 03:06:32 +02:00
|
|
|
for (size_t i = 0; i < Util::CountOf(RequiredSelectedObjects); i++) {
|
2017-08-06 02:26:14 +02:00
|
|
|
const rct_object_entry * object = &RequiredSelectedObjects[i];
|
2015-06-06 10:46:01 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
uint8 entry_type, entry_index;
|
|
|
|
if (!find_object_in_entry_group(object, &entry_type, &entry_index))
|
|
|
|
continue;
|
2015-06-06 10:46:01 +02:00
|
|
|
|
2017-11-20 10:15:52 +01:00
|
|
|
if (entry_type != OBJECT_TYPE_SCENERY_GROUP)
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
2015-06-06 10:46:01 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item* research = gResearchItems;
|
|
|
|
for (; research->entryIndex != RESEARCHED_ITEMS_END; research++){
|
2015-06-06 10:46:01 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
if ((research->entryIndex & 0xFFFFFF) != entry_index)
|
|
|
|
continue;
|
2015-06-06 10:46:01 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
research->entryIndex |= RESEARCH_ENTRY_FLAG_SCENERY_SET_ALWAYS_RESEARCHED;
|
|
|
|
_editorInventionsListDraggedItem = research;
|
|
|
|
move_research_item(gResearchItems);
|
2017-08-15 10:07:44 +02:00
|
|
|
_editorInventionsListDraggedItem = nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-04 22:15:00 +02:00
|
|
|
}
|
|
|
|
|
2014-12-16 02:24:13 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685901
|
|
|
|
*/
|
2015-06-06 10:46:01 +02:00
|
|
|
static void research_always_researched_setup()
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
research_rides_setup();
|
|
|
|
research_scenery_sets_setup();
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685A93
|
|
|
|
*/
|
|
|
|
static void research_items_shuffle()
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem, *researchOrderBase, researchItemTemp;
|
|
|
|
sint32 i, numNonResearchedItems;
|
|
|
|
|
|
|
|
// Skip pre-researched items
|
|
|
|
for (researchItem = gResearchItems; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR; researchItem++) {}
|
|
|
|
researchItem++;
|
|
|
|
researchOrderBase = researchItem;
|
|
|
|
|
|
|
|
// Count non pre-researched items
|
|
|
|
numNonResearchedItems = 0;
|
|
|
|
for (; researchItem->entryIndex != RESEARCHED_ITEMS_END; researchItem++)
|
|
|
|
numNonResearchedItems++;
|
|
|
|
|
|
|
|
// Shuffle list
|
|
|
|
for (i = 0; i < numNonResearchedItems; i++) {
|
|
|
|
sint32 ri = util_rand() % numNonResearchedItems;
|
|
|
|
if (ri == i)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
researchItemTemp = researchOrderBase[i];
|
|
|
|
researchOrderBase[i] = researchOrderBase[ri];
|
|
|
|
researchOrderBase[ri] = researchItemTemp;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void research_items_make_all_unresearched()
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem, *nextResearchItem, researchItemTemp;
|
|
|
|
|
|
|
|
sint32 sorted;
|
|
|
|
do {
|
|
|
|
sorted = 1;
|
|
|
|
for (researchItem = gResearchItems; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR; researchItem++) {
|
|
|
|
if (research_item_is_always_researched(researchItem))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nextResearchItem = researchItem + 1;
|
|
|
|
if (nextResearchItem->entryIndex == RESEARCHED_ITEMS_SEPARATOR || research_item_is_always_researched(nextResearchItem)) {
|
|
|
|
// Bubble up always researched item or separator
|
|
|
|
researchItemTemp = *researchItem;
|
|
|
|
*researchItem = *nextResearchItem;
|
|
|
|
*nextResearchItem = researchItemTemp;
|
|
|
|
sorted = 0;
|
|
|
|
|
|
|
|
if (researchItem->entryIndex == RESEARCHED_ITEMS_SEPARATOR)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!sorted);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void research_items_make_all_researched()
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem, researchItemTemp;
|
|
|
|
|
|
|
|
// Find separator
|
|
|
|
for (researchItem = gResearchItems; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR; researchItem++) { }
|
|
|
|
|
|
|
|
// Move separator below all items
|
|
|
|
for (; (researchItem + 1)->entryIndex != RESEARCHED_ITEMS_END; researchItem++) {
|
|
|
|
// Swap separator with research item
|
|
|
|
researchItemTemp = *researchItem;
|
|
|
|
*researchItem = *(researchItem + 1);
|
|
|
|
*(researchItem + 1) = researchItemTemp;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006855E7
|
|
|
|
*/
|
|
|
|
static void move_research_item(rct_research_item *beforeItem)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window *w;
|
|
|
|
rct_research_item *researchItem, draggedItem;
|
|
|
|
|
|
|
|
if (_editorInventionsListDraggedItem + 1 == beforeItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Back up the dragged item
|
|
|
|
draggedItem = *_editorInventionsListDraggedItem;
|
|
|
|
|
|
|
|
// Remove dragged item from list
|
|
|
|
researchItem = _editorInventionsListDraggedItem;
|
|
|
|
do {
|
|
|
|
*researchItem = *(researchItem + 1);
|
|
|
|
researchItem++;
|
|
|
|
} while (researchItem->entryIndex != RESEARCHED_ITEMS_END_2);
|
|
|
|
// At end of this researchItem points to the end of the list
|
|
|
|
|
|
|
|
if (beforeItem > _editorInventionsListDraggedItem)
|
|
|
|
beforeItem--;
|
|
|
|
|
|
|
|
// Add dragged item to list
|
|
|
|
do {
|
|
|
|
*researchItem = *(researchItem - 1);
|
|
|
|
researchItem--;
|
|
|
|
} while (researchItem != beforeItem);
|
|
|
|
|
|
|
|
*researchItem = draggedItem;
|
|
|
|
|
|
|
|
w = window_find_by_class(WC_EDITOR_INVENTION_LIST);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (w != nullptr) {
|
|
|
|
w->research_item = nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
window_invalidate(w);
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068558E
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
static rct_research_item *window_editor_inventions_list_get_item_from_scroll_y(sint32 scrollIndex, sint32 y)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
researchItem = gResearchItems;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
if (scrollIndex != 0) {
|
|
|
|
// Skip pre-researched items
|
|
|
|
for (; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR; researchItem++) { }
|
|
|
|
researchItem++;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
for (; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR && researchItem->entryIndex != RESEARCHED_ITEMS_END; researchItem++) {
|
2017-10-21 00:21:01 +02:00
|
|
|
y -= SCROLLABLE_ROW_HEIGHT;
|
2017-06-06 23:24:18 +02:00
|
|
|
if (y < 0)
|
|
|
|
return researchItem;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
return nullptr;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006855BB
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
static rct_research_item *window_editor_inventions_list_get_item_from_scroll_y_include_seps(sint32 scrollIndex, sint32 y)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
researchItem = gResearchItems;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
if (scrollIndex != 0) {
|
|
|
|
// Skip pre-researched items
|
|
|
|
for (; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR; researchItem++) { }
|
|
|
|
researchItem++;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
for (; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR && researchItem->entryIndex != RESEARCHED_ITEMS_END; researchItem++) {
|
2017-10-21 00:21:01 +02:00
|
|
|
y -= SCROLLABLE_ROW_HEIGHT;
|
2017-06-06 23:24:18 +02:00
|
|
|
if (y < 0)
|
|
|
|
return researchItem;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
return researchItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:08 +01:00
|
|
|
static rct_research_item *get_research_item_at(sint32 x, sint32 y)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window *w = window_find_by_class(WC_EDITOR_INVENTION_LIST);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (w != nullptr && w->x <= x && w->y < y && w->x + w->width > x && w->y + w->height > y) {
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_widgetindex widgetIndex = window_find_widget_from_point(w, x, y);
|
|
|
|
rct_widget *widget = &w->widgets[widgetIndex];
|
|
|
|
if (widgetIndex == WIDX_PRE_RESEARCHED_SCROLL || widgetIndex == WIDX_RESEARCH_ORDER_SCROLL) {
|
|
|
|
gPressedWidget.widget_index = widgetIndex;
|
|
|
|
sint32 outX, outY, outScrollArea, outScrollId;
|
|
|
|
widget_scroll_get_part(w, widget, x, y, &outX, &outY, &outScrollArea, &outScrollId);
|
|
|
|
if (outScrollArea == SCROLL_PART_VIEW) {
|
|
|
|
outScrollId = outScrollId == 0 ? 0 : 1;
|
|
|
|
|
|
|
|
sint32 scrollY = y - (w->y + widget->top) + w->scrolls[outScrollId].v_top + 5;
|
|
|
|
return window_editor_inventions_list_get_item_from_scroll_y_include_seps(outScrollId, scrollY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
return nullptr;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
2014-11-25 00:05:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00684E04
|
|
|
|
*/
|
2017-08-12 23:06:12 +02:00
|
|
|
rct_window * window_editor_inventions_list_open()
|
2014-11-25 00:05:35 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window *w;
|
|
|
|
|
|
|
|
w = window_bring_to_front_by_class(WC_EDITOR_INVENTION_LIST);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (w != nullptr)
|
2017-08-12 23:06:12 +02:00
|
|
|
return w;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
research_always_researched_setup();
|
|
|
|
|
|
|
|
w = window_create_centred(
|
|
|
|
600,
|
|
|
|
400,
|
|
|
|
&window_editor_inventions_list_events,
|
|
|
|
WC_EDITOR_INVENTION_LIST,
|
|
|
|
WF_NO_SCROLLING
|
|
|
|
);
|
|
|
|
w->widgets = window_editor_inventions_list_widgets;
|
|
|
|
w->enabled_widgets =
|
|
|
|
(1 << WIDX_CLOSE) |
|
|
|
|
(1 << WIDX_TAB_1) |
|
|
|
|
(1 << WIDX_RANDOM_SHUFFLE) |
|
|
|
|
(1 << WIDX_MOVE_ITEMS_TO_BOTTOM) |
|
|
|
|
(1 << WIDX_MOVE_ITEMS_TO_TOP);
|
|
|
|
window_init_scroll_widgets(w);
|
|
|
|
w->var_4AE = 0;
|
|
|
|
w->selected_tab = 0;
|
2017-08-15 10:07:44 +02:00
|
|
|
w->research_item = nullptr;
|
|
|
|
_editorInventionsListDraggedItem = nullptr;
|
2017-08-12 23:06:12 +02:00
|
|
|
|
|
|
|
return w;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006853D2
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_editor_inventions_list_close(rct_window *w)
|
2016-11-13 20:17:49 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
research_remove_flags();
|
|
|
|
|
|
|
|
// When used in-game (as a cheat)
|
|
|
|
if (!(gScreenFlags & SCREEN_FLAGS_EDITOR)) {
|
|
|
|
gSilentResearch = true;
|
|
|
|
research_reset_current_item();
|
|
|
|
gSilentResearch = false;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068521B
|
|
|
|
*/
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_editor_inventions_list_mouseup(rct_window *w, rct_widgetindex widgetIndex)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
switch (widgetIndex) {
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
case WIDX_RANDOM_SHUFFLE:
|
|
|
|
research_items_shuffle();
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
|
|
|
case WIDX_MOVE_ITEMS_TO_TOP:
|
|
|
|
research_items_make_all_researched();
|
|
|
|
window_init_scroll_widgets(w);
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
|
|
|
case WIDX_MOVE_ITEMS_TO_BOTTOM:
|
|
|
|
research_items_make_all_unresearched();
|
|
|
|
window_init_scroll_widgets(w);
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685392
|
|
|
|
*/
|
|
|
|
static void window_editor_inventions_list_update(rct_window *w)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
w->frame_no++;
|
|
|
|
window_event_invalidate_call(w);
|
|
|
|
widget_invalidate(w, WIDX_TAB_1);
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
if (_editorInventionsListDraggedItem == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
if (window_find_by_class(WC_EDITOR_INVENTION_LIST_DRAG) != nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
_editorInventionsListDraggedItem = nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
window_invalidate(w);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685239
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_scrollgetheight(rct_window *w, sint32 scrollIndex, sint32 *width, sint32 *height)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
*height = 0;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Count / skip pre-researched items
|
|
|
|
for (researchItem = gResearchItems; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR; researchItem++)
|
2017-10-21 00:21:01 +02:00
|
|
|
*height += SCROLLABLE_ROW_HEIGHT;
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
if (scrollIndex == 1) {
|
|
|
|
researchItem++;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Count non pre-researched items
|
|
|
|
*height = 0;
|
|
|
|
for (; researchItem->entryIndex != RESEARCHED_ITEMS_END; researchItem++)
|
2017-10-21 00:21:01 +02:00
|
|
|
*height += SCROLLABLE_ROW_HEIGHT;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006852D4
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_scrollmousedown(rct_window *w, sint32 scrollIndex, sint32 x, sint32 y)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
researchItem = window_editor_inventions_list_get_item_from_scroll_y(scrollIndex, y);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (researchItem == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-08-03 21:15:39 +02:00
|
|
|
if (researchItem->entryIndex < RESEARCHED_ITEMS_END_2 && research_item_is_always_researched(researchItem))
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
window_invalidate(w);
|
|
|
|
window_editor_inventions_list_drag_open(researchItem);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685275
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_scrollmouseover(rct_window *w, sint32 scrollIndex, sint32 x, sint32 y)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
researchItem = window_editor_inventions_list_get_item_from_scroll_y(scrollIndex, y);
|
|
|
|
if (researchItem != w->research_item) {
|
|
|
|
w->research_item = researchItem;
|
|
|
|
window_invalidate(w);
|
|
|
|
}
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068526B
|
|
|
|
*/
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_editor_inventions_list_tooltip(rct_window* w, rct_widgetindex widgetIndex, rct_string_id *stringId)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
set_format_arg(0, rct_string_id, STR_LIST);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685291
|
|
|
|
*/
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_editor_inventions_list_cursor(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y, sint32 *cursorId)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
|
|
|
sint32 scrollIndex;
|
|
|
|
|
|
|
|
switch (widgetIndex) {
|
|
|
|
case WIDX_PRE_RESEARCHED_SCROLL:
|
|
|
|
scrollIndex = 0;
|
|
|
|
break;
|
|
|
|
case WIDX_RESEARCH_ORDER_SCROLL:
|
|
|
|
scrollIndex = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
researchItem = window_editor_inventions_list_get_item_from_scroll_y(scrollIndex, y);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (researchItem == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
|
2017-08-03 21:15:39 +02:00
|
|
|
if (researchItem->entryIndex < RESEARCHED_ITEMS_END_2 && research_item_is_always_researched(researchItem)) {
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cursorId = CURSOR_HAND_OPEN;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685392
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_editor_inventions_list_invalidate(rct_window *w)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
w->pressed_widgets |= 1 << WIDX_PREVIEW;
|
|
|
|
w->pressed_widgets |= 1 << WIDX_TAB_1;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
w->widgets[WIDX_CLOSE].type =
|
|
|
|
gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR ? WWT_EMPTY : WWT_CLOSEBOX;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00684EE0
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_editor_inventions_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_widget *widget;
|
|
|
|
rct_research_item *researchItem;
|
|
|
|
rct_string_id stringId;
|
|
|
|
sint32 x, y, width;
|
|
|
|
|
|
|
|
window_draw_widgets(w, dpi);
|
|
|
|
|
|
|
|
// Tab image
|
|
|
|
x = w->x + w->widgets[WIDX_TAB_1].left;
|
|
|
|
y = w->y + w->widgets[WIDX_TAB_1].top;
|
|
|
|
gfx_draw_sprite(dpi, SPR_TAB_FINANCES_RESEARCH_0 + (w->frame_no / 2) % 8, x, y, 0);
|
|
|
|
|
|
|
|
// Pre-researched items label
|
|
|
|
x = w->x + w->widgets[WIDX_PRE_RESEARCHED_SCROLL].left;
|
|
|
|
y = w->y + w->widgets[WIDX_PRE_RESEARCHED_SCROLL].top - 11;
|
2017-08-15 10:07:44 +02:00
|
|
|
gfx_draw_string_left(dpi, STR_INVENTION_PREINVENTED_ITEMS, nullptr, COLOUR_BLACK, x, y - 1);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Research order label
|
|
|
|
x = w->x + w->widgets[WIDX_RESEARCH_ORDER_SCROLL].left;
|
|
|
|
y = w->y + w->widgets[WIDX_RESEARCH_ORDER_SCROLL].top - 11;
|
2017-08-15 10:07:44 +02:00
|
|
|
gfx_draw_string_left(dpi, STR_INVENTION_TO_BE_INVENTED_ITEMS, nullptr, COLOUR_BLACK, x, y - 1);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Preview background
|
|
|
|
widget = &w->widgets[WIDX_PREVIEW];
|
|
|
|
gfx_fill_rect(
|
|
|
|
dpi,
|
|
|
|
w->x + widget->left + 1,
|
|
|
|
w->y + widget->top + 1,
|
|
|
|
w->x + widget->right - 1,
|
|
|
|
w->y + widget->bottom - 1,
|
|
|
|
ColourMapA[w->colours[1]].darkest
|
|
|
|
);
|
|
|
|
|
|
|
|
researchItem = _editorInventionsListDraggedItem;
|
2017-08-15 10:07:44 +02:00
|
|
|
if (researchItem == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
researchItem = w->research_item;
|
|
|
|
// If the research item is null or a list separator.
|
2017-08-15 10:07:44 +02:00
|
|
|
if (researchItem == nullptr || researchItem->entryIndex < 0)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Preview image
|
|
|
|
sint32 objectEntryType = 7;
|
|
|
|
sint32 eax = researchItem->entryIndex & 0xFFFFFF;
|
|
|
|
if (eax >= 0x10000)
|
|
|
|
objectEntryType = 0;
|
|
|
|
|
|
|
|
void *chunk = object_entry_groups[objectEntryType].chunks[researchItem->entryIndex & 0xFF];
|
|
|
|
|
2017-10-15 15:53:16 +02:00
|
|
|
if (chunk == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
rct_object_entry * entry = &object_entry_groups[objectEntryType].entries[researchItem->entryIndex & 0xFF].entry;
|
|
|
|
|
|
|
|
// Draw preview
|
|
|
|
widget = &w->widgets[WIDX_PREVIEW];
|
|
|
|
|
|
|
|
void * object = object_manager_get_loaded_object(entry);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (object != nullptr) {
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_drawpixelinfo clipDPI;
|
|
|
|
x = w->x + widget->left + 1;
|
|
|
|
y = w->y + widget->top + 1;
|
|
|
|
width = widget->right - widget->left - 1;
|
|
|
|
sint32 height = widget->bottom - widget->top - 1;
|
|
|
|
if (clip_drawpixelinfo(&clipDPI, dpi, x, y, width, height)) {
|
|
|
|
object_draw_preview(object, &clipDPI, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Item name
|
|
|
|
x = w->x + ((widget->left + widget->right) / 2) + 1;
|
|
|
|
y = w->y + widget->bottom + 3;
|
|
|
|
width = w->width - w->widgets[WIDX_RESEARCH_ORDER_SCROLL].right - 6;
|
|
|
|
stringId = research_item_get_name(eax);
|
|
|
|
gfx_draw_string_centred_clipped(dpi, STR_WINDOW_COLOUR_2_STRINGID, &stringId, COLOUR_BLACK, x, y, width);
|
|
|
|
y += 15;
|
|
|
|
|
|
|
|
// Item category
|
|
|
|
x = w->x + w->widgets[WIDX_RESEARCH_ORDER_SCROLL].right + 4;
|
|
|
|
stringId = EditorInventionsResearchCategories[researchItem->category];
|
|
|
|
gfx_draw_string_left(dpi, STR_INVENTION_RESEARCH_GROUP, &stringId, COLOUR_BLACK, x, y);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006850BD
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, sint32 scrollIndex)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
|
|
|
sint32 left, top, bottom, itemY, disableItemMovement;
|
|
|
|
sint32 researchItemEndMarker;
|
|
|
|
rct_string_id stringId;
|
|
|
|
utf8 buffer[256], *ptr;
|
|
|
|
|
|
|
|
// Draw background
|
|
|
|
uint8 paletteIndex = ColourMapA[w->colours[1]].mid_light;
|
|
|
|
gfx_clear(dpi, paletteIndex);
|
|
|
|
|
|
|
|
researchItem = gResearchItems;
|
|
|
|
|
|
|
|
if (scrollIndex == 1) {
|
|
|
|
// Skip pre-researched items
|
|
|
|
for (; researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR; researchItem++) { }
|
|
|
|
researchItem++;
|
|
|
|
researchItemEndMarker = RESEARCHED_ITEMS_END;
|
|
|
|
} else {
|
|
|
|
researchItemEndMarker = RESEARCHED_ITEMS_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
2017-10-21 00:21:01 +02:00
|
|
|
// Since this is now a do while need to counteract the +SCROLLABLE_ROW_HEIGHT
|
|
|
|
itemY = -SCROLLABLE_ROW_HEIGHT;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
itemY += SCROLLABLE_ROW_HEIGHT;
|
|
|
|
if (itemY + SCROLLABLE_ROW_HEIGHT < dpi->y || itemY >= dpi->y + dpi->height)
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
uint8 colour = COLOUR_BRIGHT_GREEN | COLOUR_FLAG_TRANSLUCENT;
|
|
|
|
if (w->research_item == researchItem) {
|
2017-08-15 10:07:44 +02:00
|
|
|
if (_editorInventionsListDraggedItem == nullptr) {
|
2017-06-06 23:24:18 +02:00
|
|
|
// Highlight
|
|
|
|
top = itemY;
|
2017-10-21 00:21:01 +02:00
|
|
|
bottom = itemY + SCROLLABLE_ROW_HEIGHT - 1;
|
2017-06-06 23:24:18 +02:00
|
|
|
} else {
|
|
|
|
// Drop horizontal rule
|
|
|
|
top = itemY - 1;
|
|
|
|
bottom = itemY;
|
|
|
|
}
|
|
|
|
gfx_filter_rect(dpi, 0, top, w->width, bottom, PALETTE_DARKEN_1);
|
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
if (_editorInventionsListDraggedItem == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
colour = COLOUR_BRIGHT_GREEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (researchItem->entryIndex == RESEARCHED_ITEMS_SEPARATOR || researchItem->entryIndex == RESEARCHED_ITEMS_END)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (researchItem == _editorInventionsListDraggedItem)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
disableItemMovement = research_item_is_always_researched(researchItem);
|
|
|
|
stringId = research_item_get_name(researchItem->entryIndex & 0xFFFFFF);
|
|
|
|
|
|
|
|
ptr = buffer;
|
|
|
|
if (!disableItemMovement) {
|
|
|
|
ptr = utf8_write_codepoint(ptr, colour);
|
|
|
|
}
|
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
format_string(ptr, 256, stringId, nullptr);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
if (disableItemMovement) {
|
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_DARK;
|
2017-08-15 10:07:44 +02:00
|
|
|
if (colour == COLOUR_BRIGHT_GREEN && _editorInventionsListDraggedItem == nullptr) {
|
2017-06-06 23:24:18 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_EXTRA_DARK;
|
|
|
|
}
|
|
|
|
colour = COLOUR_FLAG_INSET | w->colours[1];
|
|
|
|
} else {
|
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
|
|
|
colour = COLOUR_BLACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
left = 1;
|
2017-10-21 00:21:01 +02:00
|
|
|
top = itemY;
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_draw_string(dpi, buffer, colour, left, top);
|
|
|
|
}while(researchItem++->entryIndex != researchItemEndMarker);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma region Drag item
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006852F4
|
|
|
|
*/
|
|
|
|
static void window_editor_inventions_list_drag_open(rct_research_item *researchItem)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
char buffer[256];
|
|
|
|
sint32 stringWidth;
|
|
|
|
rct_string_id stringId;
|
|
|
|
rct_window *w;
|
|
|
|
|
|
|
|
window_close_by_class(WC_EDITOR_INVENTION_LIST_DRAG);
|
|
|
|
_editorInventionsListDraggedItem = researchItem;
|
|
|
|
|
|
|
|
stringId = research_item_get_name(researchItem->entryIndex & 0xFFFFFF);
|
2017-08-15 10:07:44 +02:00
|
|
|
format_string(buffer, 256, stringId, nullptr);
|
2017-06-06 23:24:18 +02:00
|
|
|
stringWidth = gfx_get_string_width(buffer);
|
|
|
|
window_editor_inventions_list_drag_widgets[0].right = stringWidth;
|
|
|
|
|
|
|
|
w = window_create(
|
|
|
|
gTooltipCursorX - (stringWidth / 2),
|
|
|
|
gTooltipCursorY - 7,
|
|
|
|
stringWidth,
|
|
|
|
14,
|
|
|
|
&window_editor_inventions_list_drag_events,
|
|
|
|
WC_EDITOR_INVENTION_LIST_DRAG,
|
|
|
|
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_SNAPPING
|
|
|
|
);
|
|
|
|
w->widgets = window_editor_inventions_list_drag_widgets;
|
|
|
|
w->colours[1] = COLOUR_WHITE;
|
|
|
|
input_window_position_begin(w, 0, gTooltipCursorX, gTooltipCursorY);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068549C
|
|
|
|
*/
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_editor_inventions_list_drag_cursor(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y, sint32 *cursorId)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window *inventionListWindow = window_find_by_class(WC_EDITOR_INVENTION_LIST);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (inventionListWindow != nullptr) {
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem = get_research_item_at(x, y);
|
|
|
|
if (researchItem != inventionListWindow->research_item) {
|
|
|
|
inventionListWindow = (rct_window *)researchItem;
|
|
|
|
window_invalidate(inventionListWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*cursorId = CURSOR_HAND_CLOSED;
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00685412
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
static void window_editor_inventions_list_drag_moved(rct_window* w, sint32 x, sint32 y)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_research_item *researchItem;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
researchItem = get_research_item_at(x, y);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (researchItem != nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
move_research_item(researchItem);
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
window_close(w);
|
2017-08-15 10:07:44 +02:00
|
|
|
_editorInventionsListDraggedItem = nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
window_invalidate_by_class(WC_EDITOR_INVENTION_LIST);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006853D9
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_editor_inventions_list_drag_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2014-12-16 02:24:13 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_string_id stringId;
|
|
|
|
sint32 x, y;
|
2014-12-16 02:24:13 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
x = w->x;
|
|
|
|
y = w->y + 2;
|
|
|
|
stringId = research_item_get_name(_editorInventionsListDraggedItem->entryIndex & 0xFFFFFF);
|
|
|
|
gfx_draw_string_left(dpi, STR_WINDOW_COLOUR_2_STRINGID, &stringId, COLOUR_BLACK | COLOUR_FLAG_OUTLINE, x, y);
|
2014-12-16 02:24:13 +01:00
|
|
|
}
|
|
|
|
|
2015-06-04 17:34:47 +02:00
|
|
|
#pragma endregion
|