Tertiary drop table support now never ask me again

This commit is contained in:
ceikry 2023-09-24 15:49:49 -05:00
parent c6cd632a29
commit c7334798f6
3 changed files with 96 additions and 3 deletions

View file

@ -15,6 +15,7 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
val mainModel = object : DefaultTableModel(){}
val defaultModel = object : DefaultTableModel(){}
val charmModel = object : DefaultTableModel(){}
val tertiaryModel = object : DefaultTableModel(){}
val mainTable = object : JTable(mainModel){
override fun editCellAt(row: Int, column: Int): Boolean {
@ -143,6 +144,50 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
val charmScrollPane = JScrollPane(charmTable)
val charmSubtable = Subtable("Charm",charmScrollPane,table.charmTable,charmModel)
val tertiaryTable = object : JTable(tertiaryModel){
override fun editCellAt(row: Int, column: Int): Boolean {
if(column == 0 || column == 1){
ItemMenu.caller = {id,name ->
model.setValueAt(id,row,0)
model.setValueAt(name,row,1)
table.tertiaryTable[row].id = id
}
ItemMenu.open()
return false
}
return super.editCellAt(row, column)
}
override fun editCellAt(row: Int, column: Int, e: EventObject?): Boolean {
if(column == 0 || column == 1){
ItemMenu.caller = {id,name ->
model.setValueAt(id,row,0)
model.setValueAt(name,row,1)
table.tertiaryTable[row].id = id
}
ItemMenu.open()
return false
}
return super.editCellAt(row, column, e)
}
override fun editingStopped(e: ChangeEvent?) {
val editor = cellEditor
val newValue = editor.cellEditorValue.toString()
when(editingColumn){
2 -> table.tertiaryTable[editingRow].minAmt = newValue
3 -> table.tertiaryTable[editingRow].maxAmt = newValue
4 -> {
table.tertiaryTable.totalWeight += newValue.toDouble() - table.tertiaryTable[editingRow].weight
table.tertiaryTable[editingRow].weight = newValue.toDouble()
updateTertiaryPercentages()
}
}
super.editingStopped(e)
}
}
val tertiaryScrollPane = JScrollPane(tertiaryTable)
val tertiarySubtable = Subtable("Tertiary",tertiaryScrollPane,table.tertiaryTable,tertiaryModel)
init {
layout = BorderLayout()
val topPanel = JPanel()
@ -180,6 +225,12 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
}
topPanel.add(charmsButton)
val tertiaryButton = JButton("Edit Tertiary")
tertiaryButton.addActionListener {
tertiarySubtable.open()
}
topPanel.add(tertiaryButton)
val defaultButton = JButton("Edit Default")
defaultButton.addActionListener {
defaultSubtable.open()
@ -215,6 +266,14 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
charmModel.addColumn("Weight")
charmModel.addColumn("(%)")
tertiaryModel.addColumn("ID")
tertiaryModel.addColumn("Name")
tertiaryModel.addColumn("Min Amt")
tertiaryModel.addColumn("Max Amt")
tertiaryModel.addColumn("Weight")
tertiaryModel.addColumn("(%)")
tertiaryModel.addColumn("(1/%)")
mainTable.inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete")
mainTable.actionMap.put("delete",object : AbstractAction() {
override fun actionPerformed(e: ActionEvent?) {
@ -255,6 +314,20 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
}
})
tertiaryTable.inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete")
tertiaryTable.actionMap.put("delete",object : AbstractAction() {
override fun actionPerformed(e: ActionEvent?) {
try {
table.totalWeight -= table[tertiaryTable.selectedRow].weight
table.removeAt(tertiaryTable.selectedRow)
tertiaryModel.removeRow(tertiaryTable.selectedRow)
updateTertiaryPercentages()
} catch(e: Exception){
Logger.logErr("Tried to remove nonexistent row ${tertiaryTable.selectedRow}")
}
}
})
addWindowListener(object : WindowAdapter(){
override fun windowClosing(e: WindowEvent?) {
FileLoader.dropTableList?.populated = false
@ -333,6 +406,9 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
for(item in table){
mainModel.addRow(arrayOf(item.id,TableData.getItemName(item.id),item.minAmt,item.maxAmt,item.weight,getPercentage(item.weight,table),getInversePercentage(item.weight, table)))
}
for(item in table.tertiaryTable){
tertiaryModel.addRow(arrayOf(item.id,TableData.getItemName(item.id),item.minAmt,item.maxAmt,item.weight,getPercentage(item.weight,table.tertiaryTable),getInversePercentage(item.weight, table.tertiaryTable)))
}
isVisible = true
}
@ -350,6 +426,13 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
}
}
fun updateTertiaryPercentages(){
for(i in 0 until tertiaryModel.rowCount){
tertiaryModel.setValueAt(getPercentage(table.tertiaryTable[i].weight,table.tertiaryTable),i,5)
tertiaryModel.setValueAt(getInversePercentage(table.tertiaryTable[i].weight,table.tertiaryTable),i,6)
}
}
fun updateMainPercentages(){
for(i in 0 until mainModel.rowCount){
mainModel.setValueAt(getPercentage(table[i].weight,table),i,5)

View file

@ -33,6 +33,10 @@ enum class Editors(val data: EditorData) {
parseTable(dropTable["main"] as JSONArray,table,false)
parseTable(dropTable["default"] as JSONArray,table,true)
parseTable(dropTable["charm"] as JSONArray,table.charmTable,false)
(dropTable["tertiary"] as? JSONArray)?.let {
Logger.logInfo("Found tertiary table for " + table.ids)
parseTable(it, table.tertiaryTable, false)
}
table.description = (dropTable["description"] ?: "").toString()
TableData.tables.add(table)
counter++
@ -49,6 +53,9 @@ enum class Editors(val data: EditorData) {
val main = saveTable(table)
val charms = saveTable(table.charmTable)
val always = saveTable(table.alwaysTable)
val tertiary = saveTable(table.tertiaryTable)
if (tertiary.isNotEmpty())
t.put("tertiary", tertiary)
t.put("main",main)
t.put("charm",charms)
t.put("default",always)

View file

@ -37,6 +37,7 @@ object FileLoader{
parseTable(dropTable["main"] as JSONArray, table, false)
parseTable(dropTable["default"] as JSONArray, table, true)
parseTable(dropTable["charm"] as JSONArray, table.charmTable, false)
(dropTable["tertiary"] as? JSONArray)?.let { parseTable(it, table.tertiaryTable, false) }
table.description = (dropTable["description"] ?: "").toString()
TableData.tables.add(table)
counter++
@ -90,6 +91,8 @@ open class WeightBasedTable() : ArrayList<WeightedItem>(){
class NPCDropTable() : WeightBasedTable(){
val charmTable = WeightBasedTable()
val alwaysTable = WeightBasedTable()
val tertiaryTable = WeightBasedTable()
var ids = ""
var description = ""
override fun add(element: WeightedItem): Boolean {