public static ImagePart[] Load(XmlReader reader) { ImagePart[] textures = new ImagePart[9]; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { if (reader.Name == "bordhautgauche") textures[0] = LoadTexture(reader); else if (reader.Name == "milieuhaut") textures[1] = LoadTexture(reader); else if (reader.Name == "bordhautdroit") textures[2] = LoadTexture(reader); else if (reader.Name == "milieugauche") textures[3] = LoadTexture(reader); else if (reader.Name == "milieu") textures[4] = LoadTexture(reader); else if (reader.Name == "milieudroit") textures[5] = LoadTexture(reader); else if (reader.Name == "bordbasgauche") textures[6] = LoadTexture(reader); else if (reader.Name == "milieubas") textures[7] = LoadTexture(reader); else if (reader.Name == "bordbasdroit") textures[8] = LoadTexture(reader); break; } } } return textures; }
public static ImagePart LoadTexture( XmlReader reader ) { ImagePart tex = null; String r = reader.GetAttribute("src"); if (r != null) { tex = new ImagePart(new Texture(r)); String srcX = reader.GetAttribute("srcX"); String srcY = reader.GetAttribute("srcY"); String srcW = reader.GetAttribute("srcW"); String srcH = reader.GetAttribute("srcH"); if ((srcX != null) && (srcY != null) && (srcW != null) && (srcH != null)) { IntRect srcRec = new IntRect(int.Parse(srcX), int.Parse(srcY), int.Parse(srcW), int.Parse(srcH)); tex.SourceRectangle = srcRec; } } return tex; }
/// <summary> /// Detailed constructor. /// </summary> /// <param name="manager_"></param> /// <param name="parent_"></param> /// <param name="imagePart"></param> public Caption(UIManager manager_, Widget parent_, ImagePart imagePart ) : base(manager_, parent_) { Manager.RegisterWidgetType("Caption", "Widget"); ImagePart = imagePart; }
public void LoadContent() { // récupération du style myStyle = myApp.guiStyle.ThemeSelectionMenuStyle; myPlayer = null; themes = new List<HorizontalLayout>(); if (myGame.NumPlayers > 0) { // on trouve le joueur concerné par la sélection int numSelections = myGame.Players[0].ChosenThemes.Count; for (int i = 1; i < myGame.NumPlayers; i++) { if (myGame.Players[i].ChosenThemes.Count < numSelections) { myPlayer = myGame.Players[i]; break; } } if (myPlayer == null) myPlayer = myGame.Players[0]; // on détermine si l'on doit afficher les scores. for (int i = 0; i < myGame.NumPlayers; i++) { if (myGame.Players[i].Score > 0) { displayScores = true; break; } } } else throw new Exception("Pas de joueur?"); ImagePart[] labelTextures = myStyle.LabelsTextures; ImagePart[] playersNamesTextures = myStyle.PlayersNamesTextures; ImagePart[] playersPicsTextures = myStyle.PlayersPicsTextures; float themesLabelsBottomSpace = myStyle.ThemesLabelsBottomSpace; float themesListRightSpace = myStyle.ThemesListRightSpace; float playersSpace = myStyle.PlayersSpace; Vector2f picsSize = myStyle.PicsSize; Font font = myStyle.Font; uint fontSize = myStyle.FontSize; myUIManager = new UIManager(myApp.window); DCFont myFont = new DCFont(font); // Layout principal contenant tout le reste mainLayout = new HorizontalLayout(myUIManager, null); mainLayout.Visible = true; // Affichage des thèmes { themesLayout = new VerticalLayout(myUIManager, mainLayout); themesLayout.Visible = true; mainLayout.Add(themesLayout); for (int i = 0; i < myGame.NumThemes; i++) { HorizontalLayout themeHLayout = new HorizontalLayout(myUIManager, themesLayout); themeHLayout.Visible = true; themesLayout.Add(themeHLayout); themes.Add(themeHLayout); if (!myGame.IsThemeAvalaible(myGame.GetTheme(i))) themeHLayout.Tint = new Color(125, 125, 125); // Frame contenant le nom du thème { Frame themeFrame = new Frame(myUIManager, themeHLayout); themeFrame.BordersImagesParts = myStyle.LabelsTextures; themeFrame.Visible = true; themeHLayout.Add(themeFrame); Label themesNamelabel = new Label(myUIManager, themeFrame, myFont, myGame.GetTheme(i).Name + " " + myGame.GetTheme(i).Points.ToString(), fontSize); themesNamelabel.Tint = Color.White; themesNamelabel.Visible = true; themeFrame.ContainedWidget = themesNamelabel; } if (i < myGame.NumThemes - 1) { VerticalSpacer sp = new VerticalSpacer(myUIManager, themesLayout, themesLabelsBottomSpace); sp.Visible = true; themesLayout.Add(sp); } } } // Ajout d'un spacer HorizontalSpacer msp = new HorizontalSpacer(myUIManager, mainLayout, themesListRightSpace); msp.Visible = true; mainLayout.Add(msp); // Affichage des noms des joueurs (éventuellement leurs scores) { playersLayout = new HorizontalLayout(myUIManager, mainLayout); playersLayout.Visible = true; mainLayout.Add(playersLayout); for (int i = 0; i < myGame.NumPlayers; i++) { Player player = myGame.Players[i]; VerticalLayout playerVLayout = new VerticalLayout(myUIManager, playersLayout); playerVLayout.Alignment = HorizontalAlignment.Center; playerVLayout.Visible = true; playersLayout.Add(playerVLayout); // Chargement de la photo du joueur { Frame photoFrame = new Frame(myUIManager, playerVLayout); ; photoFrame.BordersImagesParts = playersPicsTextures; photoFrame.Visible = true; playerVLayout.Add(photoFrame); Caption playerCaption = new Caption(myUIManager, photoFrame); playerCaption.Visible = true; Texture tex = new Texture(player.PhotoSrc); ImagePart img = new ImagePart(tex); playerCaption.ImagePart = img; playerCaption.Size = picsSize; // ajout de la photo photoFrame.ContainedWidget = playerCaption; } // Ajout d'un spacer VerticalSpacer vsp = new VerticalSpacer(myUIManager, playerVLayout, 5f); vsp.Visible = true; playerVLayout.Add(vsp); // Affichage du score du joueur { Frame playerNameFrame = new Frame(myUIManager, playerVLayout); playerNameFrame.BordersImagesParts = playersNamesTextures; playerNameFrame.Visible = true; playerVLayout.Add(playerNameFrame); string str = player.Name; if (displayScores) str += " " + player.Score.ToString(); Label scoreLabel = new Label(myUIManager, playerNameFrame, myFont, str, fontSize); playersScoresLabels.Add(scoreLabel); if (player == myPlayer) scoreLabel.Tint = myStyle.FontHoveredColor; else scoreLabel.Tint = myStyle.FontNormalColor; scoreLabel.Visible = true; playerNameFrame.ContainedWidget = scoreLabel; } // on ajoute le spacer horizontal que si on ajoute pas le dernier joueur if( i < myGame.NumPlayers-1 ) { HorizontalSpacer sp = new HorizontalSpacer(myUIManager, playersLayout, playersSpace); sp.Visible = true; playersLayout.Add(sp); } } } currentChoice = myGame.GetNextAcceptableChoice(-1); ChangeChoice(); // centrage du layout principal mainLayout.CenterPosition = new Vector2f(myApp.window.Size.X / 2f, myApp.window.Size.Y / 2f); }
public static ThemeSelectionMenuStyle Load(XmlReader reader) { Color backgroundColor = new Color(0, 255, 0); ImagePart backgroundImage = null; TextureDisplayMode backgroundDisplayMode = TextureDisplayMode.Stretch; ImagePart[] labelsTextures = null; ImagePart[] hoveredLabelsTextures = null; ImagePart[] playersNamesTextures = null; ImagePart[] playersPicsTextures = null; float themesLabelsBottomSpace = 10f; float themesListRightSpace = 20f; float playersPhotoSpace = 5f; float playersSpace = 5f; Vector2f picsSize = new Vector2f(256f, 256f); Font font = null; Color fontNormalColor = new Color(255, 255, 255); Color fontHoveredColor = new Color(0, 0, 0); uint fontSize = 14; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { if (reader.Name == "backgroundColor") backgroundColor = GuiStyle.ParseColor(reader); else if (reader.Name == "backgroundImage") { String r = reader.GetAttribute("src"); if (r != null) backgroundImage = new ImagePart( new Texture(r) ); r = reader.GetAttribute("mode"); if (r != null) { if (r == "centered") backgroundDisplayMode = TextureDisplayMode.Center; else if (r == "stretched") backgroundDisplayMode = TextureDisplayMode.Stretch; } } else if (reader.Name == "labelsTextures") labelsTextures = FrameTexturesLoader.Load(reader.ReadSubtree()); else if (reader.Name == "hoveredLabelsTextures") hoveredLabelsTextures = FrameTexturesLoader.Load(reader.ReadSubtree()); else if (reader.Name == "playersNamesTextures") playersNamesTextures = FrameTexturesLoader.Load(reader.ReadSubtree()); else if (reader.Name == "playersPicsTextures") playersPicsTextures = FrameTexturesLoader.Load(reader.ReadSubtree()); else if (reader.Name == "themesLabelsBottomSpace") { String r = reader.GetAttribute("val"); if (r != null) themesLabelsBottomSpace = float.Parse(r); } else if (reader.Name == "themesListRightSpace") { String r = reader.GetAttribute("val"); if (r != null) themesListRightSpace = float.Parse(r); } else if (reader.Name == "playersPhotoSpace") { String r = reader.GetAttribute("val"); if (r != null) playersPhotoSpace = float.Parse(r); } else if (reader.Name == "playersSpace") { String r = reader.GetAttribute("val"); if (r != null) playersSpace = float.Parse(r); } else if (reader.Name == "picsSize") { String r = reader.GetAttribute("width"); if (r != null) picsSize.X = float.Parse(r); r = reader.GetAttribute("height"); if (r != null) picsSize.Y = float.Parse(r); } else if (reader.Name == "font") { String r = reader.GetAttribute("src"); if (r != null) font = new Font(r); r = reader.GetAttribute("size"); if (r != null) fontSize = uint.Parse(r); } else if (reader.Name == "fontNormalColor") fontNormalColor = GuiStyle.ParseColor(reader); else if (reader.Name == "fontHoveredColor") fontHoveredColor = GuiStyle.ParseColor(reader); break; } } } return new ThemeSelectionMenuStyle( backgroundColor, backgroundImage, backgroundDisplayMode, labelsTextures, hoveredLabelsTextures, playersNamesTextures, playersPicsTextures, themesLabelsBottomSpace, themesListRightSpace, playersPhotoSpace, playersSpace, picsSize, font, fontNormalColor, fontHoveredColor, fontSize ); }
public ThemeSelectionMenuStyle( Color backgroundColor, ImagePart backgroundImage, TextureDisplayMode backgroundDisplayMode, ImagePart[] labelsTextures, ImagePart[] hoveredLabelsTextures, ImagePart[] playersNamesTextures, ImagePart[] playersPicsTextures, float themesLabelsBottomSpace, float themesListRightSpace, float playersPhotoSpace, float playersSpace, Vector2f picsSize, Font font, Color fontNormalColor, Color fontHoveredColor, uint fontSize ) { BackgroundColor = backgroundColor; BackgroundImage = backgroundImage; BackgroundDisplayMode = backgroundDisplayMode; LabelsTextures = labelsTextures; HoveredLabelsTextures = hoveredLabelsTextures; PlayersNamesTextures = playersNamesTextures; PlayersPicsTextures = playersPicsTextures; ThemesLabelsBottomSpace = themesLabelsBottomSpace; ThemesListRightSpace = themesListRightSpace; PlayersPhotoSpace = playersPhotoSpace; PlayersSpace = playersSpace; PicsSize = picsSize; Font = font; FontNormalColor = fontNormalColor; FontHoveredColor = fontHoveredColor; FontSize = fontSize; }