예제 #1
0
        protected static SpriteFrames GetEmoteFrames()
        {
            var frames = new SpriteFrames();

            foreach (var type in new[] { "Pixel", "Vector" })
            {
                for (var style = 1; style <= 8; style++)
                {
                    var contents = new[] {
                        "_", "alert", "anger", "bars", "cash", "circle", "cloud", "cross", "dots1",
                        "dots2", "dots3", "drop", "drops", "exclamation", "exclamations", "faceAngry", "faceHappy",
                        "faceSad", "heart", "heartBroken", "hearts", "idea", "laugh", "music", "question", "sleep",
                        "sleeps", "star", "stars", "swirl"
                    };

                    foreach (var content in contents)
                    {
                        frames.Animations.Add(new SpriteFrames.Animation {
                            Speed  = 1,
                            Loop   = false,
                            Name   = $"{type}_{style}_{content}",
                            Frames = new List <IExternalResource> {
                                new Texture {
                                    Path = $"res://{type}/Style {style}/emote_{content}.png"
                                }
                            },
                        });
                    }
                }
            }

            return(frames);
        }
예제 #2
0
        public SpriteSheetHandler(int objTextureId, int startOffsetX, int startOffsetY, int offsetX, int offsetY, int width, int height)
        {
            TextureId = objTextureId;
            int imageHeight   = GraphicsUtility.TextureCollection[TextureId].Height;
            int imageWidth    = GraphicsUtility.TextureCollection[TextureId].Width;
            int currentRow    = startOffsetY;
            int currentColumn = startOffsetX;

            while (true)
            {
                if (currentColumn >= imageWidth)
                {
                    currentRow   += height + offsetY + startOffsetY;
                    currentColumn = startOffsetX;
                }

                if (currentRow >= imageHeight)
                {
                    break;
                }

                SpriteFrames.Add(new Rectangle(currentColumn, currentRow, width, height));

                currentColumn += width + offsetX + startOffsetX;
            }
            MaxFrame = SpriteFrames.Count - 1;
        }
예제 #3
0
    private void ChangeForm(PlayerForm form, bool instant = false)
    {
        IsChangingForm = true;
        CurrentForm    = form;

        GD.Print("Changing form to " + form.ToString());

        if (!SceneCache.ContainsKey(CurrentForm))
        {
            SceneCache.Add(CurrentForm, GD.Load <PackedScene>(Constants.FilePath.PLAYER_FORM_SCENES + CurrentForm.ToString() + ".tscn"));
        }
        CurrentScene = SceneCache[CurrentForm];

        string frameCacheKey = SpriteFolderName + "/" + CurrentForm.ToString();

        if (!FrameCache.ContainsKey(frameCacheKey))
        {
            FrameCache.Add(frameCacheKey, GD.Load <SpriteFrames>(Constants.FilePath.PLAYER_FRAMES + SpriteFolderName + "/" + CurrentForm.ToString() + ".tres"));
        }
        CurrentFrames = FrameCache[frameCacheKey];

        Player oldFormScene = GetChildCount() > 0 ? GetChildOrNull <Player>(0) : null;

        oldFormScene?.SetName("QueuedForDeletion");

        if (oldFormScene != null)
        {
            PreviousTransform = oldFormScene.GetGlobalTransform();
            PreviousVelocity  = oldFormScene.Velocity;

            AnimatedSprite3D sprite = GetNode <AnimatedSprite3D>(new NodePath("QueuedForDeletion/PlayerSprite"));
            PreviousSpriteFlipped = sprite.IsFlippedH();

            if (!instant)
            {
                //Create blinking state transition
                TransitionFrames.Clear("Transition");

                TransitionFrames.AddFrame("Transition", sprite.Frames.GetFrame(Player.PlayerAnimation.IDLE, 0), 0);
                TransitionFrames.AddFrame("Transition", CurrentFrames.GetFrame(Player.PlayerAnimation.IDLE, 0), 1);

                TransitionSprite.SetGlobalTransform(sprite.GetGlobalTransform().Translated(-Transform.origin));
                TransitionSprite.SetFlipH(sprite.FlipH);
                TransitionSprite.SetPixelSize(sprite.GetPixelSize());
                TransitionSprite.Play("Transition");
            }

            oldFormScene.SetProcess(false);
            oldFormScene.SetPhysicsProcess(false);
            oldFormScene.QueueFree();
        }

        if (instant)
        {
            FinishFormChange(form);
            return;
        }

        AddChild(TransitionSprite);
    }
