Added unique sound effects for multiple actions

This commit is contained in:
Yair Morgenstern
2018-12-17 13:11:50 +02:00
parent 978dac806f
commit fd2d55876d
13 changed files with 58 additions and 40 deletions

View File

@ -392,7 +392,11 @@ All the following are from [the Noun Project](https://thenounproject.com) licenc
# Sound credits # Sound credits
Sounds are from FreeSound.org Sounds are from FreeSound.org and are either Creative Commons or Public Domain
* [Click 01_Minimal UI Sounds](https://freesound.org/people/cabled_mess/sounds/370962/) By cabled_mess for most clicks * [Click 01_Minimal UI Sounds](https://freesound.org/people/cabled_mess/sounds/370962/) By cabled_mess for most clicks
* [Pencil1](https://freesound.org/people/stijn/sounds/43673/) By stijn for opening and closing the tech picker
* [SawInOut01](https://freesound.org/people/kingof_thelab/sounds/340243/) By kingof_thelab for construction picking? * [SawInOut01](https://freesound.org/people/kingof_thelab/sounds/340243/) By kingof_thelab for construction picking?
* [Chain Snare #1](https://freesound.org/people/lovesbody/sounds/322079/) By lovesbody for Fortify
* [Level up](https://freesound.org/people/Marregheriti/sounds/266100/) By Marregheriti for Promote action
* [levelup](https://freesound.org/people/Seidhepriest/sounds/382915/) By Seidhepriest for special actions (free tech, build city, hhurry wonder etc.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -163,31 +163,35 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
val tilesInRange = city.getTilesInRange() val tilesInRange = city.getTilesInRange()
// this needs to happen on update, because we can buy tiles, which changes the definition of the bought tiles... // this needs to happen on update, because we can buy tiles, which changes the definition of the bought tiles...
if (tileInfo.getCity()!=city) { // outside of city var shouldToggleTilesWorked = false
if(city.canAcquireTile(tileInfo)){ when {
tileGroup.addAcquirableIcon() tileInfo.getCity()!=city -> // outside of city
tileGroup.yieldGroup.isVisible = false if(city.canAcquireTile(tileInfo)){
} else { tileGroup.addAcquirableIcon()
tileGroup.setColor(0f, 0f, 0f, 0.3f) tileGroup.yieldGroup.isVisible = false
} else {
tileGroup.setColor(0f, 0f, 0f, 0.3f)
tileGroup.yieldGroup.isVisible = false
}
tileInfo !in tilesInRange -> // within city but not close enough to be workable
tileGroup.yieldGroup.isVisible = false tileGroup.yieldGroup.isVisible = false
!tileInfo.isCityCenter() && tileGroup.populationImage==null -> { // workable
tileGroup.addPopulationIcon()
shouldToggleTilesWorked=true
} }
} else if(tileInfo !in tilesInRange){ // within city but not close enough to be workable
tileGroup.yieldGroup.isVisible = false
} }
else if (!tileInfo.isCityCenter() && tileGroup.populationImage==null) { // workable tileGroup.onClick {
tileGroup.addPopulationIcon() selectedTile = tileInfo
tileGroup.onClick { if (shouldToggleTilesWorked) {
if (!tileInfo.isWorked() && city.population.getFreePopulation() > 0) if (!tileInfo.isWorked() && city.population.getFreePopulation() > 0)
city.workedTiles.add(tileInfo.position) city.workedTiles.add(tileInfo.position)
else if (tileInfo.isWorked()) city.workedTiles.remove(tileInfo.position) else if (tileInfo.isWorked()) city.workedTiles.remove(tileInfo.position)
city.cityStats.update() city.cityStats.update()
update()
} }
update()
} }
tileGroup.onClick {
selectedTile = tileInfo
update()
}
val positionalVector = HexMath().hex2WorldCoords(tileInfo.position.cpy().sub(cityInfo.location)) val positionalVector = HexMath().hex2WorldCoords(tileInfo.position.cpy().sub(cityInfo.location))

View File

@ -17,7 +17,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() {
init { init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
rightSideButton.setText("Pick promotion") rightSideButton.setText("Pick promotion")
rightSideButton.onClick { rightSideButton.onClick("promote") {
mapUnit.promotions.addPromotion(selectedPromotion!!.name) mapUnit.promotions.addPromotion(selectedPromotion!!.name)
if(mapUnit.promotions.canBePromoted()) game.screen = PromotionPickerScreen(mapUnit) if(mapUnit.promotions.canBePromoted()) game.screen = PromotionPickerScreen(mapUnit)
else game.setWorldScreen() else game.setWorldScreen()

View File

@ -77,11 +77,10 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
setButtonsInfo() setButtonsInfo()
rightSideButton.setText("Pick a tech".tr()) rightSideButton.setText("Pick a tech".tr())
rightSideButton.onClick { rightSideButton.onClick("paper") {
if (isFreeTechPick) { if (isFreeTechPick) civTech.getFreeTechnology(selectedTech!!.name)
civTech.getFreeTechnology(selectedTech!!.name) else civTech.techsToResearch = tempTechsToResearch
} else
civTech.techsToResearch = tempTechsToResearch
game.setWorldScreen() game.setWorldScreen()
game.worldScreen.shouldUpdate=true game.worldScreen.shouldUpdate=true
dispose() dispose()

View File

@ -122,16 +122,23 @@ fun Label.setFontSize(size:Int): Label {
return this // for chaining return this // for chaining
} }
// If there are other buttons that require special clicks then we'll have an onclick that will accept a string parameter, no worries // If there are other buttons that require special clicks then we'll have an onclick that will accept a string parameter, no worries
fun Actor.onClick(function: () -> Unit) {
fun Actor.onClick(sound:String,function: () -> Unit){
this.addListener(object : ClickListener() { this.addListener(object : ClickListener() {
override fun clicked(event: InputEvent?, x: Float, y: Float) { override fun clicked(event: InputEvent?, x: Float, y: Float) {
Sounds.play("click") Sounds.play(sound)
function() function()
} }
} ) } )
} }
fun Actor.onClick(function: () -> Unit) {
onClick("click",function)
}
fun Actor.surroundWithCircle(size:Float): IconCircleGroup { fun Actor.surroundWithCircle(size:Float): IconCircleGroup {
return IconCircleGroup(size,this) return IconCircleGroup(size,this)
} }

View File

@ -43,7 +43,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
for (tileInfo in tileMap.values) { for (tileInfo in tileMap.values) {
val tileGroup = WorldTileGroup(tileInfo) val tileGroup = WorldTileGroup(tileInfo)
tileGroup.onClick{ onTileClicked(tileInfo, tileGroup)} tileGroup.onClick{ onTileClicked(tileInfo)}
val positionalVector = HexMath().hex2WorldCoords(tileInfo.position) val positionalVector = HexMath().hex2WorldCoords(tileInfo.position)
val groupSize = 50 val groupSize = 50
@ -93,7 +93,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
}) })
} }
private fun onTileClicked(tileInfo: TileInfo, tileGroup: WorldTileGroup) { private fun onTileClicked(tileInfo: TileInfo) {
worldScreen.displayTutorials("TileClicked") worldScreen.displayTutorials("TileClicked")
if (moveToOverlay != null) moveToOverlay!!.remove() if (moveToOverlay != null) moveToOverlay!!.remove()
selectedTile = tileInfo selectedTile = tileInfo

View File

@ -54,7 +54,7 @@ class WorldScreen : CameraStageBaseScreen() {
tileMapHolder.addTiles() tileMapHolder.addTiles()
techButton.touchable=Touchable.enabled techButton.touchable=Touchable.enabled
techButton.onClick { techButton.onClick("paper") {
game.screen = TechPickerScreen(civInfo) game.screen = TechPickerScreen(civInfo)
} }

View File

@ -17,7 +17,10 @@ import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
import java.util.* import java.util.*
import kotlin.math.max import kotlin.math.max
class UnitAction(var name: String, var canAct:Boolean, var action:()->Unit) class UnitAction(var name: String, var canAct:Boolean, var action:()->Unit){
var sound="click"
fun sound(soundName:String): UnitAction {sound=soundName; return this}
}
class UnitActions { class UnitActions {
@ -44,7 +47,8 @@ class UnitActions {
if(!unit.type.isCivilian() && !unit.isEmbarked() && !unit.type.isWaterUnit() if(!unit.type.isCivilian() && !unit.isEmbarked() && !unit.type.isWaterUnit()
&& !unit.hasUnique("No defensive terrain bonus") && !unit.isFortified()) { && !unit.hasUnique("No defensive terrain bonus") && !unit.isFortified()) {
actionList += UnitAction("Fortify", unit.currentMovement != 0f) { unit.action = "Fortify 0" } actionList += UnitAction("Fortify", unit.currentMovement != 0f)
{ unit.action = "Fortify 0" }.sound("fortify")
} }
if(!unit.isFortified() && actionList.none{it.name=="Fortify"} && unit.action!="Sleep") { if(!unit.isFortified() && actionList.none{it.name=="Fortify"} && unit.action!="Sleep") {
@ -61,7 +65,7 @@ class UnitActions {
if(!unit.type.isCivilian() && unit.promotions.canBePromoted()) { if(!unit.type.isCivilian() && unit.promotions.canBePromoted()) {
actionList += UnitAction("Promote", unit.currentMovement != 0f) actionList += UnitAction("Promote", unit.currentMovement != 0f)
{ UnCivGame.Current.screen = PromotionPickerScreen(unit) } { UnCivGame.Current.screen = PromotionPickerScreen(unit) }.sound("promote")
} }
if(unit.baseUnit().upgradesTo!=null && tile.getOwner()==unit.civInfo) { if(unit.baseUnit().upgradesTo!=null && tile.getOwner()==unit.civInfo) {
@ -87,7 +91,7 @@ class UnitActions {
newunit.promotions = unit.promotions newunit.promotions = unit.promotions
newunit.updateUniques() newunit.updateUniques()
newunit.currentMovement = 0f newunit.currentMovement = 0f
} }.sound("promote")
} }
} }
@ -106,7 +110,7 @@ class UnitActions {
tile.improvement = null tile.improvement = null
unitTable.currentlyExecutingAction = null // In case the settler was in the middle of doing something and we then founded a city with it unitTable.currentlyExecutingAction = null // In case the settler was in the middle of doing something and we then founded a city with it
unit.destroy() unit.destroy()
} }.sound("chimes")
} }
if (unit.hasUnique("Can build improvements on tiles") && !unit.isEmbarked()) { if (unit.hasUnique("Can build improvements on tiles") && !unit.isEmbarked()) {
@ -143,7 +147,7 @@ class UnitActions {
val improvementName = unique.replace("Can build improvement: ","") val improvementName = unique.replace("Can build improvement: ","")
actionList += UnitAction("Create [$improvementName]", actionList += UnitAction("Create [$improvementName]",
unit.currentMovement != 0f && !tile.isCityCenter(), unit.currentMovement != 0f && !tile.isCityCenter(),
constructImprovementAndDestroyUnit(unit, improvementName)) constructImprovementAndDestroyUnit(unit, improvementName)).sound("chimes")
} }
@ -153,7 +157,7 @@ class UnitActions {
unit.civInfo.tech.freeTechs += 1 unit.civInfo.tech.freeTechs += 1
unit.destroy() unit.destroy()
worldScreen.game.screen = TechPickerScreen(true, unit.civInfo) worldScreen.game.screen = TechPickerScreen(true, unit.civInfo)
} }.sound("chimes")
} }
if (unit.name == "Great Artist" && !unit.isEmbarked()) { if (unit.name == "Great Artist" && !unit.isEmbarked()) {
@ -161,7 +165,7 @@ class UnitActions {
) { ) {
unit.civInfo.goldenAges.enterGoldenAge() unit.civInfo.goldenAges.enterGoldenAge()
unit.destroy() unit.destroy()
} }.sound("chimes")
} }
if (unit.name == "Great Engineer" && !unit.isEmbarked()) { if (unit.name == "Great Engineer" && !unit.isEmbarked()) {
@ -173,7 +177,7 @@ class UnitActions {
) { ) {
tile.getCity()!!.cityConstructions.addProduction(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) tile.getCity()!!.cityConstructions.addProduction(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5)
unit.destroy() unit.destroy()
} }.sound("chimes")
} }
if (unit.name == "Great Merchant" && !unit.isEmbarked()) { if (unit.name == "Great Merchant" && !unit.isEmbarked()) {
@ -184,7 +188,7 @@ class UnitActions {
unit.civInfo.gold += goldGained unit.civInfo.gold += goldGained
unit.civInfo.addNotification("Your trade mission has earned you [$goldGained] gold!",null, Color.GOLD) unit.civInfo.addNotification("Your trade mission has earned you [$goldGained] gold!",null, Color.GOLD)
unit.destroy() unit.destroy()
} }.sound("chimes")
} }
actionList += UnitAction("Disband unit",unit.currentMovement != 0f actionList += UnitAction("Disband unit",unit.currentMovement != 0f

View File

@ -63,7 +63,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
actionButton.add(Label(unitAction.name.tr(),CameraStageBaseScreen.skin).setFontColor(Color.WHITE)) actionButton.add(Label(unitAction.name.tr(),CameraStageBaseScreen.skin).setFontColor(Color.WHITE))
.pad(5f) .pad(5f)
actionButton.pack() actionButton.pack()
actionButton.onClick { unitAction.action(); UnCivGame.Current.worldScreen.shouldUpdate=true } actionButton.onClick(unitAction.sound) { unitAction.action(); UnCivGame.Current.worldScreen.shouldUpdate=true }
if (!unitAction.canAct) actionButton.disable() if (!unitAction.canAct) actionButton.disable()
return actionButton return actionButton
} }