Пример #1
0
        private void MCListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            //listView1.Select();
            //listView1.SelectedItems[0].Selected = true;

            if (MCListView.SelectedIndices.Count == 0)
            {
                textBox1.Clear();
            }
            else
            {
                EEUniverse.Library.Message item = messages[listView1.SelectedItems[0].Text][listBox2.SelectedIndex].Item2;
                int index = MCListView.SelectedIndices[0];
                if (item[index].GetType().ToString() == "System.Byte[]")
                {
                    textBox1.Text      = "Byte found, can't convert";
                    textBox1.ForeColor = Color.Red;
                }
                else
                {
                    textBox1.Text      = item[index].ToString();
                    textBox1.ForeColor = SystemColors.WindowText;
                }
            }
        }
Пример #2
0
 private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
 {
     MCListView.Items.Clear();
     textBox1.Clear();
     //listView1.Select();
     if (listBox2.SelectedIndex != -1)
     {
         EEUniverse.Library.Message item = messages[listView1.SelectedItems[0].Text][listBox2.SelectedIndex].Item2;
         for (int num = 0; num < item.Count; num += 1)
         {
             MCListView.Items.Add("[" + num + "]").SubItems.Add(item[num].GetType().ToString());
             if (protocol.Count > 0)
             {
                 if (protocol.ContainsKey(listView1.SelectedItems[0].Text))
                 {
                     if (protocol[listView1.SelectedItems[0].Text].Data.ContainsKey(num))
                     {
                         JToken line = protocol[listView1.SelectedItems[0].Text].Data[num];
                         if (line.ToString() == item[num].GetType().ToString())
                         {
                             MCListView.Items[num].ForeColor = Color.Green;
                         }
                         else
                         {
                             MCListView.Items[num].ForeColor = Color.Red;
                         }
                     }
                     else
                     {
                         MCListView.Items[num].ForeColor = Color.DarkBlue;
                     }
                 }
             }
             else
             {
                 MCListView.Items[num].ForeColor = Color.DarkBlue;
             }
         }
     }
 }
Пример #3
0
        private void OnMessage(object sender, Message m)
        {
            Console.WriteLine(m.Type);
            data.Parse(m);
            switch (m.Type)
            {
            case MessageType.Init:
                bgcolor = data.BackgroundColor;
                ReloadPicturebox();
                listBox1.Invoke((Action) delegate()
                {
                    listBox1.Items.Clear();
                    zones.Clear();
                    pictureBoxWithInterpolationMode1.Image = b2 = new Bitmap(data.Width, data.Height);
                    g2 = Graphics.FromImage(b2);
                    foreach (var item in data.Zones.Values)
                    {
                        var z = new MyZone(item.Id, (int)item.Type);
                        zones.Add(item.Id, z);
                        listBox1.Items.Add(z);
                    }
                });
                DrawZone(-1);
                break;

            case MessageType.ZoneEdit:
                DrawZone(-1);
                break;

            case MessageType.ZoneCreate:
            {
                int id = -1;
                listBox1.Invoke((Action) delegate()
                    {
                        id    = m.GetInt(0);
                        var z = new MyZone(id, m.GetInt(1));
                        zones.Add(id, z);
                        listBox1.Items.Add(z);
                    });
                DrawZone(-1);
                break;
            }

            case MessageType.ZoneDelete:
            {
                listBox1.Invoke((Action) delegate()
                    {
                        var id = m.GetInt(0);
                        var z  = zones[id];
                        zones.Remove(id);
                        listBox1.Items.Remove(z);
                    });
                DrawZone(-1);
                break;
            }

            case MessageType.PlaceBlock:
                this.Invoke((Action) delegate()
                {
                    int l = m.GetInt(1), x = m.GetInt(2), y = m.GetInt(3), id = m.GetInt(4);
                    if (l == 0)
                    {
                        b.SetPixel(x, y, GetColor((int)data.Blocks[1, x, y].Id, id, bgcolor));
                    }
                    else
                    {
                        b.SetPixel(x, y, GetColor(id, (int)data.Blocks[0, x, y].Id, bgcolor));
                    }
                    pictureBox1.Invalidate();
                });
                break;

            case MessageType.BgColor:
                bgcolor = m.GetInt(0);
                ReloadPicturebox();
                break;

            case MessageType.Clear:
                bgcolor = -1;
                ReloadPicturebox();
                listBox1.Invoke((Action) delegate() { listBox1.Items.Clear(); });
                zones.Clear();
                DrawZone(-1);
                break;

            case MessageType.PlayerMove:
            {
                var id = m.GetInt(0);
                if (pid == id)
                {
                    var  p     = data.Players[id];
                    var  f     = p.Keys;
                    bool space = f.HasFlag(MovementKeys.Spacebar),
                         up    = f.HasFlag(MovementKeys.Up),
                         down  = f.HasFlag(MovementKeys.Down),
                         left  = f.HasFlag(MovementKeys.Left),
                         right = f.HasFlag(MovementKeys.Right);
                    var x      = p.X;
                    var y      = p.Y;
                    this.Invoke((Action) delegate
                        {
                            var b = Color.Black;
                            var g = Color.LimeGreen;
                            pictureBoxSpace.BackColor = space ? g : b;
                            pictureBoxUp.BackColor    = up ? g : b;
                            pictureBoxDown.BackColor  = down ? g : b;
                            pictureBoxLeft.BackColor  = left ? g : b;
                            pictureBoxRight.BackColor = right ? g : b;
                            label4.Text = $"X: {x}\nY: {y}";
                        });
                }
            }
            break;

            case MessageType.PlayerAdd:
            case MessageType.PlayerJoin:
                this.Invoke((Action) delegate
                {
                    var id = m.GetInt(0);
                    var p  = new MyPlayer(id, m.GetString(1));
                    players.Add(id, p);
                    listBox2.Items.Add(p);
                });
                break;

            case MessageType.PlayerExit:
                this.Invoke((Action) delegate
                {
                    var id = m.GetInt(0);
                    var p  = players[id];
                    players.Remove(id);
                    listBox2.Items.Remove(p);
                });
                break;
            }
        }
Пример #4
0
        //CountdownEvent ce = new CountdownEvent(1);
        private void OnMessage(object sender, EEUniverse.Library.Message m)
        {
            void die()
            {
                cli.Dispose(); panelMain.InvokeX(() => EnableMainPanel());
            }

            switch (m.Type)
            {
            case MessageType.Init:
                re.Set();
                if (m.GetString(7) != m.GetString(1))
                {
                    die();
                    MessageBox.Show("not world owner", ".w.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                world = new RoomData(parsePlayerData: false);
                world.Parse(m);
                int       ww = world.Width, wh = world.Height;
                Stopwatch s = Stopwatch.StartNew();
                //ce.Reset();
                Task.Run(() =>
                {
                    //void PlaceBlock(int layer, int x, int y, int id)
                    //{
                    //    ce.AddCount();
                    //    con.SendAsync(MessageType.PlaceBlock, layer, x, y, id).ContinueWith((_) => ce.Signal());
                    //}
                    for (int j = 0; j < imgh; j++)    //y
                    {
                        int yy = j + y;
                        if (yy >= wh)
                        {
                            break;                     //out of bounds
                        }
                        for (int i = 0; i < imgw; i++) //x
                        {
                            int xx = i + x;
                            if (xx >= ww)
                            {
                                break;              //out of bounds
                            }
                            int b = idgrid[i, j];
                            if (skiptransparent && b == (int)BlockId.Black)
                            {
                                continue;
                            }
                            int l = ((BlockId)b).IsBackground() ? 0 : 1;

                            if (world[l, xx, yy].Id != b)
                            {
                                con.PlaceBlock(l, xx, yy, b);
                            }
                            if (l == 0)
                            {
                                if (glass)
                                {
                                    if (world[1, xx, yy].Id != (int)BlockId.Clear)
                                    {
                                        con.PlaceBlock(1, xx, yy, (int)BlockId.Clear);
                                    }
                                }
                                else if (world[1, xx, yy].Id != 0)
                                {
                                    con.PlaceBlock(1, xx, yy, 0);
                                }
                            }
                            //else if (i == 1)
                            //{
                            //    PlaceBlock(0, xx, yy, 0);//get rid of bg behind fg
                            //}
                        }
                    }
                    //Console.WriteLine(s.Elapsed);

                    //ce.Signal();
                    //ce.Wait();
                    s.Stop();
                    Console.WriteLine(s.Elapsed);
                    die();
                });
                break;
            }
        }