コード例 #1
0
ファイル: Main.cpp プロジェクト: Ramon-Wong/tutorials
void LoadOrSaveAMap(bool bLoad)
{
    string strMapName = "";		// Create a STL string to read in the input from the user
    char szName[255] = {0};		// Create a traditional string of characters for the file name

    // In this function we setup a prompt for the user to type in the file name to
    // either save or load.  If you want to load a file, you pass in "true", otherwise
    // we use "false" to indicate that we want to save a file.  This cuts down on code
    // since a lot of the code is the same for each action.  This function doesn't
    // actually do the saving and loading code, but handles the input from the user.
    // The save and load code is in our CMap::Load() and CMap::Save() functions that
    // we call from here.

    // Get an output handle for the console window and set the cursor position for a prompt
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOutput, g_promptPos);

    // To clear the prompt, we just print out a bunch of tabs and then reset the cursor position
    cout << "\t\t\t\t\t\t\t\t\t\t";
    SetConsoleCursorPosition(hOutput, g_promptPos);

    // Get an input handle and set the console window to allow input from the user
    // and echo it to the screen.  This is important.  If you don't set this mode,
    // the user won't see what they are typing.
    HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
    SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);

    // Below we check if we want to load or save a file, then display the appropriate message
    if(bLoad)
        cout << "Enter a map to Load: ";
    else
        cout << "Enter a map to Save: ";

    // Here we get the map name that we want to save or load
    cin >> strMapName;

    // Then we extract the string from the string class and put it in a normal array or characters
    strcpy(szName, strMapName.c_str());

    // Next we either load or save the map entered by the user, depending on bLoad
    if(bLoad)
        g_Map.Load(szName);
    else
        g_Map.Save(szName);

    // Next, we restore the console mode for getting mouse and keyboard input and redraw the screen
    SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
    g_Map.Draw();
}
コード例 #2
0
ファイル: Main.cpp プロジェクト: 88er/tutorials
void LoadOrSaveAMap(bool bLoad)
{
	string strMapName = "";		// Create a STL string to read in the input from the user
	char szName[255] = {0};		// Create a traditional string of characters for the file name

	// Get an output handle for the console window and set the cursor position for a prompt
	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOutput, g_promptPos);

	// To clear the prompt, we just print out a bunch of tabs and then reset the cursor position
	cout << "\t\t\t\t\t\t\t\t\t\t";
	SetConsoleCursorPosition(hOutput, g_promptPos);

	// Get an input handle and set the console window to allow input from the user 
	HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);			
	SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);

	// Below we check if we want to load or save a file, then display the appropriate message
	if(bLoad)
		cout << "Enter a map to Load: ";
	else
		cout << "Enter a map to Save: ";

	// Here we get the map name that we want to save or load
	cin >> strMapName;

	// Then we extract the string from the string class and put it in a normal array or characters
	strcpy(szName, strMapName.c_str());

	// Next we either load or save the map entered by the user, depending on bLoad
	if(bLoad)
		g_Map.Load(szName);
	else
		g_Map.Save(szName);

	// Next, we restore the console mode for getting mouse and keyboard input and redraw the screen
	SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
	g_Map.Draw();	
}
コード例 #3
0
ファイル: Main.cpp プロジェクト: Allenjonesing/tutorials
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;
	}
}