天行健 君子当自强而不息

Controlling Players and Characters(22)

 

download source and project

 

Creating MSL edit

 

main window design:

 

modify spell window design:

 

resouce.h

//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by MSLEdit.rc
//

#define IDD_EDIT                        101
#define IDD_MODIFY                      102
#define IDC_LOAD                        1000
#define IDC_SAVE                        1001
#define IDC_CHARACTERS                  1002
#define IDC_NEW                         1003
#define IDC_OK                          1004
#define IDC_NUM                         1005
#define IDC_WEAPON                      1006
#define IDC_ARMOR                       1007
#define IDC_SHIELD                      1008
#define IDC_HEALING                     1009
#define IDC_CONTAINER                   1010
#define IDC_MONEY                       1011
#define IDC_ACCESSORY                   1012
#define IDC_EDIBLE                      1013
#define IDC_COLLECTION                  1014
#define IDC_TRANSPORTATION              1015
#define IDC_SELLABLE                    1016
#define IDC_CANDROP                     1017
#define IDC_USEONCE                     1018
#define IDC_UNKNOWN                     1019
#define IDC_SPELLS                      1020
#define IDC_NAME                        1021
#define IDC_DESCRIPTION                 1022
#define IDC_NAME2                       1023
#define IDC_MESH1                       1023
#define IDC_WEIGHT                      1024
#define IDC_NAME3                       1024
#define IDC_SCRIPT                      1024
#define IDC_NAME4                       1025
#define IDC_SPEED1                      1025
#define IDC_VALUE                       1026
#define IDC_HEALTH                      1026
#define IDC_PRICE                       1027
#define IDC_MANA                        1027
#define IDC_CURE                        1028
#define IDC_CAUSE                       1029
#define IDC_ITEM                        1030
#define IDC_MESH                        1031
#define IDC_KILL                        1031
#define IDC_CANCEL                      1032
#define IDC_ATTACK                      1033
#define IDC_NOTHING                     1033
#define IDC_DEFENSE                     1034
#define IDC_SINGLE                      1034
#define IDC_AGILITY                     1035
#define IDC_AREA                        1035
#define IDC_ABILITY                     1036
#define IDC_SELF                        1037
#define IDC_GROUP                       1038
#define IDC_CASTER1                     1039
#define IDC_RADIO13                     1040
#define IDC_DISPEL                      1040
#define IDC_TELEPORT                    1041
#define IDC_TOTARGET1                   1042
#define IDC_TOCASTER1                   1043
#define IDC_TARGET1                     1044
#define IDC_NAME5                       1045
#define IDC_SOUND                       1045
#define IDC_SOUND1                      1045
#define IDC_NAME6                       1046
#define IDC_MESH2                       1046
#define IDC_DROPITEM                    1047
#define IDC_CASTER2                     1047
#define IDC_TODROP                      1048
#define IDC_TOTARGET2                   1048
#define IDC_CHARGE                      1049
#define IDC_DMGCLASS                    1049
#define IDC_CHARGE2                     1050
#define IDC_CHANCE                      1050
#define IDC_SPEED                       1051
#define IDC_CHARGE3                     1051
#define IDC_VALUE1                      1051
#define IDC_TOATTACK                    1052
#define IDC_CHARGE4                     1052
#define IDC_COST                        1052
#define IDC_TOMAGIC                     1053
#define IDC_CHARGE5                     1053
#define IDC_RANGE                       1053
#define IDC_CHARGE6                     1054
#define IDC_VALUE2                      1054
#define IDC_EFFECT                      1055
#define IDC_TOCASTER2                   1055
#define IDC_EDIT                        1056
#define IDC_TARGET2                     1056
#define IDC_CLEAR                       1057
#define IDC_NAME7                       1057
#define IDC_SPEED2                      1057
#define IDC_NAME8                       1058
#define IDC_MESH3                       1058
#define IDC_CASTER3                     1059
#define IDC_TOTARGET3                   1060
#define IDC_TOCASTER3                   1061
#define IDC_TARGET3                     1062
#define IDC_NAME9                       1063
#define IDC_SPEED3                      1063
#define IDC_VALUE3                      1064
#define IDC_CURECLASS                   1065
#define IDC_SOUND2                      1066
#define IDC_SOUND3                      1067
#define IDC_RAISE                       1068
#define IDC_NONE1                       1069
#define IDC_NONE2                       1070
#define IDC_NONE3                       1071
#define IDC_VALUE4                      1072
#define IDC_DISTANCE                    1073
#define IDC_SCALE1                      1074
#define IDC_SCALE2                      1075
#define IDC_SCALE3                      1076
#define IDC_LOOP1                       1077
#define IDC_LOOP2                       1078
#define IDC_LOOP3                       1079

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        103
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1078
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

 

msl_edit.rc:

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_EDIT DIALOGEX 0, 0, 267, 130
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Master Spell List Editor"
CLASS "MSLEdit"
FONT 11, "Segoe UI", 400, 0, 0x0
BEGIN
    PUSHBUTTON      "Load",IDC_LOAD,210,90,50,14
    PUSHBUTTON      "Save",IDC_SAVE,210,110,50,14
    LISTBOX         IDC_SPELLS,5,15,195,109,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
    LTEXT           "Spell List",IDC_STATIC,5,5,50,8
    PUSHBUTTON      "New",IDC_NEW,210,70,50,14
    DEFPUSHBUTTON   "Edit",IDC_EDIT,210,15,50,14
    PUSHBUTTON      "Clear",IDC_CLEAR,210,35,50,14
END

IDD_MODIFY DIALOGEX 0, 0, 321, 286
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION
CAPTION "Modify Spell"
FONT 11, "Segoe UI", 400, 0, 0x0
BEGIN
    EDITTEXT        IDC_NAME,49,20,80,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_DESCRIPTION,49,35,80,35,ES_MULTILINE | WS_VSCROLL
    EDITTEXT        IDC_DMGCLASS,49,74,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_CURECLASS,49,89,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_COST,49,105,45,12,ES_AUTOHSCROLL
    CONTROL         "Alter Health",IDC_HEALTH,"Button",BS_AUTORADIOBUTTON,140,5,65,10
    CONTROL         "Alter Mana",IDC_MANA,"Button",BS_AUTORADIOBUTTON,140,15,65,10
    CONTROL         "Cure Effect",IDC_CURE,"Button",BS_AUTORADIOBUTTON,140,24,65,10
    CONTROL         "Cause Effect",IDC_CAUSE,"Button",BS_AUTORADIOBUTTON,140,34,65,10
    CONTROL         "Raise Dead",IDC_RAISE,"Button",BS_AUTORADIOBUTTON,140,43,70,10
    CONTROL         "Instant Kill",IDC_KILL,"Button",BS_AUTORADIOBUTTON,140,53,65,10
    CONTROL         "Dispel Magic",IDC_DISPEL,"Button",BS_AUTORADIOBUTTON,140,63,65,10
    CONTROL         "Teleport",IDC_TELEPORT,"Button",BS_AUTORADIOBUTTON,140,73,65,10
    EDITTEXT        IDC_CHANCE,266,5,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_VALUE1,266,20,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_VALUE2,266,35,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_VALUE3,266,50,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_VALUE4,266,65,45,12,ES_AUTOHSCROLL
    CONTROL         "Targets Single",IDC_SINGLE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,235,90,65,8
    CONTROL         "Targets Self",IDC_SELF,"Button",BS_AUTORADIOBUTTON,235,99,55,8
    CONTROL         "Targets Area",IDC_AREA,"Button",BS_AUTORADIOBUTTON,235,109,55,8
    EDITTEXT        IDC_RANGE,151,90,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_DISTANCE,151,105,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_MESH1,49,130,45,12,ES_AUTOHSCROLL
    CONTROL         "Loop Animation",IDC_LOOP1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,145,75,10
    CONTROL         "N/A",IDC_NONE1,"Button",BS_AUTORADIOBUTTON | WS_GROUP,25,159,75,8
    CONTROL         "Caster",IDC_CASTER1,"Button",BS_AUTORADIOBUTTON,25,168,75,8
    CONTROL         "Caster to Target",IDC_TOTARGET1,"Button",BS_AUTORADIOBUTTON,25,178,75,8
    CONTROL         "Target to Caster",IDC_TOCASTER1,"Button",BS_AUTORADIOBUTTON,25,188,75,8
    CONTROL         "Target",IDC_TARGET1,"Button",BS_AUTORADIOBUTTON,25,199,75,8
    CONTROL         "Scale Distance",IDC_SCALE1,"Button",BS_AUTORADIOBUTTON,25,209,75,8
    EDITTEXT        IDC_SPEED1,61,225,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_SOUND1,61,239,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_MESH2,151,130,45,12,ES_AUTOHSCROLL
    CONTROL         "Loop Animation",IDC_LOOP2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,115,145,75,10
    CONTROL         "N/A",IDC_NONE2,"Button",BS_AUTORADIOBUTTON | WS_GROUP,115,159,75,8
    CONTROL         "Caster",IDC_CASTER2,"Button",BS_AUTORADIOBUTTON,115,168,75,8
    CONTROL         "Caster to Target",IDC_TOTARGET2,"Button",BS_AUTORADIOBUTTON,115,178,75,8
    CONTROL         "Target to Caster",IDC_TOCASTER2,"Button",BS_AUTORADIOBUTTON,115,188,75,8
    CONTROL         "Target",IDC_TARGET2,"Button",BS_AUTORADIOBUTTON,115,199,75,8
    CONTROL         "Scale Distance",IDC_SCALE2,"Button",BS_AUTORADIOBUTTON,115,209,75,8
    EDITTEXT        IDC_SPEED2,161,225,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_SOUND2,161,239,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_MESH3,245,130,45,12,ES_AUTOHSCROLL
    CONTROL         "Loop Animation",IDC_LOOP3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,210,145,75,10
    CONTROL         "N/A",IDC_NONE3,"Button",BS_AUTORADIOBUTTON | WS_GROUP,211,159,75,8
    CONTROL         "Caster",IDC_CASTER3,"Button",BS_AUTORADIOBUTTON,211,168,75,8
    CONTROL         "Caster to Target",IDC_TOTARGET3,"Button",BS_AUTORADIOBUTTON,211,178,75,8
    CONTROL         "Target to Caster",IDC_TOCASTER3,"Button",BS_AUTORADIOBUTTON,211,188,75,8
    CONTROL         "Target",IDC_TARGET3,"Button",BS_AUTORADIOBUTTON,211,199,75,8
    CONTROL         "Scale Distance",IDC_SCALE3,"Button",BS_AUTORADIOBUTTON,211,209,75,8
    EDITTEXT        IDC_SPEED3,262,225,45,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_SOUND3,262,239,45,12,ES_AUTOHSCROLL
    DEFPUSHBUTTON   "OK",IDC_OK,89,265,50,14
    PUSHBUTTON      "Cancel",IDC_CANCEL,185,266,50,14
    LTEXT           "Spell #",IDC_STATIC,5,5,25,10
    LTEXT           "#",IDC_NUM,35,5,50,10
    RTEXT           "Name",IDC_STATIC,21,20,25,10
    RTEXT           "Description",IDC_STATIC,5,35,40,10
    RTEXT           "2x Dmg Class",IDC_STATIC,0,75,45,10
    RTEXT           "Effect Chance",IDC_STATIC,210,5,50,10
    RTEXT           "Spell Value 1",IDC_STATIC,216,20,45,10
    RTEXT           "Cost (MP)",IDC_STATIC,10,106,35,10
    RTEXT           "Range",IDC_STATIC,110,90,35,10
    RTEXT           "Spell Value 2",IDC_STATIC,216,35,45,10
    RTEXT           "Speed/Time",IDC_STATIC,10,225,46,10
    RTEXT           "Sound #",IDC_STATIC,20,241,36,10
    RTEXT           "Speed/Time",IDC_STATIC,116,226,41,10
    RTEXT           "Spell Value 3",IDC_STATIC,216,50,45,10
    RTEXT           "Cure Class",IDC_STATIC,5,90,40,10
    RTEXT           "Speed/Time",IDC_STATIC,217,225,41,10
    RTEXT           "Mesh #1",IDC_STATIC,12,130,35,10
    RTEXT           "Mesh #2",IDC_STATIC,110,130,35,10
    RTEXT           "Mesh #3",IDC_STATIC,209,130,31,10
    RTEXT           "Sound #",IDC_STATIC,121,241,36,10
    RTEXT           "Sound #",IDC_STATIC,222,241,36,10
    LTEXT           "Max Distance",IDC_STATIC,102,106,46,10
    RTEXT           "Spell Value 4",IDC_STATIC,215,65,45,10
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO 
BEGIN
    IDD_EDIT, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 260
        TOPMARGIN, 7
        BOTTOMMARGIN, 123
    END

    IDD_MODIFY, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 314
        TOPMARGIN, 7
        BOTTOMMARGIN, 279
    END
END
#endif    // APSTUDIO_INVOKED


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED

#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

 

main routine:

#include <windows.h>
#include <stdio.h>
#include "resource.h"
#include "msl.h"
#include "tool.h"

#pragma warning(disable : 4996)

#define MAX_SPELLS  64

HWND g_hwnd;                   
// Window handle

OPENFILENAME g_ofn;            
// Open/Save dialog data
char g_mls_file[MAX_PATH];     // Filename for spell file

sSpell g_spells[MAX_SPELLS];   
// Spell list
long   g_edit_spell;           // Spell to modify

const WORD g_effects[8] = 
{
    IDC_HEALTH, IDC_MANA, IDC_CURE, IDC_CAUSE, IDC_RAISE, IDC_KILL, IDC_DISPEL, IDC_TELEPORT 
};

const WORD g_targets[3] = { IDC_SINGLE, IDC_SELF, IDC_AREA };

const WORD g_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,
};

const WORD g_loops[3] = { IDC_LOOP1, IDC_LOOP2, IDC_LOOP3 };

//////////////////////////////////////////////////////////////////////////////////////////////

void reset_spell(sSpell& spell)
{
    
// Reset spell damage and cure classes
    spell.damage_class  = -1;
    spell.cure_class    = -1;

    
// Reset sounds
    spell.mesh_sound[0] = -1;
    spell.mesh_sound[1] = -1;
    spell.mesh_sound[2] = -1;
}

