mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 14:24:33 +01:00
Refactor News.cpp functions
This commit is contained in:
@@ -138,8 +138,6 @@ static void window_news_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
*/
|
||||
static void window_news_update(rct_window* w)
|
||||
{
|
||||
int32_t i, j;
|
||||
|
||||
if (w->news.var_480 == -1 || --w->news.var_484 != 0)
|
||||
{
|
||||
return;
|
||||
@@ -148,34 +146,36 @@ static void window_news_update(rct_window* w)
|
||||
w->Invalidate();
|
||||
audio_play_sound(SoundId::Click2, 0, w->windowPos.x + (w->width / 2));
|
||||
|
||||
j = w->news.var_480;
|
||||
int32_t j = w->news.var_480;
|
||||
w->news.var_480 = -1;
|
||||
for (i = NEWS_ITEM_HISTORY_START; i < MAX_NEWS_ITEMS; i++)
|
||||
int32_t i = 0;
|
||||
for (; i < MAX_NEWS_ITEMS_ARCHIVE; i++)
|
||||
{
|
||||
if (news_item_is_empty(i))
|
||||
NewsItem* const newsItem = news_item_get(i + NEWS_ITEM_HISTORY_START);
|
||||
if (newsItem->IsEmpty())
|
||||
return;
|
||||
|
||||
if (j == 0)
|
||||
if (j > 0)
|
||||
{
|
||||
NewsItem* const newsItem = news_item_get(i);
|
||||
if (newsItem->Flags & NEWS_FLAG_HAS_BUTTON)
|
||||
return;
|
||||
if (w->news.var_482 == 1)
|
||||
--j;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (newsItem->Flags & NEWS_FLAG_HAS_BUTTON)
|
||||
return;
|
||||
if (w->news.var_482 == 1)
|
||||
{
|
||||
news_item_open_subject(newsItem->Type, newsItem->Assoc);
|
||||
}
|
||||
else if (w->news.var_482 > 1)
|
||||
{
|
||||
auto subjectLoc = news_item_get_subject_location(newsItem->Type, newsItem->Assoc);
|
||||
if (subjectLoc != std::nullopt && (w = window_get_main()) != nullptr)
|
||||
{
|
||||
news_item_open_subject(newsItem->Type, newsItem->Assoc);
|
||||
return;
|
||||
}
|
||||
else if (w->news.var_482 > 1)
|
||||
{
|
||||
auto subjectLoc = news_item_get_subject_location(newsItem->Type, newsItem->Assoc);
|
||||
if (subjectLoc != std::nullopt && (w = window_get_main()) != nullptr)
|
||||
{
|
||||
window_scroll_to_location(w, subjectLoc->x, subjectLoc->y, subjectLoc->z);
|
||||
}
|
||||
return;
|
||||
window_scroll_to_location(w, subjectLoc->x, subjectLoc->y, subjectLoc->z);
|
||||
}
|
||||
}
|
||||
j--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,16 +185,14 @@ static void window_news_update(rct_window* w)
|
||||
*/
|
||||
static void window_news_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height)
|
||||
{
|
||||
int32_t itemHeight = window_news_get_item_height();
|
||||
|
||||
*height = 0;
|
||||
for (int32_t i = NEWS_ITEM_HISTORY_START; i < MAX_NEWS_ITEMS; i++)
|
||||
int32_t i = 0;
|
||||
for (; i < MAX_NEWS_ITEMS_ARCHIVE; i++)
|
||||
{
|
||||
if (news_item_is_empty(i))
|
||||
NewsItem* const newsItem = news_item_get(i + NEWS_ITEM_HISTORY_START);
|
||||
if (newsItem->IsEmpty())
|
||||
break;
|
||||
|
||||
*height += itemHeight;
|
||||
}
|
||||
*height = i * window_news_get_item_height();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,18 +202,18 @@ static void window_news_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_
|
||||
static void window_news_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
|
||||
{
|
||||
int32_t itemHeight = window_news_get_item_height();
|
||||
int32_t i, buttonIndex;
|
||||
|
||||
buttonIndex = 0;
|
||||
int32_t i = 0;
|
||||
int32_t buttonIndex = 0;
|
||||
auto mutableScreenCoords = screenCoords;
|
||||
for (i = NEWS_ITEM_HISTORY_START; i < MAX_NEWS_ITEMS; i++)
|
||||
for (; i < MAX_NEWS_ITEMS_ARCHIVE; i++)
|
||||
{
|
||||
if (news_item_is_empty(i))
|
||||
NewsItem* const newsItem = news_item_get(i + NEWS_ITEM_HISTORY_START);
|
||||
if (newsItem->IsEmpty())
|
||||
break;
|
||||
|
||||
if (mutableScreenCoords.y < itemHeight)
|
||||
{
|
||||
NewsItem* const newsItem = news_item_get(i);
|
||||
if (newsItem->Flags & NEWS_FLAG_HAS_BUTTON || mutableScreenCoords.y < 14 || mutableScreenCoords.y >= 38
|
||||
|| mutableScreenCoords.x < 328)
|
||||
{
|
||||
@@ -238,7 +236,7 @@ static void window_news_scrollmousedown(rct_window* w, int32_t scrollIndex, cons
|
||||
|
||||
if (buttonIndex != 0)
|
||||
{
|
||||
w->news.var_480 = i - NEWS_ITEM_HISTORY_START;
|
||||
w->news.var_480 = i;
|
||||
w->news.var_482 = buttonIndex;
|
||||
w->news.var_484 = 4;
|
||||
w->Invalidate();
|
||||
@@ -263,13 +261,13 @@ static void window_news_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32
|
||||
{
|
||||
int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
|
||||
int32_t itemHeight = window_news_get_item_height();
|
||||
int32_t i, x, y, yy, press;
|
||||
|
||||
y = 0;
|
||||
for (i = NEWS_ITEM_HISTORY_START; i < MAX_NEWS_ITEMS; i++)
|
||||
int32_t y = 0;
|
||||
int32_t i = 0;
|
||||
for (; i < MAX_NEWS_ITEMS_ARCHIVE; i++)
|
||||
{
|
||||
NewsItem* const newsItem = news_item_get(i);
|
||||
if (news_item_is_empty(i))
|
||||
NewsItem* const newsItem = news_item_get(i + NEWS_ITEM_HISTORY_START);
|
||||
if (newsItem->IsEmpty())
|
||||
break;
|
||||
if (y >= dpi->y + dpi->height)
|
||||
break;
|
||||
@@ -296,15 +294,14 @@ static void window_news_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32
|
||||
// Subject button
|
||||
if ((news_type_properties[newsItem->Type] & NEWS_TYPE_HAS_SUBJECT) && !(newsItem->Flags & NEWS_FLAG_HAS_BUTTON))
|
||||
{
|
||||
x = 328;
|
||||
yy = y + lineHeight + 4;
|
||||
int32_t x = 328;
|
||||
int32_t yy = y + lineHeight + 4;
|
||||
|
||||
press = 0;
|
||||
int32_t press = 0;
|
||||
if (w->news.var_480 != -1)
|
||||
{
|
||||
const uint8_t idx = NEWS_ITEM_HISTORY_START + w->news.var_480;
|
||||
news_item_is_valid_idx(idx);
|
||||
if (i == idx && w->news.var_482 == 1)
|
||||
news_item_is_valid_idx(w->news.var_480 + NEWS_ITEM_HISTORY_START);
|
||||
if (i == w->news.var_480 && w->news.var_482 == 1)
|
||||
press = INSET_RECT_FLAG_BORDER_INSET;
|
||||
}
|
||||
gfx_fill_rect_inset(dpi, x, yy, x + 23, yy + 23, w->colours[2], press);
|
||||
@@ -373,15 +370,14 @@ static void window_news_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32
|
||||
// Location button
|
||||
if ((news_type_properties[newsItem->Type] & NEWS_TYPE_HAS_LOCATION) && !(newsItem->Flags & NEWS_FLAG_HAS_BUTTON))
|
||||
{
|
||||
x = 352;
|
||||
yy = y + lineHeight + 4;
|
||||
int32_t x = 352;
|
||||
int32_t yy = y + lineHeight + 4;
|
||||
|
||||
press = 0;
|
||||
int32_t press = 0;
|
||||
if (w->news.var_480 != -1)
|
||||
{
|
||||
const uint8_t idx = NEWS_ITEM_HISTORY_START + w->news.var_480;
|
||||
news_item_is_valid_idx(idx);
|
||||
if (i == idx && w->news.var_482 == 2)
|
||||
news_item_is_valid_idx(w->news.var_480 + NEWS_ITEM_HISTORY_START);
|
||||
if (i == w->news.var_480 && w->news.var_482 == 2)
|
||||
press = 0x20;
|
||||
}
|
||||
gfx_fill_rect_inset(dpi, x, yy, x + 23, yy + 23, w->colours[2], press);
|
||||
|
||||
Reference in New Issue
Block a user