mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 12:05:54 -04:00
chore: Simplified brush code - less overload functions, by adding a parameter to existing functions (reduce layers of indirection)
This commit is contained in:
parent
ce5a723e5a
commit
f398e08928
@ -227,7 +227,7 @@ class MapEditorEditImprovementsTab(
|
||||
) {
|
||||
val road = RoadStatus.entries.firstOrNull { r -> r.name == it }
|
||||
if (road != null)
|
||||
editTab.setBrush(BrushHandlerType.Road, it, "Improvement/$it") { tile ->
|
||||
editTab.setBrush(it, "Improvement/$it", handlerType = BrushHandlerType.Road) { tile ->
|
||||
tile.roadStatus = if (tile.roadStatus == road) RoadStatus.None else road
|
||||
}
|
||||
else
|
||||
@ -286,7 +286,7 @@ class MapEditorEditStartsTab(
|
||||
val eraserIcon = "Nation/${firstNation.name}"
|
||||
val eraser = FormattedLine("Remove starting locations", icon = eraserIcon, size = 24, iconCrossed = true)
|
||||
add(eraser.render(0f).apply { onClick {
|
||||
editTab.setBrush(BrushHandlerType.Direct, "Remove", eraserIcon, pediaLink = "", isRemove = true) { tile ->
|
||||
editTab.setBrush("Remove", eraserIcon, handlerType = BrushHandlerType.Direct, pediaLink = "", isRemove = true) { tile ->
|
||||
tile.tileMap.removeStartingLocations(tile.position)
|
||||
}
|
||||
} }).padBottom(0f).row()
|
||||
@ -306,7 +306,7 @@ class MapEditorEditStartsTab(
|
||||
val isMajorCiv = ruleset.nations[it]?.isMajorCiv ?: false
|
||||
val selectedUsage = if (isMajorCiv) TileMap.StartingLocation.Usage.entries[usageOptionGroup.checkedIndex]
|
||||
else TileMap.StartingLocation.Usage.Normal
|
||||
editTab.setBrush(BrushHandlerType.Direct, it.spectatorToAnyCiv(), icon, pediaLink) { tile ->
|
||||
editTab.setBrush(it.spectatorToAnyCiv(), icon, BrushHandlerType.Direct, pediaLink) { tile ->
|
||||
// toggle the starting location here, note this allows
|
||||
// both multiple locations per nation and multiple nations per tile
|
||||
if (!tile.tileMap.addStartingLocation(it, tile, selectedUsage))
|
||||
|
@ -150,16 +150,18 @@ class MapEditorEditTab(
|
||||
}
|
||||
|
||||
// "Normal" setBrush overload, using named RulesetObject icon
|
||||
fun setBrush(name: String, icon: String, pediaLink: String = icon, isRemove: Boolean = false, applyAction: (Tile)->Unit) {
|
||||
brushHandlerType = BrushHandlerType.Tile
|
||||
fun setBrush(name: String, icon: String, handlerType: BrushHandlerType = BrushHandlerType.Tile,
|
||||
pediaLink: String = icon, isRemove: Boolean = false, applyAction: (Tile)->Unit) {
|
||||
brushHandlerType = handlerType
|
||||
val brushActor = FormattedLine(name, icon = icon, iconCrossed = isRemove).render(0f)
|
||||
linkCivilopedia(brushActor, pediaLink)
|
||||
brushCell.setActor(brushActor)
|
||||
brushAction = applyAction
|
||||
}
|
||||
|
||||
// Helper overload for brushes using icons not existing as RulesetObject
|
||||
private fun setBrush(name: String, icon: Actor, pediaLink: String, applyAction: (Tile)->Unit) {
|
||||
brushHandlerType = BrushHandlerType.Tile
|
||||
fun setBrush(handlerType: BrushHandlerType, name: String, icon: Actor, pediaLink: String, applyAction: (Tile)->Unit) {
|
||||
brushHandlerType = handlerType
|
||||
val line = Table().apply {
|
||||
add(icon).padRight(10f)
|
||||
add(name.toLabel())
|
||||
@ -168,16 +170,6 @@ class MapEditorEditTab(
|
||||
brushCell.setActor(line)
|
||||
brushAction = applyAction
|
||||
}
|
||||
// This overload is used by Roads and Starting locations
|
||||
fun setBrush(handlerType: BrushHandlerType, name: String, icon: String, pediaLink: String = icon, isRemove: Boolean = false, applyAction: (Tile)->Unit) {
|
||||
setBrush(name, icon, pediaLink, isRemove, applyAction)
|
||||
brushHandlerType = handlerType
|
||||
}
|
||||
// This overload is used by Rivers
|
||||
fun setBrush(handlerType: BrushHandlerType, name: String, icon: Actor, pediaLink: String, applyAction: (Tile)->Unit) {
|
||||
setBrush(name, icon, pediaLink, applyAction)
|
||||
brushHandlerType = handlerType
|
||||
}
|
||||
|
||||
override fun activated(index: Int, caption: String, pager: TabbedPager) {
|
||||
if (editorScreen.editTabsNeedRefresh) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user