1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "common/gui_options.h"
24 
25 #include "common/config-manager.h"
26 #include "common/str.h"
27 
28 namespace Common {
29 
30 const struct GameOpt {
31 	const char *option;
32 	// Each description must be a unique identifier not containing a substring
33 	// of any other description
34 	const char *desc;
35 } g_gameOptions[] = {
36 	{ GUIO_NOSUBTITLES,  "sndNoSubs" },
37 	{ GUIO_NOMUSIC,      "sndNoMusic" },
38 	{ GUIO_NOSPEECH,     "sndNoSpeech" },
39 	{ GUIO_NOSFX,        "sndNoSFX" },
40 	{ GUIO_NOMIDI,       "sndNoMIDI" },
41 	{ GUIO_LINKSPEECHTOSFX, "sndLinkSpeechToSfx" },
42 	{ GUIO_LINKMUSICTOSFX,  "sndLinkMusicToSfx" },
43 	{ GUIO_NOSPEECHVOLUME,  "sndNoSpchVolume" },
44 
45 	{ GUIO_NOLANG,        "noLang"},
46 
47 	{ GUIO_NOLAUNCHLOAD, "launchNoLoad" },
48 
49 	{ GUIO_MIDIPCSPK,    "midiPCSpk" },
50 	{ GUIO_MIDICMS,      "midiCMS" },
51 	{ GUIO_MIDIPCJR,     "midiPCJr" },
52 	{ GUIO_MIDIADLIB,    "midiAdLib" },
53 	{ GUIO_MIDIC64,      "midiC64" },
54 	{ GUIO_MIDIAMIGA,    "midiAmiga" },
55 	{ GUIO_MIDIAPPLEIIGS,"midiAppleIIgs" },
56 	{ GUIO_MIDITOWNS,    "midiTowns" },
57 	{ GUIO_MIDIPC98,     "midiPC98" },
58 	{ GUIO_MIDISEGACD,   "midiSegaCD" },
59 	{ GUIO_MIDIMT32,     "midiMt32" },
60 	{ GUIO_MIDIGM,       "midiGM" },
61 
62 	{ GUIO_NOASPECT,     "noAspect" },
63 
64 	{ GUIO_RENDERHERCGREEN, "hercGreen" },
65 	{ GUIO_RENDERHERCAMBER, "hercAmber" },
66 	{ GUIO_RENDERCGA,       "cga" },
67 	{ GUIO_RENDEREGA,       "ega" },
68 	{ GUIO_RENDERVGA,       "vga" },
69 	{ GUIO_RENDERAMIGA,     "amiga" },
70 	{ GUIO_RENDERFMTOWNS,   "fmtowns" },
71 	{ GUIO_RENDERPC9821,    "pc9821" },
72 	{ GUIO_RENDERPC9801,    "pc9801" },
73 	{ GUIO_RENDERAPPLE2GS,  "2gs" },
74 	{ GUIO_RENDERATARIST,   "atari" },
75 	{ GUIO_RENDERMACINTOSH, "macintosh" },
76 
77 	{ GUIO_GAMEOPTIONS1, "gameOption1" },
78 	{ GUIO_GAMEOPTIONS2, "gameOption2" },
79 	{ GUIO_GAMEOPTIONS3, "gameOption3" },
80 	{ GUIO_GAMEOPTIONS4, "gameOption4" },
81 	{ GUIO_GAMEOPTIONS5, "gameOption5" },
82 	{ GUIO_GAMEOPTIONS6, "gameOption6" },
83 	{ GUIO_GAMEOPTIONS7, "gameOption7" },
84 	{ GUIO_GAMEOPTIONS8, "gameOption8" },
85 	{ GUIO_GAMEOPTIONS9, "gameOption9" },
86 	// Option strings must not contain substrings of any other options, so
87 	// "gameOption10" would be invalid here because it contains "gameOption1"
88 	{ GUIO_GAMEOPTIONS10, "gameOptionA" },
89 	{ GUIO_GAMEOPTIONS11, "gameOptionB" },
90 	{ GUIO_GAMEOPTIONS12, "gameOptionC" },
91 	{ GUIO_GAMEOPTIONS13, "gameOptionD" },
92 	{ GUIO_GAMEOPTIONS14, "gameOptionE" },
93 	{ GUIO_GAMEOPTIONS15, "gameOptionF" },
94 	{ GUIO_GAMEOPTIONS16, "gameOptionG" },
95 
96 	{ GUIO_NONE, nullptr }
97 };
98 
checkGameGUIOption(const String & option,const String & str)99 bool checkGameGUIOption(const String &option, const String &str) {
100 	for (int i = 0; g_gameOptions[i].desc; i++) {
101 		if (option.contains(g_gameOptions[i].option)) {
102 			if (str.contains(g_gameOptions[i].desc))
103 				return true;
104 			else
105 				return false;
106 		}
107 	}
108 	return false;
109 }
110 
parseGameGUIOptions(const String & str)111 String parseGameGUIOptions(const String &str) {
112 	String res;
113 
114 	for (int i = 0; g_gameOptions[i].desc; i++)
115 		if (str.contains(g_gameOptions[i].desc))
116 			res += g_gameOptions[i].option;
117 
118 	return res;
119 }
120 
getGameGUIOptionsDescription(const String & options)121 const String getGameGUIOptionsDescription(const String &options) {
122 	String res;
123 
124 	for (int i = 0; g_gameOptions[i].desc; i++)
125 		if (options.contains(g_gameOptions[i].option[0]))
126 			res += String(g_gameOptions[i].desc) + " ";
127 
128 	res.trim();
129 
130 	return res;
131 }
132 
updateGameGUIOptions(const String & options,const String & langOption)133 void updateGameGUIOptions(const String &options, const String &langOption) {
134 	const String newOptionString = getGameGUIOptionsDescription(options) + " " + langOption;
135 	ConfMan.setAndFlush("guioptions", newOptionString);
136 }
137 
138 
139 } // End of namespace Common
140