You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

716 lines
33 KiB
Python

# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.lang import Builder
from functools import partial
from kivy.uix.widget import Widget
from kivy.factory import Factory
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.config import Config
from kivy.clock import mainthread
from kivy.properties import StringProperty, ObjectProperty,NumericProperty,ReferenceListProperty
from kivy.graphics import Color, Rectangle
from kivy.event import EventDispatcher
from kivy.uix.effectwidget import PushMatrix,PopMatrix
from kivy.graphics import Rotate
from kivy.graphics import Canvas
import CardDB
from CardDB import Card
import FormationDB
from FormationDB import Formation
cardDB = CardDB.getCardDict()
cardList = CardDB.getCardList()
patriciaCardT = CardDB.patriciaReadCardDB()
patriciaFormationT = FormationDB.patriciaReadFormationDB()
# class SparseGridLayout(FloatLayout):
# # depricated -> funktioniert nicht -> pre-rendered lösung
# #Note: use test4_input as prebuilder/testground + integrate pushmatrix popmatrix
# #-> failed
# rows = NumericProperty(1)
# columns = NumericProperty(1)
# shape = ReferenceListProperty(rows, columns)
# layout_build = False
# def do_layout(self, *args):
# shape_hint = (1. / self.columns, 1. / self.rows)
# if self.layout_build is False:
# for child in self.children:
# child.size_hint = (shape_hint[0] * child.hor_span, shape_hint[1] * child.vert_span)#TODO integrate span here
# if not hasattr(child, 'row'):
# child.row = 0
# if not hasattr(child, 'column'):
# child.column = 0
# #evtl hier clickdispatch einbauen
# #evtl hier checken wegen push/pop matrix
# child.pos_hint = {'x': (shape_hint[0] * child.pos_row)+(shape_hint[0]*child.hor_offset) ,#
# 'y': (shape_hint[1] * child.pos_column)+(shape_hint[1]*child.vert_offset)}#
# #broken code-> push/pop bewegt keine hitboxen mit!! -> pre-rendered lösung
# #child.canvas.before.add(PushMatrix())
# #child.canvas.before.add(Rotate(angle = child.angle,origin = [child.get_center_x(), child.get_center_y()] ))#
# #child.canvas.after.add(PopMatrix())
# self.layout_build = True
# super(SparseGridLayout, self).do_layout(*args)
# def on_release(self):
# print('grid pressed')
# return super().on_release()
# class GridEntry(EventDispatcher):
# #depricated -> pre-rendered lösung
# pos_row = NumericProperty(0)
# pos_column = NumericProperty(0)
# vert_span = NumericProperty(1)
# hor_span = NumericProperty(1)
# vert_offset = NumericProperty(0)
# hor_offset = NumericProperty(0)
# def check_click():
# #TODO in click dispatching reinlesen
# #scheinbar wird click von sparsegrid nicht an kinder weitergegeben
# pass
# def on_release(self):
# print('gridEntry pressed')
# return super().on_release()
# class GridImage(Image, ButtonBehavior, GridEntry):
# #depricated -> pre-rendered lösung
# def __init__(self,angle=0,id=None,**kwargs):
# self.angle = angle
# self.id = id
# super(GridImage,self).__init__(**kwargs)
# def on_release(self):
# print('Pos pressed {}'.format(self.id))
# return super().on_release()
class customButton(Button):
def __init__(self,cardID,card=None,**kwargs):
Button.__init__(self,**kwargs)
self.targetCardID = cardID
self.linkedCard = card
class BackgroundColor(Widget):
def __init__(self,**kwargs):
super(BackgroundColor, self).__init__()
class BackgroundLabel(Label,BackgroundColor):
def __init__(self,**kwargs):
super(BackgroundLabel,self).__init__(**kwargs)
class Cardscroller(ScrollView):
def __init__(self,sm,**kwargs):
self.sm = sm
super(Cardscroller,self).__init__(**kwargs)
class Formscroller(ScrollView):
def __init__(self,sm,**kwargs):
self.sm = sm
super(Formscroller,self).__init__(**kwargs)
class MainScreen(Screen):
app = None
sm = None
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
def btn_pressed(self,target,*args):
if target is 'cards':
print('Change to CardSetScreen imminent...')
self.app.changeScreenTo(self.sm,"card_set_screen","left")
elif target is 'formations':
print('Change to FormationOverview screen imminent...')
self.app.changeScreenTo(self.sm,"formation_overview_screen","left")
#add new modes here
else:
print('targetscreen: {} is not defined'.format(target))
class CardSetScreen(Screen):
app = None
sm = None
currentCardSet = None
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
def btn_pressed(self,cardset,*args):
print('Set picked: {}'.format(cardset))
print('Change to OptionScreen imminent...')
self.currentCardSet = cardset
self.app.changeScreenTo(self.sm,"CardOption_screen","left")
setattr(self.manager.get_screen('CardOption_screen'), 'currentCardSet', self.currentCardSet)
setattr(self.manager.get_screen('CardOption_screen').ids['Header'],'text', '[color=fdc84a]{}[/color]'.format(self.currentCardSet))
setattr(self.manager.get_screen('CardOption_screen').ids['Img'],'source', 'Assets/Cards/THOTH_BG.png')
currentDeck = cardDB[self.currentCardSet]
setattr(self.manager.get_screen('CardOption_screen').ids['wahlBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen('CardOption_screen').ids['wahlBtn'],'background_down', currentDeck['DeckFrame_activated'])
setattr(self.manager.get_screen('CardOption_screen').ids['sucheBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen('CardOption_screen').ids['sucheBtn'],'background_down', currentDeck['DeckFrame_activated'])
class CardOptionScreen(Screen):
app = None
sm = None
currentCardSet = ''
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
def btn_pressed(self,cardset,targetScreen,*args):
print('Change to {} imminent...'.format(targetScreen))
self.currentCardSet = cardset
self.app.changeScreenTo(self.sm,targetScreen,"left")
setattr(self.manager.get_screen(targetScreen), 'currentCardSet', self.currentCardSet)
currentDeck = cardDB[self.currentCardSet]
if targetScreen == 'Cardgroups_screen':
setattr(self.manager.get_screen(targetScreen).ids['Header'], 'text', '[color=fdc84a]{}[/color]'.format(self.currentCardSet))
#TODO background variabilisieren
setattr(self.manager.get_screen(targetScreen).ids['Img'],'source', 'Assets/Cards/THOTH_BG.png')
setattr(self.manager.get_screen(targetScreen).ids['trumpBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['trumpBtn'],'background_down', currentDeck['DeckFrame_activated'])
setattr(self.manager.get_screen(targetScreen).ids['swordBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['swordBtn'],'background_down', currentDeck['DeckFrame_activated'])
setattr(self.manager.get_screen(targetScreen).ids['staffBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['staffBtn'],'background_down', currentDeck['DeckFrame_activated'])
setattr(self.manager.get_screen(targetScreen).ids['cupBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['cupBtn'],'background_down', currentDeck['DeckFrame_activated'])
if self.currentCardSet == 'Rider/Waite': #TODO make pretty
setattr(self.manager.get_screen(targetScreen).ids['coinBtn'],'text', "[color=fdc84a]Münzen[/color]")
setattr(self.manager.get_screen(targetScreen).ids['coinBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['coinBtn'],'background_down', currentDeck['DeckFrame_activated'])
else:
setattr(self.manager.get_screen(targetScreen).ids['Header'], 'text', '[color=fdc84a]Kartensuche[/color]')
setattr(self.manager.get_screen(targetScreen).ids['Img'],'source', 'Assets/Backgrounds/Background-1.png')
setattr(self.manager.get_screen(targetScreen),'previous_screen', 'CardOption_screen')
setattr(self.manager.get_screen(targetScreen).ids['checkBox_caseMatch'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['checkBox_caseMatch'],'background_down', currentDeck['DeckFrame_activated'])
setattr(self.manager.get_screen(targetScreen).ids['checkBox_allCards'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['checkBox_allCards'],'background_down', currentDeck['DeckFrame_activated'])
setattr(self.manager.get_screen(targetScreen).ids['searchBtn'],'background_normal', currentDeck['DeckFrame'])
setattr(self.manager.get_screen(targetScreen).ids['searchBtn'],'background_down', currentDeck['DeckFrame_activated'])
class CardSearchScreen(Screen):
app = None
sm = None
previous_screen = None
selectedCards = list()
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
self.ids.BackBtn.targetScreen = self.previous_screen
def toggle_checkbox(self,btn):
if btn.toggledState == False:
btn.background_normal = 'Assets/UI/ButtonFrame_majestic_activated.png'
btn.toggledState = True
else:
btn.background_normal = 'Assets/UI/ButtonFrame_majestic.png'
btn.toggledState = False
def collectCandidates(self):
print('Ich meeeesse.... q[o.o]q Ich meeeeesse.... p[o.o]p')
searchInput = self.sm.get_screen('cardSearch_screen').ids['searchWord']
searchword = searchInput.text
global patriciaCardT
try:
keyList = list()
keyList.clear()
self.selectedCards.clear()
keyList = patriciaCardT.iter(searchword)
for key in keyList:
self.selectedCards.append(patriciaCardT[key])
#sort selected cards
self.selectedCards = self.sortSelectedCardList(self.selectedCards)
print('gefundene Karten zu suchword "{}": {}'.format(searchword,self.selectedCards))
print('Kartendetails:')
for card in self.selectedCards:
print('Name: {}; Set: {}; Element: {}; ID: {}'.format(card.name,card.deck,card.elementName,card.id))
except KeyError:
print('keine Karten gefunden')
return
print('Fertig \[^.^]/')
print('Change to CardSelectorScreen imminent...')
self.app.changeScreenTo(self.sm,"card_selector_screen","left")
setattr(self.manager.get_screen('card_selector_screen').ids['Img'], 'source', "Assets/Cards/THOTH_BG.png")
setattr(self.manager.get_screen('card_selector_screen'), 'previous_screen', 'cardSearch_screen')
setattr(self.manager.get_screen('card_selector_screen'), 'cardsBuild', 'False')
setattr(self.manager.get_screen('card_selector_screen'), 'cardList', self.selectedCards)
setattr(self.manager.get_screen('card_selector_screen').ids['Header'], 'text', '[color=fdc84a]Gefundene Karten[/color]')
def sortSelectedCardList(self,cardListCollection):
sortedCardList = list()
for cardList in cardListCollection:
for card in cardList:
if not sortedCardList:
sortedCardList.append(card)
continue
#if card is allready in sorted list (due to duplicates) ignore them
if card in sortedCardList:
continue
cardWasSorted = False
for indexNr, indexCard in enumerate(sortedCardList):
#compare current card with all in orderedList and insert where it fits
if self.compareCard(indexCard,card) == True:
continue
else:
sortedCardList.insert(indexNr,card)
cardWasSorted = True
break
if cardWasSorted == True:
continue
#if no index for new card was found append nex card
sortedCardList.append(card)
return sortedCardList
def compareCard(self,cardA, cardB):
#returns True if CardA before cardB
#compare rules: Deck
# 1st Deck: Rider/waite -> Thoth
deckRank = {'Rider/Waite': 1,'Thoth (Crowley)': 2}
# 2nd ElementName: Große Arkana -> Schwerter -> Stäbe -> Kelche -> Scheiben/Münzen
elementRank = {'Große Arkana': 1, 'Schwerter':2, 'Stäbe':3, 'Kelche':4, 'Scheiben':5, 'Münzen':5}
# 3rd ID: small -> large
if cardA.deck == cardB.deck:
#same deck; check for elementgrouping
if cardA.elementName == cardB.elementName:
#same elementgrouping; check for ID
if int(cardA.id) < int(cardB.id):
return True
else:
return False
elif elementRank[cardA.elementName] < elementRank[cardB.elementName]:
return True
else:
return False
elif deckRank[cardA.deck] < deckRank[cardB.deck]:
return True
else:
return False
class CardGroupsScreen(Screen):
app = None
sm = None
currentCardSet = None
currentCardGroup = None
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
def btn_pressed(self,cardset,cardgroup,*args):
print('Change to CardSelectorScreen imminent...')
self.currentCardSet = cardset
self.currentCardGroup = cardgroup
self.app.changeScreenTo(self.sm,"card_selector_screen","left")
setattr(self.manager.get_screen('card_selector_screen').ids['Img'], 'source', cardDB[self.currentCardSet]['DeckBG'])
setattr(self.manager.get_screen('card_selector_screen'), 'cardsBuild', 'False')
selectedCards = self.getCardSelectionList(self.currentCardSet,self.currentCardGroup)
setattr(self.manager.get_screen('card_selector_screen'), 'cardList', selectedCards)
setattr(self.manager.get_screen('card_selector_screen'), 'previous_screen', 'Cardgroups_screen')
setattr(self.manager.get_screen('card_selector_screen').ids['Header'], 'text', '[color=fdc84a]{}[/color]'.format(self.currentCardGroup))
def getCardSelectionList(self, deck, element):
deck = cardDB[deck]
group = deck[element]
cardList = list()
for key,card in group.items():
cardList.append(card)
return cardList
class CardSelectorScreen(Screen):
app = None
sm = None
previous_screen = None
cardsBuild = False
cardList = list()
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
self.displaySelectedCards()
self.ids.BackBtn.targetScreen = self.previous_screen
def btn_pressed(self,card,*args):
print('Change to CardDetailScreen is imminent...')
self.app.changeScreenTo(self.sm,"card_detail_screen","left")
setattr(self.manager.get_screen('card_detail_screen'), 'currentCard', card)
setattr(self.manager.get_screen('card_detail_screen'), 'currentCardId', card.id)
setattr(self.manager.get_screen('card_detail_screen'), 'currentCardGroup',card.elementName)
setattr(self.manager.get_screen('card_detail_screen'), 'currentCardSet', card.deck)
setattr(self.manager.get_screen('card_detail_screen').ids.CardImg,'source', card.image_path)
def displaySelectedCards(self):
for child in [child for child in self.ids.grid.children]:
self.ids.grid.remove_widget(child)
self.cardsBuild = True
self.buttonSize = 0
for card in self.cardList:
tmp_cardDeck = cardDB[card.deck]
cbutton = customButton(card.id,
card,
text=card.name,
font_size = 28,
size_hint = [1,1],
background_normal= tmp_cardDeck['DeckFrame'],
background_down= tmp_cardDeck['DeckFrame_activated'],
border= [.5,1,.5,1],
font_name= "Assets/Fonts/AlexBrush-Regular")
cbutton.bind(on_release=partial(self.btn_pressed,card))
self.buttonSize += cbutton.height
self.ids.grid.add_widget(cbutton)
self.ids.grid.height = self.buttonSize
class CardDetailScreen(Screen):
app = None
sm = None
currentCardId = None
currentCardGroup = None
currentCardSet = None
currentCard = None
def on_leave(self, *args):
self.clearChildren()
self.manager.get_screen('card_detail_screen').ids['CardImg'].disabled = False
return super().on_leave(*args)
def getCardData(self):
#set screen details
self.manager.get_screen('card_detail_screen').ids['CardImg'].source = self.currentCard.image_path
self.manager.get_screen('card_detail_screen').ids['Header'].text = '[color=fdc84a]{}[/color]'.format(self.currentCard.name)
def changeDeck(self,targetSet):
self.clearChildren()
self.manager.get_screen('card_detail_screen').ids['CardImg'].disabled = False
group = self.currentCard.elementName
if group == 'Münzen':
group = 'Scheiben'
elif group == 'Scheiben':
group = 'Münzen'
global cardDB
currSetList = cardDB[targetSet]
currGroupList = currSetList[group]
self.currentCard = currGroupList[self.currentCardId]
self.getCardData()
def revealData(self):
self.shadowOverlay = Label(id='Overlay',size_hint=[1, 0.9],pos_hint={"x":0, "top": 0.9}, )
self.shadowOverlay.canvas.add(Color(0, 0, 0, 0.4))
self.shadowOverlay.canvas.add(Rectangle(pos_hint=[0,0.8],size=(self.size[0],self.size[1]*0.9)))
self.add_widget(self.shadowOverlay)
self.manager.get_screen('card_detail_screen').ids['CardImg'].disabled = True
#data grid
self.cscroller = Cardscroller(id='scroller',sm=self.sm)
if self.currentCard.deck == 'Thoth (Crowley)':
self.cscroller.ids['thothBtn'].background_normal = 'Assets/UI/ButtonFrame_majestic_activated.png'
self.cscroller.ids['thothBtn'].bind(on_release=partial(self.changeDeck,'Thoth (Crowley)'))
elif self.currentCard.deck == 'Rider/Waite':
self.cscroller.ids['riderBtn'].background_normal = 'Assets/UI/ButtonFrame_majestic_activated.png'
self.cscroller.ids['riderBtn'].bind(on_release=partial(self.changeDeck,'Rider/Waite'))
self.cscroller.ids['groupName'].text = self.currentCard.elementName
self.cscroller.ids['elementName'].text = self.currentCard.element
self.cscroller.ids['signName'].text = self.currentCard.sign
self.cscroller.ids['description'].text = self.currentCard.description
self.add_widget(self.cscroller)
def clearChildren(self):
try:
self.remove_widget(self.shadowOverlay)
self.remove_widget(self.cscroller)
except:
pass
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
self.getCardData()
class FormationOverviewScreen(Screen):
app = None
sm = None
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
def btn_pressed(self,targetScreen):
print('Change to {} imminent...'.format(targetScreen))
self.app.changeScreenTo(self.sm,targetScreen,"left")
if targetScreen == 'formation_group_screen':
self.sm.get_screen(targetScreen).ids['Header'].text = '[color=fdc84a]{}[/color]'.format('Kategorien')
else:
setattr(self.manager.get_screen(targetScreen).ids['Header'], 'text', '[color=fdc84a]Formationssuche[/color]')
setattr(self.manager.get_screen(targetScreen).ids['Img'],'source', 'Assets/Backgrounds/Background-1.png')
class FormationGroupScreen(Screen):
app = None
sm = None
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
def btn_pressed(self, targetScreen, targetGroup):
print('Change to {} imminent...'.format(targetScreen))
self.app.changeScreenTo(self.sm,targetScreen,"left")
formationList = self.collectFormationsFromGroup(targetGroup)
setattr(self.manager.get_screen(targetScreen).ids['Header'], 'text', '[color=fdc84a]{}[/color]'.format(targetGroup))
setattr(self.manager.get_screen(targetScreen),'currentGroup', targetGroup)
setattr(self.manager.get_screen(targetScreen),'formationList', formationList)
setattr(self.manager.get_screen('formation_selector_screen'), 'formsBuild', 'False')
setattr(self.manager.get_screen(targetScreen),'previous_screen', 'formation_group_screen')
def collectFormationsFromGroup(self, group):
selectedList = list()
formationsList = FormationDB.getFormationList()
for form in formationsList:
if group in form.groupList:
selectedList.append(form)
return selectedList
class FormationSearchScreen(Screen):
app = None
sm = None
selectedFormations = list()
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
def toggle_checkbox(self,btn):
if btn.toggledState == False:
btn.background_normal = 'Assets/UI/ButtonFrame_majestic_activated.png'
btn.toggledState = True
else:
btn.background_normal = 'Assets/UI/ButtonFrame_majestic.png'
btn.toggledState = False
def collectCandidates(self):
print('Ich meeeesse.... q[o.o]q Ich meeeeesse.... p[o.o]p')
searchInput = self.sm.get_screen('formation_search_screen').ids['searchWord']
searchword = searchInput.text
global patriciaFormationT
try:
keyList = list()
keyList.clear()
self.selectedFormations.clear()
keyList = patriciaFormationT.iter(searchword)
for key in keyList:
self.selectedFormations.append(patriciaFormationT[key])
#sort selected cards
self.selectedFormations = self.sortSelectedFormationsList(self.selectedFormations)
# print('gefundene Formationen zu suchword "{}": {}'.format(searchword,self.selectedFormations))
# print('Formationsdetails:')
# for card in self.selectedFormations:
# print('Name: {}; Set: {}; Element: {}; ID: {}'.format(card.name,card.deck,card.elementName,card.id))
except KeyError:
print('keine Formationen gefunden')
return
print('Fertig \[^.^]/')
print('Change to FormationSelectorScreen imminent...')
self.app.changeScreenTo(self.sm,"formation_selector_screen","left")
setattr(self.manager.get_screen('formation_selector_screen'), 'previous_screen', 'formation_search_screen')
setattr(self.manager.get_screen('formation_selector_screen'), 'formsBuild', 'False')
setattr(self.manager.get_screen('formation_selector_screen'), 'formationList', self.selectedFormations)
setattr(self.manager.get_screen('formation_selector_screen').ids['Header'], 'text', '[color=fdc84a]Gefundene Formationen[/color]')
def sortSelectedFormationsList(self,FormListCollection):
sortedFormationList = list()
for formList in FormListCollection:
for formation in formList:
if not sortedFormationList:
sortedFormationList.append(formation)
continue
#if formation is allready in sorted list (due to duplicates) ignore them
if formation in sortedFormationList:
continue
formationWasSorted = False
for indexNr, indexForm in enumerate(sortedFormationList):
#compare current formation with all in orderedList and insert where it fits
if self.compareFormation(indexForm,formation) == True:
continue
else:
sortedFormationList.insert(indexNr,formation)
formationWasSorted = True
break
if formationWasSorted == True:
continue
#if no index for new formation was found append new formation
sortedFormationList.append(formation)
return sortedFormationList
def compareFormation(self,formA, formB):
#returns True if formA before formB
#compare rules: alphabetically
for charIndex in range(0,len(formA.id)):
if formA.id[charIndex] == formB.id[charIndex]:
continue
if formA.id[charIndex] < formB.id[charIndex]:
return True
else:
return False
class FormationSelectorScreen(Screen):
app = None
sm = None
formationList = None
previous_screen = None
formsBuild = False
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
self.displaySelectedFormations()
self.ids.BackBtn.targetScreen = self.previous_screen
def btn_pressed(self,formation,*args):
print('Change to FormationDetailScreen is imminent...')
self.app.changeScreenTo(self.sm,"formation_detail_screen","left")
setattr(self.manager.get_screen('formation_detail_screen'), 'currentFormation', formation)
setattr(self.manager.get_screen('formation_detail_screen'), 'currentFormationId', formation.id)
setattr(self.manager.get_screen('formation_detail_screen').ids['Header'], 'text', '[color=fdc84a]{}[/color]'.format(formation.name))
setattr(self.manager.get_screen('formation_detail_screen').ids['FormImg'],'source', 'Assets/Formations/Formation_Detail_BG.png')
def displaySelectedFormations(self):
for child in [child for child in self.ids.grid.children]:
self.ids.grid.remove_widget(child)
self.formsBuild = True
self.buttonSize = 0
for form in self.formationList:
cbutton = customButton(form.id,
form,
text=form.name,
font_size = 28,
size_hint = [1,1],
background_normal= 'Assets/UI/ButtonFrame_majestic.png',
border= [.5,1,.5,1],
font_name= "Assets/Fonts/AlexBrush-Regular")
cbutton.bind(on_release=partial(self.btn_pressed,form))
self.buttonSize += cbutton.height
self.ids.grid.add_widget(cbutton)
self.ids.grid.height = self.buttonSize
class FormationDetailScreen(Screen):
app = None
sm = None
currentFormationId = None
currentFormation = None
def on_leave(self, *args):
self.clearChildren()
self.manager.get_screen('formation_detail_screen').ids['FormImg'].disabled = False
return super().on_leave(*args)
def cardSearch(self):
print('Change to {} imminent...'.format('CardSearch'))
setattr(self.manager.get_screen('cardSearch_screen').ids['Header'], 'text', '[color=fdc84a]Kartensuche[/color]')
setattr(self.manager.get_screen('cardSearch_screen').ids['Img'],'source', 'Assets/Backgrounds/Background-1.png')
setattr(self.manager.get_screen('cardSearch_screen'),'previous_screen', 'formation_detail_screen')
self.app.changeScreenTo(self.app.root,'cardSearch_screen',"left")
def getFormationData(self):
#set screen details
self.manager.get_screen('formation_detail_screen').ids['FormImg'].source = self.currentFormation.formImage
self.manager.get_screen('formation_detail_screen').ids['Header'].text = '[color=fdc84a]{}[/color]'.format(self.currentFormation.name)
def hide_widget(self,wid, dohide=True):
if hasattr(wid, 'saved_attrs'):
if not dohide:
wid.height, wid.size_hint_y, wid.opacity, wid.disabled = wid.saved_attrs
del wid.saved_attrs
elif dohide:
wid.saved_attrs = wid.height, wid.size_hint_y, wid.opacity, wid.disabled
wid.height = 0
wid.size_hint_y = None
wid.opacity = 0
wid.disabled = True
def revealData(self):
self.shadowOverlay = Label(id='Overlay',size_hint=[1, 0.9],pos_hint={"x":0, "top": 0.9}, )
self.shadowOverlay.canvas.add(Color(0, 0, 0, 0.4))
self.shadowOverlay.canvas.add(Rectangle(pos_hint=[0,0.8],size=(self.size[0],self.size[1]*0.9)))
self.add_widget(self.shadowOverlay)
self.manager.get_screen('formation_detail_screen').ids['FormImg'].disabled = True
#pos descriptions
self.fscroller = Formscroller(id='fscroller',sm=self.sm)
self.fscroller.ids['formationDesc'].text = self.currentFormation.description
self.fscroller.ids.grid.add_widget(BackgroundLabel(text='test'))
self.currentId = 0
for position in self.currentFormation.formPositions:
self.currentId = position.id_num
self.fscroller.ids['desc_{}'.format(position.id)].text = position.description
#hide the remaining labels
if self.currentId+1 < 13:
for id in range(self.currentId+1,13):
self.hide_widget(self.fscroller.ids['head_{}'.format(id)])
self.hide_widget(self.fscroller.ids['desc_{}'.format(id)])
self.add_widget(self.fscroller)
def clearChildren(self):
try:
self.remove_widget(self.shadowOverlay)
self.remove_widget(self.fscroller)
except:
pass
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
self.getFormationData()
class Screen_Manager(ScreenManager):
app = None
sm = None
@mainthread
def on_enter(self):
self.app = App.get_running_app()
self.sm = self.app.root
with open("KVs/MainScreen.kv", encoding='utf8') as f:
kv = Builder.load_string(f.read())
class MCsTarothCompApp(App):
#2220 x 1080 Auflösung für Target system
def build(self):
Config.set('graphics', 'fullscreen','0')
Config.set('graphics', 'height', '555')
Config.set('graphics', 'width', '270')
Config.write()
return kv
def changeScreenTo(self, smanager, targetScene, transitDirection):
smanager.current = targetScene
smanager.transition.direction = transitDirection
if __name__ == "__main__":
MCsTarothCompApp().run()