Skip to content

Commit

Permalink
add source dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDiamondPro committed May 26, 2024
1 parent b206340 commit 6c8894f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 26 deletions.
13 changes: 11 additions & 2 deletions src/main/kotlin/dev/dediamondpro/resourcify/gui/PaginatedScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ abstract class PaginatedScreen : WindowScreen(version = ElementaVersion.V5, draw
private var defaultScale = -1

init {
currentScreen?.let { backScreens.add(it) }
forwardScreens.clear()
if (!replacingScreen) {
currentScreen?.let { backScreens.add(it) }
forwardScreens.clear()
}
}

override fun onDrawScreen(matrixStack: UMatrixStack, mouseX: Int, mouseY: Int, partialTicks: Float) {
Expand Down Expand Up @@ -88,7 +90,14 @@ abstract class PaginatedScreen : WindowScreen(version = ElementaVersion.V5, draw
displayScreen(forwardScreen)
}

fun replaceScreen(screen: () -> GuiScreen) {
replacingScreen = true
displayScreen(screen())
replacingScreen = false
}

companion object {
private var replacingScreen = false
val backScreens: MutableList<GuiScreen> = mutableListOf()
val forwardScreens: MutableList<GuiScreen> = mutableListOf()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import dev.dediamondpro.resourcify.platform.Platform
import dev.dediamondpro.resourcify.services.ISearchData
import dev.dediamondpro.resourcify.services.IService
import dev.dediamondpro.resourcify.services.ProjectType
import dev.dediamondpro.resourcify.services.curseforge.CurseForgeService
import dev.dediamondpro.resourcify.services.modrinth.ModrinthService
import dev.dediamondpro.resourcify.util.localize
import dev.dediamondpro.resourcify.util.supplyAsync
import gg.essential.elementa.components.*
Expand All @@ -43,8 +45,11 @@ import java.io.File
import java.util.concurrent.CompletableFuture
import kotlin.math.ceil

class BrowseScreen(private val service: IService, private val type: ProjectType, private val downloadFolder: File) :
PaginatedScreen() {
class BrowseScreen(
private val type: ProjectType,
private val downloadFolder: File,
private val service: IService = ModrinthService
) : PaginatedScreen() {

private var offset = 0
private val selectedCategories = mutableListOf<String>()
Expand All @@ -65,20 +70,6 @@ class BrowseScreen(private val service: IService, private val type: ProjectType,
height = 100.percent()
} childOf contentBox

private val sideBoxScrollable = ScrollComponent(pixelsPerScroll = 30f, scrollAcceleration = 1.5f).constrain {
x = 0.pixels()
y = 33.pixels()
width = 160.pixels()
height = 100.percent() - 37.pixels()
} childOf sideContainer

private val categoryContainer = UIBlock(color = Color(0, 0, 0, 100)).constrain {
x = 0.pixels()
y = 0.pixels()
width = 160.pixels()
height = ChildLocationSizeConstraint()
} childOf sideBoxScrollable

private val mainBox = UIContainer().constrain {
x = 0.pixels(alignOpposite = true)
y = 0.pixels()
Expand Down Expand Up @@ -126,6 +117,43 @@ class BrowseScreen(private val service: IService, private val type: ProjectType,
height = 29.pixels()
} childOf sideContainer

val sideBoxScrollable = ScrollComponent(pixelsPerScroll = 30f, scrollAcceleration = 1.5f).constrain {
x = 0.pixels()
y = SiblingConstraint(padding = 4f)
width = 160.pixels()
height = 100.percent() - 37.pixels()
} childOf sideContainer

val servicesBox = UIBlock(color = Color(0, 0, 0, 100)).constrain {
x = 0.pixels()
y = 0.pixels()
width = 160.pixels()
height = ChildLocationSizeConstraint()
} childOf sideBoxScrollable
UIText("resourcify.browse.source".localize()).constrain {
x = 4.pixels()
y = 4.pixels()
textScale = 1.5f.pixels()
} childOf servicesBox
val services = listOf(ModrinthService, CurseForgeService).associateBy { it.getName() }
DropDown(
services.keys.toList(), onlyOneOption = true,
selectedOptions = mutableListOf(service.getName())
).constrain {
x = 4.pixels()
y = SiblingConstraint(padding = 4f)
width = 100.percent() - 8.pixels()
}.onSelectionUpdate {
replaceScreen { BrowseScreen(type, downloadFolder, services[it.first()]!!) }
} childOf servicesBox

val categoryContainer = UIBlock(color = Color(0, 0, 0, 100)).constrain {
x = 0.pixels()
y = SiblingConstraint(padding = 4f)
width = 160.pixels()
height = ChildLocationSizeConstraint()
} childOf sideBoxScrollable

val categoriesBox = UIContainer().constrain {
x = 0.pixels()
y = 0.pixels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import dev.dediamondpro.resourcify.elements.MinecraftButton
import dev.dediamondpro.resourcify.gui.browsepage.BrowseScreen
import dev.dediamondpro.resourcify.gui.update.UpdateGui
import dev.dediamondpro.resourcify.services.ProjectType
import dev.dediamondpro.resourcify.services.curseforge.CurseForgeService
import dev.dediamondpro.resourcify.services.modrinth.ModrinthService
import dev.dediamondpro.resourcify.util.Icons
import dev.dediamondpro.resourcify.util.isHidden
import gg.essential.elementa.ElementaVersion
Expand Down Expand Up @@ -85,7 +83,7 @@ object PackScreensAddition {
fun onMouseClick(mouseX: Double, mouseY: Double, button: Int, type: ProjectType, folder: File) {
if (addButton.isPointInside(mouseX.toFloat(), mouseY.toFloat()) && button == 0) {
USound.playButtonPress()
UScreen.displayScreen(BrowseScreen(ModrinthService, type, folder))
UScreen.displayScreen(BrowseScreen(type, folder))
} else if (!updateButton.isHidden() && updateButton.isPointInside(mouseX.toFloat(), mouseY.toFloat())
&& button == 0
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object NetworkUtil {
headers: Map<String, String> = emptyMap()
): CompletableFuture<ByteArray?> {
return cache[url]?.getBytes()?.let {
supply { it }
supplyAsync { it }
} ?: currentlyFetching[url] ?: startFetch(url, attempts, headers)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/resourcify/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"resourcify.browse.sort.follows": "Follows",
"resourcify.browse.sort.newest": "Newest",
"resourcify.browse.sort.updated": "Updated",
"resourcify.browse.source": "Source",
"resourcify.browse.minecraft_version": "Minecraft Version",
"resourcify.browse.minecraft_version.placeholder": "Choose Versions",
"resourcify.browse.by": "by %s",

"resourcify.project.description": "Description",
"resourcify.project.gallery": "Gallery",
"resourcify.project.versions": "Versions",
"resourcify.project.modrinth": "Modrinth",
"resourcify.project.categories": "Categories:",
"resourcify.project.external_resources": "External Resources:",
"resourcify.project.issues": "Issues",
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/resourcify/lang/ko_kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"resourcify.project.description": "설명",
"resourcify.project.gallery": "갤러리",
"resourcify.project.versions": "버전",
"resourcify.project.modrinth": "Modrinth",
"resourcify.project.categories": "카테고리:",
"resourcify.project.external_resources": "외부 리소스:",
"resourcify.project.issues": "이슈",
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/resourcify/lang/tr_tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"resourcify.project.description": "Açıklama",
"resourcify.project.gallery": "Galeri",
"resourcify.project.versions": "Sürümler",
"resourcify.project.modrinth": "Modrinth",
"resourcify.project.categories": "Kategoriler:",
"resourcify.project.external_resources": "Harici Kaynaklar:",
"resourcify.project.issues": "Sorunlar",
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/resourcify/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"resourcify.project.description": "描述",
"resourcify.project.gallery": "画廊",
"resourcify.project.versions": "版本",
"resourcify.project.modrinth": "Modrinth",
"resourcify.project.categories": "类别:",
"resourcify.project.external_resources": "外部资源:",
"resourcify.project.issues": "问题",
Expand Down

0 comments on commit 6c8894f

Please sign in to comment.