-ajout de la gestion du redimensionnement de la fenetre

-correction de plusieurs bogues
This commit is contained in:
Le_dahut 2014-06-09 19:26:39 +02:00
parent 7b0656de07
commit cab2e45517
1 changed files with 31 additions and 12 deletions

View File

@ -176,6 +176,10 @@ init()
#Bouton sensible a plusieurs évènements #Bouton sensible a plusieurs évènements
class abutton(object): class abutton(object):
def update(self,dt): def update(self,dt):
if type(self.evalx) is str:
self.x=eval(self.evalx)
if type(self.evaly) is str:
self.y=eval(self.evaly)
try: try:
self.vertex_list.delete() self.vertex_list.delete()
except: except:
@ -238,7 +242,10 @@ class abutton(object):
self.time=0 self.time=0
self.index=0 self.index=0
self.enter=0 self.enter=0
self.x=x self.window=window
self.evalx=x
self.evaly=y
self.x=x
self.y=y self.y=y
self.width=width self.width=width
self.height=height self.height=height
@ -249,7 +256,6 @@ class abutton(object):
self.typeof=typeof self.typeof=typeof
self.hint=hint self.hint=hint
self.selected=selected self.selected=selected
self.window=window
self.window.push_handlers(self.on_mouse_press) self.window.push_handlers(self.on_mouse_press)
self.window.push_handlers(self.on_mouse_motion) self.window.push_handlers(self.on_mouse_motion)
self.window.push_handlers(self.on_mouse_drag) self.window.push_handlers(self.on_mouse_drag)
@ -409,11 +415,11 @@ class menu(pyglet.window.Window):
self.labels=[pyglet.text.Label("",font_name='vademecum',font_size=380,x=0,y=0,bold=False,italic=False,batch=self.batch,group=self.p0,color=(255, 80, 80,230))] self.labels=[pyglet.text.Label("",font_name='vademecum',font_size=380,x=0,y=0,bold=False,italic=False,batch=self.batch,group=self.p0,color=(255, 80, 80,230))]
self.fond=image.load("picture/fond.png") self.fond=image.load("picture/fond.png")
self.buttons=[ self.buttons=[
abutton(self,'logo',185, self.height-200, 0, 0 , True, False, True, False, pyglet.image.load('picture/logo.png'), 'test', 'icon', '', ''), abutton(self,'logo',185, 'self.window.height-200', 0, 0 , True, False, True, False, pyglet.image.load('picture/logo.png'), 'test', 'icon', '', ''),
abutton(self,'logo2',45, self.height-150, 0, 0 , True, False, True, False, pyglet.image.load('picture/logo2.png'), 'test', 'icon', '', ''), abutton(self,'logo2',45, 'self.window.height-150', 0, 0 , True, False, True, False, pyglet.image.load('picture/logo2.png'), 'test', 'icon', '', ''),
abutton(self,'menu_0',840, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows.png'), 'test', 'icon', '', ''), abutton(self,'menu_0',840, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows.png'), 'test', 'icon', '', ''),
abutton(self,'menu_1',920, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows2.png'), 'test', 'icon', '', ''), abutton(self,'menu_1',920, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows2.png'), 'test', 'icon', '', ''),
abutton(self,'menu_2',940, self.height-100, 0, 0 , True, False, True, False, pyglet.image.load('picture/exit2.png'), 'test', 'icon', '', '') abutton(self,'menu_2',940, 'self.window.height-100', 0, 0 , True, False, True, False, pyglet.image.load('picture/exit2.png'), 'test', 'icon', '', '')
] ]
self.levels=[ self.levels=[
abutton(self,'level_0',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''), abutton(self,'level_0',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
@ -434,6 +440,10 @@ class menu(pyglet.window.Window):
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.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 on_resize(self,width, height):
super(menu, self).on_resize(width,height)
self.update()
def movefond(self,dt): def movefond(self,dt):
global loc global loc
self.loc[0]+=self.loc[2] self.loc[0]+=self.loc[2]
@ -459,7 +469,9 @@ class menu(pyglet.window.Window):
if 'obj' in locals(): if 'obj' in locals():
self.labels[0].text=obj['element'] self.labels[0].text=obj['element']
else: else:
self.labels[0].text='xx' self.labels[0].text=''
for l in range(len(self.buttons)):
self.buttons[l].update(0)
for l in range(10): for l in range(10):
if l>=len(worlds[world]): if l>=len(worlds[world]):
self.levels[l].x=-300 self.levels[l].x=-300
@ -491,7 +503,7 @@ class menu(pyglet.window.Window):
self.lock[l].y=ele['_yy']/768.0*self.height+50 self.lock[l].y=ele['_yy']/768.0*self.height+50
if 'obj' in locals() and ele['description']==obj['description']: if 'obj' in locals() and ele['description']==obj['description']:
self.special.x=ele['_xx'] self.special.x=ele['_xx']
self.special.y=ele['_yy'] self.special.y=ele['_yy']/768.0*self.height
if 'obj' not in locals(): if 'obj' not in locals():
self.special.x=-300 self.special.x=-300
@ -526,7 +538,7 @@ class menu(pyglet.window.Window):
dest=(int(worlds[n[0]][n[1]]['_xx']+self.images[0].width/2),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2)) dest=(int(worlds[n[0]][n[1]]['_xx']+self.images[0].width/2),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2))
else: else:
src=(int(ele['_xx']+self.images[0].width/2),int(ele['_yy']/768.0*self.height+self.images[0].height/2)) src=(int(ele['_xx']+self.images[0].width/2),int(ele['_yy']/768.0*self.height+self.images[0].height/2))
dest=(int(self.width),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+50)) dest=(int(1024),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+50))
if dest[0]-src[0]!=0: if dest[0]-src[0]!=0:
angle=math.atan(float(dest[1]-src[1])/float(dest[0]-src[0])) angle=math.atan(float(dest[1]-src[1])/float(dest[0]-src[0]))
else: else:
@ -556,6 +568,13 @@ class menu(pyglet.window.Window):
if n[0]==world: if n[0]==world:
src=(int(0),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2)) src=(int(0),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2))
dest=(int(worlds[n[0]][n[1]]['_xx']+self.images[0].width/2),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2)) dest=(int(worlds[n[0]][n[1]]['_xx']+self.images[0].width/2),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2))
if dest[0]-src[0]!=0:
angle=math.atan(float(dest[1]-src[1])/float(dest[0]-src[0]))
else:
angle=270*3.14/180.0
if dest[0]-src[0]<0:
angle=angle+180*3.14/180.0
dest=(dest[0]-int(self.sizes[world][0]*math.cos(angle)),dest[1]-int(self.sizes[world][1]*math.sin(angle)))
if n in finished or debug==2: if n in finished or debug==2:
params=(random.randint(0,8),20,self.colors[world],12) params=(random.randint(0,8),20,self.colors[world],12)
else: else:
@ -683,8 +702,8 @@ class menu(pyglet.window.Window):
if type(self.selected) is tuple: if type(self.selected) is tuple:
thex=x thex=x
they=y they=y
if x>self.width-20 and world+1<len(worlds): if x>1024-20 and world+1<len(worlds) and abs(self.selected[0]-world)<1:
world=+1 world+=1
self.update() self.update()
def on_mouse_release(self,x, y, button, modifiers): def on_mouse_release(self,x, y, button, modifiers):
@ -711,8 +730,8 @@ class menu(pyglet.window.Window):
'maxrayon': 99999, 'maxrayon': 99999,
'temp': 0, 'temp': 0,
'maxtemp': 99999, 'maxtemp': 99999,
'_xx': x, '_xx': x-self.images[0].width/2,
'_yy': y, '_yy': y*768/self.height-self.images[0].height/2,
'link': [], 'link': [],
'video': False, 'video': False,
'world_art': [[0,0,0],[0,0,0],[0,0,0]], 'world_art': [[0,0,0],[0,0,0],[0,0,0]],