예제 #4
0
    /// <summary>
    /// Load the set of PNGs into SpriteFrames needed for the AnimatedSprite
    /// <param name="string spritePath"></param>
    /// <param name="AnimatedSprite animatedSprite"></param>
    /// <param name="List<string> animationList"></param>
    /// </summary>
    public static void LoadSprite(string spritePath, AnimatedSprite animatedSprite, List <string> animationList)
    {
        SpriteFrames spriteFrames = new SpriteFrames();

        foreach (string animation in animationList)
        {
            var dir = new Directory();
            dir.Open(spritePath + animation);

            dir.ListDirBegin();
            var    fileName         = dir.GetNext();
            string strFileExtention = System.IO.Path.GetExtension(fileName);
            spriteFrames.AddAnimation(animation);
            int count = 0;

            while (!String.IsNullOrEmpty(fileName))
            {
                fileName = fileName.Replace(strFileExtention, "");
                var sprite = ResourceLoader.Load(spritePath + animation + "/" + fileName) as Texture;
                spriteFrames.AddFrame(animation, sprite);
                fileName = dir.GetNext();
                count++;
            }
            animatedSprite.Frames     = spriteFrames;
            animatedSprite.SpeedScale = 7;
            animatedSprite.Play("Idle");
        }
    }
예제 #5
0
    public void LoadData(PartyMemberData data)
    {
        CharacterName = data.CharacterName;
        Portrait      = data.Portrait;
        PortraitColor = data.PortraitColor;
        AnimationSet  = data.AnimationSet;

        Stats = (Statblock)GetNode("Statblock");
        Stats.LoadData(data);

        GUIManager.UpdateFor(this);
    }
예제 #6
0
    static void Main(string[] args)
    {
        // 注册序列化类型
        PKG.AllTypes.Register();

        // 填充 ways
        Ways.Fill();

        // 填充 frames, fishFrames
        SpriteFrames.Fill();

        // 创建配置实例
        var cfg = new PKG.CatchFish.Configs.Config();

        cfg.cannons     = new xx.List <PKG.CatchFish.Configs.Cannon>();
        cfg.fishs       = new xx.List <PKG.CatchFish.Configs.Fish>();
        cfg.sitPositons = new xx.List <xx.Pos>();
        cfg.stages      = new xx.List <PKG.CatchFish.Stages.Stage>();
        cfg.fixedWays   = new xx.List <PKG.CatchFish.Way>();
        cfg.weapons     = new xx.List <PKG.CatchFish.Configs.Weapon>();

        // 基于 1280 x 720 的设计尺寸
        cfg.sitPositons.Add(new xx.Pos {
            x = -250, y = -335
        });
        cfg.sitPositons.Add(new xx.Pos {
            x = 250, y = -335
        });
        cfg.sitPositons.Add(new xx.Pos {
            x = 250, y = 335
        });
        cfg.sitPositons.Add(new xx.Pos {
            x = -250, y = 335
        });
        cfg.aimTouchRadius          = 20;
        cfg.normalFishMaxRadius     = 150;
        cfg.enableBulletFastForward = false;

        // 有前后依赖
        Cannons.Fill(cfg);
        Weapons.Fill(cfg);
        Fishs.Fill(cfg);
        Stages.Fill(cfg);

        // cfg 序列化存盘
        var bb = new xx.BBuffer();

        bb.WriteRoot(cfg);
        File.WriteAllBytes(Path.Combine(outputPath, "cfg.bin"), bb.DumpData());
        bb.ReadRoot(ref cfg);   // test read
    }
