Esempio n. 1
0
        public InterfaceInputHandler(fbInterface ui)
        {
            this.ui = ui;
            game    = ui.Game;
            engine  = ui.Engine;

            new InputSubscriber(this)
            .Subscribe("move-nw")
            .Subscribe("move-n")
            .Subscribe("move-ne")
            .Subscribe("move-e")
            .Subscribe("move-se")
            .Subscribe("move-s")
            .Subscribe("move-sw")
            .Subscribe("move-w")
            .Subscribe("pass")
            .Subscribe("warp")
            .Subscribe("bombard")
            .Subscribe("dev-login")
            .Subscribe("dev-test")
            .Subscribe("dev-save")
            .Subscribe("dev-spawn-station")
            .Subscribe("dev-spawn-planet")
            .Subscribe("dev-spawn-playerstart")
            .Subscribe("select-next-idle")
            .Subscribe("quit")
            .Register();
        }
Esempio n. 2
0
        protected override void Initialize()
        {
            base.Initialize();
            SpriteBatch = new SpriteBatch(GraphicsDevice);

            Engine = new fbEngine(this);
            Engine.SetSize(1280, 720);
            LoadTexturesFromFile("cfg/textures.cfg");

            Engine.DefaultFont           = new Font();
            Engine.DefaultFont.FontSheet = Engine.GetTexture("font");
            Engine.DefaultFont.CharSize  = new Vector2(8);

            NetMessage3.Setup();

            Game       = new fbGame();
            Game.Ready = false;
            Game.SetupClientSideEventHandler(Engine);

            //eugh
            fbNetClient.Game = Game;

            UI = new fbInterface(Game, Engine);

            Engine.StartNetClient();
        }
Esempio n. 3
0
 public SmartText(
     string text, fbInterface ui
     )
 {
     Text    = text;
     this.ui = ui;
 }
Esempio n. 4
0
 protected ContainerWidget(
     fbEngine engine,
     fbInterface ui
     ) : base(engine, ui)
 {
     Children = new List <Widget>();
 }
Esempio n. 5
0
 public SideBySideWidgets(
     fbEngine engine,
     fbInterface ui,
     int internalPadding = 0
     ) : base(engine, ui)
 {
     this.internalPadding = internalPadding;
 }
Esempio n. 6
0
 public ListBox(
     fbEngine engine,
     fbInterface ui,
     int internalPadding = 0
     ) : base(engine, ui)
 {
     this.internalPadding = internalPadding;
 }
Esempio n. 7
0
 public CheckBox(
     fbEngine engine,
     fbInterface ui,
     int depth = -1
     ) : base(engine, ui, depth)
 {
     subscriber = new InputSubscriber(this);
     subscriber.Register();
 }
Esempio n. 8
0
 public Label(
     string text,
     fbEngine engine,
     fbInterface ui,
     int depth = -1
     ) : base(engine, ui, depth)
 {
     content = new SmartText(text, ui);
 }
Esempio n. 9
0
 public Image(
     string texture,
     fbEngine engine,
     fbInterface ui,
     float scale = 1f
     ) : base(engine, ui)
 {
     this.texture = texture;
     this.scale   = scale;
 }
Esempio n. 10
0
 protected Widget(
     fbEngine engine,
     fbInterface ui,
     int depth = -1
     )
 {
     this.engine = engine;
     this.ui     = ui;
     this.depth  = depth;
     Conditions  = new List <fbCondition>();
 }
Esempio n. 11
0
 public TextureButton(
     string texture,
     Action reaction,
     fbEngine engine,
     fbInterface ui,
     float scale = 1f
     ) : base("", reaction, engine, ui)
 {
     this.texture = texture;
     this.scale   = scale;
 }
Esempio n. 12
0
        public Button(
            string label,
            Action reaction,
            fbEngine engine,
            fbInterface ui
            ) : base(engine, ui)
        {
            this.label    = new SmartText(label, ui);
            this.reaction = reaction;

            subscriber = new InputSubscriber(this);
            subscriber.Register();
        }
Esempio n. 13
0
        public static Widget WidgetFromXml(
            XmlNode xml,
            fbInterface ui,
            fbEngine engine
            )
        {
            Dictionary <string, XmlNode> nodes
                = new Dictionary <string, XmlNode>();

            foreach (XmlNode child in xml.ChildNodes)
            {
                if (child.Name == "#comment")
                {
                    continue;
                }
                nodes.Add(child.Name, child);
            }

            Widget w;

            int internalPadding = 0;

            if (nodes.ContainsKey("internalpadding"))
            {
                internalPadding = Int32.Parse(
                    nodes["internalpadding"].InnerText
                    );

                nodes.Remove("internalpadding");
            }

            switch (xml.Name.ToLower())
            {
            case "button":
                w = new Button(
                    nodes["content"].InnerText,
                    null,
                    engine,
                    ui
                    );

                if (nodes.ContainsKey("keybind"))
                {
                    ((Button)w).Subscribe(nodes["keybind"].InnerText);
                    nodes.Remove("keybind");
                }

                nodes.Remove("content");
                break;

            case "checkbox":
                w = new CheckBox(
                    engine,
                    ui
                    );

                if (nodes.ContainsKey("keybind"))
                {
                    ((CheckBox)w).Subscribe(nodes["keybind"].InnerText);
                    nodes.Remove("keybind");
                }
                break;

            case "image":
                w = new Image(
                    nodes["content"].InnerText,
                    engine,
                    ui
                    );

                nodes.Remove("content");
                break;

            case "label":
                w = new Label(
                    nodes["content"].InnerText,
                    engine,
                    ui
                    );

                nodes.Remove("content");
                break;

            case "texturebutton":
                float scale = 1f;

                if (nodes.ContainsKey("scale"))
                {
                    scale = float.Parse(nodes["scale"].InnerText);
                    nodes.Remove("scale");
                }

                w = new TextureButton(
                    nodes["content"].InnerText,
                    null,
                    engine,
                    ui,
                    scale
                    );

                if (nodes.ContainsKey("keybind"))
                {
                    ((Button)w).Subscribe(nodes["keybind"].InnerText);
                    nodes.Remove("keybind");
                }

                nodes.Remove("content");
                break;

            // === === === === === === === === === ===

            case "listbox":
                w = new ListBox(
                    engine,
                    ui,
                    internalPadding
                    );
                break;

            case "sidebyside":
                w = new SideBySideWidgets(
                    engine,
                    ui,
                    internalPadding
                    );
                break;

            default:
                throw new ArgumentException();
            }

            if (nodes.ContainsKey("margins"))
            {
                int[] marginValues =
                    nodes["margins"].InnerText
                    .Split(',')
                    .Select(Int32.Parse)
                    .ToArray();

                switch (marginValues.Length)
                {
                case 1:
                    w.Margins(
                        marginValues[0]
                        );
                    break;

                case 2:
                    w.Margins(
                        marginValues[0],
                        marginValues[1]
                        );
                    break;

                case 4:
                    w.Margins(
                        marginValues[0],
                        marginValues[1],
                        marginValues[2],
                        marginValues[3]
                        );
                    break;
                }

                nodes.Remove("margins");
            }

            if (nodes.ContainsKey("padding"))
            {
                int[] paddingValues =
                    nodes["padding"].InnerText
                    .Split(',')
                    .Select(Int32.Parse)
                    .ToArray();

                switch (paddingValues.Length)
                {
                case 1:
                    w.Padding(
                        paddingValues[0]
                        );
                    break;

                case 2:
                    w.Padding(
                        paddingValues[0],
                        paddingValues[1]
                        );
                    break;

                case 4:
                    w.Padding(
                        paddingValues[0],
                        paddingValues[1],
                        paddingValues[2],
                        paddingValues[3]
                        );
                    break;
                }

                nodes.Remove("padding");
            }

            if (nodes.ContainsKey("alignment"))
            {
                string alignment = nodes["alignment"].InnerText.ToLower();
                string halign    = alignment.Split(',')[0];
                string valign    = alignment.Split(',')[1];

                Dictionary <string, HAlignment> hAlignments =
                    new Dictionary <string, HAlignment>
                {
                    { "left", HAlignment.Left },
                    { "center", HAlignment.Center },
                    { "right", HAlignment.Right }
                };

                Dictionary <string, VAlignment> vAlignments =
                    new Dictionary <string, VAlignment>
                {
                    { "top", VAlignment.Top },
                    { "center", VAlignment.Center },
                    { "bottom", VAlignment.Bottom }
                };

                w.SetAlign(hAlignments[halign], vAlignments[valign]);

                nodes.Remove("alignment");
            }

            if (nodes.ContainsKey("borderwidth"))
            {
                int width = Int32.Parse(nodes["borderwidth"].InnerText);
                w.SetBorder(width);

                nodes.Remove("borderwidth");
            }

            if (nodes.ContainsKey("backgroundalpha"))
            {
                float alpha = float.Parse(nodes["backgroundalpha"].InnerText);
                w.SetBackgroundAlpha(alpha);

                nodes.Remove("backgroundalpha");
            }

            if (nodes.ContainsKey("tooltip"))
            {
                w.SetTooltip(nodes["tooltip"].InnerText);

                nodes.Remove("tooltip");
            }

            if (nodes.ContainsKey("children"))
            {
                foreach (XmlNode child in nodes["children"].ChildNodes)
                {
                    ((ContainerWidget)w)
                    .AddChild(WidgetFromXml(child, ui, engine));
                }

                nodes.Remove("children");
            }

            if (nodes.ContainsKey("id"))
            {
                ui.NamedWidgets.Add(nodes["id"].InnerText.ToLower(), w);

                nodes.Remove("id");
            }

            //if we forgot to read some node
            //(because we want to read *EVERYTHING*
            if (nodes.Count > 0)
            {
                throw new FormatException();
            }

            return(w);
        }
Esempio n. 14
0
 public InterfaceEventHandler(fbGame game, fbInterface ui)
     : base(game)
 {
     Game    = game;
     this.ui = ui;
 }