Beispiel #1
0
                private Color GetStatusColor(MonitorInfo info, Color defaultColor)
                {
                    Color color = defaultColor;

                    InfoItem item; if (info.TryGetValue("block", out item))

                    {
                        CommonInfo commonInfo = item as CommonInfo;
                        if (commonInfo.IsBeingHacked)
                        {
                            if ((FrameCount % 1.0f) < 0.5f)
                            {
                                color = Color.Red;
                            }
                            else
                            {
                                color = Color.Yellow;
                            }
                        }
                        else if (!commonInfo.IsFunctional)
                        {
                            color = Color.Red;
                        }
                        //else if (!info.BlockInfo.IsEnabled)
                        //    color = Color.Gray;
                        else if (!commonInfo.IsWorking)
                        {
                            color = Color.Yellow;
                        }
                    }

                    return(color);
                }
Beispiel #2
0
 public void Totalize(MonitorInfo infos)
 {
     foreach (KeyValuePair <string, InfoItem> item in this)
     {
         InfoItem info; if (infos.TryGetValue(item.Key, out info))
         {
             item.Value.Totalize(info);
         }
     }
 }
Beispiel #3
0
                // ----
                public BoundingBox2 AppendBlockIcon(SpriteBuilder maker, BoxStyle style, IMonitorBlock monitorBlock, MonitorInfo info)
                {
                    BoundingBox2  box = new BoundingBox2(Cursor, Cursor);
                    SpriteBuilder sb  = new SpriteBuilder(maker);

                    InfoItem item; if (info.TryGetValue("block", out item))

                    {
                        CommonInfo commonInfo = item as CommonInfo;
                        string     icon       = "";

                        if (commonInfo.IsBeingHacked)
                        {
                            if ((FrameCount % 1.0f) < 0.5f)
                            {
                                icon = SpriteId.Danger;
                            }
                            else
                            {
                                icon = SpriteId.Cross;
                            }
                        }
                        else if (!commonInfo.IsFunctional)
                        {
                            icon = SpriteId.Cross;
                        }
                        //else if (!info.BlockInfo.IsEnabled)
                        //    icon = SpriteId.Construction;
                        else if (!commonInfo.IsWorking)
                        {
                            icon = SpriteId.Danger;
                        }

                        if (icon != "")
                        {
                            sb.SpriteBox(style, icon);
                            //box = maker.SpriteBox(Sprites, style, icon);
                        }
                        else
                        {
                            SpriteDataBuilder sdb; if (IconRes.TryGetValue(commonInfo.Icon, out sdb))
                            {
                                sb.SpriteDataBox(style, sdb);
                            }
                            //box = maker.SpriteDataBox(Sprites, style, sdb);
                        }
                    }

                    Cursor.X += sb.Box.Width;
                    //Cursor.X += box.Width;
                    Sprites.AddRange(sb.Sprites);
                    return(sb.Box);
                }
            public bool TryRender(SpriteBuilder sb, BoxStyle style, MonitorContent content, MonitorInfo info)
            {
                Func <IContentRenderer> provider; if (TryGetValue(content.Type, out provider))

                {
                    IContentRenderer renderer = provider();
                    if (renderer is IInfoContentRenderer)
                    {
                        InfoItem item; if (info.TryGetValue(content.Type, out item))
                        {
                            (renderer as IInfoContentRenderer).Render(sb, style, content, item); return(true);
                        }
                    }
                    else
                    {
                        renderer.Render(sb, style, content); return(true);
                    }
                }
                return(false);
            }
Beispiel #5
0
                public BoundingBox2 AppendMonitorContents(IMonitorBlock monb, MonitorInfo info)
                {
                    BoundingBox2  box       = new BoundingBox2(Cursor, Cursor);
                    BoundingBox2  box2      = new BoundingBox2(Cursor, Cursor);
                    bool          debug     = monb.Options.ContainsKey("debug");
                    Vector2       preCursor = Cursor;
                    SpriteBuilder mk;
                    BoxStyle      style;
                    MonitorOption opt;
                    float         padding = Padding;

                    mk = new SpriteBuilder(Surface, Cursor, Scale, FrameCount)
                    {
                        Color   = Color,
                        BGColor = BGColor
                    };

                    if (monb.Options.TryGetValue("scale", out opt))
                    {
                        mk.Scale = opt.FloatValue;
                    }
                    if (monb.Options.TryGetValue("padding", out opt))
                    {
                        padding = opt.FloatValue;
                    }
                    if (monb.Options.TryGetValue("color", out opt))
                    {
                        mk.Color = opt.ColorValue;
                    }
                    if (monb.Options.TryGetValue("bgcolor", out opt))
                    {
                        mk.BGColor = opt.ColorValue;
                    }

                    if (monb.Options.ContainsKey("sicon"))
                    {
                        style = new BoxStyle(28, 28, 2);
                        box2  = AppendBlockIcon(mk, style, monb, info);
                    }
                    else if (monb.Options.ContainsKey("icon"))
                    {
                        style = new BoxStyle(56, 56, 4);
                        box2  = AppendBlockIcon(mk, style, monb, info);
                    }

                    mk = new SpriteBuilder(Surface, Cursor, Scale, FrameCount)
                    {
                        Color   = Color,
                        BGColor = BGColor
                    };

                    if (monb.Options.TryGetValue("scale", out opt))
                    {
                        mk.Scale = opt.FloatValue;
                    }
                    if (monb.Options.TryGetValue("padding", out opt))
                    {
                        padding = opt.FloatValue;
                    }
                    if (monb.Options.TryGetValue("color", out opt))
                    {
                        mk.Color = opt.ColorValue;
                    }
                    if (monb.Options.TryGetValue("bgcolor", out opt))
                    {
                        mk.BGColor = opt.ColorValue;
                    }

                    if (monb.Options.ContainsKey("stscolor"))
                    {
                        mk.Color = GetStatusColor(info, mk.Color);
                    }

                    Vector2       cursor = mk.Cursor;
                    SpriteBuilder sb;

                    foreach (List <MonitorContent> contentList in monb.Contents)
                    {
                        sb = new SpriteBuilder(mk, cursor);

                        foreach (MonitorContent content in contentList)
                        {
                            if (content.Width == null)
                            {
                                style = new BoxStyle(content.Align, padding);
                            }
                            else
                            {
                                style = new BoxStyle(new Vector2((float)content.Width, 29), content.Align, padding);
                            }

                            if (!CRProvider.TryRender(sb, style, content, info))
                            {
                                sb.EmptyBox(style);
                            }
                        }

                        cursor.Y += sb.Box.Height;

                        //mk.Cursor.X = cursor.X;
                        //mk.Cursor.Y = Cursor.Y + box.Height;

                        Sprites.AddRange(sb.Sprites);
                        box = Merge(box, sb.Box);
                    }

                    box = Merge(box, box2);

                    if (debug)
                    {
                        MySprite rect  = MySprite.CreateSprite(SpriteId.SquareHollow, box.Center, box.Size);
                        int      index = 0;
                        InfoItem item; if (info.TryGetValue("block", out item))
                        {
                            index = (item as CommonInfo).Index;
                        }

                        if (index % 2 == 0)
                        {
                            rect.Color = new Color(255, 0, 0, 64);
                        }
                        else
                        {
                            rect.Color = new Color(255, 255, 0, 64);
                        }

                        Sprites.Add(rect);
                    }

                    Cursor.X = preCursor.X + box.Width;
                    return(box);
                }