Add in way to add in a single and multiple boxes for handling control of units.
This commit is contained in:
parent
bbf851d467
commit
7eb4b343a5
44
main.py
44
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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue