aboutsummaryrefslogtreecommitdiff
path: root/engines/sludge/winstuff.cpp
blob: 266df699d9c6e148f67bf4e772de1cbd35ad42af (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
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
#ifdef _WIN32
#include <windows.h>
#include <shellapi.h>

#include "allfiles.h"
#include "debug.h"

#include "winstuff.h"
#include "platform-dependent.h"
#include "language.h"
#include "newfatal.h"
#include "sprites.h"
#include "sprbanks.h"
#include "fonttext.h"
#include "backdrop.h"
#include "sludger.h"
#include "cursors.h"
#include "objtypes.h"
#include "region.h"
#include "people.h"
#include "talk.h"
#include "direct.h"
#include "sound.h"
#include "colours.h"
#include "moreio.h"
#include "stringy.h"

#include <shellapi.h>
#include <shlobj.h> // For SHGetFolderPath

#include "..\..\images\resource.h"

namespace Sludge {

HINSTANCE hInst;                // Handle of the main instance
extern HWND hMainWindow;

extern variableStack *noStack;

// The platform-specific functions - Windows edition.

WCHAR *ConvertToUTF16(const char *input) {
	int s = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input, -1, NULL, 0);
	WCHAR *ret = new WCHAR [s];
	checkNew(ret);
	/*int a = */MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input, -1, ret, s);
	return ret;
}

char *ConvertFromUTF16(const WCHAR *input) {
	int s = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
	char *ret = new char [s];
	checkNew(ret);
	/*int a = */WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, s, NULL, NULL);
	return ret;
}


char *grabFileName() {
	OPENFILENAME ofn;
	WCHAR path[MAX_PATH];
	WCHAR file[MAX_PATH] = TEXT("");

	hInst = GetModuleHandle(NULL);

	memset(& ofn, 0, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = NULL;
	ofn.hInstance = hInst;
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrInitialDir = path;
	ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER;
	ofn.lpstrFilter = TEXT("SLUDGE games (*.SLG)\0*.slg\0\0");
	ofn.lpstrFile = file;

	if (GetOpenFileName(& ofn)) {
		return ConvertFromUTF16(file);
	} else {
		return NULL;
	}
}

extern char **languageName;
extern int *languageTable;

HBITMAP hLogo = NULL;
extern unsigned char *gameLogo;

BOOL CALLBACK setupDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
	switch (message) {
	case WM_INITDIALOG:
		if (gameLogo) {
			hLogo = CreateBitmap(310, 88, 1, 32, gameLogo);
			SendDlgItemMessage(hDlg, 1003, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hLogo);
		}

		if (gameSettings.userFullScreen)
			CheckDlgButton(hDlg, 1000, BST_CHECKED);
		else
			CheckDlgButton(hDlg, 1000, BST_UNCHECKED);

		SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Default (best looking)")));
		SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Linear (faster but blurry)")));
		SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Off (blocky graphics)")));

		if (gameSettings.antiAlias < 0)
			SendDlgItemMessage(hDlg, 1002, CB_SETCURSEL, 1, 0);
		else if (gameSettings.antiAlias)
			SendDlgItemMessage(hDlg, 1002, CB_SETCURSEL, 0, 0);
		else
			SendDlgItemMessage(hDlg, 1002, CB_SETCURSEL, 2, 0);

		if (gameSettings.numLanguages) {
			WCHAR text[20];
			for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) {
				if (languageName[i]) {
					WCHAR *w_lang = ConvertToUTF16(languageName[i]);
					SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)w_lang));
					delete w_lang;
				} else {
					swprintf(text, TEXT("Language %d"), i);
					SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)text));
				}
			}
			SendDlgItemMessage(hDlg, 1001, CB_SETCURSEL, getLanguageForFileB(), 0);
		} else {
			const WCHAR *text = TEXT("No translations available");
			SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)text));
			SendDlgItemMessage(hDlg, 1001, CB_SETCURSEL, 0, 0);
			EnableWindow(GetDlgItem(hDlg, 1001), false);
		}
		return true;

	case WM_COMMAND:
		if (hLogo) DeleteObject(hLogo);
		switch (LOWORD(wParam)) {
		case IDOK:

			gameSettings.userFullScreen = (IsDlgButtonChecked(hDlg, 1000) == BST_CHECKED);
			gameSettings.antiAlias = SendDlgItemMessage(hDlg, 1002, CB_GETCURSEL, 0, 0);
			if (gameSettings.antiAlias == 0) gameSettings.antiAlias = 1;
			else if (gameSettings.antiAlias == 1) gameSettings.antiAlias = -1;
			else if (gameSettings.antiAlias == 2) gameSettings.antiAlias = 0;

			if (gameSettings.numLanguages) {
				gameSettings.languageID = SendDlgItemMessage(hDlg, 1001, CB_GETCURSEL, 0, 0);
				if (gameSettings.languageID < 0) gameSettings.languageID = 0;
				gameSettings.languageID = languageTable[gameSettings.languageID];
			}
			EndDialog(hDlg, true);
			return TRUE;

		case IDCANCEL:
			EndDialog(hDlg, false);
			return TRUE;
		}
		break;
	}
	return false;
}

int showSetupWindow() {

	hInst = GetModuleHandle(NULL);

	if (! hInst) debugOut("ERROR: No hInst!\n");

	if (DialogBox(hInst, TEXT("SETUPWINDOW"), NULL, setupDlgProc)) return true;
	return false;

}

void msgBox(const char *head, const char *msg) {
	WCHAR *w_head = ConvertToUTF16(head);
	WCHAR *w_msg = ConvertToUTF16(msg);
	MessageBox(NULL, w_msg, w_head, MB_OK | MB_ICONSTOP | MB_SYSTEMMODAL | MB_SETFOREGROUND);
	delete w_head;
	delete w_msg;
}

int msgBoxQuestion(const char *head, const char *msg) {
	WCHAR *w_head = ConvertToUTF16(head);
	WCHAR *w_msg = ConvertToUTF16(msg);
	int val = MessageBox(NULL, w_msg, w_head, MB_YESNO | MB_SETFOREGROUND | MB_APPLMODAL | MB_ICONQUESTION) == IDNO;
	delete w_head;
	delete w_msg;
	if (val)
		return false;
	return true;
}

void changeToUserDir() {
	TCHAR szAppData[MAX_PATH];
	/*hr = */SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szAppData);
	_wchdir(szAppData);
}

uint32_t launch(char *f) {
	WCHAR *w_f = ConvertToUTF16(f);
	uint32_t r = (uint32_t) ShellExecute(hMainWindow, TEXT("open"), w_f, NULL, TEXT("C:\\"), SW_SHOWNORMAL);
	delete w_f;
	return r;
}

bool defaultUserFullScreen() {
	return true;
}

} // End of namespace Sludge

#endif