void UniteUtilitaire::creationVille(Player* player) { if (outil == Outil::fondation) { player->creerBatiment(new Batiment(getCoordX(), getCoordY(), "Ville", "Batiment permettant d'effectuer les actions de base", Ressource::AUCUNE, 0, 0, 0, 0, 0)); int index = -1; for (int i = 0; i < player->getNombreUnite(); i++) { if (player->getUnite(i)->getCoordX() == getCoordX() && player->getUnite(i)->getCoordY() == getCoordY()) { index = i; break; } } player->detruireUnite(index); cout <<"ville fondée"<< player->getNombreBatiment() << endl; } }
void UniteUtilitaire::explorationDeSol(Player* joueur) { if (outil == Outil::kitDeGeologue) { joueur->decouvreRessource(getCoordX(), getCoordY()); outilRestant--; setAAgi(); } }
void WidgetContainer::dimensionalize() { compWidth = 0.0; compWidth += getCoordX(style.padding.left); compWidth += getCoordX(style.padding.right); compWidth += getCoordX(style.border.left); compWidth += getCoordX(style.border.right); compHeight = 0.0; compHeight += getCoordY(style.padding.top); compHeight += getCoordY(style.padding.bottom); compHeight += getCoordY(style.border.top); compHeight += getCoordY(style.border.bottom); if (layout == LAYOUT_VERTICAL) { for (auto& child : children) { child->dimensionalize(); auto cw = child->getMarginWidth(); auto ch = child->getMarginHeight(); compWidth = std::max(cw, compWidth); compHeight += ch; } } else { for (auto& child : children) { child->dimensionalize(); auto cw = child->getMarginWidth(); auto ch = child->getMarginHeight(); compHeight = std::max(ch, compHeight); compWidth += cw; } } // Set final dimensions if (style.width.type != Length::TYPE_UNDEFINED) { vertWidth = getCoordX(style.width); scrollH = compWidth > vertWidth; } else { vertWidth = compWidth; } if (style.height.type != Length::TYPE_UNDEFINED) { vertHeight = getCoordY(style.height); scrollV = compHeight > vertHeight; } else { vertHeight = compHeight; } }
glm::vec2 FieldPlane::getCoords(int x, int y) const { return glm::vec2(getCoordX(x), getCoordY(y)); }
void WidgetContainer::render() { auto offsetTop = getOffsetTop() + getCoordY(style.margin.top); auto offsetLeft = getOffsetLeft() + getCoordX(style.margin.left); // Preparing vertex input auto x1 = -1.0 + 2 * (offsetLeft); auto x2 = -1.0 + 2 * (offsetLeft + getPaddingWidth()); auto y1 = +1.0 - 2 * (offsetTop + getPaddingHeight()); auto y2 = +1.0 - 2 * (offsetTop); auto& V0 = input.vertex[0]; auto& V1 = input.vertex[1]; auto& V2 = input.vertex[2]; auto& V3 = input.vertex[3]; V0.position[0] = V1.position[0] = x1; V2.position[0] = V3.position[0] = x2; V0.position[1] = V2.position[1] = y1; V1.position[1] = V3.position[1] = y2; V0.position[2] = V1.position[2] = V2.position[2] = V3.position[2] = 0.0; V0.position[3] = V1.position[3] = V2.position[3] = V3.position[3] = 1.0; V0.background = style.background; V1.background = style.background; V2.background = style.background; V3.background = style.background; manager->pushWidgetContainer(input); auto childOffsetTop = offsetTop + getCoordY(style.padding.top); auto childOffsetLeft = offsetLeft + getCoordX(style.padding.left); // Render children widgets vertically if (layout == LAYOUT_VERTICAL) { if (style.alignV == ALIGN_VERTICAL_CENTER) { childOffsetTop += (vertHeight - compHeight) / 2.0; } if (style.alignV == ALIGN_VERTICAL_BOTTOM) { childOffsetTop += (vertHeight - compHeight); } for (auto& child : children) { // Correct horizontal alignment switch (style.alignH) { case ALIGN_HORIZONTAL_LEFT: child->setOffsetLeft(childOffsetLeft); break; case ALIGN_HORIZONTAL_CENTER: child->setOffsetLeft(childOffsetLeft + (getContentWidth() - child->getBorderWidth()) / 2.0); break; case ALIGN_HORIZONTAL_RIGHT: child->setOffsetLeft(childOffsetLeft + (getContentWidth() - child->getBorderWidth())); break; } child->setOffsetTop(childOffsetTop); child->render(); childOffsetTop += child->getMarginHeight(); } } // Render children widgets horizontally if (layout == LAYOUT_HORIZONTAL) { if (style.alignH == ALIGN_HORIZONTAL_CENTER) { childOffsetLeft += (vertWidth - compWidth) / 2.0; } if (style.alignH == ALIGN_HORIZONTAL_RIGHT) { childOffsetLeft += (vertWidth - compWidth); } for (auto& child : children) { // Correct vertical alignment switch (style.alignV) { case ALIGN_VERTICAL_TOP: child->setOffsetTop(childOffsetTop); break; case ALIGN_VERTICAL_CENTER: child->setOffsetTop(childOffsetTop + (getContentHeight() - child->getBorderHeight()) / 2.0); break; case ALIGN_VERTICAL_BOTTOM: child->setOffsetTop(childOffsetTop + (getContentHeight() - child->getBorderHeight())); break; } child->setOffsetLeft(childOffsetLeft); child->render(); childOffsetLeft += child->getMarginWidth(); } } }
float Widget::getMarginWidth() { auto marginLeft = getCoordX(style.margin.left); auto marginRight = getCoordX(style.margin.right); return vertWidth + marginLeft + marginRight; }
float Widget::getBorderWidth() { auto borderLeft = getCoordX(style.border.left); auto borderRight = getCoordX(style.border.right); return vertWidth + borderLeft + borderRight; }
float Widget::getPaddingWidth() { auto paddingLeft = getCoordX(style.padding.left); auto paddingRight = getCoordX(style.padding.right); return getContentWidth() + paddingLeft + paddingRight; }