Skip to content

Commit 75459d0

Browse files
committed
font change, clean up font usage and added base menu class
1 parent f7909dc commit 75459d0

File tree

10 files changed

+90
-32
lines changed

10 files changed

+90
-32
lines changed

config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@
7474
'marketplace': MAP_ICONS['misc'],
7575
'atm': MAP_ICONS['misc'],
7676
}
77+
78+
pygame.font.init()
79+
FONTS = {}
80+
for x in range(10, 28):
81+
FONTS[x] = pygame.font.Font('monofonto.ttf', x)

game/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def __init__(self, title, width, height, *args, **kwargs):
1111
self.window = pygame.display.set_mode((width, height))
1212
self.screen = pygame.display.get_surface()
1313
pygame.display.set_caption(title)
14-
pygame.font.init()
1514
pygame.mouse.set_visible(False)
1615

1716
self.groups = []

game/radio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def render(self, *args, **kwargs):
6969
if self.osc:
7070
self.blit(self.osc.screen, (550, 150))
7171

72-
selectFont = pygame.font.SysFont(None, 24)
73-
basicFont = pygame.font.SysFont(None, 22)
72+
selectFont = pygame.font.Font('monofonto.ttf', 24)
73+
basicFont = pygame.font.Font('monofonto.ttf', 22)
7474
text = selectFont.render(" - Random Play Radio ", True, (105, 251, 187), (0, 0, 0))
7575
self.blit(text, (75, 75))
7676
text = basicFont.render(" 'r' selects a random song ", True, (105, 251, 187), (0, 0, 0))

images/pipboy.png

6.27 KB
Loading

pypboy/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,11 @@ def __init__(self, parent, *args, **kwargs):
9696

9797
if config.SOUND_ENABLED:
9898
self.submodule_change_sfx = pygame.mixer.Sound('sounds/submodule_change.ogg')
99-
self.dial_move_sfx = pygame.mixer.Sound('sounds/dial_move.ogg')
10099

101100
def handle_action(self, action, value=0):
102101
if action.startswith("dial_"):
103-
if config.SOUND_ENABLED:
104-
self.dial_move_sfx.play()
105-
if action[4:] == "up":
106-
pass
107-
else:
108-
pass
102+
if hasattr(self, "menu"):
103+
self.menu.handle_action(action)
109104
elif action in self.action_handlers:
110105
self.action_handlers[action]()
111106

pypboy/modules/data/entities.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def __init__(self, width, render_rect=None, *args, **kwargs):
2121
self._map_surface = pygame.Surface((width, width))
2222
self._render_rect = render_rect
2323
super(Map, self).__init__((width, width), *args, **kwargs)
24-
basicFont = pygame.font.SysFont(None, 14)
25-
text = basicFont.render("Loading map...", True, (95, 255, 177), (0, 0, 0))
24+
text = config.FONTS[14].render("Loading map...", True, (95, 255, 177), (0, 0, 0))
2625
self.image.blit(text, (10, 10))
2726

2827
def fetch_map(self, position, radius):
@@ -58,8 +57,7 @@ def redraw_map(self, coef=1):
5857
image = config.MAP_ICONS['misc']
5958
pygame.transform.scale(image, (10, 10))
6059
self._map_surface.blit(image, (tag[1], tag[2]))
61-
basicFont = pygame.font.SysFont(None, 12)
62-
text = basicFont.render(tag[0], True, (95, 255, 177), (0, 0, 0))
60+
text = config.FONTS[12].render(tag[0], True, (95, 255, 177), (0, 0, 0))
6361
self._map_surface.blit(text, (tag[1] + 17, tag[2] + 4))
6462

6563
self.image.blit(self._map_surface, (0, 0), area=self._render_rect)
@@ -165,8 +163,7 @@ def draw_tags(self):
165163
pygame.transform.scale(image, (10, 10))
166164
self.image.blit(image, (self.tags[name][0], self.tags[name][1]))
167165
# try:
168-
basicFont = pygame.font.SysFont(None, 12)
169-
text = basicFont.render(name, True, (95, 255, 177), (0, 0, 0))
166+
text = config.FONTS[12].render(name, True, (95, 255, 177), (0, 0, 0))
170167
# text_width = text.get_size()[0]
171168
# pygame.draw.rect(
172169
# self,

