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