forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_note.h
163 lines (121 loc) · 5.32 KB
/
auto_note.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#pragma once
#ifndef CATA_SRC_AUTO_NOTE_H
#define CATA_SRC_AUTO_NOTE_H
#include <iosfwd>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "map_extras.h"
#include "string_id.h"
namespace auto_notes
{
class custom_symbol
{
private:
cata::optional<uint32_t> symbol;
cata::optional<nc_color> color;
public:
std::string get_symbol_string() const {
return symbol ? utf32_to_utf8( *symbol ) : "";
};
std::string get_color_string() const {
return color ? get_all_colors().get_name( *color ) : "";
};
uint32_t get_symbol() const {
return symbol ? *symbol : UTF8_getch( "N" );
};
nc_color get_color() const {
return color ? *color : c_yellow;
};
void set_symbol( const std::string &str ) {
if( !str.empty() ) {
symbol = UTF8_getch( str );
} else {
symbol.reset();
}
};
void set_color( const std::string &col ) {
if( !col.empty() ) {
color = get_all_colors().name_to_color( col );
} else {
color.reset();
}
};
};
/**
* Class implementing the user interface for the auto note configuration.
*/
class auto_note_manager_gui
{
public:
auto_note_manager_gui();
void show();
bool was_changed( bool bCharacter ) const;
void set_cached_custom_symbol( const map_extra_id &mapExtId, const custom_symbol &symbol,
bool bCharacter );
private:
/// The map extra type cache. This is initialized with all known map extra types
/// and their auto note status with every call of initialize(). All changes to this
/// will be applied to the per-character or global auto notes settings object after the user
/// closes the GUI.
std::unordered_map<map_extra_id, std::pair<const map_extra, bool>> char_mapExtraCache;
std::unordered_map<map_extra_id, std::pair<const map_extra, bool>> global_mapExtraCache;
/// All map extra types for the character that will be displayed in the GUI.
std::vector<map_extra_id> char_displayCache;
/// All map extra types for global types that will be displayed in the GUI.
std::vector<map_extra_id> global_displayCache;
std::unordered_map<map_extra_id, custom_symbol> char_custom_symbol_cache;
std::unordered_map<map_extra_id, custom_symbol> global_custom_symbol_cache;
void fill_custom_symbols_cache();
bool charwasChanged{false};
bool globalwasChanged{false};
};
/**
* A class storing auto note settings for all map features for a given player.
* Since auto note is something that is very dependent on in which stage of the game
* a player is (f.e., dead college kids are useful in the early game, but not so much
* in the late game), the settings are only available tied to a specific game save, meaning
* there is no global setting like with the auto-pickup manager.
*/
class auto_note_settings
{
// Allow private member access to the auto note manager GUI
friend class auto_note_manager_gui;
public:
bool has_auto_note_enabled( const map_extra_id &mapExtId, bool bCharacter ) const;
void set_auto_note_status( const map_extra_id &mapExtId, bool enabled, bool bCharacter );
void set_discovered( const map_extra_id &mapExtId );
bool was_discovered( const map_extra_id &mapExtId ) const;
public:
cata::optional<custom_symbol> get_custom_symbol( const map_extra_id &mapExtId ) const;
void set_custom_symbol( const map_extra_id &mapExtId, const custom_symbol &symbol,
bool bCharacter );
void clear_all_custom_symbols( bool bCharacter );
public:
void load( bool bCharacter );
bool save( bool bCharacter );
void clear();
void show_gui();
/// Perform default initialization. This will use the auto note property of
/// registered map extras in order to determine their enable status.
void default_initialize();
private:
/// Build string containing path to the auto notes save file for the active player.
std::string build_save_path() const;
private:
/// This set contains the ID strings of all map extras that have auto note enabled for a character.
std::unordered_set<map_extra_id> character_autoNoteEnabled;
/// This set contains the ID strings of all map extras that have auto note disabled globally.
std::unordered_set<map_extra_id> global_autoNoteDisabled;
/// This set contains the ID strings of all map extras that were already encountered by the player.
/// This is used in order to avoid spoilers in the GUI.
std::unordered_set<map_extra_id> discovered;
/// User-defined symbols and colors for the auto notes for this character.
std::unordered_map<map_extra_id, custom_symbol> character_custom_symbols;
/// User-defined symbols and colors for the auto notes globably.
std::unordered_map<map_extra_id, custom_symbol> global_custom_symbols;
};
} // namespace auto_notes
auto_notes::auto_note_settings &get_auto_notes_settings();
#endif // CATA_SRC_AUTO_NOTE_H