예제 #7
0
    public override void _Ready()
    {
        PreviousTransform = GetGlobalTransform();
        PreviousVelocity  = Vector3.Zero;

        TransitionFrames = new SpriteFrames();
        TransitionFrames.AddAnimation("Transition");
        TransitionFrames.SetAnimationSpeed("Transition", 10);

        TransitionSprite = new AnimatedSprite3D();
        TransitionSprite.SetName("TransitionSprite");
        TransitionSprite.SetSpriteFrames(TransitionFrames);
        TransitionSprite.SetCastShadowsSetting(GeometryInstance.ShadowCastingSetting.On);
        TransitionSprite.Transparent = true;
        TransitionSprite.AlphaCut    = SpriteBase3D.AlphaCutMode.OpaquePrepass;

        CurrentForm        = InitialForm;
        PlayerInputManager = new InputManager(PlayerNumber);

        ChangeForm(InitialForm, true);
    }
예제 #8
0
    public override void _EnterTree()
    {
        PlayerSpawners.Add(this);

        PreviousTransform = GlobalTransform;
        PreviousVelocity  = Vector3.Zero;

        TransitionFrames = new SpriteFrames();
        TransitionFrames.AddAnimation("Transition");
        TransitionFrames.SetAnimationSpeed("Transition", 10);

        TransitionSprite             = new AnimatedSprite3D();
        TransitionSprite.Name        = "TransitionSprite";
        TransitionSprite.Frames      = TransitionFrames;
        TransitionSprite.CastShadow  = GeometryInstance.ShadowCastingSetting.On;
        TransitionSprite.Transparent = true;
        TransitionSprite.AlphaCut    = SpriteBase3D.AlphaCutMode.OpaquePrepass;

        CurrentForm        = InitialForm;
        PlayerInputManager = new InputManager(PlayerNumber);

        ChangeForm(InitialForm, true);
    }
예제 #9
0
    public virtual void SetupPlayer(InputManager input, Transform transform, Vector3 velocity, SpriteFrames spriteFrames, bool spriteFlipped)
    {
        PlayerSprite      = GetNodeOrNull <AnimatedSprite3D>(new NodePath("PlayerSprite"));
        ActorDetectorArea = GetNodeOrNull <Area>(new NodePath("ActorDetector"));
        FloorRayCast      = GetNodeOrNull <RayCast>(new NodePath("FloorRayCast"));

        if (PlayerSprite == null || ActorDetectorArea == null || FloorRayCast == null)
        {
            GD.Print("One or multiple required child nodes could not be found! Some features won't work!");
        }

        InputManager        = input;
        GlobalTransform     = transform;
        Velocity            = velocity;
        PlayerSprite.Frames = spriteFrames;
        PlayerSprite.FlipH  = spriteFlipped;

        SetPlayerCollisionShape(GetDefaultCollisionShape());
    }
예제 #10
0
 void Start()
 {
     R2D = this.transform.GetComponent <Rigidbody2D>();
     SF  = GetComponent <SpriteFrames>();
 }
