void City::CreateCityMenu() { interactionMenu = Camera::GetInstance()->ObtainAMenu(position.x - menuXDimension / 2, position.y, menuXDimension, menuYDimension); /* Construct the background shape */ sf::RectangleShape shape; shape.setSize(sf::Vector2f(menuXDimension, menuYDimension)); shape.setFillColor(Camera::GetInstance()->getStyleSheets()->at("button").bodyCol); shape.setOutlineThickness(-Camera::GetInstance()->getStyleSheets()->at("button").borderSize); shape.setOutlineColor(Camera::GetInstance()->getStyleSheets()->at("button").borderCol); sf::Text text; text.setString("Train Swordsman (100)"); text.setFont(*Camera::GetInstance()->getStyleSheets()->at("button").font); text.setColor(Camera::GetInstance()->getStyleSheets()->at("button").textCol); text.setCharacterSize(menuYDimension - Camera::GetInstance()->getStyleSheets()->at("button").borderSize - 4); //4 is the padding size interactionMenu.at("menu").entries.push_back(GuiEntry("train_swordsman", shape, text)); text.setString("Train Pikeman (150)"); text.setFont(*Camera::GetInstance()->getStyleSheets()->at("button").font); text.setColor(Camera::GetInstance()->getStyleSheets()->at("button").textCol); text.setCharacterSize(menuYDimension - Camera::GetInstance()->getStyleSheets()->at("button").borderSize - 4); //4 is the padding size interactionMenu.at("menu").entries.push_back(GuiEntry("train_pikeman", shape, text)); text.setString("Train Archer (200)"); text.setFont(*Camera::GetInstance()->getStyleSheets()->at("button").font); text.setColor(Camera::GetInstance()->getStyleSheets()->at("button").textCol); text.setCharacterSize(menuYDimension - Camera::GetInstance()->getStyleSheets()->at("button").borderSize - 4); //4 is the padding size interactionMenu.at("menu").entries.push_back(GuiEntry("train_archer", shape, text)); text.setString("Train Knight (300)"); text.setFont(*Camera::GetInstance()->getStyleSheets()->at("button").font); text.setColor(Camera::GetInstance()->getStyleSheets()->at("button").textCol); text.setCharacterSize(menuYDimension - Camera::GetInstance()->getStyleSheets()->at("button").borderSize - 4); //4 is the padding size interactionMenu.at("menu").entries.push_back(GuiEntry("train_knight", shape, text)); text.setString("Improve Weapons (500)"); text.setFont(*Camera::GetInstance()->getStyleSheets()->at("button").font); text.setColor(Camera::GetInstance()->getStyleSheets()->at("button").textCol); text.setCharacterSize(menuYDimension - Camera::GetInstance()->getStyleSheets()->at("button").borderSize - 4); //4 is the padding size interactionMenu.at("menu").entries.push_back(GuiEntry("improve_weapons", shape, text)); interactionMenu.at("menu").hide(); }
/* Constructor */ Gui(sf::Vector2f dimensions, int padding, bool horizontal, GuiStyle& style, std::vector<std::pair<std::string, std::string>> entries) { visible = false; this->horizontal = horizontal; this->style = style; this->dimensions = dimensions; this->padding = padding; /* Construct the background shape */ sf::RectangleShape shape; shape.setSize(dimensions); shape.setFillColor(style.bodyCol); shape.setOutlineThickness(-style.borderSize); shape.setOutlineColor(style.borderCol); /* Construct each gui entry */ for(auto entry : entries) { /* Construct the text */ sf::Text text; text.setString(entry.first); text.setFont(*style.font); text.setColor(style.textCol); text.setCharacterSize(dimensions.y-style.borderSize-padding); this->entries.push_back(GuiEntry(entry.second, shape, text)); } }
bool City::CheckMouseClick(const sf::Vector2f* mousePos) { if (interactionMenu.at("menu").visible) { std::string msg = interactionMenu.at("menu").activate(*mousePos); if (msg == "null") { return false; } else { if (msg == "train_swordsman") { CreateUnit(Unit::UNITTYPES::SWORDSMAN); return true; } else if (msg == "train_pikeman") { CreateUnit(Unit::UNITTYPES::PIKEMAN); return true; } else if (msg == "train_archer") { CreateUnit(Unit::UNITTYPES::ARCHER); return true; } else if (msg == "train_knight") { CreateUnit(Unit::UNITTYPES::KNIGHT); return true; } else if (msg == "improve_weapons") { if (MapManager::GetInstance()->GetPlayerGold(owningPlayer) >= 500) { MapManager::GetInstance()->RemoveGold(500, owningPlayer); levelWeapons++; interactionMenu.at("menu").entries.pop_back(); sf::RectangleShape shape; shape.setSize(sf::Vector2f(menuXDimension, menuYDimension)); shape.setFillColor(Camera::GetInstance()->getStyleSheets()->at("button").bodyCol); shape.setOutlineThickness(-Camera::GetInstance()->getStyleSheets()->at("button").borderSize); shape.setOutlineColor(Camera::GetInstance()->getStyleSheets()->at("button").borderCol); sf::Text text; text.setString("Improve Weapons (1000)"); text.setFont(*Camera::GetInstance()->getStyleSheets()->at("button").font); text.setColor(Camera::GetInstance()->getStyleSheets()->at("button").textCol); text.setCharacterSize(menuYDimension - Camera::GetInstance()->getStyleSheets()->at("button").borderSize - 4); //4 is the padding size interactionMenu.at("menu").entries.push_back(GuiEntry("improve_weapons 2", shape, text)); } } else if (msg == "improve_weapons 2") { if (MapManager::GetInstance()->GetPlayerGold(owningPlayer) >= 1000) { MapManager::GetInstance()->RemoveGold(1000, owningPlayer); levelWeapons++; interactionMenu.at("menu").entries.pop_back(); } } hasSpawnedUnit = true; } } return false; }