mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Mod preview images: Dispose of Pixmap, cache images for later use
Based on CR by @SomeTroglodyte
This commit is contained in:
parent
4a7f65f281
commit
5fe8fbf99a
@ -364,6 +364,9 @@ class ModManagementScreen(
|
|||||||
modOptions.modSize
|
modOptions.modSize
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val repoUrlToPreviewImage = HashMap<String, Texture?>()
|
||||||
|
|
||||||
private fun addModInfoToActionTable(
|
private fun addModInfoToActionTable(
|
||||||
repoUrl: String,
|
repoUrl: String,
|
||||||
default_branch: String,
|
default_branch: String,
|
||||||
@ -376,19 +379,38 @@ class ModManagementScreen(
|
|||||||
// Display metadata
|
// Display metadata
|
||||||
|
|
||||||
val imageHolder = Table()
|
val imageHolder = Table()
|
||||||
Concurrency.run {
|
|
||||||
val imagePixmap = Github.tryGetPreviewImage(repoUrl, default_branch) ?: return@run
|
|
||||||
Concurrency.runOnGLThread {
|
|
||||||
val largestImageSize = max(imagePixmap.width, imagePixmap.height)
|
|
||||||
val cell = imageHolder.add(Image(Texture(imagePixmap)))
|
|
||||||
|
|
||||||
val maxAllowedImageSize = 200f
|
fun setTextureAsPreview(texture: Texture){
|
||||||
if (largestImageSize > maxAllowedImageSize) {
|
val maxAllowedImageSize = 200f
|
||||||
val resizeRatio = maxAllowedImageSize / largestImageSize
|
val cell = imageHolder.add(Image(texture))
|
||||||
cell.size(imagePixmap.width * resizeRatio, imagePixmap.height * resizeRatio)
|
val largestImageSize = max(texture.width, texture.height)
|
||||||
|
if (largestImageSize > maxAllowedImageSize) {
|
||||||
|
val resizeRatio = maxAllowedImageSize / largestImageSize
|
||||||
|
cell.size(texture.width * resizeRatio, texture.height * resizeRatio)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!repoUrlToPreviewImage.containsKey(repoUrl)) {
|
||||||
|
Concurrency.run {
|
||||||
|
val imagePixmap = Github.tryGetPreviewImage(repoUrl, default_branch)
|
||||||
|
|
||||||
|
if (imagePixmap == null) {
|
||||||
|
repoUrlToPreviewImage[repoUrl] = null
|
||||||
|
return@run
|
||||||
|
}
|
||||||
|
Concurrency.runOnGLThread {
|
||||||
|
val texture = Texture(imagePixmap)
|
||||||
|
imagePixmap.dispose()
|
||||||
|
repoUrlToPreviewImage[repoUrl] = texture
|
||||||
|
setTextureAsPreview(texture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
val texture = repoUrlToPreviewImage[repoUrl]
|
||||||
|
if (texture!=null) setTextureAsPreview(texture)
|
||||||
|
}
|
||||||
|
|
||||||
modActionTable.add(imageHolder).row()
|
modActionTable.add(imageHolder).row()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user