예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeConnections"/> class.</summary>
        /// <param name="frame">
        /// The <see cref="ImageFrame"/> whose <see cref="ImageFrame.Connections"/> to edit.</param>
        /// <param name="bitmap">
        /// The <see cref="WriteableBitmap"/> containing the <see cref="ImageFrame.Bounds"/> of the
        /// specified <paramref name="frame"/>. This argument may be a null reference.</param>
        /// <param name="info">
        /// Informational text about the <paramref name="frame"/> to display in the dialog.</param>
        /// <param name="scalingX">
        /// An <see cref="ImageScaling"/> value indicating the horizontal scaling of the specified
        /// <paramref name="frame"/>.</param>
        /// <param name="scalingY">
        /// An <see cref="ImageScaling"/> value indicating the vertical scaling of the specified
        /// <paramref name="frame"/>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="frame"/> is a null reference.</exception>
        /// <exception cref="ArgumentNullOrEmptyException">
        /// <paramref name="info"/> is a null reference or an empty string.</exception>

        public ChangeConnections(ImageFrame frame, WriteableBitmap bitmap,
                                 string info, ImageScaling scalingX, ImageScaling scalingY)
        {
            if (frame == null)
            {
                ThrowHelper.ThrowArgumentNullException("frame");
            }
            if (String.IsNullOrEmpty(info))
            {
                ThrowHelper.ThrowArgumentNullOrEmptyException("info");
            }

            this._frame = frame;
            InitializeComponent();

            // show specified frame information
            FrameInfo.Content = (string)FrameInfo.Content + " " + info;

            // show specified image frame
            FramePreview.Polygon  = MasterSection.Instance.Areas.MapGrid.Element;
            FramePreview.ScalingX = scalingX;
            FramePreview.ScalingY = scalingY;
            FramePreview.Show(frame, bitmap);

            // initialize directional toggle buttons
            this._compassControls = new CompassControl[] {
                new CompassControl(NorthToggle, Compass.North, Symbols.ArrowUp),
                new CompassControl(NorthEastToggle, Compass.NorthEast, Symbols.ArrowRightUp),
                new CompassControl(EastToggle, Compass.East, Symbols.ArrowRight),
                new CompassControl(SouthEastToggle, Compass.SouthEast, Symbols.ArrowRightDown),
                new CompassControl(SouthToggle, Compass.South, Symbols.ArrowDown),
                new CompassControl(SouthWestToggle, Compass.SouthWest, Symbols.ArrowLeftDown),
                new CompassControl(WestToggle, Compass.West, Symbols.ArrowLeft),
                new CompassControl(NorthWestToggle, Compass.NorthWest, Symbols.ArrowLeftUp)
            };

            // set checked states to Connections values
            foreach (Compass compass in frame.Connections)
            {
                int index = CompassToIndex(compass);
                this._compassControls[index].Button.IsChecked = true;
            }

            // disable controls invalid for current polygon
            EnableControls();
        }
    public bool Init()
    {
        if(!_initialized)
        {
            // these seem to return 0 sometimes if we check them too early
            // so we won't consider the pixel screen initialized until we can get back a non-zero value for these
            if(Screen.width == 0 || Screen.height == 0)
                return false;

            int screenWidth = PlayerPrefs.GetInt("screenWidth", 800);
            int screenHeight = PlayerPrefs.GetInt("screenHeight", 500);
            screenWidth = Mathf.Max(screenHeight, 300);
            screenHeight = Mathf.Max(screenHeight, 300);

            Screen.SetResolution(screenWidth, screenHeight, false);

            Camera camera = GetComponent<Camera>();
            camera.orthographic = true;
            camera.orthographicSize = 1;

            // ----------------------------------------------
            // CANVAS
            // ----------------------------------------------
            _canvas = gameObject.AddComponent<Canvas>();
            _canvas.Init(this);

            _lastCanvasWidth = _canvas.pixelWidth;
            _lastCanvasHeight = _canvas.pixelHeight;

            _copiedPixels = new Color32[_canvas.pixelWidth * _canvas.pixelHeight];
            _canvas.GetPixels(CurrentFrame).CopyTo(_copiedPixels, 0);

            _pixelDimensionsString = _canvas.pixelWidth.ToString() + "," + _canvas.pixelHeight.ToString();
            _hitbox = new PixelRect(0, 0, _canvas.pixelWidth, _canvas.pixelHeight);
            RefreshHitboxString();

            // ----------------------------------------------
            // SWATCH
            // ----------------------------------------------
            _swatch = gameObject.AddComponent<Swatch>();
            _swatch.Init(this);
            SetCurrentColor(Color.black);

            // ----------------------------------------------
            // PALETTE
            // ----------------------------------------------
            _palette = gameObject.AddComponent<Palette>();
            _palette.Init(this);

            CreateEffectPlane();

            // ----------------------------------------------
            // FRAME PREVIEW
            // ----------------------------------------------
            _framePreview = gameObject.AddComponent<FramePreview>();
            _framePreview.Init(this);

            // ----------------------------------------------
            // PATTERN VIEWER
            // ----------------------------------------------
            _patternViewer = gameObject.AddComponent<PatternViewer>();
            _patternViewer.Init(this);

            _initialized = true;

            _textStyle = new GUIStyle();
            _textStyle.font = Resources.Load("Fonts/04b03") as Font;
            _textStyle.normal.textColor = new Color(0.8f, 0.8f, 0.8f);
            _textStyle.fontSize = 20;

            _textStyleRed = new GUIStyle(_textStyle);
            _textStyleRed.normal.textColor = new Color(0.8f, 0.2f, 0.2f);

            _textStyleFocused = new GUIStyle();
            _textStyleFocused.font = Resources.Load("Fonts/04b03") as Font;
            _textStyleFocused.normal.textColor = Color.white;
            Texture2D black = new Texture2D(1, 1);
            black.SetPixel(0, 0, Color.black);
            black.Apply();
            _textStyleFocused.normal.background = black;
            _textStyleFocused.fontSize = 20;

            _toolMode = ToolMode.Brush;
        //			Cursor.SetCursor(cursorBrush, Vector2.zero, CursorMode.Auto);

            _canvas.SetOnionSkinMode((OnionSkinMode)PlayerPrefs.GetInt("onionSkinMode", 0));
            _canvas.RefreshOnionSkin();

            _canvas.SetMirroringMode((MirroringMode)PlayerPrefs.GetInt("mirroringMode", 0));

            _consoleText = gameObject.AddComponent<GUIText>();
            _consoleText.color = Color.black;
            _consoleText.font = Resources.Load("Fonts/04b03") as Font;
            _consoleText.fontSize = 12;
            _consoleText.transform.position = new Vector2(0.0025f, 0);
            _consoleText.anchor = TextAnchor.LowerLeft;

            _consoleTextWrap = gameObject.AddComponent<ConsoleTextSetter>();

            string animData = PlayerPrefs.GetString("animData", "");
            Debug.Log("animData: " + animData);
            if(animData != "")
                LoadAnimationString(animData);
        }

        return _initialized;
    }