void HandleExitTiles() { // This function handles our exit setting on the destination map. If the // exit map (destination map) isn't open, then we want to get the name of // the map to open from the user. We check to see if it's valid, and if // it's not, we need to delete all the exits on the main map since they // are invalid. If it is valid, then we want to load the destination map // so that they user can choose the spot where the player will end up on // the other map. If the exit map is already open and this function is // called, we want to go through all the exits we set and fill in their // destination information. This function is thus called twice, when we // want to load the destination map, and after we are finished placing exits. // If we don't have the exit map open if(!g_bExitMapOpen) { char szExitFile[255] = {0}; // Bring up the open dialog box and get a map to exit to if(GetExitFileName(szExitFile)) { g_ExitMap.Load(szExitFile); // Open the map to exit to g_bExitMapOpen = true; // State that we now have the exit map open g_pCurrentMap = &g_ExitMap; // Set the current map to our exit map g_pCurrentMap->SetCurrentType(EXIT_TYPE); // Set the current type to the exit type } else // If the file is invalid, delete the exits g_pCurrentMap->DeleteBlankExits(); } else // If we already have the exit map open { // Get the size of the current exit list and get the last exit tile in the list. // In other words, get the last tile we just placed on the exit map. int size = g_ExitMap.GetCurrentListSize(); CExit *pExit = (CExit*)g_ExitMap.GetCurrentListTile(size - 1); // Set the exits we just placed on the main map with the // new destination info (name, position, etc...) g_Map.SetExits(g_ExitMap.GetMapName(), pExit); // Restore the current map to our normal map we were working with g_pCurrentMap = &g_Map; g_bExitMapOpen = false; } }
void HandleMenu(int menuID) { if(menuID == ID_FILE_QUIT) // If the user chose File->Quit { PostQuitMessage(0); // Quit the program } //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// else if(menuID == ID_FILE_OPENUP) // If the user chose File->Open { // Have windows bring up the Open File dialog box and Load the file chosen if(GetOpenFileName(&g_OpenInfo)) g_Map.Load(g_OpenInfo.lpstrFile); } else if(menuID == ID_FILE_SAVEIT) // If the user chose File->Save { // If we have a n valid name for our map already, do a normal save if(strlen(g_Map.GetMapName()) > 3) g_Map.Save(g_Map.GetMapName()); else { // If haven't given our map a name yet, do a "SaveAs" and bring up the save dlg box if(GetSaveFileName(&g_OpenInfo)) g_Map.Save(g_OpenInfo.lpstrFile); } } else if(menuID == ID_FILE_SAVEAS) // If the user chose File->SaveAs { // Bring up the save dlg box and allow the user to type in a new map name and save it if(GetSaveFileName(&g_OpenInfo)) g_Map.Save(g_OpenInfo.lpstrFile); } //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// else if(menuID == ID_FILE_RESET) // If the user chose File->Reset g_Map.SetDefault(); // Destroy all the tiles on the map and start over else if(menuID == ID_TILES_TILES) // If the user chose Tiles->Tiles g_Map.SetCurrentType(TILE_TYPE); // Set the tool bar tile type to tiles else if(menuID == ID_TILES_ITEMS) // If the user chose Tiles->Items g_Map.SetCurrentType(ITEM_TYPE); // Set the tool bar tile type to items else if(menuID == ID_TILES_MONSTERS) // If the user chose Tiles->Monsters g_Map.SetCurrentType(MONSTER_TYPE); // Set the tool bar tile type to monsters else if(menuID == ID_TILES_CITIZENS) // If the user chose Tiles->Citizens g_Map.SetCurrentType(NPC_TYPE); // Set the tool bar tile type to citizens else if(menuID == ID_TILES_EXITS) // If the user chose Tiles->Exits g_Map.SetCurrentType(EXIT_TYPE); // Set the tool bar tile type to exits (no tiles of course) else if(menuID == ID_HELP_ABOUT) // If the user chose Help->About // Instead of creating a help dialog box, we can just use a simple system MessageBox() call MessageBox(g_hWnd, "www.GameTutorials.com Map Editor\n\n" "\t- Choose the desired tile type from the Tiles menu,\n" "\t then click on a tile in the tile window. You can\n" "\t then draw the tiles on the map with the left mouse button.\n\n" "\t- Right click to remove the current cursor tile.\n\n" "\t- To delete a item:monster:citizen:exit, make sure you choose\n" "\t that type from the menu, then right click on the tile.\n\n" "\t- When setting an exit you can hold down shift to place more exits.\n" "\t Once you place an exit without holding the shift key you will be\n" "\t prompted to choose the destination map. Then place one tile for\n" "\t the position where the character will end up.\n\n" "\t- Hit Esc to quit the program.", "About", MB_OK | MB_ICONINFORMATION); // Over assuming that a tile type was changed, reset the scroll bar size. // The -1 is because the tool bar window's title size offsets it a bit (being smaller). g_ScrollInfo.nMax = g_Map.GetCurrentTypeSize() - MAP_HEIGHT - 1; // If there isn't enough (or any) tiles to fill up the tool bar window, disable the scroll bar if(g_ScrollInfo.nMax < 0) { g_ScrollInfo.nMax = 0; EnableScrollBar(g_hWndTool, SB_VERT, ESB_DISABLE_BOTH); } else EnableScrollBar(g_hWndTool, SB_VERT, ESB_ENABLE_BOTH); // Enable the scroll bar if it's needed // Reset the scroll bar info g_scrollBarPosY = 0; g_ScrollInfo.nPage = 0; // Update the current scroll bar information with no need to redraw (FALSE) SetScrollInfo(g_hWndTool, SB_VERT, &g_ScrollInfo, FALSE); ShowScrollBar(g_hWndTool, SB_VERT, TRUE); // If we chose a tile type, put a check box next to it switch(menuID) { case ID_TILES_TILES: case ID_TILES_ITEMS: case ID_TILES_MONSTERS: case ID_TILES_CITIZENS: case ID_TILES_EXITS: g_pCursorTile = NULL; CheckTileType(menuID); break; } }