1 ########################################################
2 #Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors
3 #This file is part of Asgard.
5 #Asgard is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Asgard is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Asgard; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 ########################################################
20 from pygame
import Surface
22 class Drawable(Surface
):
25 """ Screen object that this Drawable is drawn on. """
28 """ String representing name of drawable. """
31 """ Integer tuple representing length and width of drawable. """
33 def __init__(self
,id,dimensions
):
35 Handles Surface inheritance.
36 @param id : identifying name of drawable
38 @param dimensions : height and width of drawable
39 @type dimensions : (int,int)
42 #self.__dimensions = dimensions
46 """ A virtual method that draws this drawable onto itself. (Surface) """
49 class MenuDrawable(Drawable
):
53 Sub MenuDrawable's that belong to this one. Mutually exclusive
54 with text. Drawn with reference to offset x,y. Think cellpadding.
59 A string to be drawn inside this MenuDrawable. Mutually exclusive
60 with menu. Drawn at offset x,y. Think cellpadding.
64 """ x,y-tuple of text or first sub-menu to be drawn to screen. """
67 """ Whether or not this MenuDrawable has a border or not."""
70 """ Index of selected submenu. """
73 """ MenuDrawable that this one belongs to. """
75 def __init__(self
,id,screen
,dimensions
,offset
,border
,text
,submenus
,selindex
):
77 Handles Drawable inheritance. Instantiates a MenuDrawable.
79 @param id : identifier of this drawable
81 @param dimensions : height and width of menu
82 @type dimensions : (int,int)
83 @param offset : location of menu with respect it's parent surface
84 @type offset : (int,int)
85 @param border : whether this menu has a border or not
87 @param text : the text displayed in this menu. mutex w/ submenus
89 @param submenu : list of submenus to be display in this menu. mutex w/ text
90 @type submenu : MenuDrawable[]
91 @param selindex : index of selected submenu (if submenus)
95 self
.dimensions
= dimensions
99 self
.submenu
= submenus
106 for md
in self
.submenu
:
109 self
.selindex
= selindex
111 def selIndexUp(self
):
112 print "was: " + str(self
.selindex
)
114 print "is: " + str(self
.selindex
)
116 print "sb" + str(len(self
.submenu
))
117 if (self
.selindex
>= len(self
.submenu
)):
120 def selIndexDown(self
):
122 if (self
.selindex
< 0):
123 self
.selindex
= len(self
.submenu
) - 1
126 """ Draws a menu onto this drawable's surface. """
127 width
= self
.dimensions
[0]
128 height
= self
.dimensions
[1]
129 font
= pygame
.font
.SysFont("andalemono", 18)
141 s
= pygame
.Surface((width
,height
))
145 s
.fill((222,186,112))
146 pygame
.draw
.rect(s
,(255,255,255),(0,0,width
,height
),2)
147 self
.screen
.cont
.display
.blit(s
,(x
,y
))
150 if self
.parent
!= None:
151 if self
.parent
.submenu
[self
.parent
.selindex
].text
== self
.text
:
155 self
.screen
.cont
.display
.blit(font
.render(self
.text
,True,(89,75,46)),(x
+40,y
+5))
157 cursor
= pygame
.image
.load("./data/images/sword.png")
159 self
.screen
.cont
.display
.blit(cursor
,(x
+5,y
+9))
162 for md
in self
.submenu
: