Skip to content

Commit aba55ab

Browse files
committed
Added LearnsetsTable, MovesTable
1 parent ca10719 commit aba55ab

15 files changed

Lines changed: 816 additions & 34 deletions

src/main/java/io/github/turtleisaac/pokeditor/DataManager.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
import io.github.turtleisaac.pokeditor.gamedata.GameFiles;
2828
import io.github.turtleisaac.pokeditor.gui.PokeditorManager;
2929
import io.github.turtleisaac.pokeditor.gui.sheets.DefaultSheetPanel;
30-
import io.github.turtleisaac.pokeditor.gui.sheets.tables.DefaultTable;
31-
import io.github.turtleisaac.pokeditor.gui.sheets.tables.EvolutionsTable;
32-
import io.github.turtleisaac.pokeditor.gui.sheets.tables.PersonalTable;
30+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.formats.EvolutionsTable;
31+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.formats.LearnsetsTable;
32+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.formats.MovesTable;
33+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.formats.PersonalTable;
3334

3435
import java.lang.reflect.ParameterizedType;
3536
import java.util.HashMap;
@@ -54,6 +55,20 @@ public static DefaultSheetPanel<EvolutionData> createEvolutions(PokeditorManager
5455
return new DefaultSheetPanel<>(manager, new EvolutionsTable(data, textData));
5556
}
5657

