From bbf851d4672e4371ff2847b98d12dfd7215cef60 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Sat, 4 Jun 2016 15:43:40 -0700 Subject: [PATCH 1/3] Switch to labels and added two ways to colour backgrounds. --- strategygame.kv | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/strategygame.kv b/strategygame.kv index e7b7481..7efe1d1 100644 --- a/strategygame.kv +++ b/strategygame.kv @@ -1,5 +1,4 @@ #:import math math -#:include debug.kv : id: _game @@ -16,12 +15,20 @@ BoxLayout: orientation: 'vertical' size_hint: .25, 1 - DebugLabel: + Label: + id: _stats text: 'status' size_hint: 1, .66 - DebugLabel: + canvas.before: + Color: + rgba: .49, .49, .81, 1 + Rectangle: + pos: _stats.pos + size: _stats.size + Button: text: 'mini-map' size_hint: 1, .33 + background_color: .75, .71, .99, 1 : From 7eb4b343a55881ae495c5248c8c3e2bcc5826d25 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Sat, 4 Jun 2016 17:37:39 -0700 Subject: [PATCH 2/3] Add in way to add in a single and multiple boxes for handling control of units. --- main.py | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 31d0ac5..b04e194 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,9 @@ import collections +import random -from kivy.app import App -from kivy import properties -from kivy import graphics -from kivy.uix import label +from kivy import app, properties +from kivy.uix import button, label from kivy.uix.floatlayout import FloatLayout -import math MapCoords = collections.namedtuple('MapCoords', ['row', 'col']) @@ -22,10 +20,18 @@ class StrategyGame(FloatLayout): for region in xrange(0, number_of_regions): row = region / self.map_cols col = region % self.map_cols - self.main_map.add_widget(self.pick_hex_cell(row=row, col=col)) + # Add hex cells to make up the map. + hex_cell = self.pick_hex_cell(row=row, col=col) + self.main_map.add_widget(hex_cell) - def pick_hex_cell(self, row, col): + # Add overlay conditionally. + # if (row % 6 == 2 and col % 2 == 0) or (row % 6 == 5 and col % 2 == 1): + if row == 2 and col == 0: + self.add_widget(HexMapControlCell(hex_bind=hex_cell)) + + @staticmethod + def pick_hex_cell(row, col): row_mod = row % 6 if col % 2 == 0: if row_mod == 0: @@ -48,10 +54,9 @@ class StrategyGame(FloatLayout): class HexMapCell(label.Label): - def __init__(self, row=0, col=0, **kwargs): - self.region_in_map = MapCoords(row, col) super(HexMapCell, self).__init__(**kwargs) + self.coords = MapCoords(row, col) class BU(HexMapCell): pass @@ -63,7 +68,26 @@ class R(HexMapCell): pass -class StrategyGameApp(App): +class HexMapControlCell(button.Button): + def __init__(self, hex_bind=None, **kwargs): + super(HexMapControlCell, self).__init__(**kwargs) + self.hex_bind = hex_bind + # self.background_color = random.random(), random.random(), random.random(), 0.1 + # self.background_color = random.random(), random.random(), random.random(), 0.25 + self.background_color = random.random(), random.random(), random.random(), 1 + self.bind(pos=self.reposition_control_cell, size=self.resize_control_cell) + + def reposition_control_cell(self, obj, value): + # import pdb + # pdb.set_trace() + self.pos = self.hex_bind.pos + + def resize_control_cell(self, obj, value): + self.height = self.hex_bind.height * 2 + self.width = self.hex_bind.width * 2 + + +class StrategyGameApp(app.App): def build(self): return StrategyGame() From 02c84566cdebe7b33f77577a257027a9db948914 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Sat, 4 Jun 2016 17:57:52 -0700 Subject: [PATCH 3/3] Attempt to create multiple control points. --- main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index b04e194..f29b13c 100644 --- a/main.py +++ b/main.py @@ -26,8 +26,8 @@ class StrategyGame(FloatLayout): self.main_map.add_widget(hex_cell) # Add overlay conditionally. - # if (row % 6 == 2 and col % 2 == 0) or (row % 6 == 5 and col % 2 == 1): - if row == 2 and col == 0: + if (row % 6 == 2 and col % 2 == 0) or (row % 6 == 5 and col % 2 == 1): + print('({}, {})'.format(row, col)) self.add_widget(HexMapControlCell(hex_bind=hex_cell)) @staticmethod @@ -58,12 +58,19 @@ class HexMapCell(label.Label): super(HexMapCell, self).__init__(**kwargs) self.coords = MapCoords(row, col) + class BU(HexMapCell): pass + + class TD(HexMapCell): pass + + class L(HexMapCell): pass + + class R(HexMapCell): pass @@ -72,14 +79,11 @@ class HexMapControlCell(button.Button): def __init__(self, hex_bind=None, **kwargs): super(HexMapControlCell, self).__init__(**kwargs) self.hex_bind = hex_bind - # self.background_color = random.random(), random.random(), random.random(), 0.1 - # self.background_color = random.random(), random.random(), random.random(), 0.25 self.background_color = random.random(), random.random(), random.random(), 1 self.bind(pos=self.reposition_control_cell, size=self.resize_control_cell) + self.text = '({}, {})'.format(self.hex_bind.coords.row, self.hex_bind.coords.col) def reposition_control_cell(self, obj, value): - # import pdb - # pdb.set_trace() self.pos = self.hex_bind.pos def resize_control_cell(self, obj, value):