/tags/Troisieme_soutenance/eradiKor/eradiKor/Structures/Window.cs
C# | 320 lines | 202 code | 40 blank | 78 comment | 19 complexity | fc5ee1498c55ea78b3359db11882e041 MD5 | raw file
Possible License(s): GPL-3.0
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Input;
-
- namespace eradiKor.Structures
- {
- #region enum GameParts
- /// <summary>
- /// Différentes parties visibles ŕ lécran.
- /// </summary>
- public enum GameParts
- {
- Map,
- Tchat,
- TowerSelection,
- ProgressBar,
- Hud,
- OthersMaps,
- Zbimout,
- KorBox,
- Info
- }
- #endregion
-
- #region struct PartDatas
- public struct PartDatas
- {
- #region Attributs
- private Structures.GameParts part;
- private Rectangle position;
- private bool focus;
- #endregion
-
- #region Constructeur
- public PartDatas(Structures.GameParts partie, Rectangle pos)
- {
- this.part = partie;
- this.position = pos;
- this.focus = false;
- }
- #endregion
-
- #region Accesseurs
- /// <summary>
- /// Partie de lécran visible par le joueur.
- /// </summary>
- public Structures.GameParts Part
- {
- get
- {
- return this.part;
- }
- }
-
- /// <summary>
- /// Position occupée par cette partie.
- /// </summary>
- public Rectangle Position
- {
- get
- {
- return this.position;
- }
- set
- {
- this.position = value;
- }
- }
-
- /// <summary>
- /// True si la souris est au dessus de cette partie.
- /// </summary>
- public bool Focus
- {
- get
- {
- return this.focus;
- }
- set
- {
- this.focus = value;
- }
- }
- #endregion
-
- }
- #endregion
-
- #region class Window
- public class Window
- {
- #region Attributs
- private int width, height;
- private int scaleCoef;
- private bool debug, heavyDebug, screenshotmode, blackWhite, hasFocus;
- private PartDatas mapPos, tchatPos, hudPos, infoPos, boitakorPos, statsPos;
- private Point lastMousePos, mouseVect;
- private General.Keymap keymap;
- #endregion
-
- #region Événements
- public delegate void WindowEventHandler(object sender, Events.WindowEventArgs e);
- public event WindowEventHandler OnResize;
- #endregion
-
- #region Constructeur
- /// <summary>
- /// Attribue les caractéristiques de la fenętre
- /// </summary>
- /// <param name="w">Largeur en pixels : Window.Clientbounds.Width</param>
- /// <param name="h">Hauteur en pixels : Window.Clientbounds.Height</param>
- /// <param name="fullscreen">Mode plein écran ou non : Window.Clientbounds</param>
- public Window(int w, int h)
- {
- this.width = 0;
- this.height = 0;
- this.scaleCoef = h / 40;
- this.debug = false;
- this.heavyDebug = false;
- this.blackWhite = true;
- this.lastMousePos = new Point(0, 0);
- this.mouseVect = new Point(0, 0);
- this.keymap = General.Keymap.US_int;
-
- this.OnResize += new WindowEventHandler(Window_OnResize);
- this.hasFocus = true;
- }
- #endregion
-
- #region Accesseur
- /// <summary>
- /// Largeur de la fenętre en pixel.
- /// </summary>
- public int Width { get { return this.width; } }
-
- /// <summary>
- /// Hauteur de la fenętre en pixel.
- /// </summary>
- public int Height { get { return this.height; } }
-
- /// <summary>
- /// Combien de pixel prend une case ŕ lécran.
- /// </summary>
- public int ScaleCoef { get { return this.scaleCoef; } }
-
- /// <summary>
- /// Place allouée ŕ la map
- /// </summary>
- public Structures.PartDatas MapPos { get { return this.mapPos; } }
-
- /// <summary>
- /// Place allouée au tchat.
- /// </summary>
- public Structures.PartDatas TchatPos { get { return this.tchatPos; } }
-
- /// <summary>
- /// Position du score, vie, argent et vagues de Kors.
- /// </summary>
- public Structures.PartDatas InfoPos { get { return this.infoPos; } }
-
- public Structures.PartDatas HudPos { get { return this.hudPos; } }
-
- public Structures.PartDatas BoitakorPos { get { return this.boitakorPos; } }
-
- public Structures.PartDatas StatsPos { get { return this.statsPos; } }
-
- /// <summary>
- /// Le mode debug est-il activé ?
- /// </summary>
- public bool Debug
- {
- get { return this.debug; }
- set { this.debug = value; }
- }
-
- /// <summary>
- /// Le mode debug lourd est-il activé ?
- /// </summary>
- public bool HeavyDebug
- {
- get { return this.heavyDebug; }
- set { this.heavyDebug = value; }
- }
-
- /// <summary>
- /// Mode screenshot (ask 4you ...).
- /// </summary>
- public bool Screenshotmode
- {
- get { return this.screenshotmode; }
- set { this.screenshotmode = value; }
- }
-
- public bool BlackWhite
- {
- get { return this.blackWhite; }
- set { this.blackWhite = value; }
- }
-
- /// <summary>
- /// Derničre position connue de la souris.
- /// </summary>
- public Point MousePos { get { return this.lastMousePos; } }
-
- /// <summary>
- /// Vecteur direction de la souris.
- /// </summary>
- public Point MouseVect { get { return this.mouseVect; } }
-
- /// <summary>
- /// Layout du clavier.
- /// </summary>
- public General.Keymap Keymap
- {
- get { return this.keymap; }
- set { this.keymap = value; }
- }
-
- public bool HasFocus
- {
- get { return this.hasFocus; }
- set { this.hasFocus = value; }
- }
- #endregion
-
- #region Méthodes
- /// <summary>
- /// Indique si la fenętre a changé.
- /// </summary>
- /// <param name="win">Précédente fenętre</param>
- /// <returns>True si la fenętre a changé.</returns>
- public bool isEqual(ref Structures.Window win)
- {
- return ((this.width == win.Width) && (this.height == win.Height));
- }
-
- /// <summary>
- /// Met ŕ jour les informations de la fenętre.
- /// </summary>
- /// <param name="w">Largeur en pixel.</param>
- /// <param name="h">Hauteur en pixel.</param>
- public void update(int w, int h, Kore.Structures.Map map, MouseState mouse, Structures.Tchat tchat)
- {
- if (w != this.width || h != this.height)
- {
- Events.WindowEventArgs e = new Events.WindowEventArgs(w, h, map, mouse, tchat);
- OnResize(this, e);
- }
-
- if (tchat != null)
- this.tchatPos.Position = new Rectangle(this.width / 50, this.height * 5 / 6 - 20 * (tchat.DispLines - 5), this.width * 17 / 40 - 30, this.height / 6 + 20 * (tchat.DispLines - 5));
-
- //position de la souris
- Point mousePos = new Point(mouse.X, mouse.Y);
- this.mapPos.Focus = this.hasFocus && this.isIn(mousePos, mapPos.Position);
- this.tchatPos.Focus = this.hasFocus && this.isIn(mousePos, tchatPos.Position);
- this.mouseVect = new Point(mouse.X - this.lastMousePos.X, mouse.Y - this.lastMousePos.Y);
- this.lastMousePos = new Point(mouse.X, mouse.Y);
- }
-
- /// <summary>
- /// Savoir si un point est dans un rectangle.
- /// </summary>
- /// <param name="mouse">Position du point.</param>
- /// <param name="area">Rectangle.</param>
- /// <returns>True si le point est dans le rectangle.</returns>
- public bool isIn(Point mouse, Rectangle area)
- {
- return (mouse.X >= area.X && mouse.X <= (area.X + area.Width)
- && mouse.Y >= area.Y && mouse.Y <= area.Y + area.Height);
- }
-
- /// <summary>
- /// Recalcul la taille et la position de l'ensemble des parties de l'écran au prochain Update !
- /// </summary>
- public void recalc()
- {
- this.width = 0;
- this.height = 0;
- }
- #endregion
-
- #region Méthodes événementielles
- void Window_OnResize(object sender, eradiKor.Events.WindowEventArgs e)
- {
- //On sauve les nouvelles tailles
- this.width = e.Width;
- this.height = e.Height;
-
- //On repositionne les différentes parties de l'écran
- this.mapPos.Position = new Rectangle(this.width * 3 / 50, this.height * 17 / 100, this.width * 13 / 20, this.height * 3 / 5);
-
- int ww = this.width - (this.tchatPos.Position.X + this.tchatPos.Position.Width + 35);
- if (ww >= 500)
- this.boitakorPos.Position = new Rectangle(this.width - 500, this.height - 130, 500, 130);
- else
- this.boitakorPos.Position = new Rectangle(this.width - ww, this.height - 130 * ww / 500, ww, 130 * ww / 500);
-
- //if (this.width - this.width * 13 / 20 >= 300) = ŕ la ligne en dessous factorisée
- if (this.width * -0.6 >= 300)
- this.hudPos.Position = new Rectangle(this.width - 300, 5, 300, this.height - 5);
- else
- this.hudPos.Position = new Rectangle(this.width * 13 / 20, 5, this.width - this.width * 13 / 20, this.height - 5);
-
- this.statsPos = new Structures.PartDatas(Structures.GameParts.OthersMaps, new Rectangle(this.hudPos.Position.X + 25, this.hudPos.Position.Y + e.Height / 3, this.hudPos.Position.Width - 27, this.hudPos.Position.Height - this.boitakorPos.Position.Height - 210));
- this.infoPos.Position = new Rectangle(0, 0, this.width * 13 / 18, this.height * 1 / 15);
-
- //On met ŕ jour le coefficient de taille des éléments
- if (e.Carte != null)
- this.scaleCoef = Math.Min(this.mapPos.Position.Width / (e.Carte.MapSizeX - 2), this.mapPos.Position.Height / (e.Carte.MapSizeY - 2));
- if (this.scaleCoef < 1)
- this.scaleCoef = 1;
- }
- #endregion
- }
- #endregion
- }