-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgTileset.cpp
executable file
·102 lines (85 loc) · 2.2 KB
/
DlgTileset.cpp
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
#include "DlgTileset.h"
#include "Resource.h"
#include "Main.h"
BOOL CALLBACK TilesetSettingsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void TilesetSettingsDialog()
{
DialogBox (Main.App.GetInstance(), MAKEINTRESOURCE(IDD_TILESET), Main.App.GetWnd(), &TilesetSettingsProc);
}
void ReloadTileset()
{
Main.DirectX.ReleaseTileset();
Main.DirectX.LoadTileset();
}
void LoadTilesetFromTitle(char* szBuffer)
{
ifstream fin;
char szBuffer2[48];
fin.open("tilesets.idx");
while (!fin.eof())
{
fin.getline(szBuffer2, 48);
if (strcmp(szBuffer, szBuffer2) == 0)
{
fin.getline(szBuffer, 48);
if (szBuffer[0] != NULL)
{
fin.close();
sprintf(Main.Settings.szTilesetDir, "%s", szBuffer);
ReloadTileset();
}
break;
}
}
fin.close();
}
BOOL CALLBACK TilesetSettingsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
ifstream fin;
long sel;
char szBuffer[48];
RECT rect, rect2;
switch (message)
{
case WM_INITDIALOG:
// Center dialog
GetWindowRect(Main.App.GetWnd(), &rect);
GetWindowRect(hWnd , &rect2);
SetWindowPos (hWnd, HWND_TOP, ((rect.left + rect.right) / 2) - ((rect2.right - rect2.left) / 2), ((rect.top + rect.bottom) / 2) - ((rect2.bottom - rect2.top) / 2), 0, 0, SWP_NOSIZE);
// Setup listbox
fin.open("tilesets.idx");
while (!fin.eof())
{
fin.getline(szBuffer, 48);
SendDlgItemMessage(hWnd, IDC_LIST , LB_ADDSTRING, 0, (LPARAM)&szBuffer);
fin.getline(szBuffer, 48);
}
fin.close();
return 1;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_LIST:
if (HIWORD(wParam) == LBN_SELCHANGE)
{
// Extract tilset dirrectory from tilesets.idx
sel = SendDlgItemMessage(hWnd, IDC_LIST, LB_GETCURSEL, 0, 0);
if (sel != LB_ERR)
{
SendDlgItemMessage(hWnd, IDC_LIST, LB_GETTEXT, sel, (LPARAM)&szBuffer);
LoadTilesetFromTitle(szBuffer);
}
SendMessage(hWnd, WM_DESTROY, 0, 0);
}
break;
case IDCANCEL:
SendMessage(hWnd, WM_DESTROY, 0, 0);
return 1;
}
break;
case WM_DESTROY:
EndDialog(hWnd, 0);
return 1;
}
return 0;
}