download source and project
master character list edit source:
#include <windows.h>
#include <stdio.h>
#include "resource.h"
#include "master_struct.h"
#include "tool.h"
#pragma warning(disable : 4996)
#define MAX_CHARACTERS 256
HWND g_hwnd;
OPENFILENAME g_ofn; // open/save dialog data
char g_mcl_file[MAX_PATH]; // filename for character file
sCharDef g_chars[MAX_CHARACTERS];
long g_edit_char;
//////////////////////////////////////////////////////////////////////////////////////////////
inline void reset_character(sCharDef& char_def)
{
char_def.weapon = -1;
char_def.armor = -1;
char_def.shield = -1;
char_def.accessory = -1;
}
//////////////////////////////////////////////////////////////////////////////////////////////
bool load_chars(const char* filename)
{
// load characters data from file and insert into listbox
// clear char structures
for(int i = 0; i < MAX_CHARACTERS; i++)
{
ZeroMemory(&g_chars[i], sizeof(sCharDef));
g_chars[i].weapon = -1;
g_chars[i].armor = -1;
g_chars[i].shield = -1;
g_chars[i].accessory = -1;
}
FILE* fp;
if((fp = fopen(filename, "rb")) == NULL)
return false;
fread(g_chars, 1, sizeof(g_chars), fp);
fclose(fp);
// update characters list box
HWND listbox = GetDlgItem(g_hwnd, IDC_CHARACTERS);
reset_listbox(listbox);
for(int i = 0; i < MAX_CHARACTERS; i++)
{
char text[256];
sprintf(text, "%5d: %s", i, g_chars[i].name);
add_string_to_listbox(listbox, text);
}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
bool new_mcl()
{
if(MessageBox(g_hwnd, "Are you sure? (Looses any unsaved MCL information)", "New MCL", MB_YESNO) != IDYES)
return false;
HWND listbox = GetDlgItem(g_hwnd, IDC_CHARACTERS);
reset_listbox(listbox);
for(int i = 0; i < MAX_CHARACTERS; i++)
{
ZeroMemory(&g_chars[i], sizeof(sCharDef));
reset_character(g_chars[i]);
char buf[16];
sprintf(buf, "%5d:", i);
insert_string_to_listbox(listbox, i, buf);
}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
bool load_mcl()
{
// Setup the open dialog info
g_ofn.hwndOwner = g_hwnd;
g_ofn.lpstrFile = g_mcl_file;
g_ofn.lpstrTitle = "Load MCL File";
g_ofn.lpstrFilter = "MCL Character Files (*.MCL)\0*.MCL\0All Files (*.*)\0*.*\0\0";
g_ofn.lpstrDefExt = "MCL";
if(! GetOpenFileName(&g_ofn))
return false;
if(! load_chars(g_mcl_file))
{
MessageBox(g_hwnd, g_mcl_file, "Unable to open file.", MB_OK);
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
bool save_mcl()
{
// Setup the open dialog info
g_ofn.hwndOwner = g_hwnd;
g_ofn.lpstrFile = g_mcl_file;
g_ofn.lpstrTitle = "Save MCL File";
g_ofn.lpstrFilter = "MCL Character Files (*.MCL)\0*.MCL\0All Files (*.*)\0*.*\0\0";
g_ofn.lpstrDefExt = "MCL";
if(! GetSaveFileName(&g_ofn))
return false;
// open filename for saving
FILE* fp;
if((fp = fopen(g_mcl_file, "wb")) == NULL)
return false;
fwrite(g_chars, 1, sizeof(g_chars), fp);
fclose(fp);
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
void update_entry(HWND dlg, long char_index)
{
char text[32];
sCharDef& char_def = g_chars[char_index];
// get text entries
GetWindowText(GetDlgItem(dlg, IDC_NAME), char_def.name, sizeof(char_def.name));
GetWindowText(GetDlgItem(dlg, IDC_ITEM), char_def.item_filename, sizeof(char_def.item_filename));
// Get numerical entries
GetWindowText(GetDlgItem(dlg, IDC_CLASS), text, sizeof(text));
char_def.class_index = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_HEALTH), text, sizeof(text));
char_def.health_points = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_MANA), text, sizeof(text));
char_def.mana_points = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_LEVEL), text, sizeof(text));
char_def.level = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_EXPERIENCE), text, sizeof(text));
char_def.exp = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_MONEY), text, sizeof(text));
char_def.money = atol(text);
///////////////////////////////////////////
GetWindowText(GetDlgItem(dlg, IDC_ATTACK), text, sizeof(text));
char_def.attack = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_DEFENSE), text, sizeof(text));
char_def.defense = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_AGILITY), text, sizeof(text));
char_def.agility = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_RESISTANCE), text, sizeof(text));
char_def.resistance = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_MENTAL), text, sizeof(text));
char_def.mental = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_TOHIT), text, sizeof(text));
char_def.to_hit = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_SPEED), text, sizeof(text));
char_def.speed = (float)atof(text);
///////////////////////////////////////////
GetWindowText(GetDlgItem(dlg, IDC_RANGE), text, sizeof(text));
char_def.attack_range = (float)atof(text);
GetWindowText(GetDlgItem(dlg, IDC_CHARGE), text, sizeof(text));
char_def.charge_rate = (float)atof(text);
GetWindowText(GetDlgItem(dlg, IDC_TOATTACK), text, sizeof(text));
char_def.to_attack = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_TOMAGIC), text, sizeof(text));
char_def.to_magic = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_DROPITEM), text, sizeof(text));
char_def.drop_item = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_TODROP), text, sizeof(text));
char_def.drop_chance = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_TOEFFECT), text, sizeof(text));
char_def.effect_chance = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_EFFECT), text, sizeof(text));
char_def.effects = atol(text);
///////////////////////////////////////////
GetWindowText(GetDlgItem(dlg, IDC_MESH), text, sizeof(text));
char_def.mesh_index = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_WEAPON), text, sizeof(text));
char_def.weapon = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_ARMOR), text, sizeof(text));
char_def.armor = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_SHIELD), text, sizeof(text));
char_def.shield = atol(text);
GetWindowText(GetDlgItem(dlg, IDC_ACCESSORY), text, sizeof(text));
char_def.accessory = atol(text);
char_def.magic_spell[0] = 0;
char_def.magic_spell[1] = 0;
HWND spell_wnd = GetDlgItem(dlg, IDC_SPELLS);
for(int i = 0; i < 64; i++)
{
if(get_listbox_sel(spell_wnd, i))
{
if(i < 32)
char_def.magic_spell[0] |= (1 << i);
else
char_def.magic_spell[1] |= (1 << (i-32));
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK modify_dialog_proc(HWND dlg, UINT msg, WPARAM word_param, LPARAM long_param)
{
char text[32];
HWND spell_wnd;
switch(msg)
{
case WM_INITDIALOG:
{
// return an error if there is no character to modify
if(g_edit_char >= MAX_CHARACTERS)
{
EndDialog(dlg, FALSE);
return FALSE;
}
// display character number
sprintf(text, "%lu", g_edit_char);
SetWindowText(GetDlgItem(dlg, IDC_NUM), text);
sCharDef& char_def = g_chars[g_edit_char];
// display text entries
SetWindowText(GetDlgItem(dlg, IDC_NAME), char_def.name);
SetWindowText(GetDlgItem(dlg, IDC_ITEM), char_def.item_filename);
// display numerical entries
sprintf(text, "%lu", char_def.class_index);
SetWindowText(GetDlgItem(dlg, IDC_CLASS), text);
sprintf(text, "%lu", char_def.health_points);
SetWindowText(GetDlgItem(dlg, IDC_HEALTH), text);
sprintf(text, "%lu", char_def.mana_points);
SetWindowText(GetDlgItem(dlg, IDC_MANA), text);
sprintf(text, "%lu", char_def.level);
SetWindowText(GetDlgItem(dlg, IDC_LEVEL), text);
sprintf(text, "%lu", char_def.exp);
SetWindowText(GetDlgItem(dlg, IDC_EXPERIENCE), text);
sprintf(text, "%lu", char_def.money);
SetWindowText(GetDlgItem(dlg, IDC_MONEY), text);
sprintf(text, "%lu", char_def.attack);
SetWindowText(GetDlgItem(dlg, IDC_ATTACK), text);
sprintf(text, "%lu", char_def.defense);
SetWindowText(GetDlgItem(dlg, IDC_DEFENSE), text);
sprintf(text, "%lu", char_def.agility);
SetWindowText(GetDlgItem(dlg, IDC_AGILITY), text);
sprintf(text, "%lu", char_def.resistance);
SetWindowText(GetDlgItem(dlg, IDC_RESISTANCE), text);
sprintf(text, "%lu", char_def.mental);
SetWindowText(GetDlgItem(dlg, IDC_MENTAL), text);
sprintf(text, "%lu", char_def.to_hit);
SetWindowText(GetDlgItem(dlg, IDC_TOHIT), text);
sprintf(text, "%lf", char_def.speed);
SetWindowText(GetDlgItem(dlg, IDC_SPEED), text);
sprintf(text, "%lf", char_def.attack_range);
SetWindowText(GetDlgItem(dlg, IDC_RANGE), text);
sprintf(text, "%lf", char_def.charge_rate);
SetWindowText(GetDlgItem(dlg, IDC_CHARGE), text);
sprintf(text, "%lu", char_def.to_attack);
SetWindowText(GetDlgItem(dlg, IDC_TOATTACK), text);
sprintf(text, "%lu", char_def.to_magic);
SetWindowText(GetDlgItem(dlg, IDC_TOMAGIC), text);
sprintf(text, "%lu", char_def.drop_item);
SetWindowText(GetDlgItem(dlg, IDC_DROPITEM), text);
sprintf(text, "%lu", char_def.drop_chance);
SetWindowText(GetDlgItem(dlg, IDC_TODROP), text);
sprintf(text, "%lu", char_def.effect_chance);
SetWindowText(GetDlgItem(dlg, IDC_TOEFFECT), text);
sprintf(text, "%lu", char_def.effects);
SetWindowText(GetDlgItem(dlg, IDC_EFFECT), text);
sprintf(text, "%lu", char_def.mesh_index);
SetWindowText(GetDlgItem(dlg, IDC_MESH), text);
sprintf(text, "%ld", char_def.weapon);
SetWindowText(GetDlgItem(dlg, IDC_WEAPON), text);
sprintf(text, "%ld", char_def.armor);
SetWindowText(GetDlgItem(dlg, IDC_ARMOR), text);
sprintf(text, "%ld", char_def.shield);
SetWindowText(GetDlgItem(dlg, IDC_SHIELD), text);
sprintf(text, "%ld", char_def.accessory);
SetWindowText(GetDlgItem(dlg, IDC_ACCESSORY), text);
// display spell list
spell_wnd = GetDlgItem(dlg, IDC_SPELLS);
reset_listbox(spell_wnd);
for(int i = 0; i < 64; i++)
{
sprintf(text, "%d", i);
insert_string_to_listbox(spell_wnd, i, text);
if(i < 32)
{
if(char_def.magic_spell[0] & (1 << i))
set_listbox_sel(spell_wnd, TRUE, i);
}
else
{
if(char_def.magic_spell[1] & (1 << (i - 32)))
set_listbox_sel(spell_wnd, TRUE, i);
}
}
return TRUE;
}
case WM_COMMAND:
switch(LOWORD(word_param))
{
case IDC_OK:
update_entry(dlg, g_edit_char);
EndDialog(dlg, TRUE);
return TRUE;
case IDC_CANCEL:
EndDialog(dlg, FALSE);
return TRUE;
case IDC_SETALL:
spell_wnd = GetDlgItem(dlg, IDC_SPELLS);
for(int i = 0; i < 64; i++)
set_listbox_sel(spell_wnd, TRUE, i);
break;
case IDC_CLEARALL:
spell_wnd = GetDlgItem(dlg, IDC_SPELLS);
for(int i = 0; i < 64; i++)
set_listbox_sel(spell_wnd, FALSE, i);
break;
}
break;
}
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM word_param, LPARAM long_param)
{
int sel;
char text[256];
HWND listbox;
switch(msg)
{
case WM_COMMAND:
switch(LOWORD(word_param))
{
case IDC_NEW: // new mcl file
new_mcl();
break;
case IDC_LOAD: // load a mcl file
load_mcl();
break;
case IDC_SAVE: // save a mcl file
save_mcl();
break;
case IDC_CLEAR: // clear an entry
listbox = GetDlgItem(g_hwnd, IDC_CHARACTERS);
// see if a spell was selected
if((sel = (int)get_listbox_cur_sel(listbox)) == LB_ERR)
break;
ZeroMemory(&g_chars[sel], sizeof(sCharDef));
reset_character(g_chars[sel]);
delete_listbox_string(listbox, sel);
sprintf(text, "%5lu:", sel);
insert_string_to_listbox(listbox, sel, text);
break;
case IDC_CHARACTERS: // edit an entry
if(HIWORD(word_param) != LBN_DBLCLK)
break;
case IDC_EDIT:
listbox = GetDlgItem(hwnd, IDC_CHARACTERS);
if((sel = (int)get_listbox_cur_sel(listbox)) == LB_ERR)
break;
g_edit_char = sel;
DialogBox(NULL, MAKEINTRESOURCE(IDD_MODIFY), hwnd, modify_dialog_proc);
delete_listbox_string(listbox, sel);
sprintf(text, "%5lu: %s", sel, g_chars[sel].name);
insert_string_to_listbox(listbox, sel, 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;
strcpy(g_mcl_file, "..\\Data\\Default.MCL");
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, word_param, long_param);
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPSTR cmd_line, int cmd_show)
{
const char* class_name = "MCLEDIT";
WNDCLASS wc;
// Register window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = window_proc;
wc.cbClsExtra = 0;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = inst;
wc.hIcon = LoadIcon(inst, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = class_name;
RegisterClass(&wc);
g_hwnd = CreateDialog(inst, MAKEINTRESOURCE(IDD_EDIT), 0, NULL);
ShowWindow(g_hwnd, cmd_show);
UpdateWindow(g_hwnd);
// Force a load of characters from default.MCL
load_chars("..\\Data\\Default.MCL");
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClass(class_name, inst);
return 0;
}