The Battle for Wesnoth  1.17.12+dev
achievements.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2022
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 #include "config.hpp"
23 #include "tstring.hpp"
24 
25 /**
26  * Represents a single achievement and its data.
27  */
29 {
30  /** The ID of the achievement. Must be unique per achievement_group */
31  std::string id_;
32  /** The name of the achievement to show on the UI. */
34  /** The name of the achievement to show on the UI if the achievement is completed. */
36  /** The description of the achievement to show on the UI. */
38  /** The name of the achievement to show on the UI if the achievement is completed. */
40  /** The icon of the achievement to show on the UI. */
41  std::string icon_;
42  /** The icon of the achievement to show on the UI if the achievement is completed. */
43  std::string icon_completed_;
44  /** Whether to show the achievement's actual name and description on the UI before it's been completed. */
45  bool hidden_;
46  /** The hint to display in place of the description if the achievement is hidden and uncompleted */
48  /** The hint to display in place of the description if the achievement is hidden and uncompleted */
50  /** Whether the achievement has been completed. */
51  bool achieved_;
52  /** When the achievement's current progress matches or equals this value, then it should be marked as completed */
54  /** The current progress value of the achievement */
56 
57  achievement(const config& cfg, bool achieved, int progress)
58  : id_(cfg["id"].str())
59  , name_(cfg["name"].t_str())
60  , name_completed_(cfg["name_completed"].t_str())
61  , description_(cfg["description"].t_str())
62  , description_completed_(cfg["description_completed"].t_str())
63  , icon_(cfg["icon"].str()+"~GS()")
64  , icon_completed_(cfg["icon_completed"].str())
65  , hidden_(cfg["hidden"].to_bool())
66  , hidden_name_(cfg["hidden_name"].t_str())
67  , hidden_hint_(cfg["hidden_hint"].t_str())
68  , achieved_(achieved)
69  , max_progress_(cfg["max_progress"].to_int(0))
70  , current_progress_(progress)
71  {
72  if(name_completed_.empty()) {
73  name_completed_ = name_;
74  }
75  if(description_completed_.empty()) {
76  description_completed_ = description_;
77  }
78  if(icon_completed_.empty()) {
79  // avoid the ~GS() appended to icon_
80  icon_completed_ = cfg["icon"].str();
81  }
82  }
83 };
84 
85 /**
86  * A set of achievements tied to a particular content. Achievements can be added to any content from any add-on, even if it's entirely unrelated.
87  */
89 {
90  /** The name of the content to display on the UI. */
92  /** The internal ID used for this content. */
93  std::string content_for_;
94  /** The achievements associated to this content. */
95  std::vector<achievement> achievements_;
96 
97  achievement_group(const config& cfg);
98 };
99 
100 /**
101  * This class is responsible for reading all available achievements from mainline's and any add-ons' achievements.cfg files for use in achievements_dialog.
102  */
104 {
105 public:
106  achievements();
107  void reload();
108  std::vector<achievement_group>& get_list()
109  {
110  return achievement_list_;
111  }
112 
113 private:
114  config read_achievements_file(const std::string& path);
115  void process_achievements_file(const config& cfg, const std::string& content_source);
116 
117  std::vector<achievement_group> achievement_list_;
118 };
This class is responsible for reading all available achievements from mainline&#39;s and any add-ons&#39; ach...
t_string name_
The name of the achievement to show on the UI.
std::vector< achievement > achievements_
The achievements associated to this content.
bool achieved_
Whether the achievement has been completed.
std::string icon_
The icon of the achievement to show on the UI.
std::string content_for_
The internal ID used for this content.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string icon_completed_
The icon of the achievement to show on the UI if the achievement is completed.
int max_progress_
When the achievement&#39;s current progress matches or equals this value, then it should be marked as com...
achievement(const config &cfg, bool achieved, int progress)
t_string description_completed_
The name of the achievement to show on the UI if the achievement is completed.
t_string description_
The description of the achievement to show on the UI.
std::string path
Definition: game_config.cpp:39
int current_progress_
The current progress value of the achievement.
t_string hidden_hint_
The hint to display in place of the description if the achievement is hidden and uncompleted.
bool hidden_
Whether to show the achievement&#39;s actual name and description on the UI before it&#39;s been completed...
std::string id_
The ID of the achievement.
t_string display_name_
The name of the content to display on the UI.
std::vector< achievement_group > achievement_list_
t_string hidden_name_
The hint to display in place of the description if the achievement is hidden and uncompleted.
bool empty() const
Definition: tstring.hpp:187
Represents a single achievement and its data.
A set of achievements tied to a particular content.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
t_string name_completed_
The name of the achievement to show on the UI if the achievement is completed.
std::vector< achievement_group > & get_list()