/
Level_Editor.py
292 lines (236 loc) · 10.3 KB
/
Level_Editor.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import sys
import string
from PySFML import sf
#from Drawable_Objects import Drawable_Toolbox,Drawable_FunctionSet
from LevelEditor_Objects import LevelEditor_Objects,Drawable_Scenario,Drawable_Box,GenerarXML
from Application import Application
class Level_Editor:
Evento = None
window = None
Fondo = None
DIRECTORIO = "images/"
def __init__(self):
self.width = 1200
self.heigth = 700
self.blanco = sf.Color(250, 250, 250)
self.negro = sf.Color(0, 0, 0)
self.window = sf.RenderWindow(sf.VideoMode(self.width, self.heigth), "CARGO BOT - LETS START")
self.Evento = sf.Event()
self.window.SetFramerateLimit(60)
self.temp = None
self.box_name = None
self.ins= None
self.dragging_box = None
self.deleteicon = None
self.idbox = 1
self.xml = GenerarXML()
# self.toolbox = Drawable_Toolbox()
self.tools = LevelEditor_Objects()
self.di = None
# self.function_set = Drawable_FunctionSet()
self.scenario = Drawable_Scenario(590, 187, 1200, 700, False)
self.goal = Drawable_Scenario(77, 187, 628, 700, True)
def DefinirFondo(self):
image = sf.Image()
image.LoadFromFile(self.DIRECTORIO+"bgs/leveleditor.png")
self.Fondo = sf.Sprite(image)
self.Fondo.Resize(1200, 700)
self.Fondo.SetCenter(0, 0)
self.Fondo.SetPosition(0,0)
def DefiniraddStackBoton(self):
image = sf.Image()
image.LoadFromFile(self.DIRECTORIO+"buttons/button_addstack.png")
self.addstack = sf.Sprite(image)
self.addstack.Resize(150,75)
self.addstack.SetCenter(0, 0)
self.addstack.SetPosition(0,0)
def DefinirdeleteStackBoton(self):
image = sf.Image()
image.LoadFromFile(self.DIRECTORIO+"buttons/button_deletestack.png")
self.deletestack = sf.Sprite(image)
self.deletestack.Resize(150,75)
self.deletestack.SetCenter(0, 0)
self.deletestack.SetPosition(0,85)
def DefinirX(self):
image = sf.Image()
image.LoadFromFile(self.DIRECTORIO+"buttons/X.png")
self.deletestackX = sf.Sprite(image)
self.deletestackX.Resize(50,50)
self.deletestackX.SetCenter(0, 0)
self.deletestackX.SetPosition(95,85)
return self.deletestackX
def DefinirSaveBoton(self):
image = sf.Image()
image.LoadFromFile(self.DIRECTORIO+"buttons/button_save.png")
self.save = sf.Sprite(image)
self.save.Resize(150,75)
self.save.SetCenter(0, 0)
self.save.SetPosition(1050,0)
def BotonHovered(self, x, y):
if(x>0 and x<150 and y>0 and y<75):
return "ADDSTACK"
if(x>0 and x<150 and y>85 and y<160):
return "DELETESTACK"
if(x>1050 and x<1200 and y>0 and y<75):
return "SAVE"
if( x>140 and x<180):
return ["goal",0]
if( x>190 and x<230 ):
return ["goal",1]
if( x>240 and x<280 ):
return ["goal",2]
if( x>290 and x<330 ):
return ["goal",3]
if( x>340 and x<380 ):
return ["goal",4]
if( x>390 and x<430 ):
return ["goal",5]
if( x>340 and x<480 ):
return ["goal",6]
if( x>490 and x<530 ):
return ["goal",7]
if( x>660 and x<705 ):
return ["scene",0]
if( x>715 and x<760 ):
return ["scene",1]
if( x>770 and x<815 ):
return ["scene",2]
if( x>825 and x<870 ):
return ["scene",3]
if( x>885 and x<930 ):
return ["scene",4]
if( x>940 and x<985 ):
return ["scene",5]
if( x>995 and x<1040 ):
return ["scene",6]
if( x>1050 and x<1095 ):
return ["scene",7]
def Pintar(self):
self.window.Draw(self.Fondo)
self.window.Draw(self.addstack)
self.window.Draw(self.deletestack)
self.window.Draw(self.save)
def DuplicateBox(self, box):
image = sf.Image()
image.LoadFromFile(self.DIRECTORIO+"gameplay/box_"+box+".png")
temp = sf.Sprite(image)
temp.Resize(40, 40)
temp.SetCenter(0, 0)
temp.SetPosition(11, 569)
return temp
def GetImage(self, box):
image = sf.Image()
image.LoadFromFile(self.DIRECTORIO+"gameplay/box_"+box+".png")
return image
def SetDraggingBox(self, box):
self.box_name = self.ins
if self.temp == None:
if self.ins != None:
self.temp = self.DuplicateBox(box)
else:
self.temp.SetImage(self.GetImage(box))
self.dragging_box = True
def Update(self):
input = self.window.GetInput()
self.DefinirFondo()
self.DefinirdeleteStackBoton()
self.DefiniraddStackBoton()
self.DefinirSaveBoton()
q = False
while not q:
x = input.GetMouseX()
y = input.GetMouseY()
boton = self.BotonHovered(x, y)
frameTime = self.window.GetFrameTime()
while self.window.GetEvent(self.Evento):
print self.Evento.Type
if self.Evento.Type == sf.Event.Closed:
self.window.Close()
if self.Evento.Type == sf.Event.MouseButtonPressed:
self.box_name = self.tools.InstructionToolboxClicked(x, y)
ins = self.box_name
print(str(x))
print(str(y))
if ins != None:
if ins != "INS_CLEAR":
if self.temp == None:
print("entro aqui y no debe")
self.temp = self.DuplicateBox(ins)
else:
self.temp.SetImage(self.GetImage(ins))
self.dragging_box = True
else:
self.goal.Clear()
self.scenario.Clear()
else:
# cual = self.BotonHovered(x,y)
if boton == "ADDSTACK":
self.scenario.addStack()
self.goal.addStack()
if boton == "DELETESTACK":
self.deleteicon = True
clickstack = False
print("por aki 1 .....")
if boton == "SAVE":
self.xml.Generar(self.scenario,self.goal)
if self.deleteicon == True:
print("por aki 2 .....")
if boton != None:
print("por aki3 .....")
if boton != "ADDSTACK" and boton != "DELETESTACK" and boton !="SAVE":
clickstack = True
# print(cual)
if clickstack == True:
print("por aki 4 .....")
self.scenario.deleteStack(boton[1])
self.goal.deleteStack(boton[1])
self.deleteicon = False
else:
if boton is not None:
if boton != "ADDSTACK" and boton != "DELETESTACK" and boton != "SAVE":
if boton[0] == "scene":
ift=self.scenario.BoxClicked(x,y,boton[1])
if boton[0] == "goal":
ift=self.goal.BoxClicked(x,y,boton[1])
#self.temp = self.goal.BoxClicked(x,y,boton[1])[0]
self.temp = ift[0]
#ins = self.goal.BoxClicked(x,y,boton[1])[1]
ins = ift[1]
self.dragging_box = True
if self.Evento.Type == sf.Event.MouseButtonReleased:
if boton is not None:
print("aqui")
if boton[0] == "goal":
if ins is not None:
self.goal.PlaceBox(boton[1],ins)
#self.idbox+=1
if boton[0] == "scene":
if ins is not None:
self.scenario.PlaceBox(boton[1],ins)
Application.putOnDeleteList(self.temp)
self.temp = None
self.dragging_box = False
self.scenario.Update(frameTime)
#self.goal.Update(frameTime)
self.window.Clear(self.blanco)
self.Pintar()
self.tools.Pintar(self.window)
self.scenario.Pintar(self.window)
self.goal.Pintar(self.window)
if self.dragging_box:
self.temp.SetPosition(x - 22, y - 22)
self.window.Draw(self.temp)
if self.deleteicon:
if self.di != None:
Application.putOnDeleteList(self.di)
self.di = self.DefinirX()
self.di.SetPosition(x-22,y-22)
self.window.Draw(self.di)
#
# else:
# self.DefinirdeleteStackBoton()
#self.window.Draw(self.deletestack)
self.window.Display()
if __name__ == "__main__":
ven = Level_Editor()
ven.Update()