Ajout d'un mode d'édition disponible depuis le mode debug en cliquant sur le logo
Il est possible de créer des liens entre les niveaux ou de les défaire et de bouger les niveaux ainsi que les suprimer et en créer de nouveaux (limite 10).
This commit is contained in:
parent
f3238217c7
commit
7684f46b39
159
WireChem.py
159
WireChem.py
|
@ -159,8 +159,6 @@ def init():
|
||||||
reference(Uworlds,['world','level'])
|
reference(Uworlds,['world','level'])
|
||||||
if len(sys.argv)>1 and sys.argv[1]=='debug':
|
if len(sys.argv)>1 and sys.argv[1]=='debug':
|
||||||
debug=1
|
debug=1
|
||||||
elif len(sys.argv)>1 and sys.argv[1]=='edit' :
|
|
||||||
debug=2
|
|
||||||
else:
|
else:
|
||||||
debug=0
|
debug=0
|
||||||
|
|
||||||
|
@ -237,6 +235,7 @@ class abutton(object):
|
||||||
|
|
||||||
def __init__(self, window, name, x, y, width, height , active, hilite, visible, selected, content, hint, typeof, text, text2):
|
def __init__(self, window, name, x, y, width, height , active, hilite, visible, selected, content, hint, typeof, text, text2):
|
||||||
self.name=name
|
self.name=name
|
||||||
|
self.time=0
|
||||||
self.index=0
|
self.index=0
|
||||||
self.enter=0
|
self.enter=0
|
||||||
self.x=x
|
self.x=x
|
||||||
|
@ -264,13 +263,12 @@ class abutton(object):
|
||||||
del self
|
del self
|
||||||
self=None
|
self=None
|
||||||
|
|
||||||
|
|
||||||
def launch(self,state):
|
def launch(self,state):
|
||||||
global debug
|
global debug
|
||||||
name=self.name.split('_')
|
name=self.name.split('_')
|
||||||
if len(name)>1 and hasattr(self.window, "on_mouse_"+state['event']+"_"+name[0]) and callable(eval("self.window.on_mouse_"+state['event']+"_"+name[0])):
|
if len(name)>1 and hasattr(self.window, "on_mouse_"+state['event']+"_"+name[0]) and callable(eval("self.window.on_mouse_"+state['event']+"_"+name[0])):
|
||||||
eval("self.window.on_mouse_"+state['event']+"_"+name[0]+"("+str(name[1])+","+str(state)+")")
|
eval("self.window.on_mouse_"+state['event']+"_"+name[0]+"("+str(name[1])+","+str(state)+")")
|
||||||
if debug>0: print state
|
if debug>0: print state,self.name
|
||||||
if hasattr(self.window, "on_mouse_"+state['event']+"_"+self.name) and callable(eval("self.window.on_mouse_"+state['event']+"_"+self.name)):
|
if hasattr(self.window, "on_mouse_"+state['event']+"_"+self.name) and callable(eval("self.window.on_mouse_"+state['event']+"_"+self.name)):
|
||||||
if self.typeof=='multicon':
|
if self.typeof=='multicon':
|
||||||
self.index+=1
|
self.index+=1
|
||||||
|
@ -278,10 +276,14 @@ class abutton(object):
|
||||||
self.index=0
|
self.index=0
|
||||||
self.update(0)
|
self.update(0)
|
||||||
eval("self.window.on_mouse_"+state['event']+"_"+self.name+"("+str(state)+")")
|
eval("self.window.on_mouse_"+state['event']+"_"+self.name+"("+str(state)+")")
|
||||||
if debug>0: print state
|
if debug>0: print state,self.name
|
||||||
|
|
||||||
def on_mouse_press(self, x, y, button, modifiers):
|
def on_mouse_press(self, x, y, button, modifiers):
|
||||||
if x>self.x and y>self.y and x<self.x+self.width and y<self.y+self.height and self.isactive() and self.isvisible():
|
if x>self.x and y>self.y and x<self.x+self.width and y<self.y+self.height and self.isactive() and self.isvisible():
|
||||||
|
if time.time()-self.time<0.30:
|
||||||
|
state={'x':x,'y':y, 'dx':0, 'dy':0, 'buttons':button, 'modifiers':modifiers, 'event': 'double'}
|
||||||
|
self.launch(state)
|
||||||
|
self.time=time.time()
|
||||||
state={'x':x,'y':y, 'dx':0, 'dy':0, 'buttons':button, 'modifiers':modifiers, 'event': 'press'}
|
state={'x':x,'y':y, 'dx':0, 'dy':0, 'buttons':button, 'modifiers':modifiers, 'event': 'press'}
|
||||||
self.launch(state)
|
self.launch(state)
|
||||||
|
|
||||||
|
@ -399,6 +401,7 @@ class menu(pyglet.window.Window):
|
||||||
self.p4 = pyglet.graphics.OrderedGroup(4)
|
self.p4 = pyglet.graphics.OrderedGroup(4)
|
||||||
self.clocks=[clock.schedule(self.draw),clock.schedule_interval(self.movefond,0.03)]
|
self.clocks=[clock.schedule(self.draw),clock.schedule_interval(self.movefond,0.03)]
|
||||||
self.loc=[0,0,1,1]
|
self.loc=[0,0,1,1]
|
||||||
|
self.selected=-1
|
||||||
self.images=[pyglet.image.load('picture/leveler0.png'),pyglet.image.load('picture/leveler1.png'),pyglet.image.load('picture/leveler2.png'),pyglet.image.load('picture/leveler3.png'),pyglet.image.load('picture/leveler4.png')]
|
self.images=[pyglet.image.load('picture/leveler0.png'),pyglet.image.load('picture/leveler1.png'),pyglet.image.load('picture/leveler2.png'),pyglet.image.load('picture/leveler3.png'),pyglet.image.load('picture/leveler4.png')]
|
||||||
self.colors=[[0,192,244],[235,118,118],[5,157,60],[215,33,255],[201,209,98]]
|
self.colors=[[0,192,244],[235,118,118],[5,157,60],[215,33,255],[201,209,98]]
|
||||||
#self.fond=pyglet.image.TileableTexture.create_for_image(image.load("picture/fond.png"))
|
#self.fond=pyglet.image.TileableTexture.create_for_image(image.load("picture/fond.png"))
|
||||||
|
@ -421,12 +424,13 @@ class menu(pyglet.window.Window):
|
||||||
abutton(self,'level_6',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
abutton(self,'level_6',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
||||||
abutton(self,'level_7',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
abutton(self,'level_7',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
||||||
abutton(self,'level_8',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
abutton(self,'level_8',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
||||||
abutton(self,'level_9',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', '')
|
abutton(self,'level_9',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
||||||
|
abutton(self,'level_10',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', '')
|
||||||
]
|
]
|
||||||
self.special=pyglet.sprite.Sprite(pyglet.image.load('picture/boss.png'),batch=self.batch, group=self.p4)
|
self.special=pyglet.sprite.Sprite(pyglet.image.load('picture/boss.png'),batch=self.batch, group=self.p4,x=-150,y=-150)
|
||||||
self.lock=[pyglet.sprite.Sprite(pyglet.image.load('picture/locked.png'),batch=self.batch, group=self.p4) for i in range(9)]
|
self.lock=[pyglet.sprite.Sprite(pyglet.image.load('picture/locked.png'),batch=self.batch, group=self.p4,x=-150,y=-150) for i in range(10)]
|
||||||
self.untitled=[pyglet.text.Label("",font_name='Vademecum',batch=self.batch, group=self.p4, font_size=23,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255)) for i in range(9)]
|
self.untitled=[pyglet.text.Label("",font_name='Vademecum',batch=self.batch, group=self.p4, font_size=23,x=-150,y=-150,bold=False,italic=False,color=(180, 180, 180,255)) for i in range(10)]
|
||||||
self.untitled2=[pyglet.text.Label("",font_name='Fluoxetine',batch=self.batch, group=self.p4, font_size=18,x=0,y=0,bold=False,italic=False,color=(255, 255, 255,255)) for i in range(9)]
|
self.untitled2=[pyglet.text.Label("",font_name='Fluoxetine',batch=self.batch, group=self.p4, font_size=18,x=-150,y=-150,bold=False,italic=False,color=(255, 255, 255,255)) for i in range(10)]
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def movefond(self,dt):
|
def movefond(self,dt):
|
||||||
|
@ -452,9 +456,15 @@ class menu(pyglet.window.Window):
|
||||||
self.labels[0].x=(1024-self.labels[0].content_width)/2-50
|
self.labels[0].x=(1024-self.labels[0].content_width)/2-50
|
||||||
self.labels[0].y=75*self.height/768
|
self.labels[0].y=75*self.height/768
|
||||||
self.labels[0].text=obj['element']
|
self.labels[0].text=obj['element']
|
||||||
for l in range(len(worlds[world])):
|
for l in range(10):
|
||||||
|
if l>=len(worlds[world]):
|
||||||
|
self.levels[l].x=-150
|
||||||
|
self.untitled[l].x=-150
|
||||||
|
self.untitled2[l].x=-150
|
||||||
|
self.lock[l].x=-150
|
||||||
|
continue
|
||||||
ele=worlds[world][l]
|
ele=worlds[world][l]
|
||||||
self.levels[l].active=(world,l) in finished
|
self.levels[l].active=(world,l) in finished or debug==2
|
||||||
self.levels[l].x=ele['_xx']
|
self.levels[l].x=ele['_xx']
|
||||||
self.levels[l].y=ele['_yy']/768.0*self.height
|
self.levels[l].y=ele['_yy']/768.0*self.height
|
||||||
self.levels[l].setselected([255,120+int(ele['_xx']/1024.0*135),155+int(ele['_xx']/1024.0*100)])
|
self.levels[l].setselected([255,120+int(ele['_xx']/1024.0*135),155+int(ele['_xx']/1024.0*100)])
|
||||||
|
@ -467,30 +477,59 @@ class menu(pyglet.window.Window):
|
||||||
self.untitled2[l].text=ele['nom'].decode('utf-8')
|
self.untitled2[l].text=ele['nom'].decode('utf-8')
|
||||||
self.untitled2[l].x=ele['_xx']-(self.untitled2[l].content_width-self.images[world].width)/2
|
self.untitled2[l].x=ele['_xx']-(self.untitled2[l].content_width-self.images[world].width)/2
|
||||||
self.untitled2[l].y=ele['_yy']/768.0*self.height-15
|
self.untitled2[l].y=ele['_yy']/768.0*self.height-15
|
||||||
if (world,l) in finished:
|
if (world,l) in finished or debug==2:
|
||||||
self.untitled2[l].color=(255,255,255,255)
|
self.untitled2[l].color=(255,255,255,255)
|
||||||
else:
|
else:
|
||||||
self.untitled2[l].color=(90,90,90,255)
|
self.untitled2[l].color=(90,90,90,255)
|
||||||
self.lock[l].visible=(world,l) not in finished
|
self.lock[l].visible=(world,l) not in finished and not debug==2
|
||||||
self.lock[l].x=ele['_xx']+10
|
self.lock[l].x=ele['_xx']+10
|
||||||
self.lock[l].y=ele['_yy']/768.0*self.height+50
|
self.lock[l].y=ele['_yy']/768.0*self.height+50
|
||||||
if ele['nom']==obj['nom']:
|
if ele['nom']==obj['nom']:
|
||||||
self.special.x=ele['_xx']
|
self.special.x=ele['_xx']
|
||||||
self.special.y=ele['_yy']
|
self.special.y=ele['_yy']
|
||||||
|
|
||||||
|
def drawLaser(self,x1,y1,x2,y2,width,power,color,randomize):
|
||||||
|
while(width > 0):
|
||||||
|
if randomize!=0: glLineStipple(random.randint(0,randomize),random.randint(0,65535))
|
||||||
|
glLineWidth(width)
|
||||||
|
glBegin(GL_LINES)
|
||||||
|
glColor3ub(min(color[0]+power*width,255),min(color[1]+power*width,255),min(color[2]+power*width,255))
|
||||||
|
glVertex2i(x1,y1)
|
||||||
|
glVertex2i(x2,y2)
|
||||||
|
width=width-1
|
||||||
|
glEnd()
|
||||||
|
glLineStipple(1,65535)
|
||||||
|
|
||||||
def draw(self,dt):
|
def draw(self,dt):
|
||||||
global loc
|
global loc,world,worlds
|
||||||
glClearColor(0,0,0,255)
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
self.clear()
|
|
||||||
#self.fond.anchor_x=self.loc[0]
|
#self.fond.anchor_x=self.loc[0]
|
||||||
#self.fond.anchor_y=self.loc[1]
|
#self.fond.anchor_y=self.loc[1]
|
||||||
|
glColor4ub(255,255,255,160)
|
||||||
self.fond.blit(self.loc[0],self.loc[1])
|
self.fond.blit(self.loc[0],self.loc[1])
|
||||||
self.fond.blit(self.loc[0]-1024,self.loc[1])
|
self.fond.blit(self.loc[0]-1024,self.loc[1])
|
||||||
self.fond.blit(self.loc[0]-1024,self.loc[1]-768)
|
self.fond.blit(self.loc[0]-1024,self.loc[1]-768)
|
||||||
self.fond.blit(self.loc[0],self.loc[1]-768)
|
self.fond.blit(self.loc[0],self.loc[1]-768)
|
||||||
#self.fond.blit_tiled(0, 0, 0, self.width, self.height)
|
#self.fond.blit_tiled(0, 0, 0, self.width, self.height)
|
||||||
|
'''for ele in worlds[world]:
|
||||||
|
for n in ele['link']:
|
||||||
|
if n!="" and n[0]==world:
|
||||||
|
if n in finished:
|
||||||
|
self.drawLaser(ele['_xx']+50,int(ele['_yy']/768.0*self.height+50),worlds[n[0]][n[1]]['_xx']+50,int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+50),random.randint(0,8),20,self.colors[world],12)
|
||||||
|
else:
|
||||||
|
self.drawLaser(ele['_xx']+50,int(ele['_yy']/768.0*self.height+50),worlds[n[0]][n[1]]['_xx']+50,int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+50),2,20,[40,40,40],0) '''
|
||||||
self.batch.draw()
|
self.batch.draw()
|
||||||
|
|
||||||
|
def on_mouse_press_logo(self, state):
|
||||||
|
global debug
|
||||||
|
if debug==1:
|
||||||
|
debug=2
|
||||||
|
self.buttons[0].setselected([255,0,0])
|
||||||
|
elif debug==2:
|
||||||
|
debug=1
|
||||||
|
self.buttons[0].setselected(False)
|
||||||
|
self.update()
|
||||||
|
|
||||||
def on_mouse_press_menu_2(self, state):
|
def on_mouse_press_menu_2(self, state):
|
||||||
pyglet.app.exit()
|
pyglet.app.exit()
|
||||||
|
|
||||||
|
@ -507,6 +546,53 @@ class menu(pyglet.window.Window):
|
||||||
def on_mouse_enter_menu(self, n, state):
|
def on_mouse_enter_menu(self, n, state):
|
||||||
self.buttons[2+n].setselected([255,0,0])
|
self.buttons[2+n].setselected([255,0,0])
|
||||||
|
|
||||||
|
def on_mouse_double_level(self, n, state):
|
||||||
|
if debug<2:
|
||||||
|
return
|
||||||
|
for ele in worlds[world]:
|
||||||
|
try:
|
||||||
|
del ele['special']
|
||||||
|
except:
|
||||||
|
dummy=0
|
||||||
|
worlds[world][n]["special"]=True
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def on_mouse_drag_level(self, n, state):
|
||||||
|
global worlds,world
|
||||||
|
if debug<2:
|
||||||
|
return
|
||||||
|
if state['buttons']==2:
|
||||||
|
worlds[world][n]["_xx"]+=state['dx']
|
||||||
|
worlds[world][n]["_yy"]+=state['dy']
|
||||||
|
self.update()
|
||||||
|
elif (state['buttons']==1 or state['buttons']==4) and self.selected==-1:
|
||||||
|
self.selected=n
|
||||||
|
|
||||||
|
def on_mouse_release_level(self, n, state):
|
||||||
|
global worlds,world
|
||||||
|
if debug<2:
|
||||||
|
return
|
||||||
|
if state['buttons']==1 and self.selected>-1 and n!=self.selected:
|
||||||
|
try:
|
||||||
|
worlds[world][n]["link"].index((world,self.selected))==-1
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
worlds[world][self.selected]["link"].index((world,n))==-1
|
||||||
|
except:
|
||||||
|
worlds[world][n]["link"].append((world,self.selected))
|
||||||
|
self.selected=-1
|
||||||
|
elif state['buttons']==4 and self.selected>-1 and n!=self.selected:
|
||||||
|
try:
|
||||||
|
worlds[world][n]["link"].remove((world,self.selected))
|
||||||
|
except:
|
||||||
|
dummy=0
|
||||||
|
try:
|
||||||
|
worlds[world][self.selected]["link"].remove((world,n))
|
||||||
|
except:
|
||||||
|
dummy=0
|
||||||
|
else:
|
||||||
|
self.selected=-1
|
||||||
|
|
||||||
def on_mouse_leave_menu(self, n, state):
|
def on_mouse_leave_menu(self, n, state):
|
||||||
self.buttons[2+n].setselected(False)
|
self.buttons[2+n].setselected(False)
|
||||||
|
|
||||||
|
@ -520,8 +606,42 @@ class menu(pyglet.window.Window):
|
||||||
self.untitled2[n].color=(255,255,255,255)
|
self.untitled2[n].color=(255,255,255,255)
|
||||||
|
|
||||||
def on_mouse_press_level(self, n, state):
|
def on_mouse_press_level(self, n, state):
|
||||||
print "level "+str(n)
|
if debug==2:
|
||||||
|
self.selected=-1
|
||||||
|
if state['modifiers']==17:
|
||||||
|
del worlds[world][n]
|
||||||
|
self.update()
|
||||||
|
return
|
||||||
|
|
||||||
|
def on_mouse_press(self, x, y, button, modifiers):
|
||||||
|
if debug<2:
|
||||||
|
return
|
||||||
|
if modifiers==18 and len(worlds[world])<10:
|
||||||
|
worlds[world].append({'nom': 'nouveau',
|
||||||
|
'description': "niveau tout neuf.",
|
||||||
|
'element': 'x',
|
||||||
|
'current': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
'victory': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
'cout': 0,
|
||||||
|
'tech': 0,
|
||||||
|
'cycle': 0,
|
||||||
|
'maxcycle': 99999,
|
||||||
|
'nrj': 0,
|
||||||
|
'maxnrj': 99999,
|
||||||
|
'rayon': 0,
|
||||||
|
'maxrayon': 99999,
|
||||||
|
'temp': 0,
|
||||||
|
'maxtemp': 99999,
|
||||||
|
'_xx': x,
|
||||||
|
'_yy': y,
|
||||||
|
'link': [],
|
||||||
|
'video': False,
|
||||||
|
'special': False,
|
||||||
|
'world_art': [[0,0,0],[0,0,0],[0,0,0]],
|
||||||
|
'world_new': [[0,0,0],[0,0,0],[0,0,0]]})
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Lancement du menu principal '''
|
''' Lancement du menu principal '''
|
||||||
|
|
||||||
|
@ -533,6 +653,7 @@ pyglet.font.add_file('font/LiberationMono-Regular.ttf')
|
||||||
menu_principal = menu()
|
menu_principal = menu()
|
||||||
menu_principal.set_minimum_size(1024, 768)
|
menu_principal.set_minimum_size(1024, 768)
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
glEnable(GL_STENCIL_TEST);
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||||
glEnable(GL_LINE_STIPPLE)
|
glEnable(GL_LINE_STIPPLE)
|
||||||
|
|
Loading…
Reference in New Issue