-
Notifications
You must be signed in to change notification settings - Fork 0
/
coopdialogs.py
executable file
·169 lines (110 loc) · 4.21 KB
/
coopdialogs.py
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
import dialogs
import button
import gfx
import prefs
import ui
import widgets
import objactions
from events import *
class okButton(button.buttonImageSprite):
def __init__(self, evManager, dialog):
images = gfx.loadImageSlices("btn_ok.png", (0,0,40,40),2)
button.buttonImageSprite.__init__(self, evManager, images[0])
self.addState(self.state_over, images[1])
self.dialog = dialog
def onClick(self, pos):
self.dialog.ok()
class cancelButton(button.buttonImageSprite):
def __init__(self, evManager, dialog):
images = gfx.loadImageSlices("btn_cancel.png", (0,0,40,40),2)
button.buttonImageSprite.__init__(self, evManager, images[0])
self.addState(self.state_over, images[1])
self.dialog = dialog
def onClick(self,pos):
self.dialog.cancel()
class genericImage(ui.CPui):
def __init__(self,image):
ui.CPui.__init__(self)
self.image = image
self.rect = self.image.get_rect()
class background(ui.CPui):
def __init__(self):
ui.CPui.__init__(self)
self.image = gfx.loadImage("dialog.png")
self.rect = self.image.get_rect()
def onClick(self, pos):
print pos
class COOPdialog(dialogs.Dialog):
def __init__(self, evManager):
dialogs.Dialog.__init__(self, evManager)
back = background()
self.setBackground(back)
self.setPos((175,125))
class COOPokDialog(COOPdialog):
def __init__(self, evManager, text):
COOPdialog.__init__(self, evManager)
self.text = text
self.okb = okButton(evManager, self)
self.okb.rect.topleft = (190,280)
self.okb.depth = 1
self.add(self.okb)
#draw text
font = prefs.config.get("fonts","dialog_font")
size = int(prefs.config.get("fonts_size","dialog_font_size"))
label = widgets.LabelSprite(self.evManager, self.text)
label.setFont(font, size)
label.depth = 2
label.color = (244,28,29)
label.rect.top = 40
label.rect.centerx = 222
label.align = "center"
self.add(label)
def ok(self):
pass
class COOPok_cancelDialog(COOPokDialog):
def __init__(self, evManager, text):
COOPokDialog.__init__(self, evManager, text)
self.okb.rect.topleft = (130,280)
self.adjustPos(self.okb)
self.cancelb = cancelButton(evManager, self)
self.cancelb.rect.topleft = (260,280)
self.cancelb.depth = 3
self.add(self.cancelb)
def cancel(self):
pass
class COOPmessageDialog(COOPokDialog):
def __init__(self, evManager, text):
COOPokDialog.__init__(self, evManager, text)
def ok(self):
self.evManager.Post( GUIDialogRemoveRequest( self ) )
class COOPinventoryDialog(COOPdialog):
def __init__(self, evManager, obj, supressStoreEvent=0):
COOPdialog.__init__(self, evManager)
self.img = genericImage( obj.getInventoryImage() )
self.img.rect.topleft = (187,50)
self.img.depth = 1
self.add(self.img)
#draw text
font = prefs.config.get("fonts","dialog_font")
size = int(prefs.config.get("fonts_size","dialog_font_size"))
label = widgets.LabelSprite(self.evManager, obj.human_name )
label.setFont(font, size)
label.depth = 2
label.color = (244,28,29)
label.rect.top = 170
label.rect.centerx = 222
label.align = "center"
self.add(label)
posx = 20
posy = 280
depth = 3
for action in obj.possible_actions:
if supressStoreEvent and action==objactions.storeAction:
continue
oaction = action( evManager, self, obj )
print posx, posy
oaction.rect.topleft = (posx, posy)
oaction.depth = depth
depth +=1
posx += oaction.rect.width +10
self.add(oaction)