/usr/lib/games/solarwolf/gamename.py is in solarwolf 1.5-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | """Game name entry handler, part of SOLARWOLF."""
# Portions Copyright (C) 2002 Aaron "APS" Schlaegel, LGPL, see lgpl.txt
import string, math
import pygame
from pygame.locals import *
import game
import gfx, snd, txt
import input
import players
import gameplay
import gamecreds
import gamenews
charset = string.uppercase + '-.'
fontlookup = {}
fontimages = []
images = []
thefont = None
nameletters = []
stars = []
def load_game_resources():
global menu, fontimages, boximages, thefont, charset, images, stars
extraimgs = {'<':gfx.load('rub.gif'), '>':gfx.load('end.gif')}
for i in extraimgs.values():
i.set_colorkey(0, RLEACCEL)
font = txt.Font(None, 100)
thefont = font
color = 120, 210, 160
color2 = 210, 230, 220
bgd = 0, 0, 0
xoffset, yoffset = 75, 175
xsize, ysize = 70, 80
step = 0
for letter in charset + '<>':
pos = xoffset+xsize*(step%10), yoffset+ysize*(step/10)
if extraimgs.has_key(letter):
img = img2 = extraimgs[letter]
r = img.get_rect()
r.center = pos
else:
img, r = font.text(color, letter, pos)
img2, r2 = font.text(color2, letter, pos)
fontimages.append((img, r, letter, img2))
step += 1
if letter in charset:
fontlookup[letter] = fontimages[-1]
xoffset = 40
for x in range(game.name_maxlength):
rect = Rect(xoffset+x*xsize, 450, xsize, 100)
rect2 = Rect(rect.left+1, rect.bottom-15, rect.width-2, 8)
nameletters.append([rect, rect2, None])
font = txt.Font(None, 40)
img = font.render('Enter Your Name:', 1, (220, 210, 180), bgd).convert()
img.set_colorkey(bgd, RLEACCEL)
r = img.get_rect()
r.center = gfx.rect.centerx, 70
images.append((img, r))
img = gfx.load('star.gif')
starsize = img.get_rect()
tmpstars = []
for x in range(1, 12*6+2, 12):
tmp=pygame.transform.rotate(img, x)
tmpstars.append(tmp)
starsize.union_ip(tmp.get_rect())
for s in tmpstars:
star = pygame.Surface(starsize.size)
r = s.get_rect()
r.center = star.get_rect().center
star.blit(s, r)
star.set_colorkey(s.get_colorkey(), RLEACCEL)
stars.append(star)
snd.preload('select_choose', 'select_move', 'incorrect', 'delete')
class GameName:
def __init__(self, prevhandler):
self.prevhandler = prevhandler
self.fontimages = fontimages
self.images = images
self.stars = stars
self.starrect = self.stars[0].get_rect()
self.starframe = 0
self.starinc = 1
if game.clock.get_fps() < 28:
self.starinc = 0
self.letter = fontimages[0]
self.selectletter(self.letter)
self.done = 0
if game.player:
self.prevname = game.player.name
game.player.name = ''
else:
self.prevname = ''
game.player = players.Player('')
for l in nameletters:
l[2] = None
self.step = 0.0
def quit(self):
snd.play('select_choose')
game.handler = self.prevhandler
self.done = 1
if not game.player.name:
game.player.name = 'NONAME'
game.player.newguid()
def drawletter(self, letter, lit):
index = (0, 3)[letter==lit]
rect = letter[1]
gfx.surface.blit(letter[index], rect)
gfx.dirty(rect)
def clearletter(self, letter, lit):
rect = letter[1]
self.background(rect)
if letter == lit:
r = self.background(self.starrect)
gfx.dirty(r)
def selectletter(self, letter):
self.clearletter(self.letter, self.letter)
self.starrect.center = letter[1].center
self.letter = letter
def addletter(self, letter):
if len(game.player.name) >= game.name_maxlength or letter not in charset:
snd.play('incorrect')
return
snd.play('select_choose')
game.player.name += letter
self.recalcname()
self.starinc = -self.starinc
def rub(self):
if game.player.name:
game.player.name = game.player.name[:-1]
self.recalcname()
snd.play('delete')
self.starinc = -self.starinc
def recalcname(self):
length = len(game.player.name)
for x in range(game.name_maxlength):
l = nameletters[x]
r = self.background(l[0])
gfx.dirty(r)
if x < length:
if not l[2]:
l[2] = thefont.render(game.player.name[x], 1, (200, 250, 200), (0, 0, 0)).convert()
l[2].set_colorkey((0, 0, 0), RLEACCEL)
else:
l[2] = None
def drawname(self):
hicolor = (int((math.sin(self.step)+1)*50+80),)*3
locolor = 50, 50, 50
lolocolor = 25, 25, 25
curletter = len(game.player.name)
for x in range(game.name_maxlength):
l = nameletters[x]
col = (x == curletter) and hicolor or locolor
if l[2]: col = lolocolor
r = gfx.surface.fill(col, l[1])
gfx.dirty(r)
if l[2]:
r = l[2].get_rect()
r.centerx = l[0].centerx
r.bottom = l[0].bottom
r = gfx.surface.blit(l[2], r)
gfx.dirty(r)
def input(self, i):
if i.release:
return
if i.type == KEYDOWN:
if i.unicode and i.unicode.upper() in charset:
return
elif i.key in (K_DELETE, K_BACKSPACE, K_RETURN, K_KP_ENTER):
return
if i.translated == input.ABORT:
return self.quit()
if i.translated == input.PRESS:
letter = self.letter[2]
if letter == '<':
self.rub()
elif letter == '>':
self.quit()
else:
self.addletter(self.letter[2])
return
change = 0
if i.translated == input.LEFT: change = -1
elif i.translated == input.RIGHT: change = 1
elif i.translated == input.UP: change = -10
elif i.translated == input.DOWN: change = 10
if not change:
return
snd.play('select_move')
current = self.fontimages.index(self.letter) + change
if current < 0:
current = len(self.fontimages) + current
if current >= len(self.fontimages):
current = current - len(self.fontimages)
self.selectletter(self.fontimages[current])
def event(self, e):
if e.type == KEYDOWN:
if e.key in (K_DELETE, K_BACKSPACE):
self.rub()
self.selectletter(self.fontimages[-2])
elif e.key in (K_RETURN, K_KP_ENTER):
self.quit()
elif e.unicode:
l = e.unicode.upper()
if l in charset:
self.selectletter(fontlookup[l])
self.addletter(l)
def run(self):
self.step += 0.5
self.starframe = (self.starframe + self.starinc) % 5
if not self.done:
self.clearletter(self.letter, self.letter)
else:
for img in self.fontimages:
self.clearletter(img, self.letter)
gfx.updatestars(self.background, gfx)
if not self.done:
r = gfx.surface.blit(self.stars[self.starframe], self.starrect)
gfx.dirty(r)
for img in self.fontimages:
self.drawletter(img, self.letter)
for img in self.images:
r = gfx.surface.blit(img[0], img[1])
gfx.dirty(r)
self.drawname()
else:
for img in self.fontimages:
gfx.dirty(img[1])
for img in self.images:
r = self.background(img[1])
gfx.dirty(r)
self.recalcname()
def background(self, area):
return gfx.surface.fill((0, 0, 0), area)
|