forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from AtomicFox556/cherrypick-fix2
Make start date and Cataclysm date adjustable
- Loading branch information
Showing
18 changed files
with
428 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
[ | ||
{ | ||
"type": "scenario", | ||
"id": "test_random_hour", | ||
"name": "Test random hour", | ||
"id": "test_custom_game", | ||
"name": "Test custom game start date", | ||
"points": 0, | ||
"description": "Test starting on random hour.", | ||
"description": "Test starting on custom game start date.", | ||
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ], | ||
"start_name": "Evac Shelter", | ||
"flags": [ "CITY_START" ], | ||
"custom_initial_date": { "hour": -1, "season": "summer" } | ||
"start_of_game": { "hour": 18, "day": 7, "season": "summer", "year": 4 } | ||
}, | ||
{ | ||
"type": "scenario", | ||
"id": "test_random_day", | ||
"name": "Test random day", | ||
"id": "test_custom_game_invalid", | ||
"name": "Test invalid custom game start date", | ||
"points": 0, | ||
"description": "Test starting on random day.", | ||
"description": "Test starting on custom start date that is before cataclysm start date.", | ||
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ], | ||
"start_name": "Evac Shelter", | ||
"flags": [ "CITY_START" ], | ||
"custom_initial_date": { "day": -1, "season": "summer" } | ||
"start_of_game": { "hour": 3, "day": 8, "season": "spring", "year": -1 } | ||
}, | ||
{ | ||
"type": "scenario", | ||
"id": "test_random_year", | ||
"name": "Test random year", | ||
"id": "test_custom_cataclysm", | ||
"name": "Test custom cataclysm start date", | ||
"points": 0, | ||
"description": "Test starting on random year.", | ||
"description": "Test starting with custom cataclysm start date.", | ||
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ], | ||
"start_name": "Evac Shelter", | ||
"flags": [ "CITY_START" ], | ||
"custom_initial_date": { "year": -1, "season": "summer" } | ||
"start_of_cataclysm": { "hour": 1, "day": 9, "season": "autumn", "year": 7 } | ||
}, | ||
{ | ||
"type": "scenario", | ||
"id": "test_custom_both", | ||
"name": "Test custom cataclysm start date and game start date", | ||
"points": 0, | ||
"description": "Test starting with custom cataclysm start date and on custom game start date.", | ||
"allowed_locs": [ "sloc_shelter_a", "sloc_shelter_b", "sloc_shelter_c" ], | ||
"start_name": "Evac Shelter", | ||
"flags": [ "CITY_START" ], | ||
"start_of_cataclysm": { "hour": 6, "day": 4, "season": "winter", "year": 6 }, | ||
"start_of_game": { "hour": 13, "day": 19, "season": "autumn", "year": 9 } | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "calendar_ui.h" | ||
|
||
#include "string_formatter.h" | ||
#include "string_input_popup.h" | ||
#include "ui.h" | ||
#include "ui_manager.h" | ||
|
||
time_point calendar_ui::select_time_point( time_point initial_value, std::string_view title ) | ||
{ | ||
time_point return_value = initial_value; | ||
auto set_turn = [&]( const int initial, const time_duration & factor, const char *const msg ) { | ||
string_input_popup pop; | ||
const int new_value = pop | ||
.title( msg ) | ||
.width( 20 ) | ||
.text( std::to_string( initial ) ) | ||
.only_digits( true ) | ||
.query_int(); | ||
if( pop.canceled() ) { | ||
return; | ||
} | ||
const time_duration offset = ( new_value - initial ) * factor; | ||
// Arbitrary maximal value. | ||
const time_point max = calendar::turn_zero + time_duration::from_turns( | ||
std::numeric_limits<int>::max() / 2 ); | ||
return_value = std::max( std::min( max, return_value + offset ), calendar::turn_zero ); | ||
}; | ||
|
||
uilist smenu; | ||
static const auto years = []( const time_point & p ) { | ||
return static_cast<int>( ( p - calendar::turn_zero ) / calendar::year_length() ); | ||
}; | ||
do { | ||
const int iSel = smenu.ret; | ||
smenu.reset(); | ||
smenu.title = title; | ||
smenu.text += string_format( "Old date: %1$s\nNew date: %2$s", | ||
colorize( to_string( initial_value ), c_light_red ), | ||
colorize( to_string( return_value ), c_light_cyan ) ); | ||
smenu.desc_enabled = true; | ||
smenu.footer_text = string_format( _( "Press <color_light_green>%s</color> when done" ), | ||
input_context( smenu.input_category ).get_desc( "UILIST.QUIT" ) ); | ||
smenu.addentry( 0, true, 'y', "%s: %d", _( "year" ), years( return_value ) + 1 ); | ||
smenu.addentry( 1, !calendar::eternal_season(), 's', "%s: %d", | ||
_( "season" ), static_cast<int>( season_of_year( return_value ) ) ); | ||
smenu.addentry( 2, true, 'd', "%s: %d", _( "day" ), day_of_season<int>( return_value ) + 1 ); | ||
smenu.addentry( 3, true, 'h', "%s: %d", _( "hour" ), hour_of_day<int>( return_value ) ); | ||
smenu.addentry( 4, true, 'm', "%s: %d", _( "minute" ), minute_of_hour<int>( return_value ) ); | ||
smenu.addentry( 5, true, 't', "%s: %d", _( "turn" ), | ||
to_turns<int>( return_value - calendar::turn_zero ) ); | ||
smenu.selected = iSel; | ||
smenu.query(); | ||
|
||
switch( smenu.ret ) { | ||
case 0: | ||
set_turn( years( return_value ) + 1, calendar::year_length(), _( "Set year to?" ) ); | ||
break; | ||
case 1: | ||
set_turn( static_cast<int>( season_of_year( return_value ) ), calendar::season_length(), | ||
_( "Set season to? (0 = spring)" ) ); | ||
break; | ||
case 2: | ||
set_turn( day_of_season<int>( return_value ) + 1, 1_days, _( "Set days to?" ) ); | ||
break; | ||
case 3: | ||
set_turn( hour_of_day<int>( return_value ), 1_hours, _( "Set hour to?" ) ); | ||
break; | ||
case 4: | ||
set_turn( minute_of_hour<int>( return_value ), 1_minutes, _( "Set minute to?" ) ); | ||
break; | ||
case 5: | ||
set_turn( to_turns<int>( return_value - calendar::turn_zero ), 1_turns, | ||
string_format( _( "Set turn to? (One day is %i turns)" ), to_turns<int>( 1_days ) ).c_str() ); | ||
break; | ||
default: | ||
break; | ||
} | ||
} while( smenu.ret != UILIST_CANCEL ); | ||
return return_value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
#ifndef CATA_SRC_CALENDAR_UI_H | ||
#define CATA_SRC_CALENDAR_UI_H | ||
|
||
#include <string> | ||
|
||
#include "calendar.h" | ||
#include "translations.h" | ||
|
||
namespace calendar_ui | ||
{ | ||
|
||
/** | ||
* Displays ui element that allows to select and return time point. | ||
*/ | ||
time_point select_time_point( time_point initial_value, | ||
std::string_view title = _( "Select time point" ) ); | ||
} // namespace calendar_ui | ||
|
||
#endif // CATA_SRC_CALENDAR_UI_H |
Oops, something went wrong.