Exemplo n.º 1
0
        internal void Load(string filename)
        {
            _cells.Clear();

            List <SCellInfo> cells = JsonToFile <List <SCellInfo> > .Load(Environment.CurrentDirectory, filename + Form1.FileExt);

            if (cells == null || !cells.Any())
            {
                _owner.AddLogToConsole($"{filename} was empty", ELogLevel.IMPORTANT_INFO);
                return;
            }

            cells.ForEach(c =>
            {
                var cellcoord    = new Vector2i(c.x, c.y);
                CTileDescr descr = _owner.GetTileDescrByTerrein(c.tile);
                if (descr != null)
                {
                    _cells.Add(cellcoord, new CCell(this, cellcoord, descr));
                }
                else
                {
                    _owner.AddLogToConsole($"Can't find descr for {c.tile} in {cellcoord}", ELogLevel.WARNING);
                }
            });

            _owner.AddLogToConsole($"{filename} was loaded", ELogLevel.IMPORTANT_INFO);
        }
Exemplo n.º 2
0
        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            int i = -1;

            switch (e.KeyChar)
            {
            case '1': i = 0; break;

            case '2': i = 1; break;

            case '3': i = 2; break;

            case '4': i = 3; break;

            case '5': i = 4; break;

            case '6': i = 5; break;

            case '7': i = 6; break;

            case '8': i = 7; break;

            case '9': i = 8; break;
            }
            if (i != -1)
            {
                CTileDescr descr = _settings.ElementAtOrDefault(i);
                if (descr != null)
                {
                    SelectDescr(descr);
                }
            }
        }
Exemplo n.º 3
0
        internal void AddCell(Rectangle inWindowRect, Point location, CTileDescr tiledescr)
        {
            Vector2i cellcoord = MouseCoordToCellCood(inWindowRect, location);

            if (_cells.ContainsKey(cellcoord))
            {
                CCell cell = _cells[cellcoord];
                if (cell.TileDescr != tiledescr)
                {
                    cell.SetTileDescr(tiledescr);
                    _owner.AddLogToConsole($"Change cell: {cellcoord}", ELogLevel.INFO);
                }
            }
            else
            {
                _cells.Add(cellcoord, new CCell(this, cellcoord, tiledescr));
                _owner.AddLogToConsole($"Add cell: {cellcoord}", ELogLevel.INFO);
            }
        }
Exemplo n.º 4
0
 public void SetTileDescr(CTileDescr inTileDescr)
 {
     TileDescr = inTileDescr;
 }
Exemplo n.º 5
0
 public CCell(CGrid owner, Vector2i inCoord, CTileDescr inTileDescr)
 {
     _owner    = owner;
     Coord     = inCoord;
     TileDescr = inTileDescr;
 }
Exemplo n.º 6
0
 void SelectDescr(CTileDescr descr)
 {
     _selected_descr = descr;
     AddLogToConsole($"Select {_selected_descr.Descr}", ELogLevel.INFO);
 }
Exemplo n.º 7
0
        void AddColorPanel(int left, int top, int index, int margin_h, int width, int height, CTileDescr tile)
        {
            var pnl = new Panel();

            pnl.Location = new Point(left, top + index * (margin_h + height));
            pnl.Size     = new Size(width, height);
            pnlColors.Controls.Add(pnl);

            var cpnl    = new Panel();
            int imargin = 2;

            cpnl.Location    = new Point(imargin, imargin);
            cpnl.Size        = new Size(height - 2 * imargin, height - 2 * imargin);
            cpnl.BackColor   = tile.TileColor;
            cpnl.BorderStyle = BorderStyle.FixedSingle;
            cpnl.MouseDown  += MouseDownOnColor;
            pnl.Controls.Add(cpnl);

            var lblSymbol = new Label();

            lblSymbol.Text      = tile.TileMarker.ToString();
            lblSymbol.TextAlign = ContentAlignment.MiddleCenter;
            lblSymbol.Font      = pnl.Font;
            lblSymbol.Location  = new Point(0, 0);
            lblSymbol.Size      = new Size(cpnl.Size.Width, cpnl.Size.Height);
            lblSymbol.Enabled   = false; //чтоб не загораживал нажатие мыши
            cpnl.Controls.Add(lblSymbol);

            var lbl = new Label();

            lbl.Text     = tile.Descr;
            lbl.Font     = pnl.Font;
            lbl.Location = new Point(height, height / 2 - lbl.Size.Height / 2);
            lbl.Size     = new Size(pnl.Size.Width - lbl.Location.X, height - 2 * imargin);
            pnl.Controls.Add(lbl);

            _panel_descr.Add(cpnl, tile);
        }