1 // Copyright (C) 2017, 2020 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 //  02110-1301, USA.
17 
18 #pragma once
19 #ifndef SCENARIO_MEDIA_H
20 #define SCENARIO_MEDIA_H
21 
22 #include <gtkmm.h>
23 #include <vector>
24 #include "PixMask.h"
25 #include "tarhelper.h"
26 #include "snd.h"
27 
28 class XML_Helper;
29 class TarFile;
30 
31 //! Scenario Media provides images/sounds/music for the scenario
32 /**
33  *
34  * Usually we use the default images, but ScenarioMedia lets us override
35  * those defaults.
36  *
37  * It lives in the savefile at lordsawar/media.
38  */
39 
40 class ScenarioMedia
41 {
42     public:
43 
44 	//! The xml tag of this object in a saved-game file.
45 	static Glib::ustring d_tag;
46 
47         //! Returns the singleton instance.
48 	static ScenarioMedia* getInstance();
49 
50         //! Returns the singleton instance by loading it from a save-file.
51 	static ScenarioMedia* getInstance(XML_Helper *helper);
52 
53         //! Explicitly deletes the singleton instance.
54         static void deleteInstance();
55 
56 
57         //Get methods
58 
getNextTurnImageName()59         Glib::ustring getNextTurnImageName() {return d_next_turn_name;}
getCityDefeatedImageName()60         Glib::ustring getCityDefeatedImageName() {return d_city_defeated_name;}
getWinningImageName()61         Glib::ustring getWinningImageName() {return d_winning_name;}
getMaleHeroImageName()62         Glib::ustring getMaleHeroImageName() {return d_male_hero_name;}
getFemaleHeroImageName()63         Glib::ustring getFemaleHeroImageName() {return d_female_hero_name;}
getRuinSuccessImageName()64         Glib::ustring getRuinSuccessImageName() {return d_ruin_success_name;}
getRuinDefeatImageName()65         Glib::ustring getRuinDefeatImageName() {return d_ruin_defeat_name;}
getParleyOfferedImageName()66         Glib::ustring getParleyOfferedImageName() {return d_parley_offered_name;}
getParleyRefusedImageName()67         Glib::ustring getParleyRefusedImageName() {return d_parley_refused_name;}
getHeroNewLevelMaleImageName()68         Glib::ustring getHeroNewLevelMaleImageName() {return d_hero_newlevel_male_name;}
getHeroNewLevelFemaleImageName()69         Glib::ustring getHeroNewLevelFemaleImageName() {return d_hero_newlevel_female_name;}
getSmallMedalsImageName()70         Glib::ustring getSmallMedalsImageName() {return d_small_medals_name;}
getBigMedalsImageName()71         Glib::ustring getBigMedalsImageName() {return d_big_medals_name;}
getCommentatorImageName()72         Glib::ustring getCommentatorImageName() {return d_commentator_name;}
getBlessSoundName()73         Glib::ustring getBlessSoundName() {return d_bless_name;}
getHeroSoundName()74         Glib::ustring getHeroSoundName() {return d_hero_name;}
getBattleSoundName()75         Glib::ustring getBattleSoundName() {return d_battle_name;}
getDefeatSoundName()76         Glib::ustring getDefeatSoundName() {return d_defeat_name;}
getVictorySoundName()77         Glib::ustring getVictorySoundName() {return d_victory_name;}
getBackSoundName()78         Glib::ustring getBackSoundName() {return d_back_name;}
79 
getNextTurnImage()80         PixMask *getNextTurnImage() {return d_next_turn_image;}
getCityDefeatedImage()81         PixMask *getCityDefeatedImage() {return d_city_defeated_image;}
getWinningImage()82         PixMask *getWinningImage() {return d_winning_image;}
getMaleHeroImage()83         PixMask *getMaleHeroImage() {return d_male_hero_image;}
getFemaleHeroImage()84         PixMask *getFemaleHeroImage() {return d_female_hero_image;}
getRuinSuccessImage()85         PixMask *getRuinSuccessImage() {return d_ruin_success_image;}
getRuinDefeatImage()86         PixMask *getRuinDefeatImage() {return d_ruin_defeat_image;}
getParleyOfferedImage()87         PixMask *getParleyOfferedImage() {return d_parley_offered_image;}
getParleyRefusedImage()88         PixMask *getParleyRefusedImage() {return d_parley_refused_image;}
getHeroNewLevelMaleImage()89         PixMask *getHeroNewLevelMaleImage() {return d_hero_newlevel_male_image;}
getHeroNewLevelMaleMask()90         PixMask *getHeroNewLevelMaleMask() {return d_hero_newlevel_male_mask;}
getHeroNewLevelFemaleImage()91         PixMask *getHeroNewLevelFemaleImage() {return d_hero_newlevel_female_image;}
getHeroNewLevelFemaleMask()92         PixMask *getHeroNewLevelFemaleMask() {return d_hero_newlevel_female_mask;}
getSmallMedalImage(guint32 i)93         PixMask *getSmallMedalImage(guint32 i)
94           {return d_small_medal_images.size () > i ? d_small_medal_images[i] : NULL;}
getBigMedalImage(guint32 i)95         PixMask *getBigMedalImage(guint32 i)
96           {return d_big_medal_images.size () > i ? d_big_medal_images[i] : NULL;}
getCommentatorImage()97         PixMask *getCommentatorImage() {return d_commentator_image;}
98 
99         void clearNextTurnImage(bool clear_name = true);
100         void clearCityDefeatedImage(bool clear_name = true);
101         void clearWinningImage(bool clear_name = true);
102         void clearMaleHeroImage(bool clear_name = true);
103         void clearFemaleHeroImage(bool clear_name = true);
104         void clearRuinSuccessImage(bool clear_name = true);
105         void clearRuinDefeatImage(bool clear_name = true);
106         void clearParleyOfferedImage(bool clear_name = true);
107         void clearParleyRefusedImage(bool clear_name = true);
108         void clearSmallMedalImage(bool clear_name = true);
109         void clearBigMedalImage(bool clear_name = true);
110         void clearHeroNewLevelMaleImage (bool clear_name = true);
111         void clearHeroNewLevelFemaleImage (bool clear_name = true);
112         void clearCommentatorImage (bool clear_name = true);
113 
114         bool instantiateNextTurnImage(TarFile *t);
115         bool instantiateCityDefeatedImage(TarFile *t);
116         bool instantiateWinningImage(TarFile *t);
117         bool instantiateMaleHeroImage(TarFile *t);
118         bool instantiateFemaleHeroImage(TarFile *t);
119         bool instantiateRuinSuccessImage(TarFile *t);
120         bool instantiateRuinDefeatImage(TarFile *t);
121         bool instantiateParleyOfferedImage(TarFile *t);
122         bool instantiateParleyRefusedImage(TarFile *t);
123         bool instantiateSmallMedalImage(TarFile *t);
124         bool instantiateBigMedalImage(TarFile *t);
125         bool instantiateHeroNewLevelMaleImage (TarFile *t);
126         bool instantiateHeroNewLevelFemaleImage (TarFile *t);
127         bool instantiateCommentatorImage (TarFile *t);
128 
129         MusicItem* getSoundEffect(Glib::ustring n);
getBackgroundMusic()130         std::vector<Glib::ustring> getBackgroundMusic() const {return d_bgMap;}
getSounds()131         std::map<Glib::ustring, MusicItem*> getSounds() const {return d_musicMap;}
132         //Set methods
133 
setNextTurnImageName(Glib::ustring n)134         void setNextTurnImageName(Glib::ustring n) {d_next_turn_name = n;}
setCityDefeatedImageName(Glib::ustring n)135         void setCityDefeatedImageName(Glib::ustring n) {d_city_defeated_name=n;}
setWinningImageName(Glib::ustring n)136         void setWinningImageName(Glib::ustring n) {d_winning_name = n;}
setMaleHeroImageName(Glib::ustring n)137         void setMaleHeroImageName(Glib::ustring n) {d_male_hero_name = n;}
setFemaleHeroImageName(Glib::ustring n)138         void setFemaleHeroImageName(Glib::ustring n) {d_female_hero_name = n;}
setRuinSuccessImageName(Glib::ustring n)139         void setRuinSuccessImageName(Glib::ustring n) {d_ruin_success_name = n;}
setRuinDefeatImageName(Glib::ustring n)140         void setRuinDefeatImageName(Glib::ustring n) {d_ruin_defeat_name = n;}
setParleyOfferedImageName(Glib::ustring n)141         void setParleyOfferedImageName(Glib::ustring n) {d_parley_offered_name = n;}
setParleyRefusedImageName(Glib::ustring n)142         void setParleyRefusedImageName(Glib::ustring n) {d_parley_refused_name = n;}
setHeroNewLevelMaleImageName(Glib::ustring n)143         void setHeroNewLevelMaleImageName(Glib::ustring n) {d_hero_newlevel_male_name = n;}
setHeroNewLevelFemaleImageName(Glib::ustring n)144         void setHeroNewLevelFemaleImageName(Glib::ustring n) {d_hero_newlevel_female_name = n;}
setSmallMedalsImageName(Glib::ustring n)145         void setSmallMedalsImageName(Glib::ustring n) {d_small_medals_name = n;}
setBigMedalsImageName(Glib::ustring n)146         void setBigMedalsImageName(Glib::ustring n) {d_big_medals_name = n;}
setCommentatorImageName(Glib::ustring n)147         void setCommentatorImageName(Glib::ustring n) {d_commentator_name = n;}
148 
setNextTurnImage(PixMask * i)149         void setNextTurnImage(PixMask *i) {d_next_turn_image = i;}
setCityDefeatedImage(PixMask * i)150         void setCityDefeatedImage(PixMask *i) {d_city_defeated_image = i;}
setWinningImage(PixMask * i)151         void setWinningImage(PixMask *i) {d_winning_image = i;}
setMaleHeroImage(PixMask * i)152         void setMaleHeroImage(PixMask *i) {d_male_hero_image = i;}
setFemaleHeroImage(PixMask * i)153         void setFemaleHeroImage(PixMask *i) {d_female_hero_image = i;}
setRuinSuccessImage(PixMask * i)154         void setRuinSuccessImage(PixMask *i) {d_ruin_success_image = i;}
setRuinDefeatImage(PixMask * i)155         void setRuinDefeatImage(PixMask *i) {d_ruin_defeat_image = i;}
setParleyOfferedImage(PixMask * i)156         void setParleyOfferedImage(PixMask *i) {d_parley_offered_image = i;}
setParleyRefusedImage(PixMask * i)157         void setParleyRefusedImage(PixMask *i) {d_parley_refused_image = i;}
setHeroNewLevelMaleImage(PixMask * i)158         void setHeroNewLevelMaleImage(PixMask *i)
159           {d_hero_newlevel_male_image=i;}
setHeroNewLevelMaleMask(PixMask * m)160         void setHeroNewLevelMaleMask(PixMask *m) {d_hero_newlevel_male_mask=m;}
setHeroNewLevelFemaleImage(PixMask * i)161         void setHeroNewLevelFemaleImage(PixMask *i)
162           {d_hero_newlevel_female_image=i;}
setHeroNewLevelFemaleMask(PixMask * m)163         void setHeroNewLevelFemaleMask(PixMask *m)
164           {d_hero_newlevel_female_mask=m;}
setSmallMedalsImage(guint32 n,PixMask * i)165         void setSmallMedalsImage(guint32 n, PixMask *i)
166           { if (n < d_small_medal_images.size ()) d_small_medal_images[n] = i;}
setBigMedalsImage(guint32 n,PixMask * i)167         void setBigMedalsImage(guint32 n, PixMask *i)
168           {if (n < d_big_medal_images.size ()) d_big_medal_images[n] = i;}
setCommentatorImage(PixMask * i)169         void setCommentatorImage (PixMask *i) {d_commentator_image = i;}
170 
setBlessSoundName(Glib::ustring n)171         void setBlessSoundName(Glib::ustring n) {d_bless_name = n;}
setHeroSoundName(Glib::ustring n)172         void setHeroSoundName(Glib::ustring n) {d_hero_name = n;}
setBattleSoundName(Glib::ustring n)173         void setBattleSoundName(Glib::ustring n) {d_battle_name = n;}
setDefeatSoundName(Glib::ustring n)174         void setDefeatSoundName(Glib::ustring n) {d_defeat_name = n;}
setVictorySoundName(Glib::ustring n)175         void setVictorySoundName(Glib::ustring n) {d_victory_name = n;}
setBackSoundName(Glib::ustring n)176         void setBackSoundName(Glib::ustring n) {d_back_name = n;}
177 
178 	// Methods that operate on class data and modify the class.
179 
180         void instantiateImages(Tar_Helper &t, bool &broken);
181         void copySounds(Tar_Helper &t, bool &broken);
182 
183 	// Methods that operate on class data and do not modify the class.
184 
185         //! Saves the scenario-media data to an opened saved-game file.
186         bool save(XML_Helper* helper) const;
187 
188 	void getFilenames(std::list<Glib::ustring> &files);
189 
190 	// Static Methods
191 
192         static Glib::ustring getDefaultNextTurnImageFilename();
193         static Glib::ustring getDefaultCityDefeatedImageFilename();
194         static Glib::ustring getDefaultWinningImageFilename();
195         static Glib::ustring getDefaultMaleHeroImageFilename();
196         static Glib::ustring getDefaultFemaleHeroImageFilename();
197         static Glib::ustring getDefaultRuinSuccessImageFilename();
198         static Glib::ustring getDefaultRuinDefeatImageFilename();
199         static Glib::ustring getDefaultParleyOfferedImageFilename();
200         static Glib::ustring getDefaultParleyRefusedImageFilename();
201         static Glib::ustring getDefaultHeroNewLevelMaleImageFilename();
202         static Glib::ustring getDefaultHeroNewLevelFemaleImageFilename();
203         static Glib::ustring getDefaultSmallMedalsImageFilename();
204         static Glib::ustring getDefaultBigMedalsImageFilename();
205         static Glib::ustring getDefaultCommentatorImageFilename();
206         static Glib::ustring getDefaultBlessSoundFilename();
207         static Glib::ustring getDefaultHeroSoundFilename();
208         static Glib::ustring getDefaultBattleSoundFilename();
209         static Glib::ustring getDefaultDefeatSoundFilename();
210         static Glib::ustring getDefaultVictorySoundFilename();
211         static Glib::ustring getDefaultBackSoundFilename();
212     protected:
213 
214 	//! Creates a new ScenarioMedia object from scratch.
215         ScenarioMedia();
216 
217 	//! Creates a new ScenarioMedia object from an opened save-file.
218         ScenarioMedia(XML_Helper *helper);
219 
220         //! Destructor.
221         ~ScenarioMedia();
222 
223     private:
224 
225         //data
226         static ScenarioMedia* d_instance;
227         Glib::ustring d_next_turn_name;
228         Glib::ustring d_city_defeated_name;
229         Glib::ustring d_winning_name;
230         Glib::ustring d_male_hero_name;
231         Glib::ustring d_female_hero_name;
232         Glib::ustring d_ruin_success_name;
233         Glib::ustring d_ruin_defeat_name;
234         Glib::ustring d_parley_offered_name;
235         Glib::ustring d_parley_refused_name;
236         Glib::ustring d_hero_newlevel_male_name;
237         Glib::ustring d_hero_newlevel_female_name;
238         Glib::ustring d_small_medals_name;
239         Glib::ustring d_big_medals_name;
240         Glib::ustring d_commentator_name;
241         Glib::ustring d_bless_name;
242         Glib::ustring d_hero_name;
243         Glib::ustring d_battle_name;
244         Glib::ustring d_defeat_name;
245         Glib::ustring d_victory_name;
246         Glib::ustring d_back_name;
247 
248         std::map<Glib::ustring, MusicItem*> d_musicMap;
249         std::vector<Glib::ustring> d_bgMap;
250 
251         PixMask *d_next_turn_image;
252         PixMask *d_city_defeated_image;
253         PixMask *d_winning_image;
254         PixMask *d_male_hero_image;
255         PixMask *d_female_hero_image;
256         PixMask *d_ruin_success_image;
257         PixMask *d_ruin_defeat_image;
258         PixMask *d_parley_offered_image;
259         PixMask *d_parley_refused_image;
260         PixMask *d_hero_newlevel_male_image;
261         PixMask *d_hero_newlevel_male_mask;
262         PixMask *d_hero_newlevel_female_image;
263         PixMask *d_hero_newlevel_female_mask;
264         std::vector<PixMask *> d_small_medal_images;
265         std::vector<PixMask *> d_big_medal_images;
266         PixMask *d_commentator_image;
267 
268         //helpers
269         void instantiateMaskedImage(Tar_Helper &t, Glib::ustring name, PixMask **image, PixMask **mask, bool &broken);
270         void instantiateImage(Tar_Helper &t, Glib::ustring name, PixMask **image, bool &broken);
271         void instantiateImageRow(Tar_Helper &t, Glib::ustring name, int num, std::vector<PixMask *>&images, bool &broken);
272         void uninstantiateImages();
273         bool anyValueSet() const;
274         void copySound(Tar_Helper &t, Glib::ustring name, Glib::ustring piece, bool &broken);
275 };
276 
277 #endif //SCENARIO_MEDIA_H
278