示例#1
0
    public DosScreen()
    {
        AddChild(Viewport = new Viewport()
        {
            Size                  = new Vector2(720, 400),
            Disable3d             = true,
            RenderTargetClearMode = Viewport.ClearMode.OnlyNextFrame,
            RenderTargetVFlip     = true,
        });

        Viewport.AddChild(new ColorRect()
        {
            Color    = Color.Color8(0, 0, 0, 255),
            RectSize = Viewport.Size,
        });

        AddChild(Sprite3D = new Sprite3D()
        {
            Texture          = Viewport.GetTexture(),
            PixelSize        = 0.00338666666f,
            Scale            = new Vector3(1f, 1.35f, 1f),
            MaterialOverride = new SpatialMaterial()
            {
                FlagsUnshaded            = true,
                FlagsDoNotReceiveShadows = true,
                FlagsDisableAmbientLight = true,
                ParamsSpecularMode       = SpatialMaterial.SpecularMode.Disabled,
                ParamsCullMode           = SpatialMaterial.CullMode.Back,
                FlagsTransparent         = false,
            },
            //GlobalTransform = new Transform(Basis.Identity, new Vector3(2.4384f / -2f, 0f, 0f)),
        });

        BitmapFont font = new BitmapFont();

        font.CreateFromFnt("res://Bm437_IBM_VGA9.fnt");
        Label label = new Label()
        {
            Theme = new Theme()
            {
                DefaultFont = font,
            },
            RectPosition = new Vector2(0, 0),
        };

        label.Set("custom_constants/line_spacing", 0);
        label.Set("custom_colors/font_color", Color.Color8(170, 170, 170, 255));
        Viewport.AddChild(label);
        Screen.Label = label;

        ColorRect cursor = new ColorRect
        {
            Color    = Color.Color8(170, 170, 170, 255),
            RectSize = new Vector2(9, 2),
        };

        Viewport.AddChild(cursor);
        Screen.Cursor = cursor;
    }
    public VirtualScreen()
    {
        AddChild(Viewport = new Viewport()
        {
            Size                  = new Vector2(64, 64),
            Disable3d             = true,
            RenderTargetClearMode = Viewport.ClearMode.OnlyNextFrame,
            RenderTargetVFlip     = true,
        });
        Viewport.AddChild(new Sprite()
        {
            Centered = false,
            Texture  = (Texture)GD.Load("res://icon.png"),
            Scale    = new Vector2(2f / 3f, 2f / 3f),
        });
        Viewport.AddChild(Target = new ColorRect()
        {
            Color    = Color.Color8(0, 0, 255, 255),
            RectSize = new Vector2(2, 2),
        });
        MeshInstance = new MeshInstance()
        {
            Mesh = new QuadMesh()
            {
                Size = new Vector2(Height, Height),
            },
            MaterialOverride = new SpatialMaterial()
            {
                AlbedoTexture            = Viewport.GetTexture(),
                FlagsUnshaded            = true,
                FlagsDoNotReceiveShadows = true,
                FlagsDisableAmbientLight = true,
                FlagsTransparent         = true,
                ParamsCullMode           = SpatialMaterial.CullMode.Disabled,
                ParamsSpecularMode       = SpatialMaterial.SpecularMode.Disabled,
            },
            Transform = new Transform(new Basis(Vector3.Up, Mathf.Pi), new Vector3(0f, 0f, PixelWidth / 2f)),
        };

        AddChild(CollisionShape = new CollisionShape()
        {
            Name  = "The Virtual Screen!",
            Shape = new BoxShape()
            {
                Extents = new Vector3(
                    ((QuadMesh)MeshInstance.Mesh).Size.x / 2f,
                    ((QuadMesh)MeshInstance.Mesh).Size.y / 2f,
                    PixelWidth / 2f
                    ),
            },
            Transform = new Transform(Basis.Identity, new Vector3(0f, 0f, -PixelWidth)),
        });
        CollisionShape.AddChild(MeshInstance);

        TargetPosition = new Vector2(Height / 2f, Height / 2f);
    }
示例#3
0
    public void startToConvertSprite()
    {
        xMin                -= 64;
        yMin                -= 64;
        xMax                += 64;
        yMax                += 64;
        captureViewport      = new Viewport();
        captureViewport.Size = new Vector2(xMax - xMin, yMax - yMin);
        captureViewport.RenderTargetUpdateMode = Viewport.UpdateMode.Always;
        captureViewport.RenderTargetClearMode  = Viewport.ClearMode.Always;
        captureViewport.TransparentBg          = true;
        captureViewport.Usage = Viewport.UsageEnum.Usage2d;
        GetTree().CurrentScene.AddChild(captureViewport);
        cloneDrawObject                = new drawObject();
        cloneDrawObject.pointList      = pointList;
        cloneDrawObject.brushColor     = brushColor;
        cloneDrawObject.brushIndexList = brushIndexList;
        cloneDrawObject.drawMode       = drawMode;
        cloneDrawObject.Position      -= new Vector2(xMin, yMin);
        captureViewport.AddChild(cloneDrawObject);
        cloneDrawObject.Update();

        cloneDrawObject.Connect("first_draw_ended", this, "finalToConvertSprite");

        //GetTree().CreateTimer(0.2f).Connect("timeout",this,"finalToConvertSprite");
    }
        public override void _Ready()
        {
            var size = GetViewportRect().Size;

            viewport = new Viewport()
            {
                Size  = size,
                Usage = Viewport.UsageEnum.Usage2d,
                RenderTargetUpdateMode = Viewport.UpdateMode.Always,
                RenderTargetClearMode  = Viewport.ClearMode.OnlyNextFrame,
                RenderTargetVFlip      = true
            };
            AddChild(viewport);

            pen = new Node2D();
            pen.Connect("draw", this, nameof(OnPenDraw));
            viewport.AddChild(pen);

            var texture = viewport.GetTexture();

            board = new TextureRect()
            {
                AnchorBottom = 1.0f,
                AnchorRight  = 1.0f,
                Texture      = texture
            };
            AddChild(board);

            // First clear on ready
            QueueClearDrawing(clearColor);
        }
示例#5
0
    Viewport LoadSolarSystemIntoViewportContainer(string solarSystemName)
    {
        var newViewportContainer = new ViewportContainer
        {
            AnchorBottom = 1f,
            AnchorTop    = 0f,
            AnchorLeft   = 0f,
            AnchorRight  = 1f,
            MarginBottom = 0f,
            MarginTop    = 0f,
            MarginLeft   = 0f,
            MarginRight  = 0f,
            Name         = solarSystemName + "ViewportContainer",
        };

        AddChild(newViewportContainer);

        var newViewport = new Viewport
        {
            Size = GetTree().Root.Size,
            Name = solarSystemName + "Viewport",
        };

        newViewportContainer.AddChild(newViewport);

        //Load new solar system scene
        PackedScene solarSystemScene = GD.Load <PackedScene>("res://Sandbox/Scenes/SolarSystems/" + solarSystemName + ".tscn");
        var         newSolarSystem   = solarSystemScene.Instance();

        newViewport.AddChild(newSolarSystem);

        //Find all the warp gates in the new solar system and disable any that aren't relevant to the current galaxy map
        var warpGatesParent = newSolarSystem.GetNode("WarpGates");

        foreach (Node2D child in warpGatesParent.GetChildren())
        {
            if (child != null && child is WarpGate)
            {
                bool     isOnMap = false;
                WarpGate gate    = (WarpGate)child;
                foreach (Node mapNode in GalaxyMap.Nodes)
                {
                    if (gate.Name.Contains(mapNode.Name))
                    {
                        isOnMap = true;
                        break;
                    }
                }

                //Delete it if it leads to a solar system that's not part of this galaxy
                if (!isOnMap)
                {
                    child.QueueFree();
                }
            }
        }

        SolarSystemViewportContainersByName.Add(solarSystemName, newViewportContainer);
        return(newViewport);
    }
示例#6
0
        private void SwapZone(string zonePath)
        {
            var zoneScene = GD.Load(zonePath) as PackedScene;
            var zone      = zoneScene.Instance() as GameZone;

            if (zone == null)
            {
                Logger.Error("Zone with path " + zonePath + " was not a " + nameof(GameZone));
                return;
            }
            _viewport.AddChild(zone);
            CreateAndPlacePlayer();
            GameEventDispatcher.DispatchZoneChangedEvent(zone.Id);
        }
示例#7
0
    public virtual void startMiniGame(Viewport root, Player thePlayer, NPC theNPC, Candy theCandy, int startingPrice)
    {
        player       = thePlayer;
        npc          = theNPC;
        initialPrice = startingPrice;
        currentPrice = startingPrice;
        targetCandy  = theCandy;

        root.AddChild(this);
        soundManager.PlaySfx(SoundManager.Sfx.Button);

        player.inMiniGame      = true;
        player.currentMiniGame = this;
        npc.inMiniGame         = true;
    }
    public override void _Process(float delta)
    {
        if (editorInterface == null) // Something's not right... bail!
        {
            return;
        }

        // View mode polling.
        var viewModeChangedThisFrame = false;
        var newViewMode = viewModeButtonGroup.GetPressedButton().GetIndex();

        if (viewModeIndex != newViewMode)
        {
            viewModeIndex            = newViewMode;
            viewModeChangedThisFrame = true;
            RecursiveChangeViewMode(GetTree().EditedSceneRoot);
        }

        // Zooming.
        if (Input.IsMouseButtonPressed((int)ButtonList.WheelUp))
        {
            zoomLevel += 1;
        }
        else if (Input.IsMouseButtonPressed((int)ButtonList.WheelDown))
        {
            zoomLevel -= 1;
        }
        float zoom = GetZoomAmount();

        // Viewport size.
        Vector2 size = GetGlobalRect().Size;

        viewport2d.Size = size;

        // Viewport transform.
        Transform2D viewportTrans = Transform2D.Identity;

        viewportTrans.x                *= zoom;
        viewportTrans.y                *= zoom;
        viewportTrans.origin            = viewportTrans.BasisXform(viewportCenter) + size / 2;
        viewport2d.CanvasTransform      = viewportTrans;
        viewportOverlay.CanvasTransform = viewportTrans;

        // Delete unused gizmos.
        var selection       = editorInterface.GetSelection().GetSelectedNodes();
        var overlayChildren = viewportOverlay.GetChildren();

        foreach (Gizmo25D overlayChild in overlayChildren)
        {
            bool contains = false;
            foreach (Node selected in selection)
            {
                if (selected == overlayChild.node25d && !viewModeChangedThisFrame)
                {
                    contains = true;
                }
            }
            if (!contains)
            {
                overlayChild.QueueFree();
            }
        }
        // Add new gizmos.
        foreach (Node sel in selection)
        {
            if (sel is Node25D selected)
            {
                var newNode = true;
                foreach (Gizmo25D overlayChild2 in overlayChildren)
                {
                    if (selected == overlayChild2.node25d)
                    {
                        newNode = false;
                    }
                }
                if (newNode)
                {
                    Gizmo25D gizmo = (Gizmo25D)gizmo25dScene.Instance();
                    viewportOverlay.AddChild(gizmo);
                    gizmo.node25d = selected;
                    gizmo.Initialize();
                }
            }
        }
    }
示例#9
0
 public void AddMap(Map m)
 {
     mainView.AddChild(m);
 }