Inheritance: Widget
Exemplo n.º 1
0
        /// <summary>
        /// Erzeugt ein neues Dialog-Objekt und initialisiert dieses mit dem zugehörigen IGameScreen-Objekt.
        /// Zudem sind Angaben zur Zeichenreihenfolge, einer Zeichenkette für den Titel und für den eingeblendeten Text Pflicht.
        /// [base=screen, drawOrder]
        /// </summary>
        public Dialog(IScreen screen, DisplayLayer drawOrder, string title)
            : base(screen, drawOrder)
        {
            // Setzte Titel und Text
            Title = title;

            // erstelle einen Spritebatch zum Zeichnen der Titelleiste
            spriteBatch = new SpriteBatch (screen.GraphicsDevice);

            // Dialoge sind nach dem erstellen sichtbar, und das Delegate zum schließen macht sie unsichtbar
            IsVisible = true;
            IsModal = true;
            Close = (time) => {
                IsVisible = false;
                Screen.RemoveGameComponents (time, this);
            };

            // Die Standardposition ist in der Mitte des Bildschirms
            Bounds.Position = ScreenPoint.Centered (screen, Bounds);
            // Die Standardgröße
            Bounds.Size = new ScreenPoint (screen, 0.500f, 0.500f);
            // Der Standardabstand
            Bounds.Padding = new ScreenPoint (screen, 0.010f, 0.010f);
            // Die Standardfarben
            BackgroundColorFunc = (s) => Design.DialogBackground;
            ForegroundColorFunc = (s) => Design.DialogForeground;
            TitleBackgroundColor = () => Design.DefaultLineColor * 0.75f;
            TitleForegroundColor = () => Design.TitleForegroundColor;

            // Einen Rahmen um den Titel des Dialogs
            titleBorder = new Border (
                screen: screen,
                drawOrder: Index,
                bounds: TitleBounds,
                lineWidth: 2,
                padding: 1,
                lineColor: TitleBackgroundColor (),
                outlineColor: Design.DefaultOutlineColor * 0.75f
            );

            // Einen Rahmen um den Dialog
            dialogBorder = new Border (
                screen: screen,
                drawOrder: Index,
                widget: this,
                lineWidth: 2,
                padding: 1,
                lineColor: TitleBackgroundColor (),
                outlineColor: Design.DefaultOutlineColor * 0.75f
            );

            // Tasten, auf die wir reagieren
            ValidKeys = new List<Keys> ();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Erzeugt ein neues CreativeLoadScreen-Objekt und initialisiert dieses mit einem Knot3Game-Objekt.
        /// </summary>
        public CreativeLoadScreen(GameCore game)
            : base(game)
        {
            savegameMenu = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            savegameMenu.Bounds.Position = ScreenContentBounds.Position;
            savegameMenu.Bounds.Size = new ScreenPoint (this, 0.300f, ScreenContentBounds.Size.Relative.Y);
            savegameMenu.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            savegameMenu.ItemAlignX = HorizontalAlignment.Left;
            savegameMenu.ItemAlignY = VerticalAlignment.Center;
            savegameMenu.ItemBackgroundColor = Design.ComboBoxItemBackgroundColorFunc;
            savegameMenu.ItemForegroundColor = Design.ComboBoxItemForegroundColorFunc;
            savegameMenu.RelativeItemHeight = Design.DataItemHeight;

            lines.AddPoints (.000f, .050f, .030f, .970f, .620f, .895f, .740f, .970f, .760f, .895f, .880f, .970f, .970f, .050f, 1.000f);

            title = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: "Load Knot");
            title.Bounds.Position = ScreenTitleBounds.Position;
            title.Bounds.Size = ScreenTitleBounds.Size;
            title.ForegroundColorFunc = (s) => Color.White;

            infoTitle = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: "Knot Info:");
            infoTitle.Bounds.Position = new ScreenPoint (this, 0.45f, 0.62f);
            infoTitle.Bounds.Size = new ScreenPoint (this, 0.900f, 0.050f);
            infoTitle.ForegroundColorFunc = (s) => Color.White;

            knotInfo = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            knotInfo.Bounds.Position = new ScreenPoint (this, 0.47f, 0.70f);
            knotInfo.Bounds.Size = new ScreenPoint (this, 0.300f, 0.500f);
            knotInfo.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            knotInfo.ItemAlignX = HorizontalAlignment.Left;
            knotInfo.ItemAlignY = VerticalAlignment.Center;

            // Erstelle einen Parser für das Dateiformat
            KnotFileIO fileFormat = new KnotFileIO ();
            // Erstelle einen Spielstand-Loader
            loader = new SavegameLoader<Knot, KnotMetaData> (fileFormat, "index-knots");

            // Preview
            Bounds previewBounds = new Bounds (this, 0.45f, 0.1f, 0.48f, 0.5f);
            previewWorld = new World (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.GameWorld,
                bounds: previewBounds
            );
            previewRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            previewWorld.Add (previewRenderer);
            previewBorder = new Border (
                screen: this,
                drawOrder: DisplayLayer.GameWorld,
                bounds: previewBounds,
                lineWidth: 2,
                padding: 0
            );
            previewInput = new KnotInputHandler (screen: this, world: previewWorld);
            previewMouseHandler = new ModelMouseHandler (screen: this, world: previewWorld);

            backButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Back",
                onClick: (time) => NextScreen = Game.Screens.Where ((s) => !(s is CreativeLoadScreen)).ElementAt (0)
            );
            backButton.AddKey (Keys.Escape);
            backButton.SetCoordinates (left: 0.770f, top: 0.910f, right: 0.870f, bottom: 0.960f);
            backButton.AlignX = HorizontalAlignment.Center;

            startButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Load",
                onClick: (time) => NextScreen = new CreativeModeScreen (game: Game, knot: loader.FileFormat.Load (previewKnotMetaData.Filename))
            );
            startButton.IsVisible = false;
            startButton.AddKey (Keys.Enter);
            startButton.SetCoordinates (left: 0.630f, top: 0.910f, right: 0.730f, bottom: 0.960f);
            startButton.AlignX = HorizontalAlignment.Center;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines ChallengeCreateScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt game.
        /// </summary>
        public ChallengeCreateScreen(GameCore game)
            : base(game)
        {
            startKnotMenu = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            startKnotMenu.Bounds = ScreenContentBounds.FromLeft (0.47f).FromTop (0.98f);
            startKnotMenu.ItemBackgroundColor = Design.ComboBoxItemBackgroundColorFunc;
            startKnotMenu.ItemForegroundColor = Design.ComboBoxItemForegroundColorFunc;
            startKnotMenu.RelativeItemHeight = Design.DataItemHeight;

            targetKnotMenu = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            targetKnotMenu.Bounds = ScreenContentBounds.FromRight (0.47f).FromTop (0.98f);
            targetKnotMenu.ItemBackgroundColor = Design.ComboBoxItemBackgroundColorFunc;
            targetKnotMenu.ItemForegroundColor = Design.ComboBoxItemForegroundColorFunc;
            targetKnotMenu.RelativeItemHeight = Design.DataItemHeight;

            challengeName = new InputItem (this, DisplayLayer.ScreenUI + DisplayLayer.MenuItem, "Name:", String.Empty);
            challengeName.Bounds.Position = ScreenContentBounds.Position + ScreenContentBounds.Size.OnlyY + new ScreenPoint (this, 0f, 0.050f);
            challengeName.Bounds.Size = new ScreenPoint (this, 0.375f, 0.040f);
            challengeName.OnValueChanged += () => TryConstructChallenge ();
            challengeName.NameWidth = 0.2f;
            challengeName.ValueWidth = 0.8f;

            createButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Create!",
                onClick: OnCreateChallenge
            );
            createButton.Bounds.Position = ScreenContentBounds.Position + ScreenContentBounds.FromLeft (0.50f).Size + new ScreenPoint (this, 0f, 0.050f);
            createButton.Bounds.Size = new ScreenPoint (this, 0.125f, 0.050f);

            createButtonBorder = new Border (this, DisplayLayer.ScreenUI + DisplayLayer.MenuItem, createButton, 4, 4);
            createButton.AlignX = HorizontalAlignment.Center;

            startKnotMenu.Bounds.Padding = targetKnotMenu.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            startKnotMenu.ItemAlignX = targetKnotMenu.ItemAlignX = HorizontalAlignment.Left;
            startKnotMenu.ItemAlignY = targetKnotMenu.ItemAlignY = VerticalAlignment.Center;

            lines.AddPoints (.000f, .050f, .030f, .970f, .760f, .895f, .880f, .970f, .970f, .050f, 1.000f);

            title = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: "Create Challenge");
            title.Bounds.Position = ScreenTitleBounds.Position;
            title.Bounds.Size = ScreenTitleBounds.Size;
            title.ForegroundColorFunc = (s) => Color.White;

            // Erstelle einen Parser für das Dateiformat
            KnotFileIO fileFormat = new KnotFileIO ();
            // Erstelle einen Spielstand-Loader
            loader = new SavegameLoader<Knot, KnotMetaData> (fileFormat, "index-knots");

            backButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Back",
                onClick: (time) => NextScreen = Game.Screens.Where ((s) => !(s is ChallengeCreateScreen)).ElementAt (0)
            );
            backButton.AddKey (Keys.Escape);
            backButton.SetCoordinates (left: 0.770f, top: 0.910f, right: 0.870f, bottom: 0.960f);

            backButton.AlignX = HorizontalAlignment.Center;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Erzeugt ein neues ConfirmDialog-Objekt und initialisiert dieses mit dem zugehörigen IGameScreen-Objekt.
        /// Zudem ist die Angabe der Zeichenreihenfolge Pflicht.
        /// </summary>
        public ComboBox(IScreen screen, DisplayLayer drawOrder, string text)
            : base(screen, drawOrder, String.Empty)
        {
            dropdown = new Menu (screen: screen, drawOrder: Index + DisplayLayer.Menu);
            dropdown.Bounds.Position = ValueBounds.Position;
            dropdown.Bounds.Size = new ScreenPoint (Screen, () => ValueBounds.Size.OnlyX + ValueBounds.Size.OnlyY * 10);
            dropdown.ItemForegroundColor = Design.ComboBoxItemForegroundColorFunc; // (s) => Container.ItemForegroundColor (s);
            dropdown.ItemBackgroundColor = Design.ComboBoxItemBackgroundColorFunc; // (s) => Design.WidgetBackground;
            dropdown.BackgroundColorFunc = (s) => Design.WidgetBackground;
            dropdown.ItemAlignX = HorizontalAlignment.Left;
            dropdown.ItemAlignY = VerticalAlignment.Center;
            dropdown.IsVisible = false;
            dropdownBorder = new Border (
                screen: screen,
                drawOrder: Index + DisplayLayer.Menu,
                widget: dropdown,
                lineWidth: 2,
                padding: 2
            );

            currentValue = new InputItem (screen: screen, drawOrder: Index, text: text, inputText: String.Empty);
            currentValue.Bounds = Bounds;
            currentValue.ForegroundColorFunc = (s) => ForegroundColor;
            currentValue.BackgroundColorFunc = (s) => Color.Transparent;
            currentValue.IsVisible = IsVisible;
            currentValue.IsMouseClickEventEnabled = false;

            ValidKeys.Add (Keys.Escape);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines ChallengeModeScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt, einem Spielerknoten playerKnot und dem Knoten challengeKnot, den der Spieler nachbauen soll.
        /// </summary>
        public ChallengeModeScreen(GameCore game, Challenge challenge)
            : base(game)
        {
            // world
            PlayerWorld = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromRight (percent: 0.5f));
            ChallengeWorld = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromLeft (percent: 0.5f));
            ChallengeWorld.Camera = PlayerWorld.Camera;
            PlayerWorld.OnRedraw += () => ChallengeWorld.Redraw = true;
            ChallengeWorld.OnRedraw += () => PlayerWorld.Redraw = true;
            // input
            playerKnotInput = new KnotInputHandler (screen: this, world: PlayerWorld);
            challengeKnotInput = new KnotInputHandler (screen: this, world: ChallengeWorld);
            // overlay
            overlay = new Overlay (screen: this, world: PlayerWorld);
            // pointer
            pointer = new MousePointer (screen: this);
            // model mouse handler
            playerModelMouseHandler = new ModelMouseHandler (screen: this, world: PlayerWorld);
            challengeModelMouseHandler = new ModelMouseHandler (screen: this, world: ChallengeWorld);

            // knot renderer
            PlayerKnotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            PlayerWorld.Add (PlayerKnotRenderer);
            ChallengeKnotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            ChallengeWorld.Add (ChallengeKnotRenderer);

            // debug displays
            debugBoundings = new DebugBoundings (screen: this, position: Vector3.Zero);

            // edge movements
            PlayerEdgeMovement = new EdgeMovement (screen: this, world: PlayerWorld, knotRenderer: PlayerKnotRenderer, position: Vector3.Zero);
            PlayerEdgeMovement.KnotMoved = OnKnotMoved;

            // assign the specified challenge
            Challenge = challenge;
            // assign the specified player knot
            PlayerKnot = challenge.Start.Clone () as Knot;
            // assign the specified target knot
            ChallengeKnotRenderer.RenderKnot (challenge.Target);
            // assign the specified start knot
            PlayerKnotRenderer.RenderKnot (PlayerKnot);

            SkyCube playerSkyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: 10000);
            PlayerWorld.Add (playerSkyCube);
            SkyCube challengeSkyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: 10000);
            ChallengeWorld.Add (challengeSkyCube);

            // Die Spielzeit-Anzeige
            playTimeDisplay = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: String.Empty);
            playTimeDisplay.Bounds.Position = new ScreenPoint (this, 0.800f, 0.01f);
            playTimeDisplay.Bounds.Size = new ScreenPoint (this, 0.15f, 0.04f);
            playTimeDisplay.BackgroundColorFunc = (s) => Design.WidgetBackground;
            playTimeDisplay.ForegroundColorFunc = (s) => Design.WidgetForeground;
            playTimeDisplay.AlignX = HorizontalAlignment.Center;
            playTimeBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                         widget: playTimeDisplay, lineWidth: 2, padding: 0);
            //Undo-Button
            undoButton = new Button (screen: this,
                                     drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                     name: "Undo",
                                     onClick: (time) => OnUndo ());
            undoButton.SetCoordinates (left: 0.55f, top: 0.900f, right: 0.65f, bottom: 0.95f);

            undoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: undoButton, lineWidth: 2, padding: 0);
            undoButton.AlignX = HorizontalAlignment.Center;
            undoButton.IsVisible = false;

            // Redo-Button
            redoButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Redo",
                onClick: (time) => OnRedo ()
            );
            redoButton.SetCoordinates (left: 0.70f, top: 0.900f, right: 0.80f, bottom: 0.95f);

            redoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: redoButton, lineWidth: 2, padding: 0);
            redoButton.AlignX = HorizontalAlignment.Center;
            redoButton.IsVisible = false;

            // die Linien
            lines = new Lines (screen: this, drawOrder: DisplayLayer.Dialog, lineWidth: 2);
            lines.AddPoints (0.500f, 0.000f, 0.500f, 1.000f);

            // Status
            state = ChallengeModeState.Start;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines CreativeModeScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt game, sowie einem Knoten knot.
        /// </summary>
        public CreativeModeScreen(GameCore game, Knot knot)
            : base(game)
        {
            // die Spielwelt
            world = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds);
            // der Input-Handler
            knotInput = new KnotInputHandler (screen: this, world: world);
            // das Overlay zum Debuggen
            overlay = new Overlay (screen: this, world: world);
            // der Mauszeiger
            pointer = new MousePointer (screen: this);
            // der Maus-Handler für die 3D-Modelle
            modelMouseHandler = new ModelMouseHandler (screen: this, world: world);

            // der Knoten-Renderer
            knotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            world.Add (knotRenderer);

            // visualisiert die BoundingSpheres
            debugBoundings = new DebugBoundings (screen: this, position: Vector3.Zero);
            world.Add (debugBoundings);

            // der Input-Handler zur Kanten-Verschiebung
            edgeMovement = new EdgeMovement (screen: this, world: world, knotRenderer : knotRenderer, position: Vector3.Zero);
            edgeMovement.KnotMoved = OnKnotMoved;

            // der Input-Handler zur Kanten-Einfärbung
            edgeColoring = new EdgeColoring (screen: this);

            // Flächen zwischen Kanten
            edgeRectangles = new EdgeRectangles (screen: this);

            // assign the specified knot
            Knot = knot;

            // Hintergrund
            Sky skyCube = new Sky (screen: this, position: Vector3.Zero);
            world.Add (skyCube);

            // Sonne
            Sun sun = new Sun (screen: this);
            world.Add (sun);

            // Undo-Button
            undoButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Undo",
                onClick: (time) => OnUndo ()
            );
            undoButton.SetCoordinates (left: 0.05f, top: 0.900f, right: 0.15f, bottom: 0.95f);
            undoButton.AlignX = HorizontalAlignment.Center;
            undoButton.IsVisible = false;

            undoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: undoButton, lineWidth: 2, padding: 0);

            // Redo-Button
            redoButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Redo",
                onClick: (time) => OnRedo ()
            );
            redoButton.SetCoordinates (left: 0.20f, top: 0.900f, right: 0.30f, bottom: 0.95f);
            redoButton.AlignX = HorizontalAlignment.Center;
            redoButton.IsVisible = false;

            redoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: redoButton, lineWidth: 2, padding: 0);

            invisible = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "menu",
            onClick: (time) => {
                // erstelle einen neuen Pausedialog
                knotInput.IsEnabled = false;
                Dialog pauseDialog = new CreativePauseDialog (screen: this, drawOrder: DisplayLayer.Dialog, knot: Knot);
                // füge ihn in die Spielkomponentenliste hinzu
                pauseDialog.Close += (t) => knotInput.IsEnabled = true;
                AddGameComponents (time, pauseDialog);
            }
            );
            invisible.SetCoordinates (left: 1.00f, top: 1.00f, right: 1.10f, bottom: 1.10f);
            invisible.IsVisible = true;
            invisible.AddKey (Keys.Escape);
        }