📄 winmain.cpp
字号:
/**************************************************
WinMain.cpp
Chapter 16 Master Spell List Editor
Programming Role-Playing Games with DirectX
by Jim Adams (01 Jan 2002)
**************************************************/
#include <windows.h>
#include <stdio.h>
#include "resource.h"
#include "MSL.h"
// Application variables ////////////////////////////////////////////
HWND g_hWnd; // Window handle
char g_szClass[] = "MSLEDIT"; // Class name
OPENFILENAME g_ofn; // Open/Save dialog data
char g_MSLFile[MAX_PATH]; // Filename for spell file
sSpell g_Spells[64]; // Spell list
long g_EditSpell; // Spell to modify
// Application prototypes ///////////////////////////////////////////
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow);
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ModifyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL UpdateEntry(HWND hWnd, long SpellNum);
BOOL LoadSpells(char *Filename);
BOOL NewMSL();
BOOL LoadMSL();
BOOL SaveMSL();
// Application //////////////////////////////////////////////////////
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
{
WNDCLASS wc;
MSG Msg;
// Register window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClass;
RegisterClass(&wc);
// Create the dialog box window and show it
g_hWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_EDIT), 0, NULL);
UpdateWindow(g_hWnd);
ShowWindow(g_hWnd, nCmdShow);
// Force a load of spells from default.MSL
LoadSpells("..\\Data\\Default.MSL");
// Message loop
while(GetMessage(&Msg, NULL, 0, 0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
// Clean up
UnregisterClass(g_szClass, hInst);
return 0;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int Selection;
char Text[256];
switch(uMsg) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
// New MSL file
case IDC_NEW:
NewMSL();
break;
// Load a MSL file
case IDC_LOAD:
LoadMSL();
break;
// Save a MSL file
case IDC_SAVE:
SaveMSL();
break;
// Clear an entry
case IDC_CLEAR:
// See if a spell was selected
if((Selection = SendMessage(GetDlgItem(g_hWnd, IDC_SPELLS), LB_GETCURSEL, 0, 0)) == LB_ERR)
break;
ZeroMemory(&g_Spells[Selection], sizeof(sSpell));
// Reset spell damage and cure classes
g_Spells[Selection].DmgClass = -1;
g_Spells[Selection].CureClass = -1;
// Reset sounds
g_Spells[Selection].MeshSound[0] = -1;
g_Spells[Selection].MeshSound[1] = -1;
g_Spells[Selection].MeshSound[2] = -1;
SendMessage(GetDlgItem(g_hWnd, IDC_SPELLS), LB_DELETESTRING, Selection, 0);
sprintf(Text, "%5lu: %s", Selection, g_Spells[Selection].Name);
SendMessage(GetDlgItem(g_hWnd, IDC_SPELLS), LB_INSERTSTRING, Selection, (LPARAM)Text);
break;
// Edit an entry
case IDC_SPELLS:
if(HIWORD(wParam) != LBN_DBLCLK)
break;
case IDC_EDIT:
// See if a spell was selected
if((Selection = SendMessage(GetDlgItem(g_hWnd, IDC_SPELLS), LB_GETCURSEL, 0, 0)) == LB_ERR)
break;
// Set the spel to edit
g_EditSpell = Selection;
// Call the modify spell dialog
DialogBox(NULL, MAKEINTRESOURCE(IDD_MODIFY), hWnd, ModifyDialogProc);
// Update spell
SendMessage(GetDlgItem(g_hWnd, IDC_SPELLS), LB_DELETESTRING, Selection, 0);
sprintf(Text, "%5lu: %s", Selection, g_Spells[Selection].Name);
SendMessage(GetDlgItem(g_hWnd, IDC_SPELLS), LB_INSERTSTRING, Selection, (LPARAM)Text);
break;
}
break;
case WM_CREATE:
// Initialize the save/load dialog box info
ZeroMemory(&g_ofn, sizeof(OPENFILENAME));
g_ofn.lStructSize = sizeof(OPENFILENAME);
g_ofn.nMaxFile = MAX_PATH;
g_ofn.nMaxFileTitle = MAX_PATH;
g_ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT;
// Set default MSL filename
strcpy(g_MSLFile, "..\\Data\\Default.MSL");
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default: return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
BOOL CALLBACK ModifyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WORD Effects[8] = {
IDC_HEALTH, IDC_MANA,
IDC_CURE, IDC_CAUSE, IDC_RAISE, IDC_KILL,
IDC_DISPEL, IDC_TELEPORT
};
WORD Targets[3] = {
IDC_SINGLE, IDC_SELF, IDC_AREA
};
WORD Positions[18] = {
IDC_NONE1, IDC_CASTER1, IDC_TOTARGET1, IDC_TOCASTER1, IDC_TARGET1, IDC_SCALE1,
IDC_NONE2, IDC_CASTER2, IDC_TOTARGET2, IDC_TOCASTER2, IDC_TARGET2, IDC_SCALE2,
IDC_NONE3, IDC_CASTER3, IDC_TOTARGET3, IDC_TOCASTER3, IDC_TARGET3, IDC_SCALE3,
};
WORD Loops[3] = { IDC_LOOP1, IDC_LOOP2, IDC_LOOP3 };
char Text[32];
long i;
switch(uMsg) {
case WM_INITDIALOG:
// Return an error if there's no spell to modify
if(g_EditSpell >= 64) {
EndDialog(hWnd, FALSE);
return FALSE;
}
// Display spell number
sprintf(Text, "%lu", g_EditSpell);
SetWindowText(GetDlgItem(hWnd, IDC_NUM), Text);
// Display text entries
SetWindowText(GetDlgItem(hWnd, IDC_NAME), g_Spells[g_EditSpell].Name);
SetWindowText(GetDlgItem(hWnd, IDC_DESCRIPTION), g_Spells[g_EditSpell].Description);
// Display numerical entries
sprintf(Text, "%ld", g_Spells[g_EditSpell].DmgClass);
SetWindowText(GetDlgItem(hWnd, IDC_DMGCLASS), Text);
sprintf(Text, "%ld", g_Spells[g_EditSpell].CureClass);
SetWindowText(GetDlgItem(hWnd, IDC_CURECLASS), Text);
sprintf(Text, "%lu", g_Spells[g_EditSpell].Cost);
SetWindowText(GetDlgItem(hWnd, IDC_COST), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].Distance);
SetWindowText(GetDlgItem(hWnd, IDC_DISTANCE), Text);
sprintf(Text, "%lu", g_Spells[g_EditSpell].Chance);
SetWindowText(GetDlgItem(hWnd, IDC_CHANCE), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].Value[0]);
SetWindowText(GetDlgItem(hWnd, IDC_VALUE1), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].Value[1]);
SetWindowText(GetDlgItem(hWnd, IDC_VALUE2), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].Value[2]);
SetWindowText(GetDlgItem(hWnd, IDC_VALUE3), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].Value[3]);
SetWindowText(GetDlgItem(hWnd, IDC_VALUE4), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].Range);
SetWindowText(GetDlgItem(hWnd, IDC_RANGE), Text);
sprintf(Text, "%lu", g_Spells[g_EditSpell].MeshNum[0]);
SetWindowText(GetDlgItem(hWnd, IDC_MESH1), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].MeshSpeed[0]);
SetWindowText(GetDlgItem(hWnd, IDC_SPEED1), Text);
sprintf(Text, "%ld", g_Spells[g_EditSpell].MeshSound[0]);
SetWindowText(GetDlgItem(hWnd, IDC_SOUND1), Text);
sprintf(Text, "%lu", g_Spells[g_EditSpell].MeshNum[1]);
SetWindowText(GetDlgItem(hWnd, IDC_MESH2), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].MeshSpeed[1]);
SetWindowText(GetDlgItem(hWnd, IDC_SPEED2), Text);
sprintf(Text, "%ld", g_Spells[g_EditSpell].MeshSound[1]);
SetWindowText(GetDlgItem(hWnd, IDC_SOUND2), Text);
sprintf(Text, "%lu", g_Spells[g_EditSpell].MeshNum[2]);
SetWindowText(GetDlgItem(hWnd, IDC_MESH3), Text);
sprintf(Text, "%lf", g_Spells[g_EditSpell].MeshSpeed[2]);
SetWindowText(GetDlgItem(hWnd, IDC_SPEED3), Text);
sprintf(Text, "%ld", g_Spells[g_EditSpell].MeshSound[2]);
SetWindowText(GetDlgItem(hWnd, IDC_SOUND3), Text);
// Display selection entries
SendMessage(GetDlgItem(hWnd, Effects[g_Spells[g_EditSpell].Effect]), BM_SETCHECK, 1, 0);
SendMessage(GetDlgItem(hWnd, Targets[g_Spells[g_EditSpell].Target]), BM_SETCHECK, 1, 0);
SendMessage(GetDlgItem(hWnd, Positions[g_Spells[g_EditSpell].MeshPos[0]]), BM_SETCHECK, 1, 0);
SendMessage(GetDlgItem(hWnd, Positions[g_Spells[g_EditSpell].MeshPos[1]+6]), BM_SETCHECK, 1, 0);
SendMessage(GetDlgItem(hWnd, Positions[g_Spells[g_EditSpell].MeshPos[2]+12]), BM_SETCHECK, 1, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -