⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winmain.cpp

📁 用DirectX编写RPG游戏-Programming.Role.Playing.Games.with.DirectX
💻 CPP
📖 第 1 页 / 共 2 页
字号:

      // Display spell list
      SendMessage(GetDlgItem(hWnd, IDC_SPELLS), LB_RESETCONTENT, 0, 0);
      for(i=0;i<64;i++) {
        sprintf(Text, "%5lu", i);
        SendMessage(GetDlgItem(hWnd, IDC_SPELLS), LB_INSERTSTRING, i, (LPARAM)Text);

        if(i < 32) {
          if(g_Characters[g_EditCharacter].MagicSpells[0] & (1<<i))
            SendMessage(GetDlgItem(hWnd, IDC_SPELLS), LB_SETSEL, TRUE, i);
        } else {
          if(g_Characters[g_EditCharacter].MagicSpells[1] & (1<<(i-32)))
            SendMessage(GetDlgItem(hWnd, IDC_SPELLS), LB_SETSEL, TRUE, i);
        }
      }

      return TRUE;

    case WM_COMMAND:
      switch(LOWORD(wParam)) {
        case IDC_OK: 
          UpdateEntry(hWnd, g_EditCharacter);
          EndDialog(hWnd, TRUE);
          return TRUE;

        case IDC_CANCEL: 
          EndDialog(hWnd, FALSE);
          return TRUE;

        case IDC_SETALL:
          for(i=0;i<64;i++)
            SendMessage(GetDlgItem(hWnd, IDC_SPELLS), LB_SETSEL, TRUE, i);
          break;

        case IDC_CLEARALL:
          for(i=0;i<64;i++)
            SendMessage(GetDlgItem(hWnd, IDC_SPELLS), LB_SETSEL, FALSE, i);
          break;
      }
      break;
  }

  return FALSE;
}

BOOL UpdateEntry(HWND hWnd, long CharNum)
{
  char Text[32];
  long i;

  // Get text entries
  GetWindowText(GetDlgItem(hWnd, IDC_NAME), g_Characters[CharNum].Name, 32);
  GetWindowText(GetDlgItem(hWnd, IDC_ITEM), g_Characters[CharNum].ItemFilename, MAX_PATH);

  // Get numerical entries
  GetWindowText(GetDlgItem(hWnd, IDC_CLASS),      Text, 32);
  g_Characters[CharNum].Class = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_HEALTH),     Text, 32);
  g_Characters[CharNum].HealthPoints = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_MANA),       Text, 32);
  g_Characters[CharNum].ManaPoints = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_LEVEL),      Text, 32);
  g_Characters[CharNum].Level = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_EXPERIENCE), Text, 32);
  g_Characters[CharNum].Experience = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_MONEY),      Text, 32);
  g_Characters[CharNum].Money = atol(Text);

  GetWindowText(GetDlgItem(hWnd, IDC_ATTACK),     Text, 32);
  g_Characters[CharNum].Attack = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_DEFENSE),    Text, 32);
  g_Characters[CharNum].Defense = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_AGILITY),    Text, 32);
  g_Characters[CharNum].Agility = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_RESISTANCE), Text, 32);
  g_Characters[CharNum].Resistance = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_MENTAL),     Text, 32);
  g_Characters[CharNum].Mental = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_TOHIT),      Text, 32);
  g_Characters[CharNum].ToHit = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_SPEED),      Text, 32);
  g_Characters[CharNum].Speed = (float)atof(Text);

  GetWindowText(GetDlgItem(hWnd, IDC_RANGE),     Text, 32);
  g_Characters[CharNum].Range = (float)atof(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_CHARGE),     Text, 32);
  g_Characters[CharNum].ChargeRate = (float)atof(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_TOATTACK),   Text, 32);
  g_Characters[CharNum].ToAttack = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_TOMAGIC),    Text, 32);
  g_Characters[CharNum].ToMagic = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_DROPITEM),   Text, 32);
  g_Characters[CharNum].DropItem = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_TODROP),     Text, 32);
  g_Characters[CharNum].DropChance = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_TOEFFECT),   Text, 32);
  g_Characters[CharNum].EffectChance = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_EFFECT),     Text, 32);
  g_Characters[CharNum].Effects = atol(Text);

  GetWindowText(GetDlgItem(hWnd, IDC_MESH),       Text, 32);
  g_Characters[CharNum].MeshNum = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_WEAPON),     Text, 32);
  g_Characters[CharNum].Weapon = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_ARMOR),      Text, 32);
  g_Characters[CharNum].Armor = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_SHIELD),     Text, 32);
  g_Characters[CharNum].Shield = atol(Text);
  GetWindowText(GetDlgItem(hWnd, IDC_ACCESSORY),  Text, 32);
  g_Characters[CharNum].Accessory = atol(Text);

  // Get spell list
  g_Characters[CharNum].MagicSpells[0] = 0;
  g_Characters[CharNum].MagicSpells[1] = 0;
  for(i=0;i<64;i++) {
    if(SendMessage(GetDlgItem(hWnd, IDC_SPELLS), LB_GETSEL, i, 0) == TRUE) {
      if(i < 32)
        g_Characters[CharNum].MagicSpells[0] |= (1<<i);
      else
        g_Characters[CharNum].MagicSpells[1] |= (1<<(i-32));
    }
  }

  return TRUE;
}

BOOL LoadCharacters(char *Filename)
{
  FILE *fp;
  long i;
  char Text[256];

  // Clear item structures
  for(i=0;i<256;i++) {
    ZeroMemory(&g_Characters[i], sizeof(sCharacterDefinition));
    g_Characters[i].Weapon    = -1;
    g_Characters[i].Armor     = -1;
    g_Characters[i].Shield    = -1;
    g_Characters[i].Accessory = -1;
  }

  // Open the file
  if((fp=fopen(Filename, "rb")) != NULL) {

    // Read in all Characters
    for(i=0;i<256;i++)
      fread(&g_Characters[i], 1, sizeof(sCharacterDefinition), fp);

    // Close file 
    fclose(fp);
  }

  // Update characters list box
  SendMessage(GetDlgItem(g_hWnd, IDC_CHARACTERS), LB_RESETCONTENT, 0, 0);
  for(i=0;i<256;i++) {
    sprintf(Text, "%5lu: %s", i, g_Characters[i].Name);
    SendMessage(GetDlgItem(g_hWnd, IDC_CHARACTERS), LB_INSERTSTRING, i, (LPARAM)Text);
  }

  return TRUE;
}

BOOL NewMCL()
{
  char Buf[16];

  if(MessageBox(g_hWnd, "Are you sure? (Looses any unsaved MCL information)", "New MCL", MB_YESNO) == IDYES) {
    SendMessage(GetDlgItem(g_hWnd, IDC_CHARACTERS), LB_RESETCONTENT, 0, 0);
    for(long i=0;i<256;i++) {
      ZeroMemory(&g_Characters[i], sizeof(sCharacterDefinition));
      g_Characters[i].Weapon    = -1;
      g_Characters[i].Armor     = -1;
      g_Characters[i].Shield    = -1;
      g_Characters[i].Accessory = -1;

      sprintf(Buf, "%5lu:", i);
      SendMessage(GetDlgItem(g_hWnd, IDC_CHARACTERS), LB_INSERTSTRING, i, (LPARAM)Buf);
    }
    return TRUE;
  }

  return FALSE;
}

BOOL LoadMCL()
{
  // Setup the open dialog info
  g_ofn.hwndOwner   = g_hWnd;
  g_ofn.lpstrFile   = g_MCLFile;
  g_ofn.lpstrTitle  = "Load MCL File";
  g_ofn.lpstrFilter = "MCL Character Files (*.MCL)\0*.MCL\0All Files (*.*)\0*.*\0\0";
  g_ofn.lpstrDefExt = "MCL";

  // Ask for filename
  if(!GetOpenFileName(&g_ofn))
    return FALSE;

  // Load the file and return result
  if(LoadCharacters(g_MCLFile) == FALSE) {
    MessageBox(g_hWnd, g_MCLFile, "Unable to open file.", MB_OK);
    return FALSE;
  }

  return TRUE;
}

BOOL SaveMCL()
{
  FILE *fp;
  long i;

  // Setup the open dialog info
  g_ofn.hwndOwner   = g_hWnd;
  g_ofn.lpstrFile   = g_MCLFile;
  g_ofn.lpstrTitle  = "Load MCL File";
  g_ofn.lpstrFilter = "MCL Character Files (*.MCL)\0*.MCL\0All Files (*.*)\0*.*\0\0";
  g_ofn.lpstrDefExt = "MCL";

  // Ask for filename
  if(!GetSaveFileName(&g_ofn))
    return FALSE;

  // Open filename for saving
  if((fp=fopen(g_MCLFile, "wb")) == NULL)
    return FALSE;

  // Save all objects
  for(i=0;i<256;i++)
    fwrite(&g_Characters[i], 1, sizeof(sCharacterDefinition), fp);

  // Close file and return success
  fclose(fp);
  
  return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -