- # -*- encoding: utf-8 -*-
- import footballstatshelper
- import helper
- from System.Threading.Tasks import Task
- from System.IO import File, Path
- ######################
- Team4Graphic = "Away"
- ######################
- def __onStart(graphicOnAirItem, momentExecution, workFlowtype):
- team = __GetTeam()
- if GameOnline.IsOnAir:
- momentExecution.Message = "ONLINE IS ON AIR!"
- momentExecution.Cancel = True
- return
- if len(team.InPlay) != 11:
- momentExecution.Message = "Lineup must have 11 players InPlay!"
- momentExecution.Cancel = True
- return
- if not team.Coach:
- momentExecution.Message = "Team has no coach!"
- momentExecution.Cancel = True
- return
- if not team.Coach.RefName:
- momentExecution.Message = "Team has no coach!"
- momentExecution.Cancel = True
- return
- ## VALIDATE TACTICS ###
- tacticTeam = __GetTacticTeam()
- tacticPlayers = list(tacticTeam.TacticPlayers)
- if list(tacticTeam.TacticPlayers).Count != 11:
- momentExecution.Message = "Please fill the tactic for %s!" % team.ShortName
- momentExecution.Cancel = True
- return
- if not __ValidateCaptains(team):
- momentExecution.Message = "Team don´t have captains!"
- momentExecution.Cancel = True
- return
- # VALIDATE PLAYER PHOTOS
- imagesFolderPath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path, "Images", "fotos", team.RefName.ToString())
- silhouettePath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path, "Images", "Fotos", "player_default.png")
- for player in team.InPlay:
- imageName = "%s.png" % player.RefName.ToString()
- playerPath = Path.Combine(imagesFolderPath, imageName)
- if not File.Exists(playerPath):
- if not File.Exists(silhouettePath):
- message = "Player without photo!\n\nName: %s\nNumber: %s\n\nExpected image:\n%s\n\nSilhouette was also not found:\n%s\n\nThe graphic will not be displayed." % (player.ShortName.ToString(), player.Number, playerPath, silhouettePath)
- UserInteraction.ShowMessageBoxYesNo("Missing Player Photo", message)
- momentExecution.Message = "Missing player photo and silhouette!"
- momentExecution.Cancel = True
- return
- message = "Player without photo!\n\nName: %s\nNumber: %s\n\nExpected image:\n%s\n\nDo you want to continue using the silhouette?" % (player.ShortName.ToString(), player.Number, playerPath)
- if UserInteraction.ShowMessageBoxYesNo("Missing Player Photo", message).ToString() != "Yes":
- momentExecution.Message = "Graphic canceled!"
- momentExecution.Cancel = True
- return
- ######################## FILL DATA ########################
- def __getData(viewBag,graphicOnAirItem, momentExecution):
- team = __GetTeam()
- tacticTeam = __GetTacticTeam()
- for i in range(1,21):
- viewBag.SetString("tPlayerNumber%02d"%i,"")
- viewBag.SetString("tPlayerName%02d"%i,"")
- viewBag.SetFloat("vYellowCardVisibility%02d"%i,0)
- # # Validação das fotos dos jogadores
- # imagesFolderPath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path, "Images", "fotos", team.RefName.ToString())
- # silhouettePath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path, "Images", "Fotos", "player_default.png")
- # missingPlayers = []
- #
- # for player in team.InPlay:
- # imageName = "%s.png" % player.RefName.ToString()
- # playerPath = Path.Combine(imagesFolderPath, imageName)
- #
- # if not File.Exists(playerPath):
- # missingPlayers.append(player)
- #
- # if missingPlayers:
- # if not File.Exists(silhouettePath):
- # UserInteraction.ShowMessageBoxYesNo("Missing Player Photo", "player_default.png was not found.\n\nPath:\n%s\n\nThe graphic will not be displayed." % silhouettePath)
- # return False
- #
- # for player in missingPlayers:
- # imageName = "%s.png" % player.RefName.ToString()
- # playerPath = Path.Combine(imagesFolderPath, imageName)
- #
- # message = "Player without photo!\n\nName: %s\nNumber: %s\n\nExpected image: %sDo you want to continue using the silhouette?" % (player.ShortName.ToString(), player.Number, playerPath)
- #
- # if UserInteraction.ShowMessageBoxYesNo("Missing Player Photo", message).ToString() != "Yes":
- # return False
- viewBag.SetTranslatedText("tTeamName", "{{%s}}" % team.ShortName.ToUpper())
- viewBag.SetImage("lgTeamBadge","Images/Equipes/%s.png"%team.RefName)
- viewBag.SetImage("lgTeamColor", "Images\Degrades_Equipes\\%s.png" %team.Initials)
- if not __FillTactic(viewBag, team, tacticTeam, graphicOnAirItem): return False
- __FillTacticsLineup(team, tacticTeam,viewBag, graphicOnAirItem)
- def __FillTactic(viewBag, team, tacticTeam, graphicOnAirItem):
- originalPlayers = list(team.InPlayByKeeperAndShirt)
- tactic = __GetTacticTeam()
- lines = tactic.Name.ToString().split("-")
- viewBag.SetString("tFormation", tactic.Name.ToString())
- lines2Vlines = list(lines)
- tacticName = tactic.Name
- while len(lines2Vlines) < 4:
- lines2Vlines.append("0")
- for idx, line in enumerate(lines2Vlines,1):
- viewBag.SetFloat("vLines%02d"%idx,line)
- tacticPlayers = list(tacticTeam.TacticPlayers)
- gkTactic = None
- fieldPlayers = []
- # Separa goleiro dos jogadores de linha
- for tacticPlayer in tacticPlayers:
- if str(tacticPlayer.Player.Position.ToString()).strip().lower() == "gk":
- gkTactic = tacticPlayer
- else:
- fieldPlayers.append(tacticPlayer)
- # Ordena primeiro pelos setores do campo
- fieldPlayers.sort(key=lambda x: x.GraphicPosition.Y)
- orderedTacticPlayers = []
- startIdx = 0
- # Separa cada setor conforme a formação e,
- # dentro do setor, ordena pela posição X
- for line in lines:
- numPlayers = int(line)
- sectorPlayers = fieldPlayers[startIdx:startIdx + numPlayers]
- sectorPlayers.sort(key=lambda x: x.GraphicPosition.X)
- orderedTacticPlayers.extend(sectorPlayers)
- startIdx += numPlayers
- # Monta a lista final com os objetos originais
- objTeamSel = []
- # Adiciona primeiro o goleiro
- if gkTactic:
- gkRefName = gkTactic.Player.RefName.ToString()
- for originalPlayer in originalPlayers:
- if originalPlayer.RefName.ToString() == gkRefName:
- objTeamSel.append(originalPlayer)
- break
- # Adiciona os jogadores de linha na ordem tática
- for tacticPlayer in orderedTacticPlayers:
- tacticPlayerRefName = tacticPlayer.Player.RefName.ToString()
- for originalPlayer in originalPlayers:
- if originalPlayer.RefName.ToString() == tacticPlayerRefName:
- objTeamSel.append(originalPlayer)
- break
- # Procura o goleiro dentro da lista final
- gk = None
- for player in objTeamSel:
- if str(player.Position.ToString()).strip().lower() == "gk":
- gk = player
- break
- if not __CheckValidations(objTeamSel, tacticName, gk, lines): return False
- totalLines = len(lines)
- totalUsedPlayers = 0
- missedPlayersVideos = []
- # Fill goalkeeper
- viewBag.SetString("tPlayerName01", gk.ShortName.ToUpper())
- viewBag.SetString("tPlayerNumberGoalkeeper", gk.Number)
- viewBag.SetVisibility("vIconVisibility01",True)
- imageName = "%s.png"%(gk.RefName.ToString())
- imagesFolderPath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path, "Images", "fotos", team.RefName.ToString())
- playerPath = Path.Combine(imagesFolderPath, imageName)
- if not File.Exists(playerPath):
- viewBag.SetImage("lgPlayerPicture01", "Images\Fotos\player_default.png")
- else:
- viewBag.SetImage("lgPlayerPicture01", playerPath)
- if gk.AtRisk:
- viewBag.SetFloat("vYellowCardGoalkeeper", 1)
- else:
- viewBag.SetFloat("vYellowCardGoalkeeper", 0)
- if gk.IsCaptain:
- viewBag.SetFloat("vCaptainVisibility01", 1)
- else:
- viewBag.SetFloat("vCaptainVisibility01", 0)
- objTeamSel.remove(gk)
- tagIdx = 2
- for lineNum in range(0, totalLines):
- numPlayers = int(lines[lineNum])
- players = list(objTeamSel)[:numPlayers]
- totalUsedPlayers += numPlayers
- # Fill other players
- for player in range(5):
- try:
- currentPlayer = players[player]
- viewBag.SetString("tPlayerName%02d" % tagIdx, currentPlayer.ShortName.ToUpper())
- viewBag.SetString("tPlayerNumber%02d" % tagIdx, currentPlayer.Number)
- imageName = "%s.png"%(currentPlayer.RefName.ToString())
- imagesFolderPath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path, "Images", "fotos", team.RefName.ToString())
- playerPath = Path.Combine(imagesFolderPath, imageName)
- if not File.Exists(playerPath):
- viewBag.SetImage("lgPlayerPicture%02d" % tagIdx, "Images\Fotos\player_default.png")
- else:
- viewBag.SetImage("lgPlayerPicture%02d" % tagIdx, playerPath)
- if currentPlayer.AtRisk:
- viewBag.SetFloat("vYellowCardVisibility%02d"%tagIdx, 1)
- else:
- viewBag.SetFloat("vYellowCardVisibility%02d"%tagIdx, 0)
- if currentPlayer.IsCaptain:
- viewBag.SetFloat("vCaptainVisibility%02d" % tagIdx, 1)
- else:
- viewBag.SetFloat("vCaptainVisibility%02d" % tagIdx, 0)
- objTeamSel.remove(currentPlayer)
- except Exception as e:
- viewBag.SetString("tPlayerName%02d" % tagIdx, "")
- viewBag.SetString("tPlayerNumber%02d" % tagIdx, "")
- tagIdx+=1
- if missedPlayersVideos:
- if MsgBox.Show("fhelper", "Missing video files for the following players: \n\r%s\n\rContinue anyway?" % ", ".join(missedPlayersVideos),MsgBox.ButtonsCombo.YesNo).ToString() == "No":
- return False
- return True
- def __FillTacticsLineup(team, tacticTeam, viewBag, graphicOnAirItem):
- ##Checks
- team = __GetTeam()
- tacticTeam = __GetTacticTeam()
- if not tacticTeam.TacticPlayers or list(tacticTeam.TacticPlayers).Count != 11:
- Core.StatusManager.Add(Dictionary.TranslateWithContext("Refaça a tática. Verifique novamente!", "Alert"))
- return False
- #objTeamSel = [player for player in tacticTeam.TacticPlayers]
- #print objTeamSel
- viewBagOld = []
- objTeamSel = [player for player in tacticTeam.TacticPlayers]
- objTeamSel.sort(__tacticsCompY)
- #print([x.Player.RefName.ToString() for x in objTeamSel])
- gks = filter(lambda x: str(x.Player.Position.ToString()).strip().lower() == "gk", objTeamSel)
- if not tacticTeam.PreTactic:
- Core.StatusManager.Add(Dictionary.TranslateWithContext("Você não salvou a tática desse time!!", "Alert"))
- return False
- tacticName = tacticTeam.PreTactic.Name
- if tacticName.ToString().strip() == "":
- Core.StatusManager.Add(Dictionary.TranslateWithContext("Selecione a Formação tática (X-X-X) desse time!!", "Alert"))
- return False
- lines = tacticName.split("-")
- #if not __CheckValidations(objTeamSel, tacticName, gks, lines): return False
- totalLines = len(lines)
- missedPlayersPhotos = []
- xmax = Tactics.FieldBounds.XMax
- xmin = Tactics.FieldBounds.XMin
- ymax = Tactics.FieldBounds.YMax
- ymin = Tactics.FieldBounds.YMin
- Tactics.FieldBounds.XMax = 2
- Tactics.FieldBounds.XMin = 0
- Tactics.FieldBounds.YMax = 2.5
- Tactics.FieldBounds.YMin = 0
- #Fill GK
- gk = gks[0]
- objTeamSelWithGk = objTeamSel
- coach = team.Coach#team.Coaches[0]
- viewBag.SetString("tFormation", tacticTeam.PreTactic.Name)
- viewBag.SetTranslatedText("tBenchTitle", "BANCO")
- viewBag.SetTranslatedText("tCoachFunction", coach.Function.ToString().ToUpper())
- viewBag.SetTranslatedText("tTeamName", team.ShortName.ToUpper())
- viewBag.SetString("tCoachName", coach.ShortName.ToUpper())
- viewBag.SetBool("vTacticalGoalkeeperVisibility", True)
- ###
- imageName = "%s.png"%(coach.RefName.ToString())
- imagesFolderPath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path, "Images", "fotos", team.RefName.ToString())
- coachPath = Path.Combine(imagesFolderPath, imageName)
- if not File.Exists(coachPath):
- viewBag.SetImage("lgCoachPicture", "Images\Fotos\player_default.png")
- else:
- viewBag.SetImage("lgCoachPicture", coachPath)
- viewBag.SetImage("lgTeamLogo","Images/Equipes/%s.png"%team.RefName)
- viewBag.SetImage("lgTeamColor", "Images\Degrades_Equipes\%s.png" %team.Initials)
- Globals["PubVideoAvailable"] = False
- videoFolderPath = Path.Combine(graphicOnAirItem.GraphicsEngine.Options.RootPath, graphicOnAirItem.Scene.Path,"Videos","PUB","Escalacao_tatica")
- pubVideo = Path.Combine(videoFolderPath,"Escalacao_%s.mov"%Team4Graphic)
- if not File.Exists(pubVideo):
- pass
- else:
- viewBag.SetVideo("vdSponsorVideo", pubVideo)
- Globals["PubVideoAvailable"] = True
- objTeamSelWithGkList = objTeamSelWithGk
- #----------------------Clear some tags before fill-------------------------------------------
- for i in range(1, 14):
- viewBag.SetVisibility("vBenchYellowCardVisibility%02d" % i, False)
- viewBag.SetVisibility("vBenchGoalkeeperIconVisibility%02d" % i, False)
- #--------------------------------FillTags---------------------------------------
- for tagIdx, player in enumerate(objTeamSelWithGkList):
- tagIdx+=1
- if player.Player.IsCaptain:
- viewBag.SetVisibility("vTacticalCaptainVisibility%02d" % tagIdx, True)
- else:
- viewBag.SetVisibility("vTacticalCaptainVisibility%02d" % tagIdx, False)
- if player.Player.AtRisk:
- viewBag.SetVisibility("vTacticalYellowCardVisibility%02d" % tagIdx, True)
- else:
- viewBag.SetVisibility("vTacticalYellowCardVisibility%02d" % tagIdx, False)
- if " " not in player.Player.ShortName:
- viewBag.SetString("tTacticalPlayerFirstName%02d" % tagIdx, player.Player.ShortName.ToUpper())
- viewBag.SetString("tTacticalPlayerLastName%02d" % tagIdx, "")
- else:
- firstAndLastName = player.Player.ShortName.split(" ")
- viewBag.SetString("tTacticalPlayerFirstName%02d" % tagIdx, firstAndLastName[0].ToUpper())
- viewBag.SetString("tTacticalPlayerLastName%02d" % tagIdx, firstAndLastName[1].ToUpper())
- viewBag.SetString("tTacticalPlayerNumber%02d" % tagIdx, player.Player.Number)
- viewBag.SetFloat("vTacticalPlayerPositionX%02d" % tagIdx, player.GraphicPosition.X )
- viewBag.SetFloat("vTacticalPlayerPositionY%02d" % tagIdx, player.GraphicPosition.Y )
- #print "X: %s" % player.GraphicPosition.X
- #print "Y: %s" % player.GraphicPosition.Y
- benchPlayers = team.InBench
- sortedBench = sorted(benchPlayers, key=lambda player: (str(player.Position).lower() != "gk", int(player.Number)))
- viewBagOld.append({"Name": "vLinesBench", "Value": len(benchPlayers), "Pipe": " ", "ToUpper": False, "IsAdvert": False, "Translate": False, "Context": "Tactical"})
- viewBag.SetString("vLinesBench", int(len(benchPlayers)))
- for tagIdx, player in enumerate(sortedBench):
- tagIdx+=1
- if player.AtRisk:
- viewBagOld.append({"Name": "vBenchYellowCardVisibility%02d" % tagIdx, "Value": True, "Pipe": " ", "ToUpper": False, "IsAdvert": False, "Translate": False, "Context": "Tactical"})
- viewBag.SetString("vBenchYellowCardVisibility%02d" % tagIdx, True)
- else:
- viewBagOld.append({"Name": "vBenchYellowCardVisibility%02d" % tagIdx, "Value": False, "Pipe": " ", "ToUpper": False, "IsAdvert": False, "Translate": False, "Context": "Tactical"})
- viewBag.SetString("vBenchYellowCardVisibility%02d" % tagIdx, False)
- viewBag.SetString("tBenchPlayerName%02d" % tagIdx, player.ShortName.ToUpper())
- viewBag.SetString("tBenchPlayerNumber%02d" % tagIdx, player.Number)
- if str(player.Position).lower() == "gk":
- viewBag.SetVisibility("vBenchGoalkeeperIconVisibility{:02d}".format(tagIdx), True)
- else:
- viewBag.SetVisibility("vBenchGoalkeeperIconVisibility{:02d}".format(tagIdx), False)
- return True
- def __CheckValidations(objTeamSel, tacticName, gks, lines):
- if gks.Count < 1:
- Core.StatusManager.Add(Dictionary.TranslateWithContext("%s team tactic has no goalkeeper!"%Team4Graphic, "Alert"))
- return False
- elif gks.Count > 1:
- Core.StatusManager.Add(Dictionary.TranslateWithContext("%s team tactic has more than 1 goalkeeper!"%Team4Graphic, "Alert"))
- return False
- if len(lines) < 3:
- Core.StatusManager.Add("Fill tactic name (use '-' to separate) Ex: 4-2-3-1")
- return False
- num = 0
- for line in lines:
- if not line.isdigit():
- Core.StatusManager.Add("%s is not a valid digit" % line)
- return False
- num+=int(line)
- if num != 10:
- Core.StatusManager.Add(Dictionary.TranslateWithContext("Tactic name isn't valid", "Alert"))
- return False
- return True
- def __getColor():
- color = ProjectSettings["GraphicColor"]
- if color == "Amarelo":
- return "235,174,0"
- elif color == "Azul Escuro":
- return "15,39,148"
- elif color == "Cian":
- return "13,133,181"
- elif color == "Laranja":
- return "203,106,0"
- elif color == "Verde":
- return "27,125,61"
- elif color == "Vermelho":
- return "199,0,27"
- elif color == "Violeta":
- return "142,36,147"
- return "255,255,255"
- def __tacticsCompY(obj1, obj2):
- return obj1.GraphicPosition.Y > obj2.GraphicPosition.Y
- def __tacticsCompX(obj1, obj2):
- return obj1.GraphicPosition.X > obj2.GraphicPosition.X
- def __afterProgram(graphicOnAirItem, momentExecution):
- graphic = GraphicTemplatesManager.GetGraphicByName(Script.Name)
- graphicOnAirItens = IntelliflowController.GetGraphicOnAirItems(graphic, OutputManager.ActiveChannelOutput)
- #Sponsor###################################
- if Globals["PubVideoAvailable"]:
- if Project.ProjectSettings["PUB Lineup"]:
- for graphic in graphicOnAirItens:
- graphic.Scene.Show("Sponsor_In")
- ###########################################
- tactic = __GetTacticTeam()
- lines = tactic.Name.ToString().split("-")
- for i in range(1, int(len(lines))+1):
- if UserInteraction.ShowMessageBoxYesNo("LineUp", "Continue Change?").ToString() != "Yes": return
- for graphic in graphicOnAirItens:
- graphic.Scene.Show("Change_%02d"%i)
- if UserInteraction.ShowMessageBoxYesNo("LineUp", "Take Tactical?").ToString() == "Yes":
- for graphic in graphicOnAirItens:
- if Project.ProjectSettings["PUB Lineup"]:
- graphic.Scene.Show("Sponsor_Out")
- graphic.Scene.Show("ChangeToTactics")
- Globals["PubVideoAvailable"] = False
- def __beforeProgramOut(graphicOnAirItem, momentExecution):
- graphic = GraphicTemplatesManager.GetGraphicByName(Script.Name)
- graphicOnAirItens = IntelliflowController.GetGraphicOnAirItems(graphic, OutputManager.ActiveChannelOutput)
- if Globals["PubVideoAvailable"]:
- if Project.ProjectSettings["PUB Lineup"]:
- for graphic in graphicOnAirItens:
- graphic.Scene.Show("Sponsor_Out")
- Globals["PubVideoAvailable"] = False
- def __GetTeam():
- if Team4Graphic == "Home":
- return Game.HomeTeam
- else:
- return Game.AwayTeam
- def __GetTacticTeam():
- if Team4Graphic == "Home":
- return Tactics.HomeTeamConfig
- else:
- return Tactics.AwayTeamConfig
- def __ValidateCaptains(team):
- captains = footballstatshelper.GetCaptainCount(team.InPlay)
- return captains
- def __CheckValidations(objTeamSel, tacticName, gk, lines):
- if not gk:
- Core.StatusManager.Add(Dictionary.TranslateWithContext("Esse time não tem goleiro! Reveja e verifique a função!", "Alert"))
- return False
- if len(lines) < 3:
- Core.StatusManager.Add("Preencha a formação tática (use '-' para separar) Ex: 4-2-3-1")
- return False
- num = 0
- for line in lines:
- if not line.isdigit():
- Core.StatusManager.Add("%s não é um dígito válido" % line)
- return False
- num+=int(line)
- if num != 10:
- Core.StatusManager.Add(Dictionary.TranslateWithContext("Tática não é válida. Refazer", "Alert"))
- return False
- return True
Untitled
From Mungo Cassowary, 2 Weeks ago, written in Plain Text, viewed 6 times.
This paste will shuffle off the mortal coil in 1 Week.
URL https://paste.afonso.co/view/48190cb7
Embed
Download Paste or View Raw
— Expand Paste to full width of browser