pypboy/modules/items/apparel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Module(pypboy.SubModule):
88

9-
label = "Apparel"
9+
label = " Apparel "
1010

1111
def __init__(self, *args, **kwargs):
1212
super(Module, self).__init__(*args, **kwargs)

pypboy/modules/items/weapons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Module(pypboy.SubModule):
88

9-
label = "Weapons"
9+
label = " Weapons "
1010

1111
def __init__(self, *args, **kwargs):
1212
super(Module, self).__init__(*args, **kwargs)

pypboy/modules/stats/status.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pygame
33
import game
44
import config
5+
import pypboy.ui
56

67

78
class Module(pypboy.SubModule):
@@ -14,12 +15,25 @@ def __init__(self, *args, **kwargs):
1415
health.rect[0] = 4
1516
health.rect[1] = 40
1617
self.add(health)
18+
self.menu = pypboy.ui.Menu(100, ["CND", "RAD", "EFF"], [self.show_cnd, self.show_rad, self.show_eff], 0)
19+
self.menu.rect[0] = 4
20+
self.menu.rect[1] = 60
21+
self.add(self.menu)
1722

1823
def handle_resume(self):
1924
self.parent.pypboy.header.headline = "STATUS"
20-
self.parent.pypboy.header.title = "Grieve - Level 27"
25+
self.parent.pypboy.header.title = " HP 160/175 | AP 62/62"
2126
super(Module, self).handle_resume()
2227

28+
def show_cnd(self):
29+
print "CND"
30+
31+
def show_rad(self):
32+
print "RAD"
33+
34+
def show_eff(self):
35+
print "EFF"
36+
2337

2438
class Health(game.Entity):
2539

@@ -28,3 +42,6 @@ def __init__(self):
2842
self.image = pygame.image.load('images/pipboy.png')
2943
self.rect = self.image.get_rect()
3044
self.image = self.image.convert()
45+
text = config.FONTS[18].render("Grieve - Level 27", True, (105, 251, 187), (0, 0, 0))
46+
text_width = text.get_size()[0]
47+
self.image.blit(text, (config.WIDTH / 2 - 8 - text_width / 2, 250))

pypboy/ui.py

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ def render(self, *args, **kwargs):
2121
if new_date != self._date:
2222
self.image.fill((0, 0, 0))
2323
pygame.draw.line(self.image, (95, 255, 177), (5, 15), (5, 35), 2)
24-
pygame.draw.line(self.image, (95, 255, 177), (5, 15), (config.WIDTH - 124, 15), 2)
25-
pygame.draw.line(self.image, (95, 255, 177), (config.WIDTH - 124, 15), (config.WIDTH - 124, 35), 2)
26-
pygame.draw.line(self.image, (95, 255, 177), (config.WIDTH - 120, 15), (config.WIDTH - 13, 15), 2)
24+
pygame.draw.line(self.image, (95, 255, 177), (5, 15), (config.WIDTH - 154, 15), 2)
25+
pygame.draw.line(self.image, (95, 255, 177), (config.WIDTH - 154, 15), (config.WIDTH - 154, 35), 2)
26+
pygame.draw.line(self.image, (95, 255, 177), (config.WIDTH - 148, 15), (config.WIDTH - 13, 15), 2)
2727
pygame.draw.line(self.image, (95, 255, 177), (config.WIDTH - 13, 15), (config.WIDTH - 13, 35), 2)
2828

