Esempio n. 1
0
 private void AudioToggleSet()
 {
     if (Data.muteAllSound || !Data.sfx && !Data.music)
     {
         audioToggleIcon.sprite = hammer2OptionsAtlas.Get("SoundOff");
     }
     else
     {
         audioToggleIcon.sprite = hammer2OptionsAtlas.Get("SoundOn");
     }
 }
Esempio n. 2
0
        public BlockTexForm(Atlas atlas, int n, int e, int s, int w, int t, int b)
        {
            InitializeComponent();

            northBox.Image  = atlas.Get(n);
            eastBox.Image   = atlas.Get(e);
            southBox.Image  = atlas.Get(s);
            westBox.Image   = atlas.Get(w);
            topBox.Image    = atlas.Get(t);
            bottomBox.Image = atlas.Get(b);

            idsLabel.Text = "   " + n + Environment.NewLine + w + " " + t + " " + e + " " + b + Environment.NewLine + "   " + s;
        }
Esempio n. 3
0
    void OnValidate()
    {
        if (atlas == null)
        {
            return;
        }

        int length = _text.Length;

        // Calculate number of characters
        int characterCount = 0;

        for (int i = 0; i < length; i++)
        {
            if (_text[i] != ' ')
            {
                characterCount++;
            }
        }

        // Get number of children
        int childCount = transform.childCount;

        if (characterCount > childCount)
        {
            // Enable all children
            for (int i = 0; i < childCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(true);
            }

            // Add new children
            for (int i = characterCount - childCount; i > 0; i--)
            {
                GameObject character = new GameObject((characterCount - i + 1).ToString());
                character.transform.SetParent(transform);
                character.transform.localScale    = Vector3.one;
                character.transform.localPosition = Vector3.zero;

                character.AddRectTransform();

                Image image = character.AddComponent <Image>();
                image.color         = _color;
                image.raycastTarget = false;
            }
        }
        else
        {
            for (int i = 0; i < characterCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(true);
            }

            for (int i = characterCount; i < childCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(false);
            }
        }

        // Check if empty
        if (length == 0)
        {
            gameObject.GetComponent <RectTransform>().sizeDelta = Vector2.zero;
            return;
        }

        int index = 0;

        float   width  = 0;
        float   height = 0;
        Vector2 size;

        // Set sprite
        for (int i = 0; i < length; i++)
        {
            char c = _text[i];

            if (c != ' ')
            {
                Transform child = transform.GetChild(index++);

                Image image = child.GetComponent <Image>();
                image.sprite = atlas.Get(c);
                image.SetNativeSize();

                size = child.GetComponent <RectTransform>().sizeDelta;

                width += size.x + _gap;

                if (size.y > height)
                {
                    height = size.y;
                }
            }
            else
            {
                width += spaceWidth - _gap;
            }
        }

        if (_text[length - 1] != ' ')
        {
            width -= _gap;
        }

        // Set size
        gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(width, height);

        // Get bottom-left position
        Vector2 position = _anchor.GetAnchoredPosition(width, height, _offsetX, _offsetY);

        RectTransform rectTransform;
        float         leftExtent;
        float         bottomExtent;

        index = 0;

        // Set position
        for (int i = 0; i < length; i++)
        {
            if (_text[i] != ' ')
            {
                Transform child = transform.GetChild(index++);

                rectTransform = child.GetComponent <RectTransform>();
                size          = rectTransform.sizeDelta;

                leftExtent   = size.x * 0.5f;
                bottomExtent = size.y * 0.5f;

                position.x += leftExtent;
                position.y += bottomExtent;

                rectTransform.anchoredPosition = position;

                position.x += size.x - leftExtent + _gap;
                position.y -= bottomExtent;
            }
            else
            {
                position.x += spaceWidth - _gap;
            }
        }
    }
