示例#1
0
        private MenuItem InitializeOPT()
        {
            MenuItem nuovo = new MenuItem("Options", false, null, null);

            nuovo.isEditable = false;


            IntSlider fx = new IntSlider(0, 100, 10);
            MenuItem  ng = new MenuItem(nuovo, "Sound Effects", false, fx, null);

            ng.setValueType(2);

            IntSlider cd = new IntSlider(0, 100, 10);
            MenuItem  lg = new MenuItem(nuovo, "Music", false, cd, null);

            lg.setValueType(2);

            IntSlider fps = new IntSlider(10, 140, 20);
            MenuItem  tl  = new MenuItem(nuovo, "FPS Ceiling", false, fps, null);

            tl.setValueType(2);

            MenuItem back = new MenuItem(nuovo, "Back", false, null, null);

            nuovo.appendChild(ng);
            nuovo.appendChild(lg);
            nuovo.appendChild(tl);
            nuovo.appendChild(back);

            return(nuovo);
        }
示例#2
0
        /// <summary>
        /// Decrementa tutti i valori associati alla voce
        /// </summary>
        protected void decreaseVoice()
        {
            MenuItem l = getItem(pointer);

            if (l.isEditable)
            {
                l.decreaseDoubleValue();
                l.decreaseIntValue();
                l.switchBoolValue();
                this.HandleChoice(l);
                updateText();
            }
        }
示例#3
0
 /// <summary>
 /// Ferma l'elaborazione dello stato della scena
 /// </summary>
 public override void Pause()
 {
     if (bgMusic != null)
     {
         while (!bgMusic.Stop())
         {
             ;
         }
     }
     timer.Stop();
     //Altro
     curLevelItems = rtLevelItems;
     pointer       = 0;
     upperItem     = null;
 }
示例#4
0
 /// <summary>
 /// Risale nella gerarchia del menù.
 /// </summary>
 protected void AscendMenu()
 {
     if (upperItem == null)
     {
         curLevelItems = rtLevelItems;
     }
     else
     {
         List <MenuItem> l = upperItem.getChildren();
         curLevelItems = l;
         upperItem     = upperItem.fatherItem;
     }
     pointer = 0;
     updateText();
 }
示例#5
0
        private MenuItem Initialize1P()
        {
            MenuItem nuovo = new MenuItem("1 Player", false, null, null);

            MenuItem ng = new MenuItem(nuovo, "New Game", false, null, null);
            //MenuItem lg = new MenuItem(nuovo, "Load Game", false, null, null);
            MenuItem tl   = new MenuItem(nuovo, "Try Level", false, null, null);
            MenuItem back = new MenuItem(nuovo, "Back", false, null, null);

            nuovo.appendChild(ng);
            //nuovo.appendChild(lg);
            nuovo.appendChild(tl);
            nuovo.appendChild(back);

            return(nuovo);
        }
示例#6
0
        private void ItemsSetup()
        {
            rtLevelItems = new List <MenuItem>();

            MenuItem back = new MenuItem("Back To Game", false, null, null);
            MenuItem Opts = InitializeOPT();
            MenuItem ret  = new MenuItem("Retry", false, null, null);
            MenuItem quit = new MenuItem("Quit Game", false, null, null);

            rtLevelItems.Add(back);
            rtLevelItems.Add(Opts);
            rtLevelItems.Add(ret);
            rtLevelItems.Add(quit);
            curLevelItems = rtLevelItems;
            pointer       = 0;
            upperItem     = null;
        }
示例#7
0
        /// <summary>
        /// Apre l'item puntato, modificando eventualmente il menù.
        /// </summary>
        protected void OpenItem()
        {
            MenuItem        chosen = getItem(pointer);
            List <MenuItem> l      = chosen.getChildren();

            if (l.Count != 0)
            {
                curLevelItems = l;
                pointer       = 0;
                upperItem     = chosen.fatherItem;
                updateText();
            }
            else
            {
                HandleChoice(chosen);
            }
        }
示例#8
0
        private void ItemsSetup()
        {
            rtLevelItems = new List <MenuItem>();

            MenuItem OneP      = Initialize1P();
            MenuItem Opts      = InitializeOPT();
            MenuItem Scores    = new MenuItem("High Scores", false, null, null);
            MenuItem LvlEditor = new MenuItem("Level Editor", false, null, null);

            rtLevelItems.Add(OneP);
            rtLevelItems.Add(Opts);
            rtLevelItems.Add(Scores);
            rtLevelItems.Add(LvlEditor);
            curLevelItems = rtLevelItems;
            pointer       = 0;
            upperItem     = null;
        }
