The Battle for Wesnoth  1.19.0-dev
achievements.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 <string>
19 #include <vector>
20 
21 #include "config.hpp"
22 #include "tstring.hpp"
23 
24 /**
25  * Represents a distinct sub-achievement within another achievement.
26  * This is intentionally a much simpler object than the regular achievements.
27  */
29 {
30  /** The ID of the sub-achievement. Must be unique per achievement */
31  std::string id_;
32  /** The description of the sub-achievement to be shown in its tooltip */
34  /** The icon of the sub-achievement to show on the UI when not completed. */
35  std::string icon_;
36  /** The icon of the sub-achievement to show on the UI when completed. */
37  std::string icon_completed_;
38  /** Whether the sub-achievement has been completed. */
39  bool achieved_;
40 
41  sub_achievement(const config& cfg, bool achieved);
42 };
43 
44 /**
45  * Represents a single achievement and its data.
46  */
48 {
49  /** The ID of the achievement. Must be unique per achievement_group */
50  std::string id_;
51  /** The name of the achievement to show on the UI. */
53  /** The name of the achievement to show on the UI if the achievement is completed. */
55  /** The description of the achievement to show on the UI. */
57  /** The name of the achievement to show on the UI if the achievement is completed. */
59  /** The icon of the achievement to show on the UI. */
60  std::string icon_;
61  /** The icon of the achievement to show on the UI if the achievement is completed. */
62  std::string icon_completed_;
63  /** Whether to show the achievement's actual name and description on the UI before it's been completed. */
64  bool hidden_;
65  /** Whether the achievement has been completed. */
66  bool achieved_;
67  /** When the achievement's current progress matches or equals this value, then it should be marked as completed */
69  /** The current progress value of the achievement */
71  /** The path to a sound to play when an achievement is completed */
72  std::string sound_path_;
73  /** The list of distinct sub-achievements for this achievement */
74  std::vector<sub_achievement> sub_achievements_;
75 
76  achievement(const config& cfg, const std::string& content_for, bool achieved, int progress);
77 };
78 
79 /**
80  * 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.
81  */
83 {
84  /** The name of the content to display on the UI. */
86  /** The internal ID used for this content. */
87  std::string content_for_;
88  /** The achievements associated to this content. */
89  std::vector<achievement> achievements_;
90 
91  achievement_group(const config& cfg);
92 };
93 
94 /**
95  * This class is responsible for reading all available achievements from mainline's and any add-ons' achievements.cfg files for use in achievements_dialog.
96  */
98 {
99 public:
100  achievements();
101  void reload();
102  std::vector<achievement_group>& get_list()
103  {
104  return achievement_list_;
105  }
106 
107 private:
108  config read_achievements_file(const std::string& path);
109  void process_achievements_file(const config& cfg, const std::string& content_source);
110 
111  std::vector<achievement_group> achievement_list_;
112 };
This class is responsible for reading all available achievements from mainline's and any add-ons' ach...
void process_achievements_file(const config &cfg, const std::string &content_source)
Processes a config object to add new achievements to achievement_list_.
std::vector< achievement_group > achievement_list_
config read_achievements_file(const std::string &path)
Reads an achievements.cfg file into a config.
std::vector< achievement_group > & get_list()
void reload()
Reads the mainline achievements.cfg and then all the achievements of each installed add-on.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
std::string path
Definition: filesystem.cpp:84
A set of achievements tied to a particular content.
std::string content_for_
The internal ID used for this content.
std::vector< achievement > achievements_
The achievements associated to this content.
t_string display_name_
The name of the content to display on the UI.
achievement_group(const config &cfg)
Represents a single achievement and its data.
std::string icon_completed_
The icon of the achievement to show on the UI if the achievement is completed.
bool hidden_
Whether to show the achievement's actual name and description on the UI before it's been completed.
t_string name_completed_
The name of the achievement to show on the UI if the achievement is completed.
achievement(const config &cfg, const std::string &content_for, 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 name_
The name of the achievement to show on the UI.
bool achieved_
Whether the achievement has been completed.
std::string id_
The ID of the achievement.
int max_progress_
When the achievement's current progress matches or equals this value, then it should be marked as com...
std::string sound_path_
The path to a sound to play when an achievement is completed.
int current_progress_
The current progress value of the achievement.
t_string description_
The description of the achievement to show on the UI.
std::vector< sub_achievement > sub_achievements_
The list of distinct sub-achievements for this achievement.
std::string icon_
The icon of the achievement to show on the UI.
Represents a distinct sub-achievement within another achievement.
std::string id_
The ID of the sub-achievement.
t_string description_
The description of the sub-achievement to be shown in its tooltip.
std::string icon_completed_
The icon of the sub-achievement to show on the UI when completed.
std::string icon_
The icon of the sub-achievement to show on the UI when not completed.
sub_achievement(const config &cfg, bool achieved)
bool achieved_
Whether the sub-achievement has been completed.