58+
public static DefaultSheetPanel<LearnsetData> createLearnsets(PokeditorManager manager, NintendoDsRom rom)
59+
{
60+
List<TextBankData> textData = DataManager.getData(rom, TextBankData.class);
61+
List<LearnsetData> data = DataManager.getData(rom, LearnsetData.class);
62+
return new DefaultSheetPanel<>(manager, new LearnsetsTable(data, textData));
63+
}
64+
65+
public static DefaultSheetPanel<MoveData> createMoves(PokeditorManager manager, NintendoDsRom rom)
66+
{
67+
List<TextBankData> textData = DataManager.getData(rom, TextBankData.class);
68+
List<MoveData> data = DataManager.getData(rom, MoveData.class);
69+
return new DefaultSheetPanel<>(manager, new MovesTable(data, textData));
70+
}
71+
5772
private static final Injector injector = Guice.createInjector(
5873
new PersonalModule(),
5974
new LearnsetsModule(),

src/main/java/io/github/turtleisaac/pokeditor/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.github.turtleisaac.pokeditor.gui.PokeditorManager;
1717
import io.github.turtleisaac.pokeditor.gui_old.projects.projectwindow.console.ConsoleWindow;
1818

19+
import java.util.Locale;
1920
import java.util.function.Supplier;
2021

2122
/**
@@ -31,6 +32,7 @@ public class Main
3132

3233
public static void main(String[] args) throws ToolCreationException
3334
{
35+
// Locale.setDefault(Locale.FRANCE);
3436
Tool tool = Tool.create();
3537
tool.setType(ProgramType.PROJECT)
3638
.setName("PokEditor")

src/main/java/io/github/turtleisaac/pokeditor/gui/PokeditorManager.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import io.github.turtleisaac.pokeditor.DataManager;
99
import io.github.turtleisaac.pokeditor.formats.GenericFileData;
1010
import io.github.turtleisaac.pokeditor.formats.evolutions.EvolutionData;
11+
import io.github.turtleisaac.pokeditor.formats.learnsets.LearnsetData;
12+
import io.github.turtleisaac.pokeditor.formats.moves.MoveData;
1113
import io.github.turtleisaac.pokeditor.formats.personal.PersonalData;
1214
import io.github.turtleisaac.pokeditor.formats.text.TextBankData;
1315
import io.github.turtleisaac.pokeditor.gamedata.Game;
@@ -112,6 +114,15 @@ public PokeditorManager(Tool tool)
112114
sheetPanels.put(EvolutionData.class, evolutionsPanel);
113115
// panels.add(evolutionsPanel);
114116

117+
DefaultSheetPanel<LearnsetData> learnsetsPanel = DataManager.createLearnsets(this, rom);
118+
learnsetsPanel.setName("Learnsets Sheet");
119+
sheetPanels.put(LearnsetData.class, learnsetsPanel);
120+
// panels.add(evolutionsPanel);
121+
122+
DefaultSheetPanel<MoveData> movesPanel = DataManager.createMoves(this, rom);
123+
movesPanel.setName("Moves Sheet");
124+
sheetPanels.put(MoveData.class, movesPanel);
125+
115126
JPanel spritesPanel = new JPanel();
116127
spritesPanel.setName("Battle Sprites");
117128

@@ -121,8 +132,9 @@ public PokeditorManager(Tool tool)
121132
waterPanel.setName("Water");
122133
PanelGroup encounters = new PanelGroup("Encounters", fieldPanel, waterPanel);
123134

124-
PanelGroup pokemonGroup = new PanelGroup("Pokémon Editing", personalPanel, evolutionsPanel, spritesPanel);
135+
PanelGroup pokemonGroup = new PanelGroup("Pokémon Editing", personalPanel, learnsetsPanel, evolutionsPanel, spritesPanel);
125136
panels.add(pokemonGroup);
137+
panels.add(movesPanel);
126138
panels.add(encounters);
127139
panels.add(placeholder);
128140
}

src/main/java/io/github/turtleisaac/pokeditor/gui/sheets/DefaultSheetPanel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ private void saveSheetButtonPressed(ActionEvent e) {
191191

192192
private void reloadSheetButtonPressed(ActionEvent e) {
193193
manager.resetData(table.getDataClass());
194+
table.getFormatModel().fireTableDataChanged();
194195
}
195196

196197
private void findButtonPressed(ActionEvent e) {

src/main/java/io/github/turtleisaac/pokeditor/gui/sheets/tables/CellTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum CellTypes
99
STRING,
1010
COMBO_BOX,
1111
COLORED_COMBO_BOX,
12+
BITFIELD_COMBO_BOX,
1213
CHECKBOX,
1314
CUSTOM;
1415

src/main/java/io/github/turtleisaac/pokeditor/gui/sheets/tables/DefaultTable.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.turtleisaac.pokeditor.formats.GenericFileData;
66
import io.github.turtleisaac.pokeditor.formats.text.TextBankData;
77
import io.github.turtleisaac.pokeditor.gui.PokeditorManager;
8+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.editors.BitfieldComboBoxEditor;
89
import io.github.turtleisaac.pokeditor.gui.sheets.tables.editors.CheckBoxEditor;
910
import io.github.turtleisaac.pokeditor.gui.sheets.tables.editors.ComboBoxCellEditor;
1011
import io.github.turtleisaac.pokeditor.gui.sheets.tables.editors.NumberOnlyCellEditor;
@@ -115,7 +116,7 @@ public DefaultTable(CellTypes[] cellTypes, FormatModel<E> model, List<TextBankDa
115116
// });
116117
}
117118

118-
abstract Queue<String[]> obtainTextSources(List<TextBankData> textData);
119+
public abstract Queue<String[]> obtainTextSources(List<TextBankData> textData);
119120

120121
public FormatModel<E> getFormatModel()
121122
{
@@ -143,15 +144,21 @@ public void loadCellRenderers(Queue<String[]> textSources)
143144
col.setCellRenderer(new CheckBoxRenderer());
144145
col.setCellEditor(new CheckBoxEditor());
145146
}
146-
else if (c == CellTypes.COMBO_BOX || c == CellTypes.COLORED_COMBO_BOX)
147+
else if (c == CellTypes.COMBO_BOX || c == CellTypes.COLORED_COMBO_BOX || c == CellTypes.BITFIELD_COMBO_BOX)
147148
{
148149
String[] text = getTextFromSource(textSources);
149-
col.setCellEditor(new ComboBoxCellEditor(text));
150+
151+
if (c != CellTypes.BITFIELD_COMBO_BOX) //normal and colored
152+
col.setCellEditor(new ComboBoxCellEditor(text));
153+
else // bitfield combo box
154+
col.setCellEditor(new BitfieldComboBoxEditor(text));
150155

151156
if (c == CellTypes.COMBO_BOX)
152157
col.setCellRenderer(new IndexedStringCellRenderer(text));
153-
else
158+
else if (c == CellTypes.COLORED_COMBO_BOX)
154159
col.setCellRenderer(new IndexedStringCellRenderer.ColoredIndexedStringCellRenderer(text, PokeditorManager.typeColors));
160+
else
161+
col.setCellRenderer(new BitfieldStringCellRenderer(text));
155162
}
156163
else if (c == CellTypes.INTEGER)
157164
{
@@ -195,7 +202,7 @@ public void resetIndexedCellRendererText()
195202
CellTypes c = cellTypes[i];
196203
TableColumn col = getColumnModel().getColumn(i);
197204

198-
if (c == CellTypes.COMBO_BOX || c == CellTypes.COLORED_COMBO_BOX)
205+
if (c == CellTypes.COMBO_BOX || c == CellTypes.COLORED_COMBO_BOX || c == CellTypes.BITFIELD_COMBO_BOX)
199206
{
200207
String[] text = textSources.remove();
201208
if (text == null)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.turtleisaac.pokeditor.gui.sheets.tables.editors;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
6+
public class BitfieldComboBoxEditor extends ComboBoxCellEditor
7+
{
8+
public BitfieldComboBoxEditor(String[] items)
9+
{
10+
super(items);
11+
}
12+
13+
@Override
14+
public Object getCellEditorValue()
15+
{
16+
int val = comboBox.getSelectedIndex();
17+
if (val == 0)
18+
return 0;
19+
20+
return (1 << val - 1);
21+
}
22+
23+
@Override
24+
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
25+
{
26+
int val = (Integer) value;
27+
if (val == 0)
28+
comboBox.setSelectedIndex(0);
29+
else {
30+
val = (int) (Math.log(val) / Math.log(2)) + 1;
31+
comboBox.setSelectedIndex(val);
32+
}
33+
34+
return comboBox;
35+
}
36+
}

src/main/java/io/github/turtleisaac/pokeditor/gui/sheets/tables/EvolutionsTable.java renamed to src/main/java/io/github/turtleisaac/pokeditor/gui/sheets/tables/formats/EvolutionsTable.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
package io.github.turtleisaac.pokeditor.gui.sheets.tables;
1+
package io.github.turtleisaac.pokeditor.gui.sheets.tables.formats;
22

33
import io.github.turtleisaac.pokeditor.formats.evolutions.EvolutionData;
44
import io.github.turtleisaac.pokeditor.formats.text.TextBankData;
55
import io.github.turtleisaac.pokeditor.gamedata.TextFiles;
6-
import io.github.turtleisaac.pokeditor.gui.PokeditorManager;
7-
import io.github.turtleisaac.pokeditor.gui.sheets.tables.editors.CheckBoxEditor;
6+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.CellTypes;
7+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.DefaultTable;
8+
import io.github.turtleisaac.pokeditor.gui.sheets.tables.FormatModel;
89
import io.github.turtleisaac.pokeditor.gui.sheets.tables.editors.ComboBoxCellEditor;
910
import io.github.turtleisaac.pokeditor.gui.sheets.tables.editors.NumberOnlyCellEditor;
10-
import io.github.turtleisaac.pokeditor.gui.sheets.tables.renderers.CheckBoxRenderer;
1111
import io.github.turtleisaac.pokeditor.gui.sheets.tables.renderers.IndexedStringCellRenderer;
1212

1313
import javax.swing.*;
1414
import javax.swing.table.DefaultTableCellRenderer;
1515
import javax.swing.table.TableCellEditor;
1616
import javax.swing.table.TableCellRenderer;
17-
import javax.swing.table.TableColumn;
1817
import java.awt.*;
1918
import java.util.LinkedList;
2019
import java.util.List;
@@ -28,11 +27,11 @@ public class EvolutionsTable extends DefaultTable<EvolutionData>
2827

2928
public EvolutionsTable(List<EvolutionData> data, List<TextBankData> textData)
3029
{
31-
super(EvolutionsTable.EvolutionsModel.evolutionsClasses, new EvolutionsTable.EvolutionsModel(data, textData), textData, columnWidths, new EvolutionRequirementCellSupplier());
30+
super(EvolutionsModel.evolutionsClasses, new EvolutionsModel(data, textData), textData, columnWidths, new EvolutionRequirementCellSupplier());
3231
}
3332

3433
@Override
35-
Queue<String[]> obtainTextSources(List<TextBankData> textData)
34+
public Queue<String[]> obtainTextSources(List<TextBankData> textData)
3635
{
3736
Queue<String[]> textSources = new LinkedList<>();
3837

@@ -84,7 +83,10 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex)
8483

8584
if (aValue instanceof String)
8685
{
87-
if (columnIndex != -1)
86+
CellTypes cellType = evolutionsClasses[columnIndex + NUM_FROZEN_COLUMNS];
87+
if (cellType == CellTypes.CHECKBOX)
88+
aValue = Boolean.parseBoolean(((String) aValue).trim());
89+
else if (cellType != CellTypes.STRING)
8890
aValue = Integer.parseInt(((String) aValue).trim());
8991
}
9092

0 commit comments

Comments
 (0)