29-
basicFont = pygame.font.SysFont(None, 17)
30-
text = basicFont.render(" %s " % self.headline, True, (105, 251, 187), (0, 0, 0))
29+
text = config.FONTS[14].render(" %s " % self.headline, True, (105, 251, 187), (0, 0, 0))
3130
self.image.blit(text, (26, 8))
32-
text = basicFont.render(self.title, True, (95, 255, 177), (0, 0, 0))
33-
self.image.blit(text, ((config.WIDTH - 124) - text.get_width() - 10, 19))
34-
text = basicFont.render(self._date, True, (95, 255, 177), (0, 0, 0))
35-
self.image.blit(text, ((config.WIDTH - 111), 19))
31+
text = config.FONTS[14].render(self.title, True, (95, 255, 177), (0, 0, 0))
32+
self.image.blit(text, ((config.WIDTH - 154) - text.get_width() - 10, 19))
33+
text = config.FONTS[14].render(self._date, True, (95, 255, 177), (0, 0, 0))
34+
self.image.blit(text, ((config.WIDTH - 141), 19))
3635
self._date = new_date
3736

3837
super(Header, self).update(*args, **kwargs)
@@ -57,11 +56,15 @@ def select(self, module):
5756
pygame.draw.line(self.image, (95, 255, 177), (5, 20), (config.WIDTH - 13, 20), 2)
5857
pygame.draw.line(self.image, (95, 255, 177), (config.WIDTH - 13, 2), (config.WIDTH - 13, 20), 2)
5958

60-
offset = 50
59+
offset = 20
6160
for m in self.menu:
62-
basicFont = pygame.font.SysFont(None, 16)
63-
text = basicFont.render(" %s " % m, True, (105, 255, 187), (0, 0, 0))
64-
text_width = text.get_size()[0]
61+
padding = 1
62+
text_width = 0
63+
while text_width < 54:
64+
spaces = " ".join([" " for x in range(padding)])
65+
text = config.FONTS[12].render("%s%s%s" % (spaces, m, spaces), True, (105, 255, 187), (0, 0, 0))
66+
text_width = text.get_size()[0]
67+
padding += 1
6568
#print(m+" : "+str(text.get_size()))
6669
if m == self.selected:
6770
pygame.draw.rect(self.image, (95, 255, 177), (offset - 2, 6, (text_width + 3), 26), 2)
@@ -70,6 +73,48 @@ def select(self, module):
7073
offset = offset + 120 + (text_width - 100)
7174

7275

76+
class Menu(game.Entity):
77+
78+
def __init__(self, width, items=[], callbacks=[], selected=0):
79+
super(Menu, self).__init__((width, config.HEIGHT - 80))
80+
self.items = items
81+
self.callbacks = callbacks
82+
self.selected = 0
83+
self.select(selected)
84+
85+
if config.SOUND_ENABLED:
86+
self.dial_move_sfx = pygame.mixer.Sound('sounds/dial_move.ogg')
87+
88+
def select(self, item):
89+
self.selected = item
90+
self.redraw()
91+
if len(self.callbacks) > item and self.callbacks[item]:
92+
self.callbacks[item]()
93+
94+
def handle_action(self, action):
95+
if action == "dial_up":
96+
if self.selected > 0:
97+
if config.SOUND_ENABLED:
98+
self.dial_move_sfx.play()
99+
self.select(self.selected - 1)
100+
if action == "dial_down":
101+
if self.selected < len(self.items) - 1:
102+
if config.SOUND_ENABLED:
103+
self.dial_move_sfx.play()
104+
self.select(self.selected + 1)
105+
106+
def redraw(self):
107+
self.image.fill((0, 0, 0))
108+
offset = 5
109+
for i in range(len(self.items)):
110+
text = config.FONTS[14].render(" %s " % self.items[i], True, (105, 255, 187), (0, 0, 0))
111+
if i == self.selected:
112+
selected_rect = (5, offset - 2, text.get_size()[0] + 6, text.get_size()[1] + 3)
113+
pygame.draw.rect(self.image, (95, 255, 177), selected_rect, 2)
114+
self.image.blit(text, (10, offset))
115+
offset += text.get_size()[1] + 6
116+
117+
73118
class Scanlines(game.Entity):
74119

75120
def __init__(self, width, height, gap, speed, colours, full_push=False):

0 commit comments

Comments
 (0)