- total_stats = data['total_stats']
- total_games = total_stats['games']
- elos = data["elos"]
- ranks = data["ranks"]
-
-
- ## create background
-
- surf = C.ImageSurface(C.FORMAT_RGB24, WIDTH, HEIGHT)
- ctx = C.Context(surf)
- ctx.set_antialias(C.ANTIALIAS_GRAY)
-
- # draw background (just plain fillcolor)
- if params['bg'] == 0:
- ctx.rectangle(0, 0, WIDTH, HEIGHT)
- ctx.set_source_rgb(0.04, 0.04, 0.04) # bgcolor of Xonotic forum
- ctx.fill()
-
- # draw background image (try to get correct tiling, too)
- if params['bg'] > 0:
- bg = None
- if params['bg'] == 1:
- bg = C.ImageSurface.create_from_png("img/dark_wall.png")
- elif params['bg'] == 2:
- bg = C.ImageSurface.create_from_png("img/asfalt.png")
- elif params['bg'] == 3:
- bg = C.ImageSurface.create_from_png("img/broken_noise.png")
- elif params['bg'] == 4:
- bg = C.ImageSurface.create_from_png("img/burried.png")
- elif params['bg'] == 5:
- bg = C.ImageSurface.create_from_png("img/dark_leather.png")
- elif params['bg'] == 6:
- bg = C.ImageSurface.create_from_png("img/txture.png")
- elif params['bg'] == 7:
- bg = C.ImageSurface.create_from_png("img/black_linen_v2.png")
- elif params['bg'] == 8:
- bg = C.ImageSurface.create_from_png("img/background_archer-v1.png")
-
- # tile image
- if bg:
- bg_w, bg_h = bg.get_width(), bg.get_height()
- bg_xoff = 0
- while bg_xoff < WIDTH:
- bg_yoff = 0
- while bg_yoff < HEIGHT:
- ctx.set_source_surface(bg, bg_xoff, bg_yoff)
- ctx.paint()
- bg_yoff += bg_h
- bg_xoff += bg_w
-
- # draw overlay graphic
- if params['overlay'] > 0:
- overlay = None
- if params['overlay'] == 1:
- overlay = C.ImageSurface.create_from_png("img/overlay.png")
- if overlay:
- ctx.set_source_surface(overlay, 0, 0)
- ctx.mask_surface(overlay)
- ctx.paint()
-
-
- ## draw player's nickname with fancy colors
-
- # deocde nick, strip all weird-looking characters
- qstr = qfont_decode(player.nick).replace('^^', '^').replace(u'\x00', '').replace(u' ', ' ')
- chars = []
- for c in qstr:
- if ord(c) < 128:
- chars.append(c)
- qstr = ''.join(chars)
- stripped_nick = strip_colors(qstr)
-
- # fontsize is reduced if width gets too large
- ctx.select_font_face(font, C.FONT_SLANT_NORMAL, C.FONT_WEIGHT_NORMAL)
- ctx.set_font_size(20)
- xoff, yoff, tw, th = ctx.text_extents(stripped_nick)[:4]
- if tw > NICK_MAXWIDTH:
- ctx.set_font_size(18)
- xoff, yoff, tw, th = ctx.text_extents(stripped_nick)[:4]
- if tw > NICK_MAXWIDTH:
- ctx.set_font_size(16)
- xoff, yoff, tw, th = ctx.text_extents(stripped_nick)[:4]
- if tw > NICK_MAXWIDTH:
- ctx.set_font_size(14)
- xoff, yoff, tw, th = ctx.text_extents(stripped_nick)[:4]
- if tw > NICK_MAXWIDTH:
- ctx.set_font_size(12)
-
-
- # split up nick into colored segments and draw each of them
-
- # split nick into colored segments
- xoffset = 0
- _all_colors = re.compile(r'(\^\d|\^x[\dA-Fa-f]{3})')
- #print qstr, _all_colors.findall(qstr), _all_colors.split(qstr)
-
- parts = _all_colors.split(qstr)
- while len(parts) > 0:
- tag = None
- txt = parts[0]
- if _all_colors.match(txt):
- tag = txt[1:] # strip leading '^'
- if len(parts) < 2:
- break
- txt = parts[1]
- del parts[1]
- del parts[0]
-
- if not txt or len(txt) == 0:
- # only colorcode and no real text, skip this
- continue
-
- r,g,b = _dec_colors[7]
- try:
- if tag.startswith('x'):
- r = int(tag[1] * 2, 16) / 255.0
- g = int(tag[2] * 2, 16) / 255.0
- b = int(tag[3] * 2, 16) / 255.0
- hue, light, satur = rgb_to_hls(r, g, b)
- if light < _contrast_threshold:
- light = _contrast_threshold
- r, g, b = hls_to_rgb(hue, light, satur)
- else:
- r,g,b = _dec_colors[int(tag[0])]
- except:
- r,g,b = _dec_colors[7]
-
- ctx.set_source_rgb(r, g, b)
- ctx.move_to(NICK_POS[0] + xoffset, NICK_POS[1])
- ctx.show_text(txt)
-
- xoff, yoff, tw, th = ctx.text_extents(txt)[:4]
- tw += (len(txt)-len(txt.strip()))*3 # account for lost whitespaces
- xoffset += tw + 2
-
-
- ## print elos and ranks
-
- # show up to three gametypes the player has participated in
- xoffset = 0
- for gt in total_stats['gametypes'][:3]:
- ctx.select_font_face(font, C.FONT_SLANT_NORMAL, C.FONT_WEIGHT_BOLD)
- ctx.set_font_size(10)
- ctx.set_source_rgb(1.0, 1.0, 1.0)
- txt = "[ %s ]" % gt.upper()
- xoff, yoff, tw, th = ctx.text_extents(txt)[:4]
- ctx.move_to(GAMES_POS[0]+xoffset-xoff-tw/2, GAMES_POS[1]-yoff-4)
- ctx.show_text(txt)
-
- old_aa = ctx.get_antialias()
- ctx.set_antialias(C.ANTIALIAS_NONE)
- ctx.set_source_rgb(0.8, 0.8, 0.8)
- ctx.set_line_width(1)
- ctx.move_to(GAMES_POS[0]+xoffset-GAMES_WIDTH/2+5, GAMES_POS[1]+8)
- ctx.line_to(GAMES_POS[0]+xoffset+GAMES_WIDTH/2-5, GAMES_POS[1]+8)
- ctx.stroke()
- ctx.move_to(GAMES_POS[0]+xoffset-GAMES_WIDTH/2+5, GAMES_POS[1]+32)
- ctx.line_to(GAMES_POS[0]+xoffset+GAMES_WIDTH/2-5, GAMES_POS[1]+32)
- ctx.stroke()
- ctx.set_antialias(old_aa)
-
- if not elos.has_key(gt) or not ranks.has_key(gt):
- ctx.select_font_face(font, C.FONT_SLANT_NORMAL, C.FONT_WEIGHT_BOLD)
- ctx.set_font_size(12)
- ctx.set_source_rgb(0.8, 0.2, 0.2)
- txt = "no stats yet!"
- xoff, yoff, tw, th = ctx.text_extents(txt)[:4]
- ctx.move_to(GAMES_POS[0]+xoffset-xoff-tw/2, GAMES_POS[1]+28-yoff-4)
- ctx.save()
- ctx.rotate(math.radians(-10))
- ctx.show_text(txt)
- ctx.restore()