Example #1
0
//DialogSetTextClr (dialog dlg, int r, int g, int b)
//set dialog text color
PROTECTED long S_DialogSetTextClr(void *owner, void *handle, int msg, WPARAM wparam, LPARAM lparam)
{
	hPARAM param;
	hFUNC func = (hFUNC)handle; assert(func);

	switch(msg)
	{
	case FUNC_CREATE:
		break;
	case FUNC_CALL:
		{
			param = (hPARAM)wparam;

			GameDialog *pDlg;
			int r,g,b;

			pDlg = (GameDialog *)IDPageQuery(*(Id*)ScriptParamGetVar(param, 0));

			r = *(int *)ScriptParamGetVar(param, 1);
			g = *(int *)ScriptParamGetVar(param, 2);
			b = *(int *)ScriptParamGetVar(param, 3);

			if(pDlg)
				pDlg->SetStringClr(r,g,b);
		}
		return FUNCRET_DONE;

	case FUNC_DESTROY:
		break;
	}

	return RETCODE_SUCCESS;
}
Example #2
0
void MainWindow::newGame() {
	GameDialog gameDialog;
	if(gameDialog.exec() == QDialog::Accepted) { 
		game::ptr game(new aw::game());

		game->set_funds_per_building(gameDialog.fundsPerBuilding());
		game->set_initial_funds(gameDialog.initialFunds());

		game->load_map(gameDialog.mapFile());


		gameController = game_controller::ptr(new game_controller);

		graphicsScene->reset();
		graphicsScene->signalClicked().connect(boost::bind(&aw::game_controller::click, gameController, _1, _2));
		graphicsScene->signalFocusChanged().connect(boost::bind(&aw::game_controller::mouse_hover_changed, gameController, _1));
		gameController->signal_scene_change().connect(boost::bind(&GameScene::setScene, graphicsScene, _1));

		//Connect the menu-callbacks
		gameController->signal_show_unit_action_menu().connect(boost::bind(&UnitActionMenu::showActionMenu, this, _1));
		gameController->signal_show_buy_menu().connect(boost::bind(&BuyMenu::showBuyMenu, this, _2, _1));
		gameController->signal_show_unload_menu().connect(boost::bind(&UnitUnloadMenu::showUnloadMenu, this, _1));

		//Connect callbacks like game-won etc.
		game->signal_game_finished().connect(boost::bind(&MainWindow::gameFinished, this, _1));

		actionEndTurn->setEnabled(true);

		gameController->start_game(game);
		mapView->setEnabled(true);
	}
}
Example #3
0
 bool GameDialog::showOpenDocumentDialog(wxWindow* parent, String& gameName, Model::MapFormat::Type& mapFormat) {
     GameDialog dialog;
     dialog.createDialog(parent, "Select Game", "TrenchBroom was unable to detect the game for the map document. Please choose a game in the game list and click OK.");
     if (dialog.ShowModal() != wxID_OK)
         return false;
     gameName = dialog.selectedGameName();
     mapFormat = dialog.selectedMapFormat();
     return true;        }
Example #4
0
 bool GameDialog::showNewDocumentDialog(wxWindow* parent, String& gameName, Model::MapFormat::Type& mapFormat) {
     GameDialog dialog;
     dialog.createDialog(parent, "Select Game", "Select a game from the list on the right, then click OK. Once the new document is created, you can set up mod directories, entity definitions and textures by going to the map inspector, the entity inspector and the face inspector, respectively.");
     if (dialog.ShowModal() != wxID_OK)
         return false;
     gameName = dialog.selectedGameName();
     mapFormat = dialog.selectedMapFormat();
     return true;
 }
Example #5
0
MatchRequest * NetworkConnection::getAndCloseGameDialog(const PlayerListing * opponent)
{
	GameDialog * gd = getIfGameDialog(opponent);
	MatchRequest * new_mr = 0;
	if(gd)
	{
		MatchRequest * mr = gd->getMatchRequest();
		new_mr = new MatchRequest(*mr);
		closeGameDialog(opponent);
	}
	else
        qDebug("Couldn't find gamedialog for opponent: %s", opponent->name.toLatin1().constData());
	return new_mr;
}
Example #6
0
//DialogSetText (dialog dlg, string text)
//set dialog text
PROTECTED long S_DialogSetText(void *owner, void *handle, int msg, WPARAM wparam, LPARAM lparam)
{
	hPARAM param;
	hFUNC func = (hFUNC)handle; assert(func);

	int *pIDat = (int *)ScriptFuncGetData(func);

	switch(msg)
	{
	case FUNC_CREATE:
		pIDat = new int;
		*pIDat = 0;
		ScriptFuncSetData(func, pIDat);
		break;
	case FUNC_CALL:
		{
			param = (hPARAM)wparam;

			GameDialog *pDlg;
			char *str;

			pDlg = (GameDialog *)IDPageQuery(*(Id*)ScriptParamGetVar(param, 0));

			if(*pIDat == 0)
			{
				if(ScriptParamGetType(param, 1) == eVarPtr)
					str = (char *)((string *)ScriptParamGetVar(param, 1))->c_str();
				else
					str = (char *)ScriptParamGetVar(param, 1);

				if(pDlg)
				{
					pDlg->SetString(str);
					*pIDat = 1;
				}
			}
			else if(pDlg->IsTextComplete())
				return FUNCRET_DONE;
		}
		return FUNCRET_NOTDONE;

	case FUNC_DESTROY:
		if(pIDat)
			delete pIDat;
		break;
	}

	return RETCODE_SUCCESS;
}
Example #7
0
//DialogSetFont (dialog dlg, string typeName, int size, int fmtFlag)
//set the dialog font
PROTECTED long S_DialogSetFont(void *owner, void *handle, int msg, WPARAM wparam, LPARAM lparam)
{
	hPARAM param;
	hFUNC func = (hFUNC)handle; assert(func);

	switch(msg)
	{
	case FUNC_CREATE:
		break;
	case FUNC_CALL:
		{
			param = (hPARAM)wparam;

			GameDialog *pDlg;
			char *typeStr;
			float size;
			int fmtFlag;

			pDlg = (GameDialog *)IDPageQuery(*(Id*)ScriptParamGetVar(param, 0));
				
			if(ScriptParamGetType(param, 1) == eVarPtr)
				typeStr = (char *)((string *)ScriptParamGetVar(param, 1))->c_str();
			else
				typeStr = (char *)ScriptParamGetVar(param, 1);

			size = *(float *)ScriptParamGetVar(param, 2);

			fmtFlag = *(int *)ScriptParamGetVar(param, 3);

			if(pDlg)
				pDlg->SetFont(typeStr, size, fmtFlag);
		}
		return FUNCRET_DONE;

	case FUNC_DESTROY:
		break;
	}

	return RETCODE_SUCCESS;
}
Example #8
0
//DialogOpen (dialog dlg, int bOpen)
//open/close dialog (bOpen == 0 close, 1 open)
PROTECTED long S_DialogOpen(void *owner, void *handle, int msg, WPARAM wparam, LPARAM lparam)
{
	hPARAM param;
	hFUNC func = (hFUNC)handle; assert(func);

	switch(msg)
	{
	case FUNC_CREATE:
		break;
	case FUNC_CALL:
		{
			param = (hPARAM)wparam;

			GameDialog *pDlg;
			int bOpen;

			pDlg = (GameDialog *)IDPageQuery(*(Id*)ScriptParamGetVar(param, 0));

			bOpen = *(int *)ScriptParamGetVar(param, 1);

			if(pDlg)
			{
				if(bOpen)
					pDlg->Open();
				else
					pDlg->Close();
			}
		}
		return FUNCRET_DONE;

	case FUNC_DESTROY:
		break;
	}

	return RETCODE_SUCCESS;
}
Example #9
0
/** \brief Initialize the game core.
 *
 *  Initialize SDL, load required files, start the main game loop.
 */
