|
1
|
|
|
# |
|
2
|
|
|
# Copyright 2001 - 2016 Ludek Smid [http://www.ospace.net/] |
|
3
|
|
|
# |
|
4
|
|
|
# This file is part of Outer Space. |
|
5
|
|
|
# |
|
6
|
|
|
# Outer Space is free software; you can redistribute it and/or modify |
|
7
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
|
9
|
|
|
# (at your option) any later version. |
|
10
|
|
|
# |
|
11
|
|
|
# Outer Space is distributed in the hope that it will be useful, |
|
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
# along with Outer Space; if not, write to the Free Software |
|
18
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
19
|
|
|
# |
|
20
|
|
|
|
|
21
|
|
|
import pygameui as ui |
|
22
|
|
|
from osci import gdata, client |
|
23
|
|
|
import ige.ospace.Const as Const |
|
24
|
|
|
from ige.ospace import ShipUtils, Rules |
|
25
|
|
|
|
|
26
|
|
|
class FleetsAnalysisDlg: |
|
27
|
|
|
"""Displays analysis on existing fleets. |
|
28
|
|
|
|
|
29
|
|
|
Dialog displays list of current ship designs |
|
30
|
|
|
and list of fleets containing particular ship |
|
31
|
|
|
design. |
|
32
|
|
|
""" |
|
33
|
|
|
def __init__(self, app): |
|
34
|
|
|
self._textRows = 0 |
|
35
|
|
|
self.app = app |
|
36
|
|
|
self.createUI() |
|
37
|
|
|
|
|
38
|
|
|
def display(self): |
|
39
|
|
|
self.show() |
|
40
|
|
|
# show window |
|
41
|
|
|
if not self.win.visible: |
|
42
|
|
|
self.win.show() |
|
43
|
|
|
|
|
44
|
|
|
def hide(self): |
|
45
|
|
|
self.win.setStatus(_("Ready.")) |
|
46
|
|
|
self.win.hide() |
|
47
|
|
|
|
|
48
|
|
|
def update(self): |
|
49
|
|
|
if self.win.visible: |
|
50
|
|
|
self.show() |
|
51
|
|
|
|
|
52
|
|
|
def show(self): |
|
53
|
|
|
player = client.getPlayer() |
|
54
|
|
|
|
|
55
|
|
|
self.fleetsByDesign = {} |
|
56
|
|
|
self.fleetCountsByDesign = {} |
|
57
|
|
|
items = [] |
|
58
|
|
|
for designID in player.shipDesigns: |
|
59
|
|
|
spec = player.shipDesigns[designID] |
|
60
|
|
|
fleets = {} |
|
61
|
|
|
fleetCounts = {} |
|
62
|
|
|
for fleetID in player.fleets: |
|
63
|
|
|
fleet = client.get(fleetID) |
|
64
|
|
|
count = 0 |
|
65
|
|
|
for tmpDesignID, hp, shieldHP, exp in fleet.ships: |
|
66
|
|
|
if tmpDesignID == designID: |
|
67
|
|
|
count += 1 |
|
68
|
|
|
fleets[fleet] = 1 |
|
69
|
|
|
fleetCounts[fleetID] = count |
|
70
|
|
|
self.fleetsByDesign[designID] = fleets.keys() |
|
71
|
|
|
self.fleetCountsByDesign[designID] = fleetCounts |
|
72
|
|
|
item = ui.Item(spec.name, tDesignID = designID, tShipsCount = len(fleets.keys())) |
|
73
|
|
|
items.append(item) |
|
74
|
|
|
self.win.vDesigns.items = items |
|
75
|
|
|
self.win.vDesigns.itemsChanged() |
|
76
|
|
|
|
|
77
|
|
|
def onClose(self, widget, action, data): |
|
78
|
|
|
self.hide() |
|
79
|
|
|
|
|
80
|
|
|
def onSelectDesign(self, widget, action, data): |
|
81
|
|
|
player = client.getPlayer() |
|
82
|
|
|
fleets = self.fleetsByDesign[data.tDesignID] |
|
83
|
|
|
fleetCounts = self.fleetCountsByDesign[data.tDesignID] |
|
84
|
|
|
spec = player.shipDesigns[data.tDesignID] |
|
85
|
|
|
self.win.vFleetsTitle.text = _("Fleets contains design %s") % spec.name |
|
86
|
|
|
items = [] |
|
87
|
|
|
if fleets: |
|
88
|
|
|
for fleet in fleets: |
|
89
|
|
|
if hasattr(fleet,'customname') and fleet.customname: |
|
90
|
|
|
fleetname = fleet.customname |
|
91
|
|
|
else: |
|
92
|
|
|
fleetname = fleet.name |
|
93
|
|
|
items.append(ui.Item(fleetname, tShipsCount = len(fleet.ships), fleet = fleet, tClassCount = fleetCounts[fleet.oid], tFleetID = fleet.oid)) |
|
94
|
|
|
self.win.vFleets.items = items |
|
95
|
|
|
self.win.vFleets.itemsChanged() |
|
96
|
|
|
|
|
97
|
|
|
def onSelectFleet(self, widget, action, data): |
|
98
|
|
|
item = self.win.vFleets.selection[0] |
|
99
|
|
|
fleet = item.fleet #client.get(item.tFleetID, noUpdate = 1) |
|
100
|
|
|
# if hasattr(fleet, "owner") and fleet.owner == client.getPlayerID(): |
|
101
|
|
|
# show dialog |
|
102
|
|
|
gdata.mainGameDlg.onSelectMapObj(None, None, item.tFleetID) |
|
103
|
|
|
|
|
104
|
|
|
def onShowLocation(self, widget, action, data): |
|
105
|
|
|
# center on map |
|
106
|
|
|
if hasattr(data.fleet, "x"): |
|
107
|
|
|
gdata.mainGameDlg.win.vStarMap.highlightPos = (data.fleet.x, data.fleet.y) |
|
108
|
|
|
gdata.mainGameDlg.win.vStarMap.setPos(data.fleet.x, data.fleet.y) |
|
109
|
|
|
self.hide() |
|
110
|
|
|
return |
|
111
|
|
|
self.win.setStatus(_("Cannot show location")) |
|
112
|
|
|
|
|
113
|
|
View Code Duplication |
def createUI(self): |
|
|
|
|
|
|
114
|
|
|
screenWidth, screenHeight = gdata.scrnSize |
|
115
|
|
|
# size of dialog in layout metrics (for SimpleGridLM) |
|
116
|
|
|
cols = 36 |
|
117
|
|
|
rows = 27 |
|
118
|
|
|
# dialog width and height in pixels |
|
119
|
|
|
width = cols * 20 + 5 |
|
120
|
|
|
height = rows * 20 + 4 |
|
121
|
|
|
#creating dialog window |
|
122
|
|
|
self.win = ui.Window(self.app, |
|
123
|
|
|
modal = 1, |
|
124
|
|
|
escKeyClose = 1, |
|
125
|
|
|
movable = 0, |
|
126
|
|
|
title = _("Fleets analysis"), |
|
127
|
|
|
rect = ui.Rect((screenWidth - width) / 2, (screenHeight - height) / 2, width, height), |
|
128
|
|
|
layoutManager = ui.SimpleGridLM(), |
|
129
|
|
|
) |
|
130
|
|
|
self.win.subscribeAction('*', self) |
|
131
|
|
|
# first row is window title |
|
132
|
|
|
rows -= 1 |
|
133
|
|
|
|
|
134
|
|
|
halfCols = cols / 2 |
|
135
|
|
|
ui.Title(self.win, layout = (0, 0, halfCols, 1), text = _("Ship designs"), |
|
136
|
|
|
align = ui.ALIGN_W, id = "vDesignsTitle", font = "normal-bold") |
|
137
|
|
|
ui.Listbox(self.win, layout = (0, 1, halfCols, rows - 2), id = "vDesigns", |
|
138
|
|
|
columns = ( |
|
139
|
|
|
(_("Design name"), "text", halfCols - 5, ui.ALIGN_W), |
|
140
|
|
|
(_("# fleets"), "tShipsCount", 4, ui.ALIGN_E) |
|
141
|
|
|
), |
|
142
|
|
|
columnLabels = 1, action = "onSelectDesign", sortable = True) |
|
143
|
|
|
|
|
144
|
|
|
ui.Title(self.win, layout = (halfCols, 0, halfCols, 1), text = "", |
|
145
|
|
|
align = ui.ALIGN_W, id = "vFleetsTitle", font = "normal-bold") |
|
146
|
|
|
ui.Listbox(self.win, layout = (halfCols, 1, halfCols, rows - 2), id = "vFleets", |
|
147
|
|
|
columns = ( |
|
148
|
|
|
(_("Fleet name"), "text", halfCols - 9, ui.ALIGN_W), |
|
149
|
|
|
(_("Ships"), "tClassCount",4, ui.ALIGN_E), |
|
150
|
|
|
(_("Fleet size"), "tShipsCount", 4, ui.ALIGN_E) |
|
151
|
|
|
), |
|
152
|
|
|
columnLabels = 1, action = "onSelectFleet", rmbAction = "onShowLocation", sortable = True) |
|
153
|
|
|
|
|
154
|
|
|
# dialog bottom line |
|
155
|
|
|
ui.Title(self.win, layout = (0, rows - 1, cols - 5, 1)) |
|
156
|
|
|
ui.TitleButton(self.win, layout = (cols - 5, rows - 1, 5, 1), text = _("Close"), action = "onClose") |
|
157
|
|
|
|