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
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
* [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?
* [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()
// 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
if(city.canAcquireTile(tileInfo)){
tileGroup.addAcquirableIcon()
tileGroup.yieldGroup.isVisible = false
} else {
tileGroup.setColor(0f, 0f, 0f, 0.3f)
var shouldToggleTilesWorked = false
when {
tileInfo.getCity()!=city -> // outside of city
if(city.canAcquireTile(tileInfo)){
tileGroup.addAcquirableIcon()
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
!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.addPopulationIcon()
tileGroup.onClick {
tileGroup.onClick {
selectedTile = tileInfo
if (shouldToggleTilesWorked) {
if (!tileInfo.isWorked() && city.population.getFreePopulation() > 0)
city.workedTiles.add(tileInfo.position)
else if (tileInfo.isWorked()) city.workedTiles.remove(tileInfo.position)
city.cityStats.update()
update()
}
update()
}
tileGroup.onClick {
selectedTile = tileInfo
update()
}
val positionalVector = HexMath().hex2WorldCoords(tileInfo.position.cpy().sub(cityInfo.location))

View File

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

View File

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

View File

@ -122,16 +122,23 @@ fun Label.setFontSize(size:Int): Label {
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
fun Actor.onClick(function: () -> Unit) {
fun Actor.onClick(sound:String,function: () -> Unit){
this.addListener(object : ClickListener() {
override fun clicked(event: InputEvent?, x: Float, y: Float) {
Sounds.play("click")
Sounds.play(sound)
function()
}
} )
}
fun Actor.onClick(function: () -> Unit) {
onClick("click",function)
}
fun Actor.surroundWithCircle(size:Float): IconCircleGroup {
return IconCircleGroup(size,this)
}

View File

@ -43,7 +43,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
for (tileInfo in tileMap.values) {
val tileGroup = WorldTileGroup(tileInfo)
tileGroup.onClick{ onTileClicked(tileInfo, tileGroup)}
tileGroup.onClick{ onTileClicked(tileInfo)}
val positionalVector = HexMath().hex2WorldCoords(tileInfo.position)
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")
if (moveToOverlay != null) moveToOverlay!!.remove()
selectedTile = tileInfo

View File

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

View File

@ -17,7 +17,10 @@ import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
import java.util.*
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 {
@ -44,7 +47,8 @@ class UnitActions {
if(!unit.type.isCivilian() && !unit.isEmbarked() && !unit.type.isWaterUnit()
&& !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") {
@ -61,7 +65,7 @@ class UnitActions {
if(!unit.type.isCivilian() && unit.promotions.canBePromoted()) {
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) {
@ -87,7 +91,7 @@ class UnitActions {
newunit.promotions = unit.promotions
newunit.updateUniques()
newunit.currentMovement = 0f
}
}.sound("promote")
}
}
@ -106,7 +110,7 @@ class UnitActions {
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
unit.destroy()
}
}.sound("chimes")
}
if (unit.hasUnique("Can build improvements on tiles") && !unit.isEmbarked()) {
@ -143,7 +147,7 @@ class UnitActions {
val improvementName = unique.replace("Can build improvement: ","")
actionList += UnitAction("Create [$improvementName]",
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.destroy()
worldScreen.game.screen = TechPickerScreen(true, unit.civInfo)
}
}.sound("chimes")
}
if (unit.name == "Great Artist" && !unit.isEmbarked()) {
@ -161,7 +165,7 @@ class UnitActions {
) {
unit.civInfo.goldenAges.enterGoldenAge()
unit.destroy()
}
}.sound("chimes")
}
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)
unit.destroy()
}
}.sound("chimes")
}
if (unit.name == "Great Merchant" && !unit.isEmbarked()) {
@ -184,7 +188,7 @@ class UnitActions {
unit.civInfo.gold += goldGained
unit.civInfo.addNotification("Your trade mission has earned you [$goldGained] gold!",null, Color.GOLD)
unit.destroy()
}
}.sound("chimes")
}
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))
.pad(5f)
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()
return actionButton
}