aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/wii/options.cpp
blob: 2a47958e3bc54ea3aa2faf7ab323fc1627576106 (plain)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include <errno.h>
#include <network.h>
#include <gxflux/gfx.h>

#include "common/config-manager.h"
#include "gui/dialog.h"
#include "backends/fs/wii/wii-fs-factory.h"

#include "common/translation.h"

#include "options.h"

WiiOptionsDialog::WiiOptionsDialog(bool doubleStrike) :
	Dialog((640 - 400) / 2, (480 - 340) / 2, 400, 340),
	_doubleStrike(doubleStrike) {

	if (_doubleStrike) {
		_strUnderscanX = "wii_video_ds_underscan_x";
		_strUnderscanY = "wii_video_ds_underscan_y";
	} else {
		_strUnderscanX = "wii_video_default_underscan_x";
		_strUnderscanY = "wii_video_default_underscan_y";
	}

	new ButtonWidget(this, _w - 108 - 16, _h - 24 - 16, 108, 24, _("OK"), 0, 'k');
	new ButtonWidget(this, _w - 216 - 32, _h - 24 - 16, 108, 24, _("Cancel"), 0, 'c');
	_tab = new TabWidget(this, 0, 0, _w, _h - 54);

	_tabVideo = _tab->addTab(_("Video"));

	new StaticTextWidget(_tab, 16, 16, 128, 16,
						 _("Current video mode:"), Graphics::kTextAlignRight);
	new StaticTextWidget(_tab, 160, 16, 128, 16,
						 _doubleStrike ? _("Double-strike") : _("Default"),
							Graphics::kTextAlignLeft);

	new StaticTextWidget(_tab, 16, 48, 128, 16,
						 _("Horizontal underscan:"), Graphics::kTextAlignRight);
	_sliderUnderscanX = new SliderWidget(_tab, 160, 47, 128, 18, 0, 'x');
	_sliderUnderscanX->setMinValue(0);
	_sliderUnderscanX->setMaxValue(32);

	new StaticTextWidget(_tab, 16, 80, 128, 16,
						 _("Vertical underscan:"), Graphics::kTextAlignRight);
	_sliderUnderscanY = new SliderWidget(_tab, 160, 79, 128, 18, 0, 'y');
	_sliderUnderscanY->setMinValue(0);
	_sliderUnderscanY->setMaxValue(32);

	_tabInput = _tab->addTab(_("Input"));

	new StaticTextWidget(_tab, 16, 16, 128, 16,
						 _("GC Pad sensitivity:"), Graphics::kTextAlignRight);
	_sliderPadSensitivity = new SliderWidget(_tab, 160, 15, 128, 18, 0, 'x');
	_sliderPadSensitivity->setMinValue(0);
	_sliderPadSensitivity->setMaxValue(64);

	new StaticTextWidget(_tab, 16, 44, 128, 16,
						 _("GC Pad acceleration:"), Graphics::kTextAlignRight);
	_sliderPadAcceleration = new SliderWidget(_tab, 160, 43, 128, 18, 0, 'y');
	_sliderPadAcceleration->setMinValue(0);
	_sliderPadAcceleration->setMaxValue(8);

#ifdef USE_WII_DI
	_tabDVD = _tab->addTab(_("DVD"));

	new StaticTextWidget(_tab, 16, 16, 64, 16,
						 _("Status:"), Graphics::kTextAlignRight);
	_textDVDStatus = new StaticTextWidget(_tab, 96, 16, 272, 16, _("Unknown"),
											Graphics::kTextAlignLeft);

	new ButtonWidget(_tab, 16, 48, 108, 24, _("Mount DVD"), 0, 'mdvd');
	new ButtonWidget(_tab, 140, 48, 108, 24, _("Unmount DVD"), 0, 'udvd');
#endif

#ifdef USE_WII_SMB
	_tabSMB = _tab->addTab(_("SMB"));

	new StaticTextWidget(_tab, 16, 16, 64, 16,
						 _("Status:"), Graphics::kTextAlignRight);
	_textSMBStatus = new StaticTextWidget(_tab, 96, 16, 272, 16, _("Unknown"),
											Graphics::kTextAlignLeft);

	new StaticTextWidget(_tab, 16, 52, 64, 16,
						 _("Server:"), Graphics::kTextAlignRight);
	_editSMBServer = new EditTextWidget(_tab, 96, 48, _w - 96 - 32, 24, "");

	new StaticTextWidget(_tab, 16, 92, 64, 16,
						 _("Share:"), Graphics::kTextAlignRight);
	_editSMBShare = new EditTextWidget(_tab, 96, 88, _w - 96 - 32, 24, "");

	new StaticTextWidget(_tab, 16, 132, 64, 16,
						 _("Username:"), Graphics::kTextAlignRight);
	_editSMBUsername = new EditTextWidget(_tab, 96, 128, _w - 96 - 32, 24, "");

	new StaticTextWidget(_tab, 16, 172, 64, 16,
						 _("Password:"), Graphics::kTextAlignRight);
	_editSMBPassword = new EditTextWidget(_tab, 96, 168, _w - 96 - 32, 24, "");

	new ButtonWidget(_tab, 16, 208, 108, 24, _("Init network"), 0, 'net');

	new ButtonWidget(_tab, 140, 208, 108, 24, _("Mount SMB"), 0, 'msmb');
	new ButtonWidget(_tab, 264, 208, 108, 24, _("Unmount SMB"), 0, 'usmb');
#endif

	_tab->setActiveTab(_tabVideo);

	load();
}

WiiOptionsDialog::~WiiOptionsDialog() {
}

