Skip to content

Commit

Permalink
Port DDA title screen update with BN-specific tweaks (#2519)
Browse files Browse the repository at this point in the history
* Move get_holiday_from_time to cata_utility

(cherry picked from commit 348d239ec08e1301b2f63477ec1351ed49b6e33b)

* Fix symbol collision

* Fix character name covering world name

(cherry picked from commit 60b363d30853f94cde54e7f42a64791333b035ff)

* Only use empty worlds when selecting "Play Now"

(cherry picked from commit fdbe06d53a48e7a3191f7ffb23e5b49b6de7f146)

* Clarify 'delete world?' message

(cherry picked from commit aa08e09b1bd052a450d3f3986beae94f6a6259f1)

* Reduce merge conflicts

* Migrate g->add_msg_if_player -> add_msg

(cherry picked from commit a2510c6d12be5e4efebec3219239ae36ae797a83)

* Allow traversing main menu horizontally with TAB and SHIFT + TAB

(cherry picked from commit 6847331)

* Rename and make special_game_type a class enum

(cherry picked from commit 09ab0494dfed16fa77292b2cf5c60b46737c6b2e)

* (Partial) Global reference migration part 30

(cherry picked from commit f95326e8ad4dddc653f3e459d270f0947a61936a)

* Add g->scen accessors

* (Partial) Fix spelling issues

(cherry picked from commit c380afc798df064ab76645a0a2f66358d425e3bc)

* Enable clang-tidy check bugprone-unused-return-value

* Fix bugprone-unused-return-value

Biggest change here was to mapbuffer, which now stores submaps via
unique_ptr rather than raw pointers, simplifying the destructor.

Unfortunately, we have to retain the strange pointer-based API for
mapbuffer, because the submap ownership logic in map is so convoluted.
That can be fixed another day.

Also, renamed mapbuffer::reset() to clear(), for consistency.

In trait_group, removed a couple of calls to reset() that this warning
was highlighting.  They didn't do anything anyway.

* Enable clang-tidy bugprone-unused-return-value

(cherry picked from commit 1c4f47adc95c9a7e87aec501113a310ffab18cc5)

* (Partial) Fix some cases of readability-isolate-declaration

(cherry picked from commit a8f17b497e3fe255daadcd04e331a2d1dbfc21b6)

* (Partial) Fox some cases of modernize-use-emplace

(cherry picked from commit 8cc6378fc55bca9f7af06c623c70786de43df1ee)

* (Partial) Fix some cases of cata-combine-locals-into-point

(cherry picked from commit e067da4d920ab00662adc5319b8c2b4e37cb8d4a)

* (Partial) Fix some cases of bugprone-branch-clone

Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>
Co-authored-by: Kevin Granade <kevin.granade@gmail.com>
(cherry picked from commit 159413daa279694aeaf7885edde67f496d61d473)

* Refactor: isolate points_left

(cherry picked from commit e0ad76e03960df71797752d1120e23f476fef727)

* Decouple save file name from Character::name

(cherry picked from commit f0c2c3b123ae44f3b2a6d5d29fc18350be0c4dfd)

* (Reduce conflicts) (Partial) Remove ime.h/cpp

(cherry picked from commit 722b94b7207c114cc6a34cd140e0619d01f180fd)

* Fix compilation

* Main menu overhaul (Part 1):  Mouse controls + Vertical submenus

(cherry picked from commit 369fc6fcf207ba30609eadd02ca4830950596c14)

* Fix MOTD/Credits scrolling bug

Co-authored-by: David Seguin <davidseguin@live.ca>
(cherry picked from commit 293c808cb2c8d0891ca26e9580e17eabcab62e51)

* Fix crash when pressing load button in main menu if there is no world

(cherry picked from commit 5ac426dfe46f768910bf5354566393147e0a719a)

* Add hotkeys for world interaction

(cherry picked from commit b7142b23189354fa81a94e83920a0398f83af76b)

* monologue messages return after the start of the new game

Co-authored-by: EI IKao <you@example.com>
(cherry picked from commit d291072370c32ea9027f4c40eaefce49dceec138)

* Fix compilation

* Fix JSON

* Fix JSON style

* Remove bits of mouse code

* Fix functionality lost during merge

* Redraw screen when confirming quitting

* Merge 'Special' category into 'New Game'

* Fix hotkeys mismatch in world menu

* Mute colors a bit, use yellow hotkeys in lists

* Fix lack of sound when moving in lists

* Reorder entries in world menu

* Revert color mute

* Add quick return from lists

* Make more space for hints at the bottom

* Get rid of errflag, fix error when trying to load with no world

* Fix uninitialized variable

* Reduce code duplication

* Auto-create world on "Play Now"

* Fix tutorial and defence

* Fix starting vehicle in character template

---------

Co-authored-by: David Seguin <davidseguin@live.ca>
Co-authored-by: Dylan Greer <greerd248@yahoo.com>
Co-authored-by: Jianxiang Wang (王健翔) <qrox@sina.com>
Co-authored-by: Kevin Granade <kevin.granade@gmail.com>
Co-authored-by: Simon Jansson <simonj12@hotmail.se>
Co-authored-by: ZhilkinSerg <ZhilkinSerg@users.noreply.github.com>
Co-authored-by: John Bytheway <jbytheway@gmail.com>
Co-authored-by: Andrey Bienkowski <hexagon-recursion@posteo.net>
Co-authored-by: eltank <8000047+eltank@users.noreply.github.com>
Co-authored-by: Ezrashaw <Ezrasure@outlook.com>
Co-authored-by: Binrui Dong <brett.browning.dong@gmail.com>
Co-authored-by: anothersimulacrum <anothersimulacrum@gmail.com>
Co-authored-by: EI IKaO <109350502+EIIKaO@users.noreply.github.com>
  • Loading branch information
14 people authored Apr 7, 2023
1 parent 75f0a38 commit 09f67f8
Show file tree
Hide file tree
Showing 29 changed files with 948 additions and 1,078 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Checks: >
-bugprone-infinite-loop,
-bugprone-misplaced-widening-cast,
-bugprone-narrowing-conversions,
-bugprone-unused-return-value,
-bugprone-redundant-branch-condition,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
Expand Down
21 changes: 21 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2922,6 +2922,27 @@
{ "input_method": "keyboard", "key": "ESC" }
]
},
{
"type": "keybinding",
"id": "LOAD",
"category": "LOAD_DELETE_CANCEL",
"name": "Load",
"bindings": [ { "input_method": "keyboard", "key": "L" } ]
},
{
"type": "keybinding",
"id": "DELETE",
"category": "LOAD_DELETE_CANCEL",
"name": "Delete",
"bindings": [ { "input_method": "keyboard", "key": "D" } ]
},
{
"type": "keybinding",
"id": "CANCEL",
"category": "LOAD_DELETE_CANCEL",
"name": "Cancel",
"bindings": [ { "input_method": "keyboard", "key": "C" } ]
},
{
"type": "keybinding",
"id": "YES",
Expand Down
2 changes: 1 addition & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mission *avatar::get_active_mission() const
return active_mission;
}

