-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started adding gui designer for plugin
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
plugin/src/main/kotlin/com/mattmx/ktgui/creator/GuiDesigner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mattmx.ktgui.creator | ||
|
||
import com.mattmx.ktgui.components.screen.GuiScreen | ||
import com.mattmx.ktgui.utils.not | ||
|
||
class GuiDesigner( | ||
val name: String | ||
) : GuiScreen(!"Designer ($name&r)") { | ||
|
||
init { | ||
click.any { | ||
event.isCancelled = false | ||
|
||
// todo save instance | ||
} | ||
} | ||
|
||
fun export(): String { | ||
val start = "gui(\"$name\") {" | ||
val middle = items.values.filterIsInstance<GuiDesignerButton>() | ||
.joinToString("\n") { it.full + " childOf this" } | ||
val end = "}" | ||
|
||
return "$start$middle$end" | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
plugin/src/main/kotlin/com/mattmx/ktgui/creator/GuiDesignerButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.mattmx.ktgui.creator | ||
|
||
import com.mattmx.ktgui.components.button.GuiButton | ||
import com.mattmx.ktgui.utils.legacy | ||
import org.bukkit.inventory.ItemStack | ||
|
||
class GuiDesignerButton(item: ItemStack) : GuiButton<GuiDesignerButton>(item) { | ||
|
||
val enchantPart: String | ||
get() { | ||
val start = "enchant { " | ||
val enchantments = getItemStack()!!.enchantments.entries | ||
if (enchantments.isEmpty()) return "" | ||
|
||
val middle = enchantments.joinToString("\n") { (e, l) -> | ||
" this += Enchantment.${e.name} lvl $l" | ||
} | ||
return "$start$middle\n}" | ||
} | ||
|
||
val lorePart: String | ||
get() { | ||
val start = "lore {" | ||
val lore = getItemStack()!!.lore() | ||
?: return "" | ||
if (lore.isEmpty()) return "" | ||
|
||
val middle = lore.joinToString("\n") { | ||
" add(\"${it.legacy()}\")" | ||
} | ||
return "$start$middle\n}" | ||
} | ||
|
||
val namedPart: String | ||
get() { | ||
val name = getItemStack()!!.displayName().legacy() | ||
return "named(\"$name\")" | ||
} | ||
|
||
val slotsPart: String | ||
get() { | ||
return "slots listOf(${slots().joinToString(", ")})" | ||
} | ||
|
||
val full: String | ||
get() { | ||
val start = "button(Material.${getItemStack()!!.type}) {" | ||
|
||
val tab = " " | ||
var middle = tab | ||
middle += namedPart + "\n" | ||
middle += lorePart.split("\n").joinToString("\n$tab") + "\n" | ||
middle += enchantPart.split("\n").joinToString("\n$tab") + "\n" | ||
|
||
val end = "} $slotsPart" | ||
|
||
return start + middle + end | ||
} | ||
|
||
} |