示例#9
0
 /// <summary>
 /// Metodo per inizializzare in maniera standard un GameMenu. (Inizializza lo stato del menù)
 /// </summary>
 /// <param name="sc">SceneContainer che conterrà il GameMenu generato</param>
 protected void GameMenuMutualPart(SceneContainer sc)
 {
     if (sc != null)
     {
         inDebug         = false;
         container       = sc;
         timer           = new Stopwatch();
         rtLevelItems    = null;
         curLevelItems   = null;
         upperItem       = null;
         pointer         = 0;
         this.clipRegion = new Rectangle(0, 0, 800, 600);
         header          = null;
         background      = null;
         cursor          = null;
         updateText();
     }
 }
示例#10
0
        /// <summary>
        /// Gestisce la scelta di un item del menù
        /// </summary>
        /// <param name="chosen">Menuitem scelto</param>
        protected override void HandleChoice(MenuItem chosen)
        {
            base.HandleChoice(chosen);
            if (chosen != null)
            {
                string dscr = chosen.description;
                switch (dscr)
                {
                case ("Back"):
                {
                    this.AscendMenu();
                    break;
                }

                case ("FPS Ceiling"):
                {
                    this.container.ChangeFPSCap((byte)chosen.int32Value.Value);
                    break;
                }

                case ("Music"):
                {
                    this.container.VolumeMusic = chosen.int32Value.Value;
                    if (bgMusic != null)
                    {
                        bgMusic.PlayLooping(this.container.VolumeMusic);
                    }
                    break;
                }

                case ("Sound Effects"):
                {
                    this.container.VolumeFX = chosen.int32Value.Value;
                    if (selectSound != null)
                    {
                        selectSound.SetVolume(this.container.VolumeFX);
                    }
                    break;
                }

                case ("Back To Game"):
                {
                    this.container.changeScene(GameConstraints.GameScreen.ID);
                    break;
                }

                case ("Retry"):
                {
                    game.PromptRetry();
                    this.container.changeScene(GameConstraints.GameScreen.ID);
                    break;
                }

                case ("Quit Game"):
                {
                    game.PromptQuit();
                    this.container.changeScene(GameConstraints.GameScreen.ID);
                    break;
                }
                }
            }
        }
示例#11
0
 /// <summary>
 /// (Overridabile): Compie un'azione in funzione al menuitem aperto.
 /// </summary>
 /// <param name="chosen">MenuItem che è stato selezionato e provoca l'azione</param>
 protected virtual void HandleChoice(MenuItem chosen)
 {
     //TODO, questa voce provoca un'azione
 }
