Moved console command, window invalidation, fix help.

This commit is contained in:
Aaron van Geffen 2018-01-07 12:57:59 +01:00
parent bf1bb33b86
commit c023f6a3f7
4 changed files with 59 additions and 55 deletions

View File

@ -573,9 +573,11 @@ static void window_cheats_money_mousedown(rct_window *w, rct_widgetindex widgetI
break;
case WIDX_DATE_SET:
date_set(year_spinner_value, month_spinner_value, day_spinner_value);
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);
break;
case WIDX_DATE_RESET:
date_set(1, 1, 1);
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);
widget_invalidate(w, WIDX_YEAR_BOX);
widget_invalidate(w, WIDX_MONTH_BOX);
widget_invalidate(w, WIDX_DAY_BOX);

View File

@ -1328,6 +1328,62 @@ static sint32 cc_show_limits(const utf8 ** argv, sint32 argc)
return 0;
}
static sint32 cc_for_date(const utf8 **argv, sint32 argc)
{
sint32 year = 0;
sint32 month = 0;
sint32 day = 0;
if (argc < 1 || argc > 3)
{
return -1;
}
// All cases involve providing a year, so grab that first
year = atoi(argv[0]);
if (year < 1 || year > 8192)
{
return -1;
}
// YYYY (no month provided, preserve existing month)
if (argc == 1)
{
month = gDateMonthsElapsed % MONTH_COUNT + 1;
}
// YYYY MM or YYYY MM DD (month provided)
if (argc >= 2)
{
month = atoi(argv[1]);
month -= 2;
if (month < 1 || month > MONTH_COUNT)
{
return -1;
}
}
// YYYY OR YYYY MM (no day provided, preserve existing day)
if (argc <= 2)
{
day = Math::Clamp(1, gDateMonthTicks / (0x10000 / days_in_month[month - 1]) + 1, (int)days_in_month[month - 1]);
}
// YYYY MM DD (year, month, and day provided)
if (argc == 3)
{
day = atoi(argv[2]);
if (day < 1 || day > days_in_month[month-1])
{
return -1;
}
}
date_set(year, month, day);
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);
return 1;
}
typedef sint32 (*console_command_func)(const utf8 **argv, sint32 argc);
typedef struct console_command {
@ -1407,7 +1463,7 @@ static const console_command console_command_table[] = {
{ "remove_unused_objects", cc_remove_unused_objects, "Removes all the unused objects from the object selection.", "remove_unused_objects" },
{ "remove_park_fences", cc_remove_park_fences, "Removes all park fences from the surface", "remove_park_fences"},
{ "show_limits", cc_show_limits, "Shows the map data counts and limits.", "show_limits" },
{ "date", cmdline_for_date, "Sets the date to a given date. Format YYYY MM DD, YYYY MM, or YYYY."}
{ "date", cc_for_date, "Sets the date to a given date.", "Format <year>[ <month>[ <day>]]."}
};
static sint32 cc_windows(const utf8 **argv, sint32 argc) {

View File

@ -17,7 +17,6 @@
#include <time.h>
#include "../Game.h"
#include "../core/Math.hpp"
#include "../interface/window.h"
#include "Date.h"
#include "StringIds.h"
@ -67,7 +66,6 @@ void date_reset()
gDateMonthsElapsed = 0;
gDateMonthTicks = 0;
gCurrentTicks = 0;
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);
}
void date_set(sint32 year, sint32 month, sint32 day)
@ -77,57 +75,6 @@ void date_set(sint32 year, sint32 month, sint32 day)
day = Math::Clamp(1, day, (int)days_in_month[month - 1]);
gDateMonthsElapsed = (year - 1) * MONTH_COUNT + month - 1;
gDateMonthTicks = 0x10000 / days_in_month[month - 1] * (day - 1) + 4;
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);
}
sint32 cmdline_for_date(const utf8 **argv, sint32 argc)
{
sint32 year = 0;
sint32 month = 0;
sint32 day = 0;
if (argc < 1 || argc > 3)
{
return -1;
}
//All cases involve providing a year, so grab that first
year = atoi(argv[0]);
if (year < 1 || year > 8192) {
return -1;
}
//YYYY (no month provided, preserve existing month)
if (argc == 1)
{
month = gDateMonthsElapsed % MONTH_COUNT + 1;
}
////YYYY MM or YYYY MM DD (month provided)
if (argc >= 2)
{
month = atoi(argv[1]);
month -= 2;
if (month < 1 || month > MONTH_COUNT) {
return -1;
}
}
//YYYY OR YYYY MM (no day provided, preserve existing day)
if (argc <= 2)
{
day = Math::Clamp(1, gDateMonthTicks / (0x10000 / days_in_month[month - 1]) + 1, (int)days_in_month[month - 1]);
}
//YYYY MM DD (year, month, and day provided)
if (argc == 3)
{
day = atoi(argv[2]);
if (day < 1 || day > days_in_month[month-1]) {
return -1;
}
}
date_set(year, month, day);
return 1;
}
void date_update()

View File

@ -61,7 +61,6 @@ extern openrct_timeofday gRealTimeOfDay;
sint32 date_get_month(sint32 months);
sint32 date_get_year(sint32 months);
sint32 date_get_total_months(sint32 month, sint32 year);
sint32 cmdline_for_date(const utf8 **argv, sint32 argc);
void date_reset();
void date_update();
void date_set(sint32 year, sint32 month, sint32 day);