Breakout map regions into standalone widget.

This commit is contained in:
Dorian 2016-06-04 12:35:33 -07:00
parent 57b8de4470
commit 5decaf284d
1 changed files with 13 additions and 1 deletions

14
main.py
View File

@ -1,9 +1,14 @@
import collections
from kivy.app import App from kivy.app import App
from kivy import properties from kivy import properties
from kivy.uix import button from kivy.uix import button
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
class StrategyGame(FloatLayout): class StrategyGame(FloatLayout):
main_map = properties.ObjectProperty(None) main_map = properties.ObjectProperty(None)
map_rows = properties.NumericProperty(0) map_rows = properties.NumericProperty(0)
@ -16,7 +21,14 @@ 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(button.Button(text='({}, {})'.format(row, col))) self.main_map.add_widget(MapRegion(row=row, col=col))
class MapRegion(button.Button):
def __init__(self, row=0, col=0, **kwargs):
self.region_in_map = MapCoords(row, col)
super(MapRegion, self).__init__(**kwargs)
self.text = '({}, {})'.format(self.region_in_map.row, self.region_in_map.col)
class StrategyGameApp(App): class StrategyGameApp(App):