void WiiOptionsDialog::handleTickle() {
	WiiFilesystemFactory &fsf = WiiFilesystemFactory::instance();

	int tab = _tab->getActiveTab();

#ifdef USE_WII_DI
	if (tab == _tabDVD) {
		if (fsf.isMounted(WiiFilesystemFactory::kDVD)) {
			_textDVDStatus->setLabel(_("DVD Mounted successfully"));
		} else {
			if (fsf.failedToMount(WiiFilesystemFactory::kDVD))
				_textDVDStatus->setLabel(_("Error while mounting the DVD"));
			else
				_textDVDStatus->setLabel(_("DVD not mounted"));
		}
	}
#endif

#ifdef USE_WII_SMB
	if (tab == _tabSMB) {
		s32 status = net_get_status();
		String label;

		switch (status) {
		case 0:
			if (fsf.isMounted(WiiFilesystemFactory::kSMB)) {
				label = _("Network up, share mounted");
			} else {
				label = _("Network up");

				if (fsf.failedToMount(WiiFilesystemFactory::kSMB))
					label += _(", error while mounting the share");
				else
					label += _(", share not mounted");
			}

			break;

		case -ENETDOWN:
			label = _("Network down");
			break;

		case -EBUSY:
			label = _("Initialising network");
			break;

		case -ETIMEDOUT:
			label = _("Timeout while initialising network");
			break;

		default:
			label = String::printf(_("Network not initialised (%d)"), status);
			break;
		}

		_textSMBStatus->setLabel(label);
	}
#endif

	Dialog::handleTickle();
}

void WiiOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd,
										uint32 data) {
	WiiFilesystemFactory &fsf = WiiFilesystemFactory::instance();

	switch (cmd) {
	case 'x':
	case 'y':
		gfx_set_underscan(_sliderUnderscanX->getValue(),
							_sliderUnderscanY->getValue());
		break;

	case 'k':
		save();
		close();
		break;

	case 'c':
		revert();
		close();
		break;

#ifdef USE_WII_DI
	case 'mdvd':
		fsf.mount(WiiFilesystemFactory::kDVD);
		break;

	case 'udvd':
		fsf.umount(WiiFilesystemFactory::kDVD);
		break;
#endif

#ifdef USE_WII_SMB
	case 'net':
		fsf.asyncInitNetwork();
		break;

	case 'msmb':
		fsf.setSMBLoginData(_editSMBServer->getEditString(),
							_editSMBShare->getEditString(),
							_editSMBUsername->getEditString(),
							_editSMBPassword->getEditString());
		fsf.mount(WiiFilesystemFactory::kSMB);
		break;

	case 'usmb':
		fsf.umount(WiiFilesystemFactory::kSMB);
		break;
#endif

	default:
		Dialog::handleCommand(sender, cmd, data);
		break;
	}
}

void WiiOptionsDialog::revert() {
	gfx_set_underscan(ConfMan.getInt(_strUnderscanX,
									Common::ConfigManager::kApplicationDomain),
						ConfMan.getInt(_strUnderscanY,
									Common::ConfigManager::kApplicationDomain));
}

void WiiOptionsDialog::load() {
	int i;

	i = ConfMan.getInt(_strUnderscanX,
							Common::ConfigManager::kApplicationDomain);
	_sliderUnderscanX->setValue(i);

	i = ConfMan.getInt(_strUnderscanY,
							Common::ConfigManager::kApplicationDomain);
	_sliderUnderscanY->setValue(i);

	i = ConfMan.getInt("wii_pad_sensitivity",
							Common::ConfigManager::kApplicationDomain);
	_sliderPadSensitivity->setValue(i);

	i = ConfMan.getInt("wii_pad_acceleration",
							Common::ConfigManager::kApplicationDomain);
	_sliderPadAcceleration->setValue(i);

#ifdef USE_WII_SMB
	_editSMBServer->setEditString(ConfMan.get("wii_smb_server",
									Common::ConfigManager::kApplicationDomain));
	_editSMBShare->setEditString(ConfMan.get("wii_smb_share",
									Common::ConfigManager::kApplicationDomain));
	_editSMBUsername->setEditString(ConfMan.get("wii_smb_username",
									Common::ConfigManager::kApplicationDomain));
	_editSMBPassword->setEditString(ConfMan.get("wii_smb_password",
									Common::ConfigManager::kApplicationDomain));
#endif
}

void WiiOptionsDialog::save() {
	ConfMan.setInt(_strUnderscanX,
					_sliderUnderscanX->getValue(),
					Common::ConfigManager::kApplicationDomain);
	ConfMan.setInt(_strUnderscanY,
					_sliderUnderscanY->getValue(),
					Common::ConfigManager::kApplicationDomain);

	ConfMan.setInt("wii_pad_sensitivity",
					_sliderPadSensitivity->getValue(),
					Common::ConfigManager::kApplicationDomain);
	ConfMan.setInt("wii_pad_acceleration",
					_sliderPadAcceleration->getValue(),
					Common::ConfigManager::kApplicationDomain);

#ifdef USE_WII_SMB
	ConfMan.set("wii_smb_server", _editSMBServer->getEditString(),
				Common::ConfigManager::kApplicationDomain);
	ConfMan.set("wii_smb_share", _editSMBShare->getEditString(),
				Common::ConfigManager::kApplicationDomain);
	ConfMan.set("wii_smb_username", _editSMBUsername->getEditString(),
				Common::ConfigManager::kApplicationDomain);
	ConfMan.set("wii_smb_password", _editSMBPassword->getEditString(),
				Common::ConfigManager::kApplicationDomain);
#endif

	ConfMan.flushToDisk();
}