//////////////////////////////////////////////////////////////////////////////////////////////

bool load_spells(const char* filename)
{
    
// load all spells from file and insert into listbox.

    // Clear item structures
    for(long i = 0; i < MAX_SPELLS; i++) 
    {
        ZeroMemory(&g_spells[i], 
sizeof(sSpell));
        reset_spell(g_spells[i]);
    }

    FILE* fp;

    
if((fp  = fopen(filename, "rb")) == NULL)
        
return false;

    fread(g_spells, 1, 
sizeof(g_spells), fp);
    fclose(fp);

    
// update spell's listbox

    HWND listbox = GetDlgItem(g_hwnd, IDC_SPELLS);
    reset_listbox(listbox);

    
for(long i = 0; i < MAX_SPELLS; i++)
    {
        
char text[256];
        sprintf(text, "%5lu: %s", i, g_spells[i].name);
        add_string_to_listbox(listbox, text);
    }

    
return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////

bool new_msl()
{
    
if(MessageBox(g_hwnd, "Are you sure? (Looses any unsaved MSL information)", "New MSL", MB_YESNO) != IDYES)
        
return false;

    HWND listbox = GetDlgItem(g_hwnd, IDC_SPELLS);
    reset_listbox(listbox);

    
for(long i = 0; i < MAX_SPELLS; i++)
    {
        ZeroMemory(&g_spells[i], 
sizeof(sSpell));
        reset_spell(g_spells[i]);

        
char buf[16];
        sprintf(buf, "%5lu:", i);
        add_string_to_listbox(listbox, buf);
    }

    
return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////

bool load_msl()
{
    
// Setup the open dialog info
    g_ofn.hwndOwner   = g_hwnd;
    g_ofn.lpstrFile   = g_mls_file;
    g_ofn.lpstrTitle  = "Load MSL File";
    g_ofn.lpstrFilter = "MSL Spell Files (*.MSL)\0*.MSL\0All Files (*.*)\0*.*\0\0";
    g_ofn.lpstrDefExt = "MSL";
  
    
if(! GetOpenFileName(&g_ofn))
        
return false;

    
if(! load_spells(g_mls_file))
    {
        MessageBox(g_hwnd, g_mls_file, "Unable to open file.", MB_OK);
        
return false;
    }

    
return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////

bool save_msl()
{
    
// Setup the open dialog info
    g_ofn.hwndOwner   = g_hwnd;
    g_ofn.lpstrFile   = g_mls_file;
    g_ofn.lpstrTitle  = "Load MSL File";
    g_ofn.lpstrFilter = "MSL Spell Files (*.MSL)\0*.MSL\0All Files (*.*)\0*.*\0\0";
    g_ofn.lpstrDefExt = "MSL";

    
if(! GetSaveFileName(&g_ofn))
        
return false;

    FILE* fp;

    
if((fp = fopen(g_mls_file, "wb")) == NULL)
        
return false;

    fwrite(g_spells, 1, 
sizeof(g_spells), fp);
    fclose(fp);
  
    
return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////

void update_entry(HWND hwnd, long spell_index)
{
    sSpell& spell = g_spells[spell_index];

    
// Get text entries
    GetWindowText(GetDlgItem(hwnd, IDC_NAME), spell.name, sizeof(spell.name));
    GetWindowText(GetDlgItem(hwnd, IDC_DESCRIPTION), spell.desc, 
sizeof(spell.desc));

    
char text[32];

    
// Get numerical entries
    GetWindowText(GetDlgItem(hwnd, IDC_DMGCLASS), text, sizeof(text));
    spell.damage_class = atol(text);
    GetWindowText(GetDlgItem(hwnd, IDC_CURECLASS), text, 
sizeof(text));
    spell.cure_class = atol(text);

    GetWindowText(GetDlgItem(hwnd, IDC_COST), text, 
sizeof(text));
    spell.cost = atol(text);

    GetWindowText(GetDlgItem(hwnd, IDC_DISTANCE), text, 
sizeof(text));
    g_spells[g_edit_spell].max_dist = (
float)atof(text);

    GetWindowText(GetDlgItem(hwnd, IDC_CHANCE), text, 
sizeof(text));
    spell.chance = atol(text);
    GetWindowText(GetDlgItem(hwnd, IDC_VALUE1), text, 
sizeof(text));
    spell.value[0] = (
float)atof(text);
    GetWindowText(GetDlgItem(hwnd, IDC_VALUE2), text, 
sizeof(text));
    spell.value[1] = (
float)atof(text);
    GetWindowText(GetDlgItem(hwnd, IDC_VALUE3), text, 
sizeof(text));
    spell.value[2] = (
float)atof(text);
    GetWindowText(GetDlgItem(hwnd, IDC_VALUE4), text, 
sizeof(text));
    spell.value[3] = (
float)atof(text);
    GetWindowText(GetDlgItem(hwnd, IDC_RANGE), text, 
sizeof(text));
    spell.range = (
float)atof(text);

    GetWindowText(GetDlgItem(hwnd, IDC_MESH1), text, 
sizeof(text));
    spell.mesh_index[0] = atol(text);
    GetWindowText(GetDlgItem(hwnd, IDC_SPEED1), text, 
sizeof(text));
    spell.mesh_speed[0] = (
float)atof(text);
    GetWindowText(GetDlgItem(hwnd, IDC_SOUND1), text, 
sizeof(text));
    spell.mesh_sound[0] = atol(text);

    GetWindowText(GetDlgItem(hwnd, IDC_MESH2), text, 
sizeof(text));
    spell.mesh_index[1] = atol(text);
    GetWindowText(GetDlgItem(hwnd, IDC_SPEED2), text, 
sizeof(text));
    spell.mesh_speed[1] = (
float)atof(text);
    GetWindowText(GetDlgItem(hwnd, IDC_SOUND2), text, 
sizeof(text));
    spell.mesh_sound[1] = atol(text);

    GetWindowText(GetDlgItem(hwnd, IDC_MESH3), text, 
sizeof(text));
    spell.mesh_index[2] = atol(text);
    GetWindowText(GetDlgItem(hwnd, IDC_SPEED3), text, 
sizeof(text));
    spell.mesh_speed[2] = (
float)atof(text);
    GetWindowText(GetDlgItem(hwnd, IDC_SOUND3), text, 
sizeof(text));
    spell.mesh_sound[2] = atol(text);

    
// Get selection entries

    
for(long i = 0; i < 8; i++) 
    {
      
if(SendMessage(GetDlgItem(hwnd, g_effects[i]), BM_GETCHECK, 0, 0)) 
      {
        spell.effect = i;
        
break;
      }
    }

    
for(long i = 0; i < 3; i++) 
    {
      
if(SendMessage(GetDlgItem(hwnd, g_targets[i]), BM_GETCHECK, 0, 0)) 
      {
        spell.target = i;
        
break;
      }
    }

    
for(long i = 0; i < 6; i++) 
    {
      
if(SendMessage(GetDlgItem(hwnd, g_positions[i]), BM_GETCHECK, 0, 0))
        spell.mesh_pos[0] = i;

      
if(SendMessage(GetDlgItem(hwnd, g_positions[i+6]), BM_GETCHECK, 0, 0))
        spell.mesh_pos[1] = i;

      
if(SendMessage(GetDlgItem(hwnd, g_positions[i+12]), BM_GETCHECK, 0, 0))
        spell.mesh_pos[2] = i;
    }

    
// Get loops
    spell.mesh_loop[0] = (BOOL) get_button_state(GetDlgItem(hwnd, g_loops[0]));        
    spell.mesh_loop[1] = (BOOL) get_button_state(GetDlgItem(hwnd, g_loops[1]));
    spell.mesh_loop[2] = (BOOL) get_button_state(GetDlgItem(hwnd, g_loops[2]));
}

//////////////////////////////////////////////////////////////////////////////////////////////

BOOL CALLBACK modify_dialog_proc(HWND hwnd, UINT msg, WPARAM word_param, LPARAM long_param)
{
    
switch(msg)
    {
    
case WM_INITDIALOG:
      {
        
// return an error if there is no spell to modify
        if(g_edit_spell >= MAX_SPELLS)
        {
            EndDialog(hwnd, FALSE);
            
return FALSE;
        }

        
char text[32];

        
// display spell number
        sprintf(text, "%lu", g_edit_spell);
        SetWindowText(GetDlgItem(hwnd, IDC_NUM), text);

        sSpell& spell = g_spells[g_edit_spell];

        
// Display text entries
        SetWindowText(GetDlgItem(hwnd, IDC_NAME), spell.name);
        SetWindowText(GetDlgItem(hwnd, IDC_DESCRIPTION), spell.desc);

        
// Display numerical entries
        sprintf(text, "%ld", spell.damage_class);
        SetWindowText(GetDlgItem(hwnd, IDC_DMGCLASS), text);
        sprintf(text, "%ld", spell.cure_class);
        SetWindowText(GetDlgItem(hwnd, IDC_CURECLASS), text);

        sprintf(text, "%lu", spell.cost);
        SetWindowText(GetDlgItem(hwnd, IDC_COST), text);

        sprintf(text, "%lf", spell.max_dist);
        SetWindowText(GetDlgItem(hwnd, IDC_DISTANCE), text);
        sprintf(text, "%lf", spell.range);
        SetWindowText(GetDlgItem(hwnd, IDC_RANGE), text);

        sprintf(text, "%lu", spell.chance);
        SetWindowText(GetDlgItem(hwnd, IDC_CHANCE), text);
        sprintf(text, "%lf", spell.value[0]);
        SetWindowText(GetDlgItem(hwnd, IDC_VALUE1), text);
        sprintf(text, "%lf", spell.value[1]);
        SetWindowText(GetDlgItem(hwnd, IDC_VALUE2), text);
        sprintf(text, "%lf", spell.value[2]);
        SetWindowText(GetDlgItem(hwnd, IDC_VALUE3), text);
        sprintf(text, "%lf", spell.value[3]);
        SetWindowText(GetDlgItem(hwnd, IDC_VALUE4), text);      

        sprintf(text, "%lu", spell.mesh_index[0]);
        SetWindowText(GetDlgItem(hwnd, IDC_MESH1), text);
        sprintf(text, "%lf", spell.mesh_speed[0]);
        SetWindowText(GetDlgItem(hwnd, IDC_SPEED1), text);
        sprintf(text, "%ld", spell.mesh_sound[0]);
        SetWindowText(GetDlgItem(hwnd, IDC_SOUND1), text);

        sprintf(text, "%lu", spell.mesh_index[1]);
        SetWindowText(GetDlgItem(hwnd, IDC_MESH2), text);
        sprintf(text, "%lf", spell.mesh_speed[1]);
        SetWindowText(GetDlgItem(hwnd, IDC_SPEED2), text);
        sprintf(text, "%ld", spell.mesh_sound[1]);
        SetWindowText(GetDlgItem(hwnd, IDC_SOUND2), text);

        sprintf(text, "%lu", spell.mesh_index[2]);
        SetWindowText(GetDlgItem(hwnd, IDC_MESH3), text);
        sprintf(text, "%lf", spell.mesh_speed[2]);
        SetWindowText(GetDlgItem(hwnd, IDC_SPEED3), text);
        sprintf(text, "%ld", spell.mesh_sound[2]);
        SetWindowText(GetDlgItem(hwnd, IDC_SOUND3), text);

        
// Display selection entries
        set_button_state(GetDlgItem(hwnd, g_effects[spell.effect]), TRUE);
        set_button_state(GetDlgItem(hwnd, g_targets[spell.target]), TRUE);
        set_button_state(GetDlgItem(hwnd, g_positions[spell.mesh_pos[0]]), TRUE);
        set_button_state(GetDlgItem(hwnd, g_positions[spell.mesh_pos[1]+6]), TRUE);
        set_button_state(GetDlgItem(hwnd, g_positions[spell.mesh_pos[2]+12]), TRUE);
                
        
// Display loops
        set_button_state(GetDlgItem(hwnd, g_loops[0]), spell.mesh_loop[0]);
        set_button_state(GetDlgItem(hwnd, g_loops[1]), spell.mesh_loop[1]);
        set_button_state(GetDlgItem(hwnd, g_loops[2]), spell.mesh_loop[2]);
    
        
return TRUE;
      }

    
case WM_COMMAND:
        
switch(LOWORD(word_param))
        {
        
case IDC_OK:
            update_entry(hwnd, g_edit_spell);
            EndDialog(hwnd, TRUE);
            
return TRUE;

        
case IDC_CANCEL:
            EndDialog(hwnd, FALSE);
            
return TRUE;
        }

        
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 msl file
            new_msl();
            
break;

        
case IDC_LOAD:  // load a msl file
            load_msl();
            
break;

        
case IDC_SAVE:  // save a msl file
            save_msl();
            
break;

        
case IDC_CLEAR: // clear an entry          
            listbox = GetDlgItem(g_hwnd, IDC_SPELLS);

            
// see if a spell was selected
            if((sel = (int)get_listbox_cur_sel(listbox)) == LB_ERR)
                
break;
            
            ZeroMemory(&g_spells[sel], 
sizeof(sSpell));
            reset_spell(g_spells[sel]);

            delete_listbox_string(listbox, sel);
            sprintf(text, "%5lu:", sel);
            insert_string_to_listbox(listbox, sel, text);
            
break;

        
case IDC_SPELLS:    // edit an entry
            if(HIWORD(word_param) != LBN_DBLCLK)
                
break;
        
case IDC_EDIT:
            listbox = GetDlgItem(hwnd, IDC_SPELLS);

            
// see if a spell was selected
            if((sel = (int)get_listbox_cur_sel(listbox)) == LB_ERR)
                
break;

            g_edit_spell = sel;

            DialogBox(NULL, MAKEINTRESOURCE(IDD_MODIFY), hwnd, modify_dialog_proc);

            
// update spell
            delete_listbox_string(listbox, sel);
            sprintf(text, "%5lu: %s", sel, g_spells[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;

        
// Set default MSL filename
        strcpy(g_mls_file, "..\\Data\\Default.MSL");

        
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 = "MSLEDIT";

    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 spells from default.MSL
    load_spells("..\\Data\\Default.MSL");

    MSG Msg;

    
while(GetMessage(&Msg, NULL, 0, 0)) 
    {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
    }

    UnregisterClass(class_name, inst);

    
return 0;
}
 

posted on 2007-11-16 17:57 lovedday 阅读(432) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


公告

导航

统计

常用链接

随笔分类(178)

3D游戏编程相关链接

搜索

最新评论