예제 #11
0
        /// <summary>
        /// This must be passed the "SpriteData" node of the JSON
        /// </summary>
        /// <param name="tileSet">The tileset that the data belongs to</param>
        /// <param name="spriteDataToken">The JSON to pull the data from. MUST have a root of "SpriteData"</param>
        /// <returns></returns>
        public bool AddSpriteDataFromJson(Dictionary spriteDict)
        {
            List <SpriteData>        spriteData   = new List <SpriteData>();
            Dictionary               tileSetDict  = this.ValueExtractor.GetValueFromDictionary <Dictionary>(spriteDict, "TileSet");
            string                   tileSetName  = this.ValueExtractor.GetValueFromDictionary <string>(tileSetDict, "Name");
            Array                    tileSetArray = this.ValueExtractor.GetValueFromDictionary <Array>(tileSetDict, "SpriteData");
            ICollection <Dictionary> tileSetDicts =
                this.ValueExtractor.GetCollectionFromArray <Dictionary>(tileSetArray);

            foreach (Dictionary dict in tileSetDicts)
            {
                try
                {
                    List <SpritePart> parts = new List <SpritePart>();

                    string name       = this.ValueExtractor.GetValueFromDictionary <string>(dict, "Name");
                    string state      = this.ValueExtractor.GetValueFromDictionary <string>(dict, "State") ?? "default";
                    Array  partsArray = this.ValueExtractor.GetValueFromDictionary <Array>(dict, "Part");
                    ICollection <Dictionary> partDicts =
                        this.ValueExtractor.GetCollectionFromArray <Dictionary>(partsArray);
                    foreach (Dictionary innerDict in partDicts)
                    {
                        string partName   = this.ValueExtractor.GetValueFromDictionary <string>(innerDict, "Name");
                        int    partFrames = innerDict.Contains("Frames")
                            ? this.ValueExtractor.GetValueFromDictionary <int>(innerDict, "Frames")
                            : 1;
                        string fileName  = this.ValueExtractor.GetValueFromDictionary <string>(innerDict, "Filename");
                        int    sortOrder = this.ValueExtractor.GetValueFromDictionary <int>(innerDict, "SortOrder");
                        int    position  = this.ValueExtractor.GetValueFromDictionary <int>(innerDict, "Position");
                        NinePatchRect.AxisStretchMode stretchMode =
                            GraphicsHelper.ParseStretchMode(
                                this.ValueExtractor.GetValueFromDictionary <string>(innerDict, "FillType"));
                        bool drawCentre = !innerDict.Contains("DrawCentre") ||
                                          this.ValueExtractor.GetValueFromDictionary <bool>(innerDict, "DrawCentre");
                        Array marginArray = this.ValueExtractor.GetValueFromDictionary <Array>(
                            innerDict,
                            "PatchMargins");
                        ICollection <int> patchMargins = marginArray.IsNullOrEmpty()
                            ? new[] { 0, 0, 0, 0 }
                            : this.ValueExtractor.GetCollectionFromArray <int>(marginArray);

                        Array partDataArray = innerDict.Contains("Data")
                            ? this.ValueExtractor.GetValueFromDictionary <Array>(innerDict, "Data")
                            : new Array();
                        ICollection <string> data = this.ValueExtractor.GetCollectionFromArray <string>(partDataArray);
                        Array partColourArray     =
                            this.ValueExtractor.GetValueFromDictionary <Array>(innerDict, "Colour");
                        ICollection <Color>  colours     = new List <Color>();
                        ICollection <string> colourCodes = partColourArray.IsNullOrEmpty()
                            ? new List <string>
                        {
                            "#ffffff"
                        }
                            : this.ValueExtractor.GetCollectionFromArray <string>(partColourArray);
                        foreach (string code in colourCodes)
                        {
                            colours.Add(new Color(code));
                        }

                        Texture texture = GD.Load <Texture>(
                            GlobalConstants.GODOT_ASSETS_FOLDER +
                            GlobalConstants.SPRITES_FOLDER +
                            fileName);

                        Image          image      = texture.GetData();
                        int            frameWidth = texture.GetWidth() / partFrames;
                        List <Texture> frames     = new List <Texture>();
                        for (int i = 0; i < texture.GetWidth(); i += frameWidth)
                        {
                            ImageTexture imageTexture = new ImageTexture();
                            imageTexture.CreateFromImage(image.GetRect(new Rect2(new Vector2(i, 0),
                                                                                 new Vector2(frameWidth, frameWidth))), 2);
                            imageTexture.ResourceLocalToScene = true;
                            frames.Add(imageTexture);
                        }

                        int halfway = frames.Count / 2;
                        if (frames.Count > 1)
                        {
                            for (int i = halfway; i >= halfway; i--)
                            {
                                frames.Add(frames[i]);
                            }
                        }

                        SpriteFrames spriteFrames = new SpriteFrames();
                        if (spriteFrames.GetAnimationNames().Contains(state) == false)
                        {
                            spriteFrames.AddAnimation(state);
                            spriteFrames.SetAnimationLoop(state, true);
                            spriteFrames.SetAnimationSpeed(state, GlobalConstants.FRAMES_PER_SECOND);
                        }

                        for (int i = 0; i < frames.Count; i++)
                        {
                            spriteFrames.AddFrame(state, frames[i], i);
                        }

                        SpritePart part = new SpritePart
                        {
                            m_Data            = data.ToArray(),
                            m_Filename        = fileName,
                            m_Frames          = partFrames,
                            m_FrameSprite     = spriteFrames,
                            m_Name            = partName,
                            m_Position        = position,
                            m_PossibleColours = colours.ToList(),
                            m_SortingOrder    = sortOrder,
                            m_PatchMargins    = patchMargins.ToArray(),
                            m_DrawCentre      = drawCentre,
                            m_StretchMode     = stretchMode
                        };

                        parts.Add(part);
                    }

                    spriteData.Add(
                        new SpriteData
                    {
                        m_Name  = name,
                        m_Parts = parts,
                        m_State = state
                    });
                }
                catch (Exception e)
                {
                    GlobalConstants.ActionLog.Log("Could not load sprite data from JSON. Offending JSON to follow.");
                    GlobalConstants.ActionLog.Log(dict);
                    GlobalConstants.ActionLog.StackTrace(e);
                }
            }

            return(this.AddSpriteDataRange(tileSetName, spriteData));
        }
