Example #1
0
/**
**  Draw a map viewport.
*/
void CViewport::Draw() const
{
	PushClipping();
	this->SetClipping();

	/* this may take while */
	this->DrawMapBackgroundInViewport();

	CurrentViewport = this;
	{
		// Now we need to sort units, missiles, particles by draw level and draw them
		std::vector<CUnit *> unittable;
		std::vector<Missile *> missiletable;
		std::vector<CParticle *> particletable;

		FindAndSortUnits(*this, unittable);
		const size_t nunits = unittable.size();
		FindAndSortMissiles(*this, missiletable);
		const size_t nmissiles = missiletable.size();
		ParticleManager.prepareToDraw(*this, particletable);
		const size_t nparticles = particletable.size();

		size_t i = 0;
		size_t j = 0;
		size_t k = 0;


		while ((i < nunits && j < nmissiles) || (i < nunits && k < nparticles)
			   || (j < nmissiles && k < nparticles)) {
			if (i == nunits) {
				if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
					missiletable[j]->DrawMissile(*this);
					++j;
				} else {
					particletable[k]->draw();
					++k;
				}
			} else if (j == nmissiles) {
				if (unittable[i]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
					unittable[i]->Draw(*this);
					++i;
				} else {
					particletable[k]->draw();
					++k;
				}
			} else if (k == nparticles) {
				if (unittable[i]->Type->DrawLevel < missiletable[j]->Type->DrawLevel) {
					unittable[i]->Draw(*this);
					++i;
				} else {
					missiletable[j]->DrawMissile(*this);
					++j;
				}
			} else {
				if (unittable[i]->Type->DrawLevel <= missiletable[j]->Type->DrawLevel) {
					if (unittable[i]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
						unittable[i]->Draw(*this);
						++i;
					} else {
						particletable[k]->draw();
						++k;
					}
				} else {
					if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
						missiletable[j]->DrawMissile(*this);
						++j;
					} else {
						particletable[k]->draw();
						++k;
					}
				}
			}
		}
		for (; i < nunits; ++i) {
			unittable[i]->Draw(*this);
		}
		for (; j < nmissiles; ++j) {
			missiletable[j]->DrawMissile(*this);
		}
		for (; k < nparticles; ++k) {
			particletable[k]->draw();
		}
		ParticleManager.endDraw();
	}

	this->DrawMapFogOfWar();

	//
	// Draw orders of selected units.
	// Drawn here so that they are shown even when the unit is out of the screen.
	//
	if (!Preference.ShowOrders) {
	} else if (Preference.ShowOrders < 0
			   || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
		for (int i = 0; i < NumSelected; ++i) {
			ShowOrder(*Selected[i]);
		}
	}

	//
	// Draw unit's name popup
	//
	if (CursorOn == CursorOnMap && Preference.ShowNameDelay && (ShowNameDelay < GameCycle) && (GameCycle < ShowNameTime)) {
		const Vec2i tilePos = this->ScreenToTilePos(CursorScreenPos);
		const bool isMapFieldVisile = Map.Field(tilePos)->playerInfo.IsTeamVisible(*ThisPlayer);

		if (UI.MouseViewport->IsInsideMapArea(CursorScreenPos) && UnitUnderCursor
			&& ((isMapFieldVisile && !UnitUnderCursor->Type->BoolFlag[ISNOTSELECTABLE_INDEX].value) || ReplayRevealMap)) {
			ShowUnitName(*this, CursorScreenPos, UnitUnderCursor);
		} else if (!isMapFieldVisile) {
			ShowUnitName(*this, CursorScreenPos, NULL, true);
		}
	}

	DrawBorder();
	PopClipping();
}
Example #2
0
/**
**  Draw a map viewport.
*/
void CViewport::Draw() const
{
	PushClipping();
	this->SetClipping();

	/* this may take while */
	this->DrawMapBackgroundInViewport();

	CurrentViewport = this;
	{
		// Now we need to sort units, missiles, particles by draw level and draw them
		std::vector<CUnit *> unittable;
		std::vector<Missile *> missiletable;
		std::vector<CParticle *> particletable;

		FindAndSortUnits(*this, unittable);
		const size_t nunits = unittable.size();
		FindAndSortMissiles(*this, missiletable);
		const size_t nmissiles = missiletable.size();
		ParticleManager.prepareToDraw(*this, particletable);
		const size_t nparticles = particletable.size();
		
		size_t i = 0;
		size_t j = 0;
		size_t k = 0;


		while ((i < nunits && j < nmissiles) || (i < nunits && k < nparticles)
			   || (j < nmissiles && k < nparticles)) {
			if (i == nunits) {
				if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
					missiletable[j]->DrawMissile(*this);
					++j;
				} else {
					particletable[k]->draw();
					++k;
				}
			} else if (j == nmissiles) {
				if (unittable[i]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
					unittable[i]->Draw(*this);
					++i;
				} else {
					particletable[k]->draw();
					++k;
				}
			} else if (k == nparticles) {
				if (unittable[i]->Type->DrawLevel < missiletable[j]->Type->DrawLevel) {
					unittable[i]->Draw(*this);
					++i;
				} else {
					missiletable[j]->DrawMissile(*this);
					++j;
				}
			} else {
				if (unittable[i]->Type->DrawLevel <= missiletable[j]->Type->DrawLevel) {
					if (unittable[i]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
						unittable[i]->Draw(*this);
						++i;
					} else {
						particletable[k]->draw();
						++k;
					}
				} else {
					if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
						missiletable[j]->DrawMissile(*this);
						++j;
					} else {
						particletable[k]->draw();
						++k;
					}
				}
			}
		}
		for (; i < nunits; ++i) {
			unittable[i]->Draw(*this);
		}
		for (; j < nmissiles; ++j) {
			missiletable[j]->DrawMissile(*this);
		}
		for (; k < nparticles; ++k) {
			particletable[k]->draw();
		}
		ParticleManager.endDraw();
		//Wyrmgus start
		//draw fog of war below the "click missile"
		this->DrawMapFogOfWar();
		j = 0;
		for (; j < nmissiles; ++j) {
			if (!ClickMissile.empty() && ClickMissile == missiletable[j]->Type->Ident) {
				missiletable[j]->DrawMissile(*this); //draw click missile again to make it appear on top of the fog of war
			}
		}
		//Wyrmgus end
	}

	//Wyrmgus start
