Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding Curtis' dialog backgrounds and adding current player colour

  • Loading branch information...
commit 50a3ef00559ddbf8140bd161d6db14baf1f59bb9 1 parent 332bb63
@elElmo elElmo authored
View
10 risk/graphics/assets/base.py
@@ -1,6 +1,7 @@
import pygame
from pygame import Surface
+GREY = (190, 190, 190)
BLACK = (0, 0, 0)
BROWN = (139, 69, 19)
WHITE = (255, 255, 255)
@@ -32,3 +33,12 @@ def get_width(self):
def get_height(self):
return self.surface.get_height()
+
+class ColourBlockAsset(PicassoAsset):
+ def __init__(self, x, y, width, height, colour):
+ surface = pygame.Surface((width, height))
+ surface.fill(colour)
+ PicassoAsset.__init__(self, surface, x, y)
+
+ def set_colour(self, colour):
+ self.surface.fill(colour)
View
4 risk/graphics/assets/clickable.py
@@ -14,12 +14,13 @@ class ClickableAsset(PicassoAsset):
def __init__(self, x, y, width, height, msg, size=16,
text_colour=base.BLACK, bg_colour=base.WHITE,
highlight_text=base.WHITE, highlight_bg=base.BLACK,
- offset_x=0, offset_y=0):
+ offset_x=0, offset_y=0, bold=False):
self.normal = pygame.Surface((width, height))
self.normal.fill(bg_colour)
font = Font(_FONT, size)
+ font.set_bold(bold)
font_width, font_height = font.size(msg)
font_x = (width - font_width) / 2
font_y = (height - font_height) / 2
@@ -90,4 +91,3 @@ def _normal_surface(self):
def _highlighted_surface(self):
return self.current
-
View
44 risk/graphics/assets/dialog.py
@@ -9,8 +9,12 @@
from risk.graphics.event import pump
from risk.graphics.assets.base import BLACK, BROWN, WHITE
from risk.graphics.assets.base import PicassoAsset
-from risk.graphics.assets.text import TextAsset
+from risk.graphics.assets.text import TextAsset, CentredTextAsset
from risk.graphics.assets.clickable import ClickableAsset
+from risk.graphics.assets.image import ScaledImageAsset
+
+BODY_BACKGROUND = 'assets/art/gui/dialog_body.png'
+TITLE_BACKGROUND = 'assets/art/gui/dialog_title.png'
class DialogAsset(PicassoAsset):
_BORDER_PIXELS = 5
@@ -26,9 +30,16 @@ def __init__(self, x, y, title, width=400, height=200, colour=BROWN):
self._BORDER_PIXELS,
width - 2 * self._BORDER_PIXELS,
self._TITLE_HEIGHT_PIXELS - self._BORDER_PIXELS,
- " == %s == " % title,
- size=16,
+ ''
)
+ # HAX, fuck it, make go now
+ self.title_background = ScaledImageAsset(0, 0, width,
+ self._TITLE_HEIGHT_PIXELS, TITLE_BACKGROUND)
+ self.title_text = CentredTextAsset(0, 2, width,
+ self._TITLE_HEIGHT_PIXELS, "== %s ==" % title, size=16, bold=True)
+ self.body = ScaledImageAsset(
+ 0, self._TITLE_HEIGHT_PIXELS, width,
+ height - self._TITLE_HEIGHT_PIXELS, BODY_BACKGROUND)
self.title.offset_x = x
self.title.offset_y = y
self.assets = []
@@ -36,17 +47,22 @@ def __init__(self, x, y, title, width=400, height=200, colour=BROWN):
def draw(self):
self.background.fill(BLACK)
- pygame.draw.rect(self.background, self.colour, pygame.Rect(
- self._BORDER_PIXELS, self._BORDER_PIXELS,
- self.width - 2 * self._BORDER_PIXELS,
- self.height - 2 * self._BORDER_PIXELS,
- ))
- pygame.draw.line(self.background, BLACK,
- (0, self._TITLE_HEIGHT_PIXELS),
- (self.width, self._TITLE_HEIGHT_PIXELS),
- self._BORDER_PIXELS,
- )
+ #pygame.draw.rect(self.background, self.colour, pygame.Rect(
+ # self._BORDER_PIXELS, self._BORDER_PIXELS,
+ # self.width - 2 * self._BORDER_PIXELS,
+ # self.height - 2 * self._BORDER_PIXELS,
+ #))
+ #pygame.draw.line(self.background, BLACK,
+ # (0, self._TITLE_HEIGHT_PIXELS),
+ # (self.width, self._TITLE_HEIGHT_PIXELS),
+ # self._BORDER_PIXELS,
+ #)
self.background.blit(self.title.draw(), self.title.get_coordinate())
+ self.background.blit(self.title_background.draw(),
+ self.title_background.get_coordinate())
+ self.background.blit(self.title_text.draw(),
+ self.title_text.get_coordinate())
+ self.background.blit(self.body.draw(), self.body.get_coordinate())
assets = list(self.assets)
for asset in assets:
self.background.blit(asset.draw(), (asset.x,
@@ -143,7 +159,7 @@ def __init__(self, x, y, title, range_min, range_max,
self.finished_button = ClickableAsset(button_x, button_y,
self.FINISHED_WIDTH, self.FINISHED_HEIGHT, "DONE",
bg_colour=BLACK, highlight_bg=WHITE, text_colour=WHITE,
- highlight_text=BLACK)
+ highlight_text=BLACK, bold=True)
self.finished_button.offset_x = self.x
self.finished_button.offset_y = self.y
View
5 risk/graphics/assets/image.py
@@ -16,6 +16,11 @@ def __init__(self, x, y, path, scale_x=1.0, scale_y=1.0):
int(self.surface.get_height() * scale_y)))
PicassoAsset.__init__(self, self.surface, x, y)
+class ScaledImageAsset(ImageAsset):
+ def __init__(self, x, y, width, height, path):
+ ImageAsset.__init__(self, x, y, path)
+ self.surface = pygame.transform.scale(self.surface, (width, height))
+
class ToggleImageAsset(ImageAsset):
def __init__(self, x, y, path, start_state=ON):
ImageAsset.__init__(self, x, y, path)
View
19 risk/graphics/graphics.py
@@ -22,6 +22,7 @@
from risk.graphics.picasso import get_picasso
from risk.graphics.assets.territory import build_territory_asset
from risk.graphics.assets.territory import build_player_colour_mapping
+from risk.graphics.assets.territory import TerritoryAsset
DEFAULT_WIDTH = 1152
DEFAULT_HEIGHT = 720
@@ -125,6 +126,7 @@ def add_graphic_hooks(game_master):
game_master.add_start_turn_callback(update_game_info_panel)
game_master.add_end_action_callback(update_game_info_panel)
game_master.add_end_phase_callback(update_current_phase)
+ game_master.add_start_turn_callback(show_current_human_player)
#game_master.add_end_action_callback(delay)
def initialize_territories(picasso, game_master):
@@ -155,6 +157,10 @@ def initialize_other_graphic_assets(picasso, game_master):
picasso.add_asset('999_ontop', game_info_asset)
datastore.add_entry('game_info', game_info_asset)
add_state_indicators(picasso, game_master)
+ human_player_asset = assets.base.ColourBlockAsset(
+ 1000, 548, 123, 80, assets.base.GREY)
+ datastore.add_entry('player_colour', human_player_asset)
+ picasso.add_asset('999_ontop', human_player_asset)
def add_state_indicators(picasso, game_master):
datastore = Datastore()
@@ -202,6 +208,19 @@ def show_human_player(game_master):
else:
get_picasso().remove_asset('1_text', asset)
+def show_current_human_player(game_master):
+ datastore = Datastore()
+ asset = datastore.get_entry('player_colour')
+ player = game_master.current_player()
+ if isinstance(player, risk.player.HumonRiskPlayer):
+ try:
+ asset.set_colour(TerritoryAsset.mapping[player])
+ except KeyError:
+ error("couldn't find key entry for player: %s" % player.name)
+ asset.set_colour(assets.base.BLACK)
+ else:
+ asset.set_colour(assets.base.GREY)
+
def is_human_player(game_master):
return isinstance(game_master.current_player(),
risk.player.HumonRiskPlayer)
Please sign in to comment.
Something went wrong with that request. Please try again.