Beispiel #1
0
    public void ShowPattern(DesignServer.Pattern pattern, PatternExchange exchange)
    {
        try
        {
            PatternExchange = exchange;
            Pattern         = pattern;
            if (CurrentTexture != null)
            {
                CurrentTexture.Dispose();
                CurrentTexture = null;
            }

            ACNHFileFormat format = new ACNHFileFormat(pattern.Bytes);
            DesignPattern  patt   = null;
            if (format.IsPro)
            {
                patt = new ProDesignPattern();
                patt.CopyFrom(format);
            }
            else
            {
                patt = new SimpleDesignPattern();
                patt.CopyFrom(format);
            }

            CurrentTexture = patt.GetBitmap();
            CurrentTexture.Apply();
            CurrentTexture.Texture.filterMode = FilterMode.Point;
            CurrentTexture.Texture.wrapMode   = TextureWrapMode.Clamp;
            this.Image.texture = CurrentTexture.Texture;
        }
        catch (System.Exception e)
        {
        }
    }
Beispiel #2
0
    void Start()
    {
        AddTagButton.onClick.AddListener(() =>
        {
            AddCurrentTag();
        });

        ConfirmButton.OnClick = () => {
            string patternName = this.NameInputField.text;
            string creatorName = this.CreatorInputField.text;
            PlayerPrefs.SetString("CreatorName", this.CreatorInputField.text);
            //string name, List<string> tags
            Controller.Instance.Popup.SetText("Uploading pattern to\r\npattern exchange", true);
            System.Threading.Tasks.Task.Run(() => {
                try
                {
                    var msgPattern     = new DesignServer.Pattern();
                    msgPattern.Type    = (byte)Pattern.Type;
                    msgPattern.Name    = patternName;
                    msgPattern.Creator = creatorName;
                    msgPattern.Tags    = Tags.ToArray();
                    msgPattern.Code    = "";
                    msgPattern.ID      = 0;
                    var file           = ACNHFileFormat.FromPattern(Pattern);
                    msgPattern.Bytes   = file.ToBytes();

                    var msg = new DesignServer.Messages.UploadPattern(msgPattern);
                    Client.Connection.SendMessage(msg, (response) => {
                        if (response is DesignServer.Messages.UploadPatternResponse resp)
                        {
                            UploadedPattern = resp.Pattern;
                        }
                    });
                }
                catch (System.Exception e)
                {
                    Controller.Instance.Popup.SetText(e.Message, false, () => { return(true); });
                }
            });
        };

        CancelButton.OnClick = () => {
            Cancel?.Invoke();
        };
    }
Beispiel #3
0
 private void Update()
 {
     if (UploadedPattern != null)
     {
         Confirm?.Invoke(UploadedPattern);
         Controller.Instance.Popup.Close();
         UploadedPattern = null;
     }
     if (WasFocused && Input.GetKeyDown(KeyCode.Return))
     {
         AddCurrentTag();
         TagInputField.OnPointerClick(new UnityEngine.EventSystems.PointerEventData(null)
         {
             button = UnityEngine.EventSystems.PointerEventData.InputButton.Left
         });
     }
     WasFocused = TagInputField.isFocused;
 }
    public static ACNHFileFormat FromPattern(DesignServer.Pattern pattern)
    {
        var result = new ACNHFileFormat();

        result.Name    = pattern.Name;
        result.Type    = (DesignPattern.TypeEnum)pattern.Type;
        result.Palette = new DesignPattern.Color[15];

        for (int i = 0; i < result.Palette.Length; i++)
        {
            result.Palette[i] = new DesignPattern.Color()
            {
                R = pattern.Bytes[i * 3 + 0], G = pattern.Bytes[i * 3 + 1], B = pattern.Bytes[i * 3 + 2]
            }
        }
        ;

        result.Pixels = new byte[(result.Width / 2) * result.Height];
        Array.Copy(pattern.Bytes, 15 * 3, result.Pixels, 0, result.Pixels.Length);
        return(result);
    }
    public void ShowDesign(DesignServer.Pattern pattern, System.Action confirm)
    {
        if (confirm == null && Cancel == null && Confirm == null && ConfirmImport == null)
        {
            return;
        }
        // we are coming from items
        if (confirm == null)
        {
            SelectedPattern = pattern;
            CancelPop.PopOut();
        }
        if (CurrentPreview != null)
        {
            CurrentPreview.Dispose();
            CurrentPreview = null;
        }
        if (CurrentUpscaledPreview != null)
        {
            CurrentUpscaledPreview.Dispose();
            CurrentUpscaledPreview = null;
        }

        this.Pattern = pattern;
        this.Confirm = confirm;
        this.DesignName.Open();
        this.DesignName.Text  = Pattern.Name;
        this.CreatorName.text = Pattern.Creator;
        var t = (DesignPattern.TypeEnum)Pattern.Type;

        try
        {
            var acnhFileFormat = new ACNHFileFormat(pattern.Bytes);
            if (acnhFileFormat.IsPro)
            {
                DesignPattern = new ProDesignPattern();
                DesignPattern.CopyFrom(acnhFileFormat);
            }
            else
            {
                DesignPattern = new SimpleDesignPattern();
                DesignPattern.CopyFrom(acnhFileFormat);
            }
            CurrentPreview = DesignPattern.GetBitmap();
            CurrentPreview.Apply();
            CurrentPreview.Texture.filterMode = FilterMode.Point;
            CurrentPreview.Texture.wrapMode   = TextureWrapMode.Clamp;

            CurrentUpscaledPreview = new TextureBitmap(CurrentPreview.Width * 4, CurrentPreview.Height * 4);

            int[] src    = CurrentPreview.ConvertToInt();
            int[] target = new int[CurrentUpscaledPreview.Width * CurrentUpscaledPreview.Height];
            var   scaler = new xBRZScaler();
            scaler.ScaleImage(4, src, target, CurrentPreview.Width, CurrentPreview.Height, new xBRZNet.ScalerCfg(), 0, int.MaxValue);
            CurrentUpscaledPreview.FromInt(target);
            CurrentUpscaledPreview.Apply();

            Previews.AllPreviews[DesignPattern.Type].SetTexture(CurrentUpscaledPreview.Texture);
            Previews.AllPreviews[DesignPattern.Type].Render();
            PatternPreview.texture = CurrentPreview.Texture;
            DesignPreview.texture  = Previews.AllPreviews[DesignPattern.Type].Camera.targetTexture;

            this.DesignType.text = DesignPatternInformation.Types[t].Name;
            this.DesignCode.text = "DE-" + pattern.Code;
        }
        catch (System.Exception e)
        {
        }
        StartCoroutine(ShowDesignCoroutine());
    }