Browse Source

Implement ships page

master
Chris Smith 15 years ago
parent
commit
fb553185d8

+ 19
- 7
src/uk/co/md87/evetool/api/wrappers/CharacterSheet.java View File

@@ -34,6 +34,7 @@ import uk.co.md87.evetool.api.wrappers.data.BasicCharInfo;
34 34
 import uk.co.md87.evetool.api.wrappers.data.BasicCloneInfo;
35 35
 import uk.co.md87.evetool.api.wrappers.data.BasicCorpInfo;
36 36
 import uk.co.md87.evetool.api.wrappers.data.Implant;
37
+import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
37 38
 import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
38 39
 
39 40
 /**
@@ -51,7 +52,7 @@ public class CharacterSheet {
51 52
     private final List<Implant> implants;
52 53
     private final Map<Attribute, Integer> baseAttributes;
53 54
     private final Map<Attribute, Double> attributes;
54
-    private final List<TrainedSkillInfo> skills;
55
+    private final Map<Integer, TrainedSkillInfo> skills;
55 56
     private final List<Integer> certificates;
56 57
 
57 58
     private final BasicCharInfo charInfo;
@@ -73,7 +74,7 @@ public class CharacterSheet {
73 74
         this.baseAttributes = new HashMap<Attribute, Integer>();
74 75
         parseAttributes(resultElement.getChild("attributes"));
75 76
 
76
-        this.skills = new ArrayList<TrainedSkillInfo>();
77
+        this.skills = new HashMap<Integer, TrainedSkillInfo>();
77 78
         parseSkills(resultElement.getRowset("skills"));
78 79
 
79 80
         this.certificates = new ArrayList<Integer>();
@@ -93,7 +94,7 @@ public class CharacterSheet {
93 94
     public long getSkillPoints() {
94 95
         long res = 0;
95 96
 
96
-        for (TrainedSkillInfo skill : getSkills()) {
97
+        for (TrainedSkillInfo skill : getSkills().values()) {
97 98
             res += skill.getSP();
98 99
         }
99 100
 
@@ -101,7 +102,7 @@ public class CharacterSheet {
101 102
     }
102 103
 
103 104
     public void associateSkills(final SkillList skilltree) {
104
-        for (TrainedSkillInfo skill : skills) {
105
+        for (TrainedSkillInfo skill : skills.values()) {
105 106
             skill.setSkill(skilltree.getSkillById(skill.getId()));
106 107
         }
107 108
 
@@ -139,7 +140,7 @@ public class CharacterSheet {
139 140
             final int id = row.getNumericAttribute("typeID");
140 141
             final int level = row.getNumericAttribute("level");
141 142
             final int sp = row.getNumericAttribute("skillpoints");
142
-            skills.add(new TrainedSkillInfo(this, id, level, sp));
143
+            skills.put(id, new TrainedSkillInfo(this, id, level, sp));
143 144
         }
144 145
     }
145 146
 
@@ -169,7 +170,7 @@ public class CharacterSheet {
169 170
     protected int getSkillBonus(final String name) {
170 171
         int count = 0;
171 172
 
172
-        for (TrainedSkillInfo skill : skills) {
173
+        for (TrainedSkillInfo skill : skills.values()) {
173 174
             if (skill.getSkillInfo() != null) {
174 175
                 for (Map.Entry<String, String> bonus : skill.getSkillInfo()
175 176
                         .getBonuses().entrySet()) {
@@ -239,10 +240,21 @@ public class CharacterSheet {
239 240
         return race;
240 241
     }
241 242
 
242
-    public List<TrainedSkillInfo> getSkills() {
243
+    public Map<Integer, TrainedSkillInfo> getSkills() {
243 244
         return skills;
244 245
     }
245 246
 
247
+    public boolean hasSkills(final List<SkillRequirement> reqs) {
248
+        for (SkillRequirement req : reqs) {
249
+            if (!skills.containsKey(req.getSkillId()) ||
250
+                    skills.get(req.getSkillId()).getLevel() < req.getRequiredLevel()) {
251
+                return false;
252
+            }
253
+        }
254
+
255
+        return true;
256
+    }
257
+
246 258
     /** {@inheritDoc} */
247 259
     @Override
