コード例 #1
0
/**
 * Draw the list, start from startId, until the max icons in the list to be drawn.
 *
 * @param startId
 */
void cBuildingListDrawer::drawList(cBuildingList *list, int listIDToDraw, int startId, bool shouldDrawStructureSize) {
	// starting draw coordinates
	int iDrawX=getDrawX();
	int iDrawY=getDrawY();

	int maxYClip = maxListYCoordinate;
	int minYClip = 45;
	int minXClip = game.screen_x - 69;
	int maxXClip = game.screen_x;
	set_clip_rect(bmp_screen, minXClip, minYClip, maxXClip, maxYClip);

	int end = startId + maximumItemsToDraw; // max 5 icons are showed at once

	// is building an item in the list?
	bool isBuildingItemInList = list->isBuildingItem();

	// draw the icons
	for (int i = startId; i < end; i++) {
		cBuildingListItem * item = list->getItem(i);

		if (item == NULL) {
			break; // stop. List became empty.
		}

		int iDrawXEnd = iDrawX + 63;
		int iDrawYEnd = iDrawY + 47;

		// icon id must be set , assert it.
		assert(item->getIconId() > -1);

		rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(255, 255, 255));
		line(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(255, 255, 255));

		draw_sprite(bmp_screen, (BITMAP *)gfxinter[item->getIconId()].dat, iDrawX, iDrawY);

		if (shouldDrawStructureSize) {
			drawStructureSize(item->getBuildId(), iDrawX, iDrawY);
		}

		bool cannotPayIt = item->getBuildCost() > player[HUMAN].credits;

		// when this item is being built.
		if (item->isBuilding()) {
			int iTotalBuildPoints = 0;

			// get the total build time
			if (listIDToDraw == LIST_CONSTYARD) {
				iTotalBuildPoints = structures[item->getBuildId()].build_time;
			}
			else if (listIDToDraw != LIST_STARPORT) {
				iTotalBuildPoints = units[item->getBuildId()].build_time;
			}

			// Now calculate the right frame.
			float iPiece = iTotalBuildPoints / 31; // = 17 - 1 (of above)

			if (iPiece < 0.1) {
				iPiece = 0.1;
			}

			int iFrame = health_bar(31, item->getProgress(), iTotalBuildPoints);

			if (iFrame > 31) {
				iFrame = 31;
			}

			if (item->getProgress() < iTotalBuildPoints) {
				// draw the other progress stuff
				set_trans_blender(0, 0, 0, 128);
				draw_trans_sprite(bmp_screen, (BITMAP *)gfxinter[PROGRESSFIX].dat, iDrawX+2, iDrawY+2);
				draw_trans_sprite(bmp_screen, (BITMAP *)gfxinter[PROGRESS001+iFrame].dat, iDrawX+2, iDrawY+2);

			} else {
				// draw 'ready' text when done building.
				if (listIDToDraw == LIST_CONSTYARD) {
					draw_sprite(bmp_screen, (BITMAP *)gfxinter[READY01].dat, iDrawX+3, iDrawY+16);
				}
			}
		} else {
			// this item is not being built. So we do not draw a progress indicator.
			// however, it could be that an other item is being built.

			// draw the item 'unavailable' when:
			// - is not available (doh)
			// - we cant pay it
			// - some other item is being built
			// - list is being upgraded, so you cannot build items
			 /*|| cannotPayIt*/
			if (!item->isAvailable() || isBuildingItemInList || list->isUpgrading() || !list->isAcceptsOrders()) {
				set_trans_blender(0,0,0,128);
				fblend_trans((BITMAP *)gfxinter[PROGRESSNA].dat, bmp_screen, iDrawX, iDrawY, 64);
			}

			if (list->getType() == LIST_STARPORT) {
				if (cannotPayIt) {
					set_trans_blender(0,0,0,128);
					fblend_trans((BITMAP *)gfxinter[PROGRESSNA].dat, bmp_screen, iDrawX, iDrawY, 64);
					rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(game.fade_select, 0, 0));
					line(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(game.fade_select, 0, 0));
					line(bmp_screen, iDrawX, iDrawY+47, iDrawX+63, iDrawY, makecol(game.fade_select, 0, 0));
					set_trans_blender(0,0,0,128);
				}
			}

			// last built id
			if (list->getLastClickedId() == i) {
				rect(bmp_screen, (iDrawX + 1), (iDrawY + 1), (iDrawXEnd - 1), (iDrawYEnd - 1), makecol(game.fade_select, game.fade_select, game.fade_select));
				rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(game.fade_select, game.fade_select, game.fade_select));
			}
		}

		int amountToShow = item->getTimesToBuild();
		if (amountToShow <= 0) {
			amountToShow = item->getTimesOrdered();
		}

		if (amountToShow > 0) {
			// draw number of times to build this thing (queueing)
			int textX = iDrawX + 41;
			int textY = iDrawY + 16;

			if (amountToShow < 10) {
				textX += 10;
			}

			// draw
			alfont_textprintf(bmp_screen, game_font, textX + 1,textY + 1, makecol(0,0,0), "%d", amountToShow);
			alfont_textprintf(bmp_screen, game_font, textX,textY, makecol(255,255,255), "%d", amountToShow);
		}

		// draw rectangle when mouse hovers over icon
		if (isOverItemCoordinates_Boolean(mouse_x, mouse_y, iDrawX, iDrawY)) {
			int iColor=makecol(game.fade_select, game.fade_select, game.fade_select);

			if (player[0].getHouse() == ATREIDES) {
				iColor = makecol(0, 0, game.fade_select);
			}

			if (player[0].getHouse() == HARKONNEN) {
				iColor = makecol(game.fade_select, 0, 0);
			}

			if (player[0].getHouse() == ORDOS) {
				iColor = makecol(0, game.fade_select, 0);
			}

			rect(bmp_screen, (iDrawX + 1), (iDrawY + 1), (iDrawXEnd - 1), (iDrawYEnd - 1), iColor);
			rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, iColor);
		}

		iDrawY+=48;
	}

	set_clip_rect(bmp_screen, 0, 0, game.screen_x, game.screen_y);
}
コード例 #2
0
void PlaceItDrawer::drawStatusOfStructureAtCell(cBuildingListItem *itemToPlace, int cell) {
	assert(itemToPlace);
	if (cell < 0)
		return;

	cStructureUtils structureUtils;
	int structureId = itemToPlace->getBuildId();
	assert(structureId > -1);

	bool bOutOfBorder = true;
	bool bMayPlace = true;

	int iTile = PLACE_ROCK; // rocky placement = ok, but bad for power

	BITMAP *temp;
	temp = create_bitmap(structures[structureId].bmp_width, structures[structureId].bmp_height);
	clear_bitmap(temp);

	int width = structureUtils.getWidthOfStructureTypeInCells(structureId);
	int height = structureUtils.getHeightOfStructureTypeInCells(structureId);

	int iTotalBlocks = width * height;

	int iTotalRocks = 0.0f;

#define SCANWIDTH	1

	CellCalculator * cellCalculator = new CellCalculator(map);

	int iCellX = cellCalculator->getX(cell);
	int iCellY = cellCalculator->getY(cell);

	delete cellCalculator;

	// check
	int iStartX = iCellX - SCANWIDTH;
	int iStartY = iCellY - SCANWIDTH;

	int iEndX = iCellX + SCANWIDTH + width;
	int iEndY = iCellY + SCANWIDTH + height;

	// Fix up the boundaries
	FIX_POS(iStartX, iStartY);
	FIX_POS(iEndX, iEndY);

	// Determine if the structure may be placed or not (true/false)
	for (int iX = iStartX; iX < iEndX; iX++) {
		for (int iY = iStartY; iY < iEndY; iY++) {
			int iCll = createCellWithoutMapBorders(iX, iY);
			if (map->cell[iCll].gameObjectId[MAPID_STRUCTURES] > -1) {
				int iID = map->cell[iCll].gameObjectId[MAPID_STRUCTURES];

				if (structure[iID]->isOwnerHuman()) {
					bOutOfBorder = false; // connection!
				} else {
					bMayPlace = false;
				}
			}

			if (map->cell[iCll].terrainTypeGfxDataIndex == TERRAIN_WALL || map->cell[iCll].terrainTypeGfxDataIndex == TERRAIN_SLAB) {
				bOutOfBorder = false;
				// TODO: here we should actually find out if the slab is ours or not??
			}
		}
	}

	if (bOutOfBorder) {
		bMayPlace = false;
	}

	int iDrawX = map->mouse_draw_x();
	int iDrawY = map->mouse_draw_y();

	// Draw over it the mask for good/bad placing (decorates temp bitmap)
	for (int iX = 0; iX < width; iX++) {
		for (int iY = 0; iY < height; iY++) {
			iTile = PLACE_ROCK;

			if ((iCellX + iX > 62) || (iCellY + iY > 62)) {
				bOutOfBorder = true;
				bMayPlace = false;
				break;
			}

			int iCll = createCellWithoutMapBorders((iCellX + iX), (iCellY + iY));

			if (map->cell[iCll].passable == false)
				iTile = PLACE_BAD;

			if (map->cell[iCll].terrainTypeGfxDataIndex != TERRAIN_ROCK)
				iTile = PLACE_BAD;

			if (map->cell[iCll].terrainTypeGfxDataIndex == TERRAIN_SLAB)
				iTile = PLACE_GOOD;

			// occupied by units or structures
			if (map->cell[iCll].gameObjectId[MAPID_STRUCTURES] > -1)
				iTile = PLACE_BAD;

			int unitIdOnMap = map->cell[iCll].gameObjectId[MAPID_UNITS];
			if (unitIdOnMap > -1) {
				if (!unit[unitIdOnMap].bPickedUp) // only when not picked up, take this in (fixes carryall carrying this unit bug)
					iTile = PLACE_BAD;
			}

			// DRAWING & RULER
			if (iTile == PLACE_BAD && structureId != SLAB4)
				bMayPlace = false;

			// Count this as GOOD stuff
			if (iTile == PLACE_GOOD)
				iTotalRocks++;

			// Draw bad gfx on spot
			draw_sprite(temp, (BITMAP *) gfxdata[iTile].dat, iX * 32, iY * 32);
		}

		if (bOutOfBorder) {
			clear_to_color(temp, makecol(160, 0, 0));
		}
	}

	// draw temp bitmap
	set_trans_blender(0, 0, 0, 64);

	draw_trans_sprite(bmp_screen, temp, iDrawX, iDrawY);

	// reset to normal
	set_trans_blender(0, 0, 0, 128);

	destroy_bitmap(temp);

	// clicked mouse button
	if (Mouse::getInstance()->isLeftButtonClicked()) {
		if (bMayPlace && bOutOfBorder == false) {
			int iHealthPercent = 50; // the minimum is 50% (with no slabs)

			if (iTotalRocks > 0) {
				iHealthPercent += health_bar(50, iTotalRocks, iTotalBlocks);
			}

			play_sound_id(SOUND_PLACE, -1);

			//cStructureFactory::getInstance()->createStructure(iMouseCell, iStructureID, 0, iHealthPercent);

			player[HUMAN].getStructurePlacer()->placeStructure(cell, structureId, iHealthPercent);

			/*game.bPlaceIt = false;*/

			itemToPlace->decreaseTimesToBuild();
			itemToPlace->setPlaceIt(false);
			itemToPlace->setIsBuilding(false);
			itemToPlace->setProgress(0);
			if (itemToPlace->getTimesToBuild() < 1) {
				player[HUMAN].getItemBuilder()->removeItemFromList(itemToPlace);
			}
		}
	}
	//iDrawX *=32;
	//iDrawY *=32;

	//rect(bmp_screen, iDrawX, iDrawY, iDrawX+(iWidth*32), iDrawY+(iHeight*32), makecol(255,255,255));
}