Resolved #2894 - Map editor button only opens popup once

This commit is contained in:
Yair Morgenstern 2020-07-27 19:53:50 +03:00
parent f18f6d4a29
commit b816d1036d
5 changed files with 61 additions and 53 deletions

View File

@ -109,18 +109,21 @@
{
"name": "Warrior Code",
"effect": "+20% production when training melee units",
"uniques":["+20% production when training melee units"],
"row": 1,
"column": 2
},
{
"name": "Discipline",
"effect": "+15% combat strength for melee units which have another military unit in an adjacent tile",
"uniques":["+15% combat strength for melee units which have another military unit in an adjacent tile"],
"row": 1,
"column": 4
},
{
"name": "Military Tradition",
"effect": "Military units gain 50% more Experience from combat",
"uniques":["Military units gain 50% more Experience from combat"],
"requires": ["Warrior Code"],
"row": 2,
"column": 2
@ -128,6 +131,7 @@
{
"name": "Military Caste",
"effect": "Each city with a garrison increases happiness by 1 and culture by 2",
"uniques": ["[+1 Happiness, +2 Culture] in all cities with a garrison"]
"requires": ["Discipline"],
"row": 2,
"column": 4

View File

@ -96,7 +96,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
table.add(multiplayerTable).row()
val mapEditorScreenTable = getTableBlock("Map editor", "OtherIcons/MapEditor")
{ openMapEditorPopup() }
{ if(stage.actors.none { it is MapEditorMainScreenPopup }) MapEditorMainScreenPopup(this) }
table.add(mapEditorScreenTable).padBottom(0f)
// set the same width for all buttons
@ -118,56 +118,57 @@ class MainMenuScreen: CameraStageBaseScreen() {
/** Shows the [Popup] with the map editor initialization options */
private fun openMapEditorPopup() {
class MapEditorMainScreenPopup(screen: MainMenuScreen):Popup(screen){
init{
defaults().pad(10f)
val mapEditorPopup = Popup(this)
mapEditorPopup.defaults().pad(10f)
val tableBackground = ImageGetter.getBackground(colorFromRGB(29, 102, 107))
val tableBackground = ImageGetter.getBackground(colorFromRGB(29, 102, 107))
val newMapButton = getTableBlock("New map", "OtherIcons/New") {
game.setScreen(NewMapScreen())
dispose()
}
newMapButton.background = tableBackground
mapEditorPopup.add(newMapButton).row()
val loadMapButton = getTableBlock("Load map", "OtherIcons/Load") {
val loadMapScreen = LoadMapScreen(null)
loadMapScreen.closeButton.isVisible = true
loadMapScreen.closeButton.onClick {
game.setScreen(MainMenuScreen())
loadMapScreen.dispose()
val newMapButton = screen.getTableBlock("New map", "OtherIcons/New") {
screen.game.setScreen(NewMapScreen())
screen.dispose()
}
game.setScreen(loadMapScreen)
dispose()
}
newMapButton.background = tableBackground
add(newMapButton).row()
loadMapButton.background = tableBackground
mapEditorPopup.add(loadMapButton).row()
if (UncivGame.Current.settings.extendedMapEditor) {
val loadScenarioButton = getTableBlock("Load scenario", "OtherIcons/Scenario") {
val loadScenarioScreen = LoadScenarioScreen(null)
loadScenarioScreen.closeButton.isVisible = true
loadScenarioScreen.closeButton.onClick {
game.setScreen(MainMenuScreen())
loadScenarioScreen.dispose()
val loadMapButton = screen.getTableBlock("Load map", "OtherIcons/Load") {
val loadMapScreen = LoadMapScreen(null)
loadMapScreen.closeButton.isVisible = true
loadMapScreen.closeButton.onClick {
screen.game.setScreen(MainMenuScreen())
loadMapScreen.dispose()
}
game.setScreen(loadScenarioScreen)
dispose()
screen.game.setScreen(loadMapScreen)
screen.dispose()
}
loadScenarioButton.background = tableBackground
mapEditorPopup.add(loadScenarioButton).row()
loadMapButton.background = tableBackground
add(loadMapButton).row()
if (UncivGame.Current.settings.extendedMapEditor) {
val loadScenarioButton = screen.getTableBlock("Load scenario", "OtherIcons/Scenario") {
val loadScenarioScreen = LoadScenarioScreen(null)
loadScenarioScreen.closeButton.isVisible = true
loadScenarioScreen.closeButton.onClick {
screen.game.setScreen(MainMenuScreen())
loadScenarioScreen.dispose()
}
screen.game.setScreen(loadScenarioScreen)
screen.dispose()
}
loadScenarioButton.background = tableBackground
add(loadScenarioButton).row()
}
add(screen.getTableBlock("Close", "OtherIcons/Close") { close() }
.apply { background=tableBackground })
open(force = true)
}
mapEditorPopup.add(getTableBlock("Close", "OtherIcons/Close") { mapEditorPopup.close() }
.apply { background=tableBackground })
mapEditorPopup.open(force = true)
}
private fun autoLoadGame() {
try {
game.loadGame(autosave)

View File

@ -236,7 +236,7 @@ object Battle {
return
var XPModifier = 1f
if (thisCombatant.getCivInfo().policies.isAdopted("Military Tradition")) XPModifier += 0.5f
if (thisCombatant.getCivInfo().hasUnique("Military units gain 50% more Experience from combat")) XPModifier += 0.5f
if (thisCombatant.unit.hasUnique("50% Bonus XP gain")) XPModifier += 0.5f
val XPGained = (amount * XPModifier).toInt()

View File

@ -71,7 +71,7 @@ object BattleDamage {
modifiers["Populism"] = 0.25f
}
if (civInfo.policies.hasEffect("+15% combat strength for melee units which have another military unit in an adjacent tile")
if (civInfo.hasUnique("+15% combat strength for melee units which have another military unit in an adjacent tile")
&& combatant.isMelee()
&& combatant.getTile().neighbors.flatMap { it.getUnits() }
.any { it.civInfo == civInfo && !it.type.isCivilian() && !it.type.isAirUnit() })

View File

@ -14,6 +14,7 @@ import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
import com.unciv.models.translations.equalsPlaceholderText
import com.unciv.models.translations.getPlaceholderParameters
import com.unciv.models.translations.getPlaceholderText
class CityStats {
@ -215,9 +216,11 @@ class CityStats {
if (civInfo.hasUnique("+1 happiness for every city connected to capital")
&& cityInfo.isConnectedToCapital())
happinessFromPolicies += 1f
if (civInfo.policies.hasEffect("Each city with a garrison increases happiness by 1 and culture by 2"
) && cityInfo.getCenterTile().militaryUnit != null)
happinessFromPolicies += 1
if (cityInfo.getCenterTile().militaryUnit != null)
for (unique in civInfo.policies.policyEffects)
if (unique.equalsPlaceholderText("[] in all cities with a garrison"))
happinessFromPolicies += Stats.parse(unique.getPlaceholderParameters()[0]).happiness
newHappinessList["Policies"] = happinessFromPolicies
@ -230,7 +233,7 @@ class CityStats {
newHappinessList["Wonders"] = 1f
newHappinessList["Tile yields"] = getStatsFromTiles().happiness
// we don't want to modify the existing happiness list because that leads
// to concurrency problems if we iterate on it while changing
happinessList = newHappinessList
@ -267,9 +270,10 @@ class CityStats {
if (adoptedPolicies.hasEffect("+3 culture in capital") && cityInfo.isCapital())
stats.culture += 3f
for(effect in adoptedPolicies.policyEffects) {
if (effect.equalsPlaceholderText("[] in capital") && cityInfo.isCapital())
stats.add(Stats.parse(effect.getPlaceholderParameters()[0]))
else if(effect.equalsPlaceholderText("[] in all cities"))
val placeholderText = effect.getPlaceholderText()
if ((placeholderText == "[] in capital" && cityInfo.isCapital())
|| placeholderText == "[] in all cities"
|| (placeholderText == "[] in all cities with a garrison" && cityInfo.getCenterTile().militaryUnit != null))
stats.add(Stats.parse(effect.getPlaceholderParameters()[0]))
}
if (adoptedPolicies.hasEffect("+1 gold and -1 unhappiness for every 2 citizens in capital") && cityInfo.isCapital())
@ -278,8 +282,6 @@ class CityStats {
stats.culture += 1f
if (adoptedPolicies.hasEffect("+1 production in every city, +5% production when constructing buildings"))
stats.production += 1f
if (adoptedPolicies.hasEffect("Each city with a garrison increases happiness by 1 and culture by 2") && cityInfo.getCenterTile().militaryUnit != null)
stats.culture += 2
if (adoptedPolicies.hasEffect("+1 production per 5 population"))
stats.production += (cityInfo.population.population / 5).toFloat()
if (adoptedPolicies.hasEffect("+1 culture for every 2 citizens"))
@ -337,7 +339,8 @@ class CityStats {
stats.production += 50f
if (policies.contains("Republic") && currentConstruction is Building)
stats.production += 5f
if (policies.contains("Warrior Code") && currentConstruction is BaseUnit && currentConstruction.unitType.isMelee())
if (cityInfo.civInfo.hasUnique("+20% production when training melee units")
&& currentConstruction is BaseUnit && currentConstruction.unitType.isMelee())
stats.production += 20
if (policies.contains("Piety")
&& listOf("Monument", "Temple", "Opera House", "Museum", "Broadcast Tower").contains(currentConstruction.name))