248 260
     public String toString() {

+ 2
- 2
src/uk/co/md87/evetool/api/wrappers/ShipList.java View File

@@ -56,7 +56,7 @@ public class ShipList {
56 56
                 final int graphicID = ship.getNumericAttribute("graphicID");
57 57
                 final List<SkillRequirement> reqs = new ArrayList<SkillRequirement>();
58 58
                 
59
-                final int[][] values = new int[ship.getRowset("attributes").size()][2];
59
+                final int[][] values = new int[ship.getRowset("attributes").size() / 2][2];
60 60
                 for (ApiElement req : ship.getRowset("attributes")) {
61 61
                     String atName = req.getStringAttribute("attributeName").substring(13);
62 62
 
@@ -68,7 +68,7 @@ public class ShipList {
68 68
                         atName = atName.substring(0, atName.length() - 5);
69 69
                     }
70 70
 
71
-                    int number = Integer.parseInt(atName);
71
+                    int number = Integer.parseInt(atName) - 1;
72 72
                     values[number][index] = req.getNumericAttribute("value");
73 73
                 }
74 74
 

+ 6
- 0
src/uk/co/md87/evetool/api/wrappers/data/SkillRequirement.java View File

@@ -65,4 +65,10 @@ public class SkillRequirement {
65 65
         return skillId;
66 66
     }
67 67
 
68
+    /** {@inheritDoc} */
69
+    @Override
70
+    public String toString() {
71
+        return "[" + skillId + "@" + requiredLevel + "]";
72
+    }
73
+
68 74
 }

+ 2
- 0
src/uk/co/md87/evetool/ui/MainWindow.java View File

@@ -44,6 +44,7 @@ import uk.co.md87.evetool.ApiFactory;
44 44
 import uk.co.md87.evetool.ui.ContentPanel.Page;
45 45
 import uk.co.md87.evetool.ui.data.AccountChar;
46 46
 import uk.co.md87.evetool.ui.pages.OverviewPage;
47
+import uk.co.md87.evetool.ui.pages.ShipsPage;
47 48
 import uk.co.md87.evetool.ui.pages.SkillPage;
48 49
 
49 50
 /**
@@ -80,6 +81,7 @@ public class MainWindow extends JFrame {
80 81
         pages = new TreeMap<String, ContentPanel.Page>();
81 82
         pages.put("Overview", new OverviewPage(this, manager, factory));
82 83
         pages.put("Skills", new SkillPage(this, manager, factory));
84
+        pages.put("Ships", new ShipsPage(this, manager, factory));
83 85
 
84 86
         this.menuPanel = new MenuPanel(this, pages);
85 87
         this.contentPanel = new ContentPanel(this, manager, factory, pages);

+ 55
- 0
src/uk/co/md87/evetool/ui/data/BasicShipInfoSurrogate.java View File

@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (c) 2009 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.evetool.ui.data;
24
+
25
+import uk.co.md87.evetool.api.wrappers.CharacterSheet;
26
+import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
27
+import uk.co.md87.evetool.ui.listable.ListableImpl;
28
+import uk.co.md87.evetool.ui.listable.Retrievable;
29
+
30
+/**
31
+ *
32
+ * TODO: Document BasicShipInfoSurrogate
33
+ * @author chris
34
+ */
35
+public class BasicShipInfoSurrogate extends ListableImpl {
36
+
37
+    private final BasicShipInfo info;
38
+    private final CharacterSheet sheet;
39
+
40
+    public BasicShipInfoSurrogate(final BasicShipInfo info, final CharacterSheet sheet) {
41
+        this.info = info;
42
+        this.sheet = sheet;
43
+    }
44
+
45
+    @Retrievable(deferred=true)
46
+    public BasicShipInfo getInfo() {
47
+        return info;
48
+    }
49
+
50
+    @Retrievable
51
+    public boolean canFly() {
52
+        return sheet.hasSkills(info.getRequirements());
53
+    }
54
+
55
+}

+ 19
- 2
src/uk/co/md87/evetool/ui/data/TrainedSkillInfoSurrogate.java View File

@@ -1,6 +1,23 @@
1 1
 /*
2
- * To change this template, choose Tools | Templates
3
- * and open the template in the editor.
2
+ * Copyright (c) 2009 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
4 21
  */
5 22
 
6 23
 package uk.co.md87.evetool.ui.data;

+ 3
- 3
src/uk/co/md87/evetool/ui/dialogs/listableconfig/ListableConfigDialog.java View File

@@ -65,7 +65,7 @@ import uk.co.md87.evetool.ui.listable.ListableConfig.CompoundConfigElement;
65 65
 import uk.co.md87.evetool.ui.listable.ListableConfig.ConfigElement;
66 66
 import uk.co.md87.evetool.ui.listable.ListableConfig.LiteralConfigElement;
67 67
 import uk.co.md87.evetool.ui.listable.ListableParser;
68
-import uk.co.md87.evetool.ui.pages.SkillPage;
68
+import uk.co.md87.evetool.ui.pages.ListablePage;
69 69
 
70 70
 /**
71 71
  *
@@ -95,7 +95,7 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
95 95
     private final JPanel configPanel, previewPanel;
96 96
     private final ListablePanel panel;
97 97
 
98
-    private final SkillPage page;
98
+    private final ListablePage page;
99 99
 
100 100
     private static ImageIcon editInactiveIcon, editActiveIcon;
101 101
 
@@ -111,7 +111,7 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
111 111
         }
112 112
     }
113 113
 
114
-    public ListableConfigDialog(final Window window, final SkillPage page,
114
+    public ListableConfigDialog(final Window window, final ListablePage page,
115 115
             final ListableConfig config, final Listable sample) {
116 116
         super(window, "Display Configuration", ModalityType.APPLICATION_MODAL);
117 117
 

+ 44
- 0
src/uk/co/md87/evetool/ui/pages/ListablePage.java View File

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2009 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.evetool.ui.pages;
24
+
25
+import uk.co.md87.evetool.ui.ContentPanel.Page;
26
+import uk.co.md87.evetool.ui.listable.ListableConfig;
27
+
28
+/**
29
+ *
30
+ * TODO: Document ListablePage
31
+ * @author chris
32
+ */
33
+public class ListablePage extends Page {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 10;
41
+
42
+    public void setConfig(final ListableConfig config) {}
43
+
44
+}

+ 165
- 0
src/uk/co/md87/evetool/ui/pages/ShipsPage.java View File

@@ -0,0 +1,165 @@
1
+/*
2
+ * Copyright (c) 2009 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.evetool.ui.pages;
24
+
25
+import java.awt.event.ActionEvent;
26
+import java.awt.event.ActionListener;
27
+import java.util.ArrayList;
28
+import java.util.Collections;
29
+
30
+import java.util.List;
31
+import javax.swing.JSeparator;
32
+
33
+import net.miginfocom.swing.MigLayout;
34
+
35
+import uk.co.md87.evetool.AccountManager;
36
+import uk.co.md87.evetool.ApiFactory;
37
+import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
38
+import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
39
+import uk.co.md87.evetool.ui.ContextPanel;
40
+import uk.co.md87.evetool.ui.MainWindow;
41
+import uk.co.md87.evetool.ui.components.FilterButton;
42
+import uk.co.md87.evetool.ui.components.HeaderPanel;
43
+import uk.co.md87.evetool.ui.components.ListablePanel;
44
+import uk.co.md87.evetool.ui.data.BasicShipInfoSurrogate;
45
+import uk.co.md87.evetool.ui.data.TrainedSkillInfoSurrogate;
46
+import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
47
+import uk.co.md87.evetool.ui.listable.ListableComparator;
48
+import uk.co.md87.evetool.ui.listable.ListableConfig;
49
+import uk.co.md87.evetool.ui.listable.ListableParser;
50
+
51
+/**
52
+ *
53
+ * TODO: Document ShipsPage
54
+ * @author chris
55
+ */
56
+public class ShipsPage extends ListablePage implements ActionListener {
57
+
58
+    /**
59
+     * A version number for this class. It should be changed whenever the class
60
+     * structure is changed (or anything else that would prevent serialized
61
+     * objects being unserialized with the new class).
62
+     */
63
+    private static final long serialVersionUID = 10;
64
+
65
+    private final MainWindow window;
66
+    private final ApiFactory factory;
67
+
68
+    private ListableConfig config;
69
+
70
+    public ShipsPage(final MainWindow window, final AccountManager manager,
71
+            final ApiFactory factory) {
72
+        this.window = window;
73
+        this.factory = factory;
74
+
75
+        setLayout(new MigLayout("fillx, wrap 1"));
76
+
77
+        config = new ListableConfig();
78
+        config.topLeft = new ListableConfig.BasicConfigElement("name");
79
+        config.topRight = new ListableConfig.CompoundConfigElement();
80
+        config.bottomLeft = new ListableConfig.BasicConfigElement("can fly");
81
+        config.bottomRight = new ListableConfig.CompoundConfigElement();
82
+        config.group = new ListableConfig.BasicConfigElement("group name");
83
+
84
+        config.sortOrder = new ListableConfig.ConfigElement[]{
85
+            new ListableConfig.BasicConfigElement("group name"),
86
+            new ListableConfig.BasicConfigElement("name"),
87
+        };
88
+    }
89
+
90
+    /** {@inheritDoc} */
91
+    @Override
92
+    public boolean isReady() {
93
+        return character != null && character.getSheet() != null
94
+                && character.getSheet().wasSuccessful();
95
+    }
96
+
97
+    /** {@inheritDoc} */
98
+    @Override
99
+    public void activated(final ContextPanel context) {
100
+        final FilterButton button = new FilterButton();
101
+        button.addActionListener(this);
102
+        context.add(button, "growy, al right");
103
+        
104
+        updatePage();
105
+    }
106
+
107
+
108
+    protected void updatePage() {
109
+        removeAll();
110
+
111
+        final ListableParser parser = new ListableParser(BasicShipInfoSurrogate.class);
112
+        final List<BasicShipInfoSurrogate> list = new ArrayList<BasicShipInfoSurrogate>();
113
+
114
+        for (BasicShipInfo ship : factory.getApi().getShipList().getResult()
115
+                .getShips().values()) {
116
+            list.add(new BasicShipInfoSurrogate(ship, character.getSheet().getResult()));
117
+        }
118
+
119
+        if (config.sortOrder != null) {
120
+            Collections.sort(list, new ListableComparator(config.sortOrder, parser));
121
+        }
122
+
123
+        String lastGroup = null;
124
+        boolean first = true;
125
+        
126
+        for (BasicShipInfoSurrogate ship : list) {
127
+            if (config.group != null) {
128
+                final String thisGroup = config.group.getValue(ship, parser);
129
+
130
+                if (lastGroup == null || !thisGroup.equals(lastGroup)) {
131
+                    first = true;
132
+                    lastGroup = thisGroup;
133
+                    add(new HeaderPanel(lastGroup), "growx, pushx");
134
+                }
135
+            }
136
+
137
+            if (first) {
138
+                first = false;
139
+            } else {
140
+                add(new JSeparator(), "growx, pushx");
141
+            }
142
+
143
+            add(new ListablePanel(ship, parser, config),
144
+                    "growx, pushx");
145
+        }
146
+
147
+        revalidate();
148
+    }
149
+
150
+    public void setConfig(final ListableConfig config) {
151
+        this.config = config;
152
+        
153
+        updatePage();
154
+    }
155
+
156
+    /** {@inheritDoc} */
157
+    @Override
158
+    public void actionPerformed(final ActionEvent e) {
159
+        new ListableConfigDialog(window, this, config,
160
+                new BasicShipInfoSurrogate(factory.getApi().getShipList()
161
+                .getResult().getShips().values().iterator().next(),
162
+                character.getSheet().getResult())).setVisible(true);
163
+    }
164
+
165
+}

+ 2
- 3
src/uk/co/md87/evetool/ui/pages/SkillPage.java View File

@@ -35,7 +35,6 @@ import net.miginfocom.swing.MigLayout;
35 35
 import uk.co.md87.evetool.AccountManager;
36 36
 import uk.co.md87.evetool.ApiFactory;
37 37
 import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
38
-import uk.co.md87.evetool.ui.ContentPanel.Page;
39 38
 import uk.co.md87.evetool.ui.ContextPanel;
40 39
 import uk.co.md87.evetool.ui.MainWindow;
41 40
 import uk.co.md87.evetool.ui.components.FilterButton;
@@ -52,7 +51,7 @@ import uk.co.md87.evetool.ui.listable.ListableParser;
52 51
  * TODO: Document SkillPage
53 52
  * @author chris
54 53
  */
55
-public class SkillPage extends Page implements ActionListener {
54
+public class SkillPage extends ListablePage implements ActionListener {
56 55
 
57 56
     /**
58 57
      * A version number for this class. It should be changed whenever the class
@@ -114,7 +113,7 @@ public class SkillPage extends Page implements ActionListener {
114 113
         final ListableParser parser = new ListableParser(TrainedSkillInfoSurrogate.class);
115 114
         final List<TrainedSkillInfoSurrogate> list = new ArrayList<TrainedSkillInfoSurrogate>();
116 115
 
117
-        for (TrainedSkillInfo skill : character.getSheet().getResult().getSkills()) {
116
+        for (TrainedSkillInfo skill : character.getSheet().getResult().getSkills().values()) {
118 117
             list.add(new TrainedSkillInfoSurrogate(skill));
119 118
         }
120 119
 

Loading…
Cancel
Save