void avatar::reset_all_misions()
void avatar::reset_all_missions()
{
active_mission = nullptr;
active_missions.clear();
Expand Down
13 changes: 12 additions & 1 deletion src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class avatar : public player
void randomize( bool random_scenario, points_left &points, bool play_now = false );
bool load_template( const std::string &template_name, points_left &points );
void save_template( const std::string &name, const points_left &points );
void character_to_template( const std::string &name );

bool is_avatar() const override {
return true;
Expand All @@ -84,6 +85,13 @@ class avatar : public player
return this;
}

std::string get_save_id() const {
return save_id.empty() ? name : save_id;
}
void set_save_id( const std::string &id ) {
save_id = id;
}

void toggle_map_memory();
bool should_show_map_memory();
void prepare_map_memory_region( const tripoint &p1, const tripoint &p2 );
Expand All @@ -103,7 +111,7 @@ class avatar : public player
/** Provides the window and detailed morale data */
void disp_morale();
/** Resets all missions before saving character to template */
void reset_all_misions();
void reset_all_missions();

std::vector<mission *> get_active_missions() const;
std::vector<mission *> get_completed_missions() const;
Expand Down Expand Up @@ -220,6 +228,9 @@ class avatar : public player
}

private:
// The name used to generate save filenames for this avatar. Not serialized in json.
std::string save_id;