//	this->DrawMapFogOfWar();
	//Wyrmgus end

	//
	// Draw orders of selected units.
	// Drawn here so that they are shown even when the unit is out of the screen.
	//
	if (!Preference.ShowOrders) {
	} else if (Preference.ShowOrders < 0
			   || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
		for (size_t i = 0; i != Selected.size(); ++i) {
			ShowOrder(*Selected[i]);
		}
	}
	
	//Wyrmgus start
	//if a selected unit has a rally point, show it
	//better to not show it all the time, so that there's no clutter
	/*
	for (size_t i = 0; i != Selected.size(); ++i) {
		if (!Selected[i]Destroyed && !Selected[i]Removed && Selected[i]->RallyPointPos.x != -1 && Selected[i]->RallyPointPos.y != -1) {
			Video.FillCircleClip(ColorGreen, CurrentViewport->TilePosToScreen_Center(Selected[i]->RallyPointPos), 3);
		}
	}
	*/
	//Wyrmgus end

	//
	// Draw unit's name popup
	//
	//Wyrmgus start
	/*
	//Wyrmgus start
//	if (CursorOn == CursorOnMap && Preference.ShowNameDelay && (ShowNameDelay < GameCycle) && (GameCycle < ShowNameTime)) {
	if (CursorOn == CursorOnMap && (!Preference.ShowNameDelay || ShowNameDelay < GameCycle) && (!Preference.ShowNameTime || GameCycle < ShowNameTime)) {
	//Wyrmgus end
		const Vec2i tilePos = this->ScreenToTilePos(CursorScreenPos);
		//Wyrmgus start
//		const bool isMapFieldVisile = Map.Field(tilePos)->playerInfo.IsTeamVisible(*ThisPlayer);
		const bool isMapFieldVisile = Map.Field(tilePos, UI.CurrentMapLayer->ID)->playerInfo.IsTeamVisible(*ThisPlayer);
		//Wyrmgus end

		if (UI.MouseViewport->IsInsideMapArea(CursorScreenPos) && UnitUnderCursor
			//Wyrmgus start
//			&& ((isMapFieldVisile && !UnitUnderCursor->Type->BoolFlag[ISNOTSELECTABLE_INDEX].value) || ReplayRevealMap)) {
			&& ((isMapFieldVisile && !UnitUnderCursor->Type->BoolFlag[ISNOTSELECTABLE_INDEX].value) || ReplayRevealMap) && UnitUnderCursor->IsAliveOnMap()) {
//			ShowUnitName(*this, CursorScreenPos, UnitUnderCursor);
			PixelPos unit_center_pos = Map.TilePosToMapPixelPos_TopLeft(UnitUnderCursor->tilePos, UnitUnderCursor->MapLayer);
			unit_center_pos = MapToScreenPixelPos(unit_center_pos);
			std::string unit_name;
			if (UnitUnderCursor->Unique || UnitUnderCursor->Prefix || UnitUnderCursor->Suffix || UnitUnderCursor->Work || UnitUnderCursor->Elixir || UnitUnderCursor->Spell || UnitUnderCursor->Character != nullptr) {
				if (!UnitUnderCursor->Identified) {
					unit_name = UnitUnderCursor->GetTypeName() + " (" + _("Unidentified") + ")";
				} else {
					unit_name = UnitUnderCursor->GetName();
				}
			} else {
				unit_name = UnitUnderCursor->GetTypeName();
			}
			if (UnitUnderCursor->Player->Index != PlayerNumNeutral) {
				unit_name += " (" + UnitUnderCursor->Player->Name + ")";
			}
			//hackish way to make the popup appear correctly for the unit under cursor
			ButtonAction *ba = new ButtonAction;
			ba->Hint = unit_name;
			ba->Action = ButtonUnit;
			ba->Value = UnitNumber(*UnitUnderCursor);
			ba->Popup = "popup-unit-under-cursor";
			DrawPopup(*ba, unit_center_pos.x, unit_center_pos.y);
			delete ba;
			LastDrawnButtonPopup = nullptr;
			//Wyrmgus end
		//Wyrmgus start
//		} else if (!isMapFieldVisile) {
//			ShowUnitName(*this, CursorScreenPos, nullptr, true);
		//Wyrmgus end
		}
	}
	*/
	//Wyrmgus end

	DrawBorder();
	PopClipping();
}
Example #3
0
/**
**  Draw a map viewport.
*/
void CViewport::Draw() const
{
    PushClipping();
    this->SetClipping();

    /* this may take while */
    this->DrawMapBackgroundInViewport();

    CurrentViewport = this;
    {
        std::vector<CUnit *> unittable;
        std::vector<Missile *> missiletable;

        // We find and sort units after draw level.
        FindAndSortUnits(*this, unittable);
        const size_t nunits = unittable.size();
        FindAndSortMissiles(*this, missiletable);
        const size_t nmissiles = missiletable.size();
        size_t i = 0;
        size_t j = 0;

        while (i < nunits && j < nmissiles) {
            if (unittable[i]->Type->DrawLevel <= missiletable[j]->Type->DrawLevel) {
                unittable[i]->Draw(*this);
                ++i;
            } else {
                missiletable[j]->DrawMissile(*this);
                ++j;
            }
        }
        for (; i < nunits; ++i) {
            unittable[i]->Draw(*this);
        }
        for (; j < nmissiles; ++j) {
            missiletable[j]->DrawMissile(*this);
        }
    }

    ParticleManager.draw(*this);

    this->DrawMapFogOfWar();

    //
    // Draw orders of selected units.
    // Drawn here so that they are shown even when the unit is out of the screen.
    //
    if (!Preference.ShowOrders) {
    } else if (Preference.ShowOrders < 0
               || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
        for (int i = 0; i < NumSelected; ++i) {
            ShowOrder(*Selected[i]);
        }
    }

    //
    // Draw unit's name popup
    //
    if (CursorOn == CursorOnMap && Preference.ShowNameDelay && (ShowNameDelay < GameCycle) && (GameCycle < ShowNameTime)) {
        const Vec2i tilePos = this->ScreenToTilePos(CursorScreenPos);
        const bool isMapFieldVisile = Map.Field(tilePos)->playerInfo.IsTeamVisible(*ThisPlayer);

        if (UI.MouseViewport->IsInsideMapArea(CursorScreenPos)
                && (isMapFieldVisile || ReplayRevealMap)) {
            ShowUnitName(*this, CursorScreenPos, UnitUnderCursor);
        } else if (!isMapFieldVisile) {
            ShowUnitName(*this, CursorScreenPos, NULL, true);
        }
    }

    DrawBorder();
    PopClipping();
}