예제 #12
0
	public static void Dialogue(string sourceFile, int dialogueSet, string leftClientName, string leftClientColor, SpriteFrames leftClientPortrait, string rightClientName = "NULL", string rightClientColor = "#ffffff", SpriteFrames rightClientPortrait = null, bool restoreMovement = true, Node signalConnection = null, string signalMethod = "")
	{
		Player.State = Player.ST.NO_INPUT;
		var dlg = Controller.Main.DialogueRef.Instance() as Dialogue;
		dlg.SourceFile = sourceFile;
		dlg.TextSet = dialogueSet;
		dlg.SecondClient = rightClientPortrait != null;

		dlg.LeftClientName = leftClientName;
		dlg.LeftClientColor = new Color(leftClientColor);
		dlg.LeftClientPortrait = leftClientPortrait;

		dlg.RightClientName = rightClientName;
		dlg.RightClientColor = new Color(rightClientColor);
		dlg.RightClientPortrait = rightClientPortrait;

		dlg.RestoreMovement = restoreMovement;

		if (rightClientPortrait != null)
			dlg.LineEnd = 248;
		else
		{
			dlg.TextLeft += 35;

			// Shift box positions (start)
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Start").TrackSetKeyValue(0, 0, new Vector2(335, 424));
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Start").TrackSetKeyValue(0, 1, new Vector2(335, 284));
			
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Start").TrackSetKeyValue(1, 0, new Vector2(83, 368));
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Start").TrackSetKeyValue(1, 1, new Vector2(83, 228));
		
			// Shift box positions (finish)
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Finish").TrackSetKeyValue(0, 0, new Vector2(335, 284));
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Finish").TrackSetKeyValue(0, 1, new Vector2(335, 424));
			
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Finish").TrackSetKeyValue(1, 0, new Vector2(83, 228));
			dlg.GetNode<AnimationPlayer>("AnimationPlayer").GetAnimation("Finish").TrackSetKeyValue(1, 1, new Vector2(83, 368));
		}
			
		dlg.Position = new Vector2(Player.GetCamera().GetCameraScreenCenter().x - 300, Player.GetCamera().GetCameraScreenCenter().y - 180);
		Controller.Main.GetTree().GetRoot().AddChild(dlg);
		dlg.InitializePortraits();

		if (signalConnection != null && signalMethod != "")
			dlg.Connect("text_ended", signalConnection, signalMethod);
	}
예제 #13
0
 void Start()
 {
     SF  = GetComponent <SpriteFrames>();
     R2D = GetComponent <Rigidbody2D>();
 }
 public static int GetLastFrame(this SpriteFrames spriteFrames, string animationName) =>
 spriteFrames.GetFrameCount(animationName) - 1;