示例#12
0
        /// <summary>
        /// Aggiorna il layer del testo.
        /// </summary>
        protected void updateText()
        {
            //Setup del canvas dove scrivere il testo e delle regioni che toccano il testo
            if (text == null)
            {
                text = new Bitmap(480, 360);
            }
            if (textBoxes == null)
            {
                textBoxes = new List <Rectangle>();
            }
            if (curLevelItems == null)
            {
                return;
            }
            int   txtW   = text.Width;
            int   txtH   = text.Height;
            float f_txtW = (float)txtW;
            float f_txtH = (float)txtH;

            //Inizializzazione delle variabili che delimiteranno il testo
            int   len = curLevelItems.Count;
            float cellHeight = Math.Min(f_txtH / ((float)len), f_txtH / 5.0f);
            int   cellH, cellW, cellX, cellY;
            float desiredFont = cellHeight / 1.8f;


            //Inizializzazione degli strumenti per disegnare
            Graphics     txtModder = Graphics.FromImage(text);
            GraphicsPath p         = new GraphicsPath();
            Pen          penna     = Pens.Black;
            SolidBrush   pennello  = new SolidBrush(Color.FromArgb(80, 150, 150, 150));

            //Inizializzazione dello stile della stringa
            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            //Svuoto l'array relativo al disegno del testo
            txtModder.Clear(Color.FromArgb(0, 0, 0, 0));
            textBoxes.Clear();

            /* Forall i in T:
             * Exists k. (Forall i in T => i.Height == k);
             * max(i in T){i.Width} <= txtLayer.W;
             * Product(i in T)[i.Height] <= txtLayer.H;
             */
            for (int j = 0; j < curLevelItems.Count; j++)
            {
                MenuItem i = curLevelItems.ElementAt <MenuItem>(j);

                Font ft      = new Font("Verdana", desiredFont, FontStyle.Bold);
                Size curCell = TextRenderer.MeasureText(i.ToString(), ft);

                if (curCell.Width > txtW || curCell.Height > cellHeight)
                {
                    float wRatio           = ((float)(curCell.Width)) / (f_txtW);
                    float hRatio           = ((float)(curCell.Height)) / ((float)cellHeight);
                    float cur_desiredRatio = Math.Max(wRatio, hRatio);
                    desiredFont = desiredFont / (cur_desiredRatio + 0.2f);
                }
            }

            /* Forall i in T:
             * i.X = (txtLayer.Width - i.Width)/2
             * i.Y = Sum(j < i)[j.Height]
             * Rectangle(i) = new Rectangle(i.X, i.Y, i.Width, i.Height)
             */
            cellY = 0;
            for (int j = 0; j < curLevelItems.Count; j++)
            {
                MenuItem i = curLevelItems.ElementAt <MenuItem>(j);

                Font ft      = new Font("Verdana", desiredFont, FontStyle.Bold);
                Size curCell = TextRenderer.MeasureText(i.ToString(), ft);

                cellH = curCell.Height;
                cellW = Math.Min(curCell.Width, txtW);
                cellX = (txtW - cellW) / 2;

                Rectangle txtBox = new Rectangle(cellX, cellY, cellW, cellH);
                textBoxes.Add(txtBox);

                p.AddString(i.ToString(), new FontFamily("Verdana"), (int)FontStyle.Bold, desiredFont, txtBox, sf);
                p.FillMode = FillMode.Winding;
                p.CloseAllFigures();

                cellY += cellH;
            }

            //Disegno e poi ripongo tutte le risorse.
            txtModder.FillPath(pennello, p);
            txtModder.DrawPath(penna, p);
            p.Reset();
            p.Dispose();
            txtModder.Dispose();
            //penna.Dispose();
            //pennello.Dispose();
        }
示例#13
0
        /// <summary>
        /// Gestisce la scelta di un item del menù
        /// </summary>
        /// <param name="chosen">Menuitem scelto</param>
        protected override void HandleChoice(MenuItem chosen)
        {
            base.HandleChoice(chosen);
            if (chosen != null)
            {
                string dscr = chosen.description;
                switch (dscr)
                {
                case ("Back"):
                {
                    this.AscendMenu();
                    break;
                }

                case ("FPS Ceiling"):
                {
                    this.container.ChangeFPSCap((byte)chosen.int32Value.Value);
                    break;
                }

                case ("Music"):
                {
                    this.container.VolumeMusic = chosen.int32Value.Value;
                    if (bgMusic != null)
                    {
                        bgMusic.PlayLooping(this.container.VolumeMusic);
                    }
                    break;
                }

                case ("Sound Effects"):
                {
                    this.container.VolumeFX = chosen.int32Value.Value;
                    if (selectSound != null)
                    {
                        selectSound.SetVolume(this.container.VolumeFX);
                    }
                    break;
                }

                case ("Try Level"):
                {
                    //TOCHECK
                    Thread t = new Thread(pickLevel);         //Creo un thread in sta, sarà lui a gestirmi il dialog
                    t.SetApartmentState(ApartmentState.STA);
                    t.Start();
                    t.Join();
                    string lvl = tryFileName;
                    if (lvl != null)
                    {
                        game.NewGame(lvl, true);
                        this.Container.changeScene(GameConstraints.GameScreen.ID);
                    }
                    break;
                }

                case ("Level Editor"):
                {
                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName       = GameApp.CurDir() + "\\LvlEditor.exe";
                    psi.WindowStyle    = ProcessWindowStyle.Normal;
                    psi.CreateNoWindow = false;
                    MessageBox.Show("Now starting the level editor: the game is now shutting down.");
                    System.Diagnostics.Process.Start(psi);
                    Application.Exit();
                    break;
                }

                case ("New Game"):
                {
                    game.NewGame();
                    this.container.changeScene(GameConstraints.GameScreen.ID);
                    break;
                }

                case ("High Scores"):
                {
                    tabellone.ShowHighscores();
                    break;
                }
                }
            }
        }