summaryrefslogtreecommitdiff
path: root/src/com/dabomstew/pkrandom/gui/CodeTweaksDialog.java
blob: 4bfaaa62ef7e1ad71bc113273a99d67f1a6b8bc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dabomstew.pkrandom.gui;

import java.util.ResourceBundle;

import com.dabomstew.pkrandom.CodeTweaks;

/**
 * 
 * @author Stewart
 */
public class CodeTweaksDialog extends javax.swing.JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1771633141425200187L;
	private static final ResourceBundle bundle = ResourceBundle
			.getBundle("com/dabomstew/pkrandom/gui/Bundle");
	private boolean pressedOk;

	/**
	 * Creates new form CodeTweaksDialog
	 */
	public CodeTweaksDialog(RandomizerGUI parent, int current, int available) {
		super(parent, true);
		initComponents();
		initialState(available);
		if (current != 0) {
			current &= available;
			restoreFrom(current);
		}
		pressedOk = false;
		setLocationRelativeTo(parent);
		setVisible(true);

	}

	private void initialState(int available) {
		bwPatchCB.setVisible((available & CodeTweaks.BW_EXP_PATCH) > 0);
		nerfXAccCB.setVisible((available & CodeTweaks.NERF_X_ACCURACY) > 0);
		critRateFixCB.setVisible((available & CodeTweaks.FIX_CRIT_RATE) > 0);
	}

	private void restoreFrom(int current) {
		bwPatchCB.setSelected((current & CodeTweaks.BW_EXP_PATCH) > 0);
		nerfXAccCB.setSelected((current & CodeTweaks.NERF_X_ACCURACY) > 0);
		critRateFixCB.setSelected((current & CodeTweaks.FIX_CRIT_RATE) > 0);
	}

	public boolean pressedOK() {
		return pressedOk;
	}

	public int getChoice() {
		int choice = 0;
		if (bwPatchCB.isSelected()) {
			choice |= CodeTweaks.BW_EXP_PATCH;
		}
		if (nerfXAccCB.isSelected()) {
			choice |= CodeTweaks.NERF_X_ACCURACY;
		}
		if (critRateFixCB.isSelected()) {
			choice |= CodeTweaks.FIX_CRIT_RATE;
		}
		return choice;
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        headerLabel = new javax.swing.JLabel();
        bwPatchCB = new javax.swing.JCheckBox();
        nerfXAccCB = new javax.swing.JCheckBox();
        critRateFixCB = new javax.swing.JCheckBox();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("com/dabomstew/pkrandom/gui/Bundle"); // NOI18N
        setTitle(bundle.getString("CodeTweaksDialog.title")); // NOI18N

        headerLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        headerLabel.setText(bundle.getString("CodeTweaksDialog.headerLabel.text")); // NOI18N

        bwPatchCB.setText(bundle.getString("CodeTweaksDialog.bwPatchCB.text")); // NOI18N
        bwPatchCB.setToolTipText(bundle.getString("CodeTweaksDialog.bwPatchCB.toolTipText")); // NOI18N

        nerfXAccCB.setText(bundle.getString("CodeTweaksDialog.nerfXAccCB.text")); // NOI18N
        nerfXAccCB.setToolTipText(bundle.getString("CodeTweaksDialog.nerfXAccCB.toolTipText")); // NOI18N

        critRateFixCB.setText(bundle.getString("CodeTweaksDialog.critRateFixCB.text")); // NOI18N
        critRateFixCB.setToolTipText(bundle.getString("CodeTweaksDialog.critRateFixCB.toolTipText")); // NOI18N

        okButton.setText(bundle.getString("CodeTweaksDialog.okButton.text")); // NOI18N
        okButton.setMaximumSize(new java.awt.Dimension(65, 23));
        okButton.setMinimumSize(new java.awt.Dimension(65, 23));
        okButton.setPreferredSize(new java.awt.Dimension(65, 23));
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText(bundle.getString("CodeTweaksDialog.cancelButton.text")); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cancelButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(critRateFixCB)
                            .addComponent(nerfXAccCB)
                            .addComponent(bwPatchCB)
                            .addComponent(headerLabel))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(headerLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bwPatchCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(nerfXAccCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(critRateFixCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_okButtonActionPerformed
		pressedOk = true;
		setVisible(false);
	}// GEN-LAST:event_okButtonActionPerformed

	private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed
		pressedOk = false;
		setVisible(false);
	}// GEN-LAST:event_cancelButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox bwPatchCB;
    private javax.swing.JButton cancelButton;
    private javax.swing.JCheckBox critRateFixCB;
    private javax.swing.JLabel headerLabel;
    private javax.swing.JCheckBox nerfXAccCB;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
}