std::unique_ptr<map_memory> player_map_memory;
bool show_map_memory = true;

Expand Down
102 changes: 102 additions & 0 deletions src/cata_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>

#include "debug.h"
#include "enum_conversions.h"
#include "filesystem.h"
#include "json.h"
#include "options.h"
Expand Down Expand Up @@ -670,3 +671,104 @@ void deserialize_wrapper( const std::function<void( JsonIn & )> &callback, const
JsonIn jsin( buffer );
callback( jsin );
}

/* compare against table of easter dates */
static bool is_easter( int day, int month, int year )
{
if( month == 3 ) {
switch( year ) {
// *INDENT-OFF*
case 2024: return day == 31;
case 2027: return day == 28;
default: break;
// *INDENT-ON*
}
} else if( month == 4 ) {
switch( year ) {
// *INDENT-OFF*
case 2021: return day == 4;
case 2022: return day == 17;
case 2023: return day == 9;
case 2025: return day == 20;
case 2026: return day == 5;
case 2028: return day == 16;
case 2029: return day == 1;
case 2030: return day == 21;
default: break;
// *INDENT-ON*
}
}
return false;
}

holiday get_holiday_from_time( std::time_t time, bool force_refresh )
{
static holiday cached_holiday = holiday::none;
static bool is_cached = false;

if( force_refresh ) {
is_cached = false;
}
if( is_cached ) {
return cached_holiday;
}

is_cached = true;

bool success = false;

std::tm local_time;
std::time_t current_time = time == 0 ? std::time( nullptr ) : time;

/* necessary to pass LGTM, as threadsafe version of localtime differs by platform */
#if defined(_WIN32)

errno_t err = localtime_s( &local_time, &current_time );
if( err == 0 ) {
success = true;
}

#else

success = !!localtime_r( &current_time, &local_time );

#endif

if( success ) {

const int month = local_time.tm_mon + 1;
const int day = local_time.tm_mday;
const int wday = local_time.tm_wday;
const int year = local_time.tm_year + 1900;

/* check date against holidays */
if( month == 1 && day == 1 ) {
cached_holiday = holiday::new_year;
return cached_holiday;
}
// only run easter date calculation if currently March or April
else if( ( month == 3 || month == 4 ) && is_easter( day, month, year ) ) {
cached_holiday = holiday::easter;
return cached_holiday;
} else if( month == 7 && day == 4 ) {
cached_holiday = holiday::independence_day;
return cached_holiday;
}
// 13 days seems appropriate for Halloween
else if( month == 10 && day >= 19 ) {
cached_holiday = holiday::halloween;
return cached_holiday;
} else if( month == 11 && ( day >= 22 && day <= 28 ) && wday == 4 ) {
cached_holiday = holiday::thanksgiving;
return cached_holiday;
}
// For the 12 days of Christmas, my true love gave to me...
else if( month == 12 && ( day >= 14 && day <= 25 ) ) {
cached_holiday = holiday::christmas;
return cached_holiday;
}
}
// fall through to here if localtime fails, or none of the day tests hit
cached_holiday = holiday::none;
return cached_holiday;
}
13 changes: 12 additions & 1 deletion src/cata_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
#ifndef CATA_SRC_CATA_UTILITY_H
#define CATA_SRC_CATA_UTILITY_H