Esempio n. 4
0
        private void drawMap(Graphics gfx, int blockSize, int byteNum)
        {
            if (byteNum == -3)
            {
                return;
            }

            // draw map
            SolidBrush brush    = new SolidBrush(Color.Black);
            SolidBrush poiBrush = new SolidBrush(Color.Black);

            pois = new List <MapPointOfInterest>();

            int   i, c, r;
            byte  b;
            float h;
            float scale = 255 / (maxHeight - minHeight);

            // selection lists
            List <int> selectedCellsColumn = new List <int>();

            if (highlightColumnsCheckbox.Checked)
            {
                foreach (ListViewItem item in columnTable.SelectedItems)
                {
                    selectedCellsColumn.Add((item.Tag as ColumnItem).ID);
                }
            }

            List <int> selectedCellsBlock = new List <int>();

            if (highlightBlockTexCheckbox.Checked)
            {
                foreach (ListViewItem item in blockTexTable.SelectedItems)
                {
                    int id = (item.Tag as BlockTexItem).ID;

                    // find all columns using this id
                    foreach (KeyValuePair <int, ColumnItem> cPair in columnItems)
                    {
                        ColumnItem cItem = cPair.Value;
                        if (cItem.FloorTextureID == id ||
                            cItem.A == id ||
                            cItem.B == id ||
                            cItem.C == id ||
                            cItem.D == id ||
                            cItem.E == id ||
                            cItem.F == id ||
                            cItem.G == id ||
                            cItem.H == id)
                        {
                            selectedCellsBlock.Add(cItem.ID);
                        }
                    }
                }
            }

            for (int y = 0; y < 160; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    int baseOffset = 404620 + (x + y * 256) * 12;

                    if (byteNum == -2)
                    {
                        int cid = BitConverter.ToInt16(data, baseOffset + 4);
                        r = (data[baseOffset + 10] >> 4);

                        if (cid < 0)
                        {
                            cid = columnItems[-cid].FloorTextureID;
                        }

                        gfx.DrawImage(atlas.Get(cid, r), x * blockSize, y * blockSize, blockSize, blockSize);

                        // collect points of interest
                        int poiValue = (data[baseOffset + 7] << 8) | data[baseOffset + 6];
                        if (poiValue > 0)
                        {
                            MapPointOfInterest poi = new MapPointOfInterest();
                            poi.Position = new PointF(x * blockSize + blockSize * 0.5f, y * blockSize + blockSize * 0.5f);
                            poi.Value    = poiValue;
                            pois.Add(poi);
                        }
                    }
                    else
                    {
                        if (byteNum >= 0)
                        {
                            // simple byte map (NOTE: some planes contain values invisible in grayscale)
                            i           = baseOffset + byteNum;
                            b           = data[i];
                            brush.Color = Color.FromArgb(255, b, b, b);
                        }
                        else
                        {
                            // normalized heightmap
                            i           = baseOffset + 2;
                            h           = data[i] / 256 + data[i + 1] - minHeight;
                            c           = (int)Math.Floor(h * scale);
                            c           = Math.Max(0, Math.Min(255, c));
                            brush.Color = Color.FromArgb(255, c, c, c);

                            // special areas

                            /*if (data[baseOffset + 10] > 0)
                             * {
                             *  brush.Color = Color.Red;
                             * }*/
                        }

                        if (selectedCellsColumn.Count > 0 || selectedCellsBlock.Count > 0)
                        {
                            // get map column index at current position
                            int cid = BitConverter.ToInt16(data, baseOffset + 4);
                            if (cid < 0)
                            {
                                if (selectedCellsColumn.Contains(-cid))
                                {
                                    brush.Color = Color.Purple;
                                }
                                if (selectedCellsBlock.Contains(-cid))
                                {
                                    brush.Color = Color.Violet;
                                }
                            }
                        }

                        gfx.FillRectangle(brush, x * blockSize, y * blockSize, blockSize, blockSize);
                    }
                }
            }


            foreach (MapPointOfInterest poi in pois)
            {
                poiBrush.Color = Color.FromArgb(20, 255, 255, 0);
                //gfx.FillRectangle(Brushes.Yellow, x * blockSize, y * blockSize, blockSize, blockSize);
                gfx.FillCircle(poiBrush, poi.Position.X, poi.Position.Y, 3.0f * blockSize);
                SizeF ts = gfx.MeasureString(poi.Value.ToString(), SystemFonts.DefaultFont);
                gfx.DrawString(poi.Value.ToString(), SystemFonts.DefaultFont, Brushes.Black, poi.Position.X - ts.Width * 0.5f + 1, poi.Position.Y - ts.Height * 0.5f + 1);
                gfx.DrawString(poi.Value.ToString(), SystemFonts.DefaultFont, Brushes.White, poi.Position.X - ts.Width * 0.5f, poi.Position.Y - ts.Height * 0.5f);
            }
        }