Wednesday, February 11, 2009

Java: CharSi Update #19

I decided to break up the item generator task into three parts. Specifically there will be three tabs in the generator tab, one for runewords, charms and magical/rare items. As runewords are the most useful and important, I'll create that tab first.

As it turns out this tab wasn't as difficulty as I first assumed. It did help that I borrowed several GUI and listener pieces from the Armor and Runeword Wizard class files. This made putting the GUI together pretty much academic. Although for the base item panel I did have to change all of the components from JCheckBoxes to JRadioButtons, I didn't want more than one selected at a time.


Once the GUI was setup the listeners had to be attached to their designated components, and that is where the fun began. Just about every component has more than one listener attached, and vice versa, with all sorts of checks in place to ensure everything is set correctly. For example, when a JRadioButton is selected in the Base Items panel this marks a flag variable that designates which folder to view when looking for base item files. Also this populates the Possible Runeword JList with all runewords that can be made in this base item.

Still each listener only affected so much and therefore everything was put in order relatively quickly. The biggest, and most important, listener was the one attached to the Create Runeword JButton. This was the one that pretty much performed the actions the panel was created for. What it does is take the text from the Base Item Display and save this information into a set of String variables and an integer array. At the same time it does the same for the text in the Runeword Stats JTextArea, except that the majority of the mods are saved in a StringBuffer rather than an integer array. Only the mods affecting damage and defense are saved in an integer array. The reason for this is that once the base and runeword mods are saved, the variables pertaining to damage and defense are entered into the appropriate equations to determine their final outcomes. Once calculated all of the mod information is then combined into a StringBuffer variable and then exported to a newly created file.

While the creation is taking place the user is prompted to choose the values for any variable mods, as well as the name of the item being created. Once the runeword is finished it's name is displayed in the Completed Items JList, and selecting it will show the final result in the middle JTextArea component.

Of course, just being able to create these files isn't enough, it has to be possible to equip them on a virtual character as well. So the Importable Items JLists in the equipment tabs have their listeners set to populate the components once the application is launched. Once done it is now possible to equip user created runewords onto the virtual character.

Next step, allow the creation of rare and magical items by the user. This panel will borrow extensively from the runeword generator panel with only a few modifications. I don't think this will take too much time, but obtaining the full list of prefix and suffix mods and entering them into the code will be a bit time consuming.

No comments: