diff --git a/core/src/com/unciv/ui/options/AdvancedTab.kt b/core/src/com/unciv/ui/options/AdvancedTab.kt index 099fb24443..ff75984069 100644 --- a/core/src/com/unciv/ui/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/options/AdvancedTab.kt @@ -3,7 +3,11 @@ package com.unciv.ui.options import com.badlogic.gdx.Application import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input +import com.badlogic.gdx.files.FileHandle import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.Pixmap +import com.badlogic.gdx.graphics.PixmapIO +import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.ui.Cell import com.badlogic.gdx.scenes.scene2d.ui.SelectBox @@ -11,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Array import com.unciv.UncivGame import com.unciv.models.metadata.GameSettings +import com.unciv.models.metadata.ScreenSize import com.unciv.models.translations.TranslationFileWriter import com.unciv.models.translations.tr import com.unciv.ui.popup.ConfirmPopup @@ -27,9 +32,14 @@ import com.unciv.ui.utils.extensions.onClick import com.unciv.ui.utils.extensions.setFontColor import com.unciv.ui.utils.extensions.toLabel import com.unciv.ui.utils.extensions.toTextButton +import com.unciv.ui.utils.extensions.withoutItem import com.unciv.utils.concurrency.Concurrency import com.unciv.utils.concurrency.launchOnGLThread +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import java.util.* +import java.util.zip.Deflater fun advancedTab( optionsPopup: OptionsPopup, @@ -188,6 +198,73 @@ private fun addTranslationGeneration(table: Table, optionsPopup: OptionsPopup) { generateTranslationsButton.keyShortcuts.add(Input.Keys.F12) generateTranslationsButton.addTooltip("F12", 18f) table.add(generateTranslationsButton).colspan(2).row() + + + val generateScreenshotsButton = "Generate screenshots".toTextButton() + + generateScreenshotsButton.onActivation { + optionsPopup.tabs.selectPage("Advanced") + generateScreenshotsButton.setText("Working...".tr()) + Concurrency.run("GenerateScreenshot") { + val extraImagesLocation = "../../extraImages" + generateScreenshots(arrayListOf( + ScreenshotConfig(630, 500, ScreenSize.Medium, "$extraImagesLocation/itch.io image.png", Vector2(-2f, 2f),false), + ScreenshotConfig(1280, 640, ScreenSize.Medium, "$extraImagesLocation/GithubPreviewImage.png", Vector2(-2f, 4f)), + ScreenshotConfig(1024, 500, ScreenSize.Medium, "$extraImagesLocation/Feature graphic - Google Play.png",Vector2(-2f, 6f)) + )) + } + } + table.add(generateScreenshotsButton).colspan(2).row() + +} + +data class ScreenshotConfig(val width: Int, val height: Int, val screenSize: ScreenSize, var fileLocation:String, var centerTile:Vector2, var attackCity:Boolean=true) + +private fun CoroutineScope.generateScreenshots(configs:ArrayList) { + val currentConfig = configs.first() + launchOnGLThread { + val screenshotGame = + UncivGame.Current.files.loadGameByName("ScreenshotGenerationGame") + UncivGame.Current.settings.screenSize = currentConfig.screenSize + val newScreen = UncivGame.Current.loadGame(screenshotGame) + + + newScreen.stage.viewport.update(currentConfig.width, currentConfig.height, true) + + // Reposition mapholder and minimap whose position was based on the previous stage size... + newScreen.mapHolder.setSize(newScreen.stage.width, newScreen.stage.height) + newScreen.mapHolder.layout() + newScreen.minimapWrapper.x = newScreen.stage.width - newScreen.minimapWrapper.width + + newScreen.mapHolder.setCenterPosition( // Center on the city + currentConfig.centerTile, + immediately = true, + selectUnit = true + ) + + newScreen.mapHolder.onTileClicked(newScreen.mapHolder.tileMap[-2, 3]) // Then click on Keshik + if (currentConfig.attackCity) + newScreen.mapHolder.onTileClicked(newScreen.mapHolder.tileMap[-2, 2]) // Then click city again for attack table + newScreen.mapHolder.zoomIn() + withContext(Dispatchers.IO) { + Thread.sleep(300) + launchOnGLThread { + val pixmap = Pixmap.createFromFrameBuffer( + 0, 0, + currentConfig.width, currentConfig.height + ) + PixmapIO.writePNG( + FileHandle(currentConfig.fileLocation), + pixmap, + Deflater.DEFAULT_COMPRESSION, + true + ) + pixmap.dispose() + val newConfigs = configs.withoutItem(currentConfig) + if (newConfigs.isNotEmpty()) generateScreenshots(newConfigs) + } + } + } } private fun addSetUserId(table: Table, settings: GameSettings) { diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index 4d4b22f300..e4f4185c7d 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -169,7 +169,7 @@ class WorldMapHolder( layout() // Fit the scroll pane to the contents - otherwise, setScroll won't work! } - private fun onTileClicked(tileInfo: TileInfo) { + fun onTileClicked(tileInfo: TileInfo) { if (!worldScreen.viewingCiv.hasExplored(tileInfo) && tileInfo.neighbors.all { worldScreen.viewingCiv.hasExplored(it) }) diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 9855a7bb62..fd6faba6be 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -120,7 +120,7 @@ class WorldScreen( val bottomUnitTable = UnitTable(this) private val battleTable = BattleTable(this) private val zoomController = ZoomButtonPair(mapHolder) - private val minimapWrapper = MinimapHolder(mapHolder) + internal val minimapWrapper = MinimapHolder(mapHolder) private val bottomTileInfoTable = TileInfoTable(viewingCiv) private val notificationsScroll = NotificationsScroll(this) private val nextTurnButton = NextTurnButton() diff --git a/docs/Developers/Generating-screenshots.md b/docs/Developers/Generating-screenshots.md deleted file mode 100644 index 9192c7b901..0000000000 --- a/docs/Developers/Generating-screenshots.md +++ /dev/null @@ -1,32 +0,0 @@ -# Generating Screenshots - -Images are the first way that a player viscerally connects to the game, -and so making our screenshots better leads to a direct increase in interest. - -For us to continue to generate screenshots as the UI improves, we have a saved game named "ScreenshotGenerationGame" in the extraImages folder. - -The easiest way to create screenshots is by: - -- WRITE DOWN which file you're working on! They all look the same! -- Editing the gamesettings.json to the required height/width -- Loading the ScreenshotGenerationGame -- Centering on Elephantine -- Selecting the top-right Keshik, then clicking on Elephantine -- Screenshotting the entire window -- Cropping the area off the top (I use Shutter on Ubuntu for the above 2 steps) -- Save! - -Quick dimensions checklist for y'all! - -- Github preview image - 1280*640 -- Feature Graphic - Google Play - 1024*500 - best in 900x600 resolution (options - display) -- Itch.io image - 630*500 - best in 1050x700 resolution - -# Generating Steam images with Gimp - -- Open map editor -- Take a screenshot of a nice-looking piece of map in the required dimensions (I use Shutter) -- Take the latest Unciv icon, add as another layer, and resize the layer until it's like 90% of the height -- Go here: https://text.imageonline.co/ and select color-black, font-Nobile, and Bold. -- Generate text in a good size to fit into the rest of your image, screenshot that (with the white background) and paste in a new layer -- Use the Bucket Fill, mode-erase, with opacity to get rid of most of the white, this should leave a small outline of white around our black text! diff --git a/extraImages/Feature graphic - Google Play.png b/extraImages/Feature graphic - Google Play.png index 55c3e087f7..51746752a9 100644 Binary files a/extraImages/Feature graphic - Google Play.png and b/extraImages/Feature graphic - Google Play.png differ diff --git a/extraImages/Feature graphic.png b/extraImages/Feature graphic.png deleted file mode 100644 index 1f478edb7f..0000000000 Binary files a/extraImages/Feature graphic.png and /dev/null differ diff --git a/extraImages/GithubPreviewImage.png b/extraImages/GithubPreviewImage.png index 1eb0380f3b..63cc6d3760 100644 Binary files a/extraImages/GithubPreviewImage.png and b/extraImages/GithubPreviewImage.png differ diff --git a/extraImages/itch.io image.png b/extraImages/itch.io image.png index 80f905f205..27b8145051 100644 Binary files a/extraImages/itch.io image.png and b/extraImages/itch.io image.png differ