int GameCore::Init(int w, int h) {
    bool Escape = false;
    width = w; height = h;
    if (SDL_Init(SDL_INIT_EVERYTHING) == -1) return 1;

    // TODO: This might need to be changed to SDL_SWSURFACE for speed.
    screen = SDL_SetVideoMode(w, h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL) return 1;

    SDL_WM_SetCaption("The Adventures Of Knil", NULL);

    GameDraw::screen = screen;

    ga.Init();
    ga.PlayMusic("Sounds/Tank Battle.mp3");

    GamePlayer gp;
    gp.loadKCA("CharAnis\\modernbody.kca");
    gp.setPos(368, 528);
    GameDialog dialog;
    // Test load a map
    gm.Init(&gp, &dialog);
    if (!gm.LoadMap("Maps\\HouseMap.map")) {
        return ErrorScreen();
    }
    gm.drawMap();

    while (!quit) {
        // Update GameInput. Check if we should quit.
        gi.Update();
        if (gi.GetKeyState(SDLK_ESCAPE)) {
            if (!Escape && dialog.isActive()) {
                Escape = true;
                dialog.Close();
            }
        } else {
            Escape = false;
        }
        if (gi.GetQuit() || (gi.GetKeyState(SDLK_ESCAPE) && !Escape)) {
            quit = true;
            break;
        }

        if (!dialog.isActive() && gi.GetKeyState(SDLK_F1)) {
            dialog.clearPages();
            dialog.addPage(HELPTEXT1);
            dialog.addPage(HELPTEXT2);
            dialog.addPage(HELPTEXT3);
            dialog.addPage(HELPTEXT4);
            dialog.ShowPage(0);
        }

        // Calculate FPS and frame time
        int dt = CalcFPS();

        gp.tick(dt);
        if (!dialog.isActive())
            gp.handleInput(&gi, &gm);
        gm.handleInput(&gi);
        gm.runScripts(dt);
        dialog.handleInput(&gi);

        // Move screen with player
        if (gp.getX() > (width / 2)) {
            mapOffX = gp.getX() - (width / 2);
            if ((mapOffX + width) > (gm.GetWidth() * 16) ) {
                mapOffX = gm.GetWidth() * 16 - width;
            }
        } else
            mapOffX = 0;
        if (gp.getY() > (height / 2)) {
            mapOffY = gp.getY() - (height / 2);
            if ((mapOffY + height) > (gm.GetHeight() * 16) ) {
                mapOffY = gm.GetHeight() * 16 - height;
            }
        } else
            mapOffY = 0;

        SDL_Rect clip;
        clip.x = mapOffX;
        clip.y = mapOffY;
        clip.w = width;
        clip.h = height;

        GameDraw::SurfaceClear(screen, SDL_MapRGB(screen->format, 0, 0, 0));

        GameDraw::RenderToSurface(0, 0, gm.GetMapBottom(), screen, &clip);
        // Render NPCs on Layer 0
        vector<GameNPC*>* mapNPC = gm.getNPCList();
        for (unsigned int i = 0; i < mapNPC->size(); i++) {
            if (mapNPC->at(i)->GetLayer()) continue;
            if (!mapNPC->at(i)->GetSurface()) continue;
            SDL_Rect r = mapNPC->at(i)->GetBlock();
            r.x -= mapOffX; r.y -= mapOffY;
            int npcx = mapNPC->at(i)->GetX() - mapOffX;
            int npcy = mapNPC->at(i)->GetY() - mapOffY;
            GameDraw::RenderToSurface(npcx, npcy, mapNPC->at(i)->GetSurface(), screen, &mapNPC->at(i)->GetSurface()->clip_rect);
        }

        // Render Player
        GameDraw::RenderToSurface(gp.getX() - mapOffX, gp.getY() - mapOffY, gp.getSurface(), screen, &gp.getSurface()->clip_rect);

        // Render NPCs on Layer != 0
        for (unsigned int i = 0; i < mapNPC->size(); i++) {
            if (!mapNPC->at(i)->GetLayer()) continue;
            if (!mapNPC->at(i)->GetSurface()) continue;
            SDL_Rect r = mapNPC->at(i)->GetBlock();
            r.x -= mapOffX; r.y -= mapOffY;
            int npcx = mapNPC->at(i)->GetX() - mapOffX;
            int npcy = mapNPC->at(i)->GetY() - mapOffY;
            GameDraw::RenderToSurface(npcx, npcy, mapNPC->at(i)->GetSurface(), screen, &mapNPC->at(i)->GetSurface()->clip_rect);
        }

        // If there is an active dialog, draw it in the middle of the screen, at the bottom.
        if (dialog.isActive())
            GameDraw::RenderToSurface(width / 2 - GameDialog::DIALOGWIDTH / 2, height - GameDialog::DIALOGHEIGHT - 30, dialog.getSurface(), screen, &dialog.getSurface()->clip_rect);
        GameDraw::FlipToScreen(screen);
    }

    return 0;
}