mirror of https://github.com/OpenRCT2/OpenRCT2.git
Fix dragging crash and some bugs
This commit is contained in:
parent
5ce3d4b947
commit
1265913bdb
|
@ -152,7 +152,7 @@ static rct_window_event_list window_editor_inventions_list_drag_events = {
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
static ResearchItem *_editorInventionsListDraggedItem;
|
static ResearchItem _editorInventionsListDraggedItem;
|
||||||
|
|
||||||
static constexpr const rct_string_id EditorInventionsResearchCategories[] = {
|
static constexpr const rct_string_id EditorInventionsResearchCategories[] = {
|
||||||
STR_RESEARCH_NEW_TRANSPORT_RIDES,
|
STR_RESEARCH_NEW_TRANSPORT_RIDES,
|
||||||
|
@ -198,37 +198,28 @@ static void research_rides_setup()
|
||||||
*/
|
*/
|
||||||
static void move_research_item(ResearchItem* beforeItem)
|
static void move_research_item(ResearchItem* beforeItem)
|
||||||
{
|
{
|
||||||
rct_window* w;
|
research_remove(&_editorInventionsListDraggedItem);
|
||||||
ResearchItem *researchItem, draggedItem;
|
|
||||||
|
|
||||||
if (_editorInventionsListDraggedItem + 1 == beforeItem)
|
bool foundBeforeItem = false;
|
||||||
return;
|
|
||||||
|
|
||||||
// Back up the dragged item
|
for (size_t i = 0; i < gResearchItemsInvented.size() && !foundBeforeItem; i++)
|
||||||
draggedItem = *_editorInventionsListDraggedItem;
|
|
||||||
|
|
||||||
// Remove dragged item from list
|
|
||||||
researchItem = _editorInventionsListDraggedItem;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
*researchItem = *(researchItem + 1);
|
if (beforeItem == nullptr || gResearchItemsInvented[i].Equals(beforeItem))
|
||||||
researchItem++;
|
{
|
||||||
} while (researchItem->rawValue != RESEARCHED_ITEMS_END_2);
|
gResearchItemsInvented.insert((gResearchItemsInvented.begin() + i + 1), _editorInventionsListDraggedItem);
|
||||||
// At end of this researchItem points to the end of the list
|
foundBeforeItem = true;
|
||||||
|
}
|
||||||
if (beforeItem > _editorInventionsListDraggedItem)
|
}
|
||||||
beforeItem--;
|
for (size_t i = 0; i < gResearchItemsUninvented.size() && !foundBeforeItem; i++)
|
||||||
|
|
||||||
// Add dragged item to list
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
*researchItem = *(researchItem - 1);
|
if (beforeItem == nullptr || gResearchItemsUninvented[i].Equals(beforeItem))
|
||||||
researchItem--;
|
{
|
||||||
} while (researchItem != beforeItem);
|
gResearchItemsUninvented.insert((gResearchItemsUninvented.begin() + i + 1), _editorInventionsListDraggedItem);
|
||||||
|
foundBeforeItem = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*researchItem = draggedItem;
|
rct_window* w = window_find_by_class(WC_EDITOR_INVENTION_LIST);
|
||||||
|
|
||||||
w = window_find_by_class(WC_EDITOR_INVENTION_LIST);
|
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
w->research_item = nullptr;
|
w->research_item = nullptr;
|
||||||
|
@ -322,7 +313,7 @@ rct_window* window_editor_inventions_list_open()
|
||||||
w->var_4AE = 0;
|
w->var_4AE = 0;
|
||||||
w->selected_tab = 0;
|
w->selected_tab = 0;
|
||||||
w->research_item = nullptr;
|
w->research_item = nullptr;
|
||||||
_editorInventionsListDraggedItem = nullptr;
|
_editorInventionsListDraggedItem.rawValue = -1;
|
||||||
|
|
||||||
w->min_width = WW;
|
w->min_width = WW;
|
||||||
w->min_height = WH;
|
w->min_height = WH;
|
||||||
|
@ -401,13 +392,13 @@ static void window_editor_inventions_list_update(rct_window* w)
|
||||||
window_event_invalidate_call(w);
|
window_event_invalidate_call(w);
|
||||||
widget_invalidate(w, WIDX_TAB_1);
|
widget_invalidate(w, WIDX_TAB_1);
|
||||||
|
|
||||||
if (_editorInventionsListDraggedItem == nullptr)
|
if (_editorInventionsListDraggedItem.IsInventedEndMarker())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (window_find_by_class(WC_EDITOR_INVENTION_LIST_DRAG) != nullptr)
|
if (window_find_by_class(WC_EDITOR_INVENTION_LIST_DRAG) != nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_editorInventionsListDraggedItem = nullptr;
|
_editorInventionsListDraggedItem.rawValue = -1;
|
||||||
w->Invalidate();
|
w->Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,11 +411,11 @@ static void window_editor_inventions_list_scrollgetheight(rct_window* w, int32_t
|
||||||
*height = 0;
|
*height = 0;
|
||||||
if (scrollIndex == 0)
|
if (scrollIndex == 0)
|
||||||
{
|
{
|
||||||
*height += gResearchItemsInvented.size() * SCROLLABLE_ROW_HEIGHT;
|
*height += (int32_t)gResearchItemsInvented.size() * SCROLLABLE_ROW_HEIGHT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*height += gResearchItemsUninvented.size() * SCROLLABLE_ROW_HEIGHT;
|
*height += (int32_t)gResearchItemsUninvented.size() * SCROLLABLE_ROW_HEIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,8 +573,8 @@ static void window_editor_inventions_list_paint(rct_window* w, rct_drawpixelinfo
|
||||||
dpi, w->x + widget->left + 1, w->y + widget->top + 1, w->x + widget->right - 1, w->y + widget->bottom - 1,
|
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);
|
ColourMapA[w->colours[1]].darkest);
|
||||||
|
|
||||||
researchItem = _editorInventionsListDraggedItem;
|
researchItem = &_editorInventionsListDraggedItem;
|
||||||
if (researchItem == nullptr)
|
if (researchItem->IsInventedEndMarker())
|
||||||
researchItem = w->research_item;
|
researchItem = w->research_item;
|
||||||
// If the research item is null or a list separator.
|
// If the research item is null or a list separator.
|
||||||
if (researchItem == nullptr || researchItem->rawValue < 0)
|
if (researchItem == nullptr || researchItem->rawValue < 0)
|
||||||
|
@ -641,7 +632,7 @@ static void window_editor_inventions_list_scrollpaint(rct_window* w, rct_drawpix
|
||||||
// Draw background
|
// Draw background
|
||||||
uint8_t paletteIndex = ColourMapA[w->colours[1]].mid_light;
|
uint8_t paletteIndex = ColourMapA[w->colours[1]].mid_light;
|
||||||
gfx_clear(dpi, paletteIndex);
|
gfx_clear(dpi, paletteIndex);
|
||||||
|
|
||||||
int16_t boxWidth = (w->widgets[WIDX_RESEARCH_ORDER_SCROLL].right - w->widgets[WIDX_RESEARCH_ORDER_SCROLL].left);
|
int16_t boxWidth = (w->widgets[WIDX_RESEARCH_ORDER_SCROLL].right - w->widgets[WIDX_RESEARCH_ORDER_SCROLL].left);
|
||||||
int16_t columnSplitOffset = boxWidth / 2;
|
int16_t columnSplitOffset = boxWidth / 2;
|
||||||
int32_t itemY = -SCROLLABLE_ROW_HEIGHT;
|
int32_t itemY = -SCROLLABLE_ROW_HEIGHT;
|
||||||
|
@ -656,7 +647,7 @@ static void window_editor_inventions_list_scrollpaint(rct_window* w, rct_drawpix
|
||||||
if (w->research_item == &researchItem)
|
if (w->research_item == &researchItem)
|
||||||
{
|
{
|
||||||
int32_t top, bottom;
|
int32_t top, bottom;
|
||||||
if (_editorInventionsListDraggedItem == nullptr)
|
if (_editorInventionsListDraggedItem.IsInventedEndMarker())
|
||||||
{
|
{
|
||||||
// Highlight
|
// Highlight
|
||||||
top = itemY;
|
top = itemY;
|
||||||
|
@ -672,7 +663,7 @@ static void window_editor_inventions_list_scrollpaint(rct_window* w, rct_drawpix
|
||||||
gfx_filter_rect(dpi, 0, top, boxWidth, bottom, PALETTE_DARKEN_1);
|
gfx_filter_rect(dpi, 0, top, boxWidth, bottom, PALETTE_DARKEN_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (&researchItem == _editorInventionsListDraggedItem)
|
if (researchItem.Equals(&_editorInventionsListDraggedItem))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
utf8 groupNameBuffer[256], vehicleNameBuffer[256];
|
utf8 groupNameBuffer[256], vehicleNameBuffer[256];
|
||||||
|
@ -682,7 +673,7 @@ static void window_editor_inventions_list_scrollpaint(rct_window* w, rct_drawpix
|
||||||
uint8_t colour;
|
uint8_t colour;
|
||||||
if (research_item_is_always_researched(&researchItem))
|
if (research_item_is_always_researched(&researchItem))
|
||||||
{
|
{
|
||||||
if (w->research_item == &researchItem && _editorInventionsListDraggedItem == nullptr)
|
if (w->research_item == &researchItem && _editorInventionsListDraggedItem.IsInventedEndMarker())
|
||||||
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_EXTRA_DARK;
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_EXTRA_DARK;
|
||||||
else
|
else
|
||||||
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_DARK;
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_DARK;
|
||||||
|
@ -741,7 +732,7 @@ static void window_editor_inventions_list_drag_open(ResearchItem* researchItem)
|
||||||
rct_window* w;
|
rct_window* w;
|
||||||
|
|
||||||
window_close_by_class(WC_EDITOR_INVENTION_LIST_DRAG);
|
window_close_by_class(WC_EDITOR_INVENTION_LIST_DRAG);
|
||||||
_editorInventionsListDraggedItem = researchItem;
|
_editorInventionsListDraggedItem = *researchItem;
|
||||||
rct_string_id stringId = research_item_get_name(researchItem);
|
rct_string_id stringId = research_item_get_name(researchItem);
|
||||||
|
|
||||||
ptr = buffer;
|
ptr = buffer;
|
||||||
|
@ -810,7 +801,7 @@ static void window_editor_inventions_list_drag_moved(rct_window* w, int32_t x, i
|
||||||
move_research_item(researchItem);
|
move_research_item(researchItem);
|
||||||
|
|
||||||
window_close(w);
|
window_close(w);
|
||||||
_editorInventionsListDraggedItem = nullptr;
|
_editorInventionsListDraggedItem.rawValue = -1;
|
||||||
window_invalidate_by_class(WC_EDITOR_INVENTION_LIST);
|
window_invalidate_by_class(WC_EDITOR_INVENTION_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -825,7 +816,7 @@ static void window_editor_inventions_list_drag_paint(rct_window* w, rct_drawpixe
|
||||||
|
|
||||||
x = w->x;
|
x = w->x;
|
||||||
y = w->y + 2;
|
y = w->y + 2;
|
||||||
drawString = window_editor_inventions_list_prepare_name(_editorInventionsListDraggedItem, true);
|
drawString = window_editor_inventions_list_prepare_name(&_editorInventionsListDraggedItem, true);
|
||||||
gfx_draw_string_left(dpi, drawString, gCommonFormatArgs, COLOUR_BLACK | COLOUR_FLAG_OUTLINE, x, y);
|
gfx_draw_string_left(dpi, drawString, gCommonFormatArgs, COLOUR_BLACK | COLOUR_FLAG_OUTLINE, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,9 +444,9 @@ void research_remove(ResearchItem* researchItem)
|
||||||
auto& researchItem2 = *it;
|
auto& researchItem2 = *it;
|
||||||
if (researchItem2.Equals(researchItem))
|
if (researchItem2.Equals(researchItem))
|
||||||
{
|
{
|
||||||
|
gResearchItemsInvented.erase(it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gResearchItemsInvented.erase(it);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,6 +853,7 @@ void research_items_make_all_unresearched()
|
||||||
{
|
{
|
||||||
auto& researchItem = *it;
|
auto& researchItem = *it;
|
||||||
gResearchItemsUninvented.push_back(researchItem);
|
gResearchItemsUninvented.push_back(researchItem);
|
||||||
|
gResearchItemsInvented.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,6 +863,7 @@ void research_items_make_all_researched()
|
||||||
{
|
{
|
||||||
auto& researchItem = *it;
|
auto& researchItem = *it;
|
||||||
gResearchItemsInvented.push_back(researchItem);
|
gResearchItemsInvented.push_back(researchItem);
|
||||||
|
gResearchItemsUninvented.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,6 @@ struct ResearchItem
|
||||||
uint8_t category;
|
uint8_t category;
|
||||||
|
|
||||||
bool IsInventedEndMarker() const;
|
bool IsInventedEndMarker() const;
|
||||||
bool IsRandomEndMarker() const;
|
|
||||||
bool IsUninventedEndMarker() const;
|
|
||||||
bool Equals(const ResearchItem* otherItem) const;
|
bool Equals(const ResearchItem* otherItem) const;
|
||||||
bool Exists() const;
|
bool Exists() const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue