]> icculus.org git repositories - theoddone33/hheretic.git/blob - pyhexen/menu.py
Add heretic folder, menu changes.
[theoddone33/hheretic.git] / pyhexen / menu.py
1 import struct
2 import wad
3 import vid
4
5 class SubMenu:
6         ITT_EMPTY = 0
7         ITT_EFUNC = 1
8         ITT_LRFUNC = 2
9         ITT_SETMENU = 3
10         ITT_INERT = 4
11         
12         def __init__ (self, menu, name, x, y, prev):
13                 self.menu = menu
14                 self.x = x
15                 self.y = y
16                 self.name = name
17                 self.items = [ ]
18                 self.prev = prev
19                 
20         def Draw (self):
21                 pass
22                 
23         def AddItem (self, type, name, func, arg, menu):
24                 self.items.append ((type,name,func,arg,menu))
25                 
26         def Choose (self, item):
27                 pass
28                 
29 class Menu:
30         ITEM_HEIGHT = 20
31         SELECTOR_YOFFSET = -1
32         SELECTOR_XOFFSET = -28
33         def __init__ (self, wad, vid):
34                 self.wad = wad
35                 self.vid = vid
36                 self.time = 0
37                 self.active = False
38                 self.current = 0
39                 self.currentitem = 0
40                 self.old = 0
41                 self.menus = [ ]
42                 self.FontABaseLump = self.wad.GetNumForName("FONTA_S")+1
43                 self.FontBBaseLump = self.wad.GetNumForName("FONTB_S")+1
44                 
45         def AddMenu (self, menu):
46                 self.menus.append (menu)
47                 
48         def ProcessText (self, text, x, y, baselump, draw=True):
49                 for c in text:
50                         if ord (c) < 33:
51                                 x = x + 5
52                         else:
53                                 patch = self.wad.CacheLumpNum (baselump + ord (c) - 33)
54                                 (w, h) = struct.unpack_from ('<hh', patch, 0)
55                                 if draw:
56                                         self.vid.DrawPatch (x, y, patch)
57                                 x  = x + w - 1
58                 return x
59                 
60         def DrawTextA (self, text, x, y):
61                 self.ProcessText (text, x, y, self.FontABaseLump)
62                 
63         def TextAWidth (self, text):
64                 return self.ProcessText (text, 0, 0, self.FontABaseLump, False)
65                 
66         def DrawTextB (self, text, x, y):
67                 self.ProcessText (text, x, y, self.FontBBaseLump)
68                 
69         def TextBWidth (self, text):
70                 return self.ProcessText (text, 0, 0, self.FontBBaseLump, False)
71                 
72         def Tick (self):
73                 if self.active:
74                         self.time = self.time + 1
75
76         def Activate (self):
77                 self.current = self.old
78                 self.time = 0
79                 self.active = True
80                 
81         def Deactivate (self):
82                 self.active = False
83                 self.old = self.current
84                 
85         def Draw (self):
86                 self.menus[self.current].Draw ()
87                 x = self.menus[self.current].x
88                 y = self.menus[self.current].y
89                 for item in self.menus[self.current].items:
90                         self.DrawTextB (item[1], x, y)
91                         y = y + Menu.ITEM_HEIGHT
92                 y = self.menus[self.current].y+(self.currentitem*Menu.ITEM_HEIGHT)+Menu.SELECTOR_YOFFSET
93                 if self.time & 16:
94                         selName = 'M_SLCTR1'
95                 else:
96                         selName = 'M_SLCTR2'
97                 self.vid.DrawPatch(x + Menu.SELECTOR_XOFFSET, y, self.wad.CacheLumpName (selName))
98