#include <algorithm>
#include <cstddef>
#include <ctime>
#include <functional>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <memory>
#include <type_traits>

#include "enums.h"

/**
* Greater-than comparison operator; required by the sort interface
*/
Expand Down Expand Up @@ -285,4 +289,11 @@ class restore_on_out_of_scope
// *INDENT-ON*
};

/**
* Get the current holiday based on the given time, or based on current time if time = 0
* @param time The timestampt to assess
* @param force_refresh Force recalculation of current holiday, otherwise use cached value
*/
holiday get_holiday_from_time( std::time_t time = 0, bool force_refresh = false );

#endif // CATA_SRC_CATA_UTILITY_H
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ class Character : public Creature, public visitable<Character>
bool crossed_threshold() const;

// --------------- Values ---------------
std::string name;
std::string name; // Pre-cataclysm name, invariable
bool male = true;

std::list<item> worn;
Expand Down
27 changes: 21 additions & 6 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,24 +803,39 @@ void character_edit_menu( Character &c )
case edit_character::desc: {
uilist smenu;
smenu.text = _( "Select a value and press enter to change it." );
smenu.addentry( 0, true, 'n', "%s: %s", _( "Current name" ), p.get_name() );
smenu.addentry( 1, true, 'a', "%s: %d", _( "Current age" ), p.base_age() );
smenu.addentry( 2, true, 'h', "%s: %d", _( "Current height in cm" ), p.base_height() );
if( p.is_avatar() ) {
smenu.addentry( 0, true, 's', "%s: %s", _( "Current save file name" ), get_avatar().get_save_id() );
}
smenu.addentry( 1, true, 'n', "%s: %s", _( "Current pre-Cataclysm name" ), p.name );
smenu.addentry( 2, true, 'a', "%s: %d", _( "Current age" ), p.base_age() );
smenu.addentry( 3, true, 'h', "%s: %d", _( "Current height in cm" ), p.base_height() );
smenu.query();
switch( smenu.ret ) {
case 0: {
std::string buf = get_avatar().get_save_id();
string_input_popup popup;
popup
.title( _( "Rename save file (WARNING: this will duplicate the save):" ) )
.width( 85 )
.edit( buf );
if( popup.confirmed() ) {
get_avatar().set_save_id( buf );
}
}
break;
case 1: {
std::string buf = p.name;
string_input_popup popup;
popup
.title( _( "Rename:" ) )
.title( _( "Rename character:" ) )
.width( 85 )
.edit( buf );
if( popup.confirmed() ) {
p.name = buf;
}
}
break;
case 1: {
case 2: {
string_input_popup popup;
popup
.title( _( "Enter age in years. Minimum 16, maximum 55" ) )
Expand All @@ -832,7 +847,7 @@ void character_edit_menu( Character &c )
}
}
break;
case 2: {
case 3: {
string_input_popup popup;
popup
.title( _( "Enter height in centimeters. Minimum 145, maximum 200" ) )
Expand Down
12 changes: 6 additions & 6 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enum visibility_type {
};

// Matching rules for comparing a string to an overmap terrain id.
enum ot_match_type {
enum class ot_match_type {
// The provided string must completely match the overmap terrain id, including
// linear direction suffixes for linear terrain types or rotation suffixes
// for rotated terrain types.
Expand All @@ -89,11 +89,11 @@ struct enum_traits<ot_match_type> {
static constexpr ot_match_type last = ot_match_type::num_ot_match_type;
};

enum special_game_id : int {
SGAME_NULL = 0,
SGAME_TUTORIAL,
SGAME_DEFENSE,
NUM_SPECIAL_GAMES
enum class special_game_type : int {
NONE = 0,
TUTORIAL,
DEFENSE,
NUM_SPECIAL_GAME_TYPES
};

enum art_effect_passive : int {
Expand Down
Loading

0 comments on commit 09f67f8

Please sign in to comment.