Add in way to add in a single and multiple boxes for handling control of units.

This commit is contained in:
Dorian 2016-06-04 17:37:39 -07:00
parent bbf851d467
commit 7eb4b343a5
1 changed files with 34 additions and 10 deletions

44
main.py
View File

@ -1,11 +1,9 @@
import collections import collections
import random
from kivy.app import App from kivy import app, properties
from kivy import properties from kivy.uix import button, label
from kivy import graphics
from kivy.uix import label
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
import math
MapCoords = collections.namedtuple('MapCoords', ['row', 'col']) MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
@ -22,10 +20,18 @@ class StrategyGame(FloatLayout):
for region in xrange(0, number_of_regions): for region in xrange(0, number_of_regions):
row = region / self.map_cols row = region / self.map_cols
col = 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 row_mod = row % 6
if col % 2 == 0: if col % 2 == 0:
if row_mod == 0: if row_mod == 0:
@ -48,10 +54,9 @@ class StrategyGame(FloatLayout):
class HexMapCell(label.Label): class HexMapCell(label.Label):
def __init__(self, row=0, col=0, **kwargs): def __init__(self, row=0, col=0, **kwargs):
self.region_in_map = MapCoords(row, col)
super(HexMapCell, self).__init__(**kwargs) super(HexMapCell, self).__init__(**kwargs)
self.coords = MapCoords(row, col)
class BU(HexMapCell): class BU(HexMapCell):
pass pass
@ -63,7 +68,26 @@ class R(HexMapCell):
pass 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): def build(self):
return StrategyGame() return StrategyGame()