Add grid layout with coordinates for map.

This commit is contained in:
Dorian 2016-06-04 12:23:40 -07:00
parent d28564bca4
commit 57b8de4470
2 changed files with 19 additions and 2 deletions

15
main.py
View File

@ -1,9 +1,22 @@
from kivy.app import App from kivy.app import App
from kivy import properties
from kivy.uix import button
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
class StrategyGame(FloatLayout): class StrategyGame(FloatLayout):
pass main_map = properties.ObjectProperty(None)
map_rows = properties.NumericProperty(0)
map_cols = properties.NumericProperty(0)
def __init__(self, **kwargs):
super(StrategyGame, self).__init__(**kwargs)
number_of_regions = self.map_rows * self.map_cols
for region in xrange(0, number_of_regions):
row = region / self.map_cols
col = region % self.map_cols
self.main_map.add_widget(button.Button(text='({}, {})'.format(row, col)))
class StrategyGameApp(App): class StrategyGameApp(App):

View File

@ -2,12 +2,16 @@
#:include debug.kv #:include debug.kv
<StrategyGame>: <StrategyGame>:
id: _game
main_map: _main_map main_map: _main_map
map_rows: 10
map_cols: 10
BoxLayout: BoxLayout:
orientation: 'horizontal' orientation: 'horizontal'
GridLayout: GridLayout:
id: _main_map id: _main_map
cols: 10 game: _game
cols: root.map_cols
size_hint: .75, 1 size_hint: .75, 1
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'