コード例 #1
0
ファイル: InputSubscriber.cs プロジェクト: Koneke/Farbase
        public void Update(fbEngine engine)
        {
            if (subscriptions == null)
            {
                return;
            }

            foreach (string binding in subscriptions)
            {
                if (binding[0] == '+')
                {
                    string _binding = binding.Substring(1, binding.Length - 1);
                    if (engine.BindingHeld(_binding))
                    {
                        subscriber.ReceiveInput(binding);
                    }
                }
                else
                {
                    if (engine.BindingPressed(binding))
                    {
                        subscriber.ReceiveInput(binding);
                    }
                }
            }
        }
コード例 #2
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();
        }
コード例 #3
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 protected ContainerWidget(
     fbEngine engine,
     fbInterface ui
     ) : base(engine, ui)
 {
     Children = new List <Widget>();
 }
コード例 #4
0
ファイル: fbApplication.cs プロジェクト: Koneke/Farbase
        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();
        }
コード例 #5
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 public SideBySideWidgets(
     fbEngine engine,
     fbInterface ui,
     int internalPadding = 0
     ) : base(engine, ui)
 {
     this.internalPadding = internalPadding;
 }
コード例 #6
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 public ListBox(
     fbEngine engine,
     fbInterface ui,
     int internalPadding = 0
     ) : base(engine, ui)
 {
     this.internalPadding = internalPadding;
 }
コード例 #7
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 public Label(
     string text,
     fbEngine engine,
     fbInterface ui,
     int depth = -1
     ) : base(engine, ui, depth)
 {
     content = new SmartText(text, ui);
 }
コード例 #8
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 public CheckBox(
     fbEngine engine,
     fbInterface ui,
     int depth = -1
     ) : base(engine, ui, depth)
 {
     subscriber = new InputSubscriber(this);
     subscriber.Register();
 }
コード例 #9
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 public Image(
     string texture,
     fbEngine engine,
     fbInterface ui,
     float scale = 1f
     ) : base(engine, ui)
 {
     this.texture = texture;
     this.scale   = scale;
 }
コード例 #10
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 protected Widget(
     fbEngine engine,
     fbInterface ui,
     int depth = -1
     )
 {
     this.engine = engine;
     this.ui     = ui;
     this.depth  = depth;
     Conditions  = new List <fbCondition>();
 }
コード例 #11
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
 public TextureButton(
     string texture,
     Action reaction,
     fbEngine engine,
     fbInterface ui,
     float scale = 1f
     ) : base("", reaction, engine, ui)
 {
     this.texture = texture;
     this.scale   = scale;
 }
コード例 #12
0
ファイル: fbGame.cs プロジェクト: Koneke/Farbase
 //moving this out like this and *MANUALLY* calling it in fbApplication.
 //this means that fbGame doesn't even need an engine reference any more.
 //that in turn means that we can keep an entire fbGame in our server
 //app, which acts exactly like a normal client would.
 //only difference is that we give it another eventhandler.
 public void SetupClientSideEventHandler(fbEngine engine)
 {
     EventHandler = new GameEventHandler(this, engine)
                    .Subscribe(engine, EventType.NameEvent)
                    .Subscribe(engine, EventType.UnitMoveEvent)
                    .Subscribe(engine, EventType.BuildStationEvent)
                    .Subscribe(engine, EventType.BuildUnitEvent)
                    .Subscribe(engine, EventType.CreateUnitEvent)
                    .Subscribe(engine, EventType.PlayerDisconnect)
                    .Subscribe(engine, EventType.SetProjectEvent)
                    .Subscribe(engine, EventType.ProjectFinishedEvent);
 }
コード例 #13
0
ファイル: fbUI.cs プロジェクト: Koneke/Farbase
        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();
        }
コード例 #14
0
ファイル: fbCamera.cs プロジェクト: Koneke/Farbase
        public fbCamera(fbEngine engine)
        {
            this.engine = engine;
            Camera      = new fbRectangle(
                Vector2.Zero,
                engine.GetSize()
                );

            new InputSubscriber(this)
            .Subscribe("+camera-up")
            .Subscribe("+camera-down")
            .Subscribe("+camera-left")
            .Subscribe("+camera-right")
            .Register();
        }
コード例 #15
0
ファイル: fbInterface.cs プロジェクト: Koneke/Farbase
        public fbInterface(
            fbGame game,
            fbEngine engine
            )
        {
            Game         = game;
            Engine       = engine;
            Camera       = new fbCamera(engine);
            Widgets      = new List <Widget>();
            NamedWidgets = new Dictionary <string, Widget>();

            DefaultTheme = new Theme(
                new ColorSet(
                    Color.White,
                    Color.White,
                    Color.Gray
                    ),
                new ColorSet(
                    new Color(0, 0, 0, 0.6f),
                    Color.DarkGray * 0.9f,
                    Color.DarkGray * 0.7f
                    ),
                new ColorSet(
                    Color.White * 0.8f,
                    Color.White * 0.8f,
                    Color.White * 0.8f
                    )
                );

            LoadUIFromXml("ui/main.xml");

            EventHandler = (InterfaceEventHandler)
                           new InterfaceEventHandler(game, this)
                           .Subscribe(engine, EventType.NameEvent)
                           .Subscribe(engine, EventType.BuildUnitEvent);

            new InterfaceInputHandler(this);
        }
コード例 #16
0
ファイル: Bite.cs プロジェクト: Koneke/Farbase
        public void Draw(fbEngine engine)
        {
            int col = 0;
            int row = 0;

            foreach (char c in Text)
            {
                if (c == '\n')
                {
                    col = 0;
                    row++;
                    continue;
                }

                Vector2 fontSpot =
                    new Vector2(
                        c % 16,
                        (c - (c % 16)) / 16f
                        ) * (Font.CharSize + new Vector2(1))
                    + new Vector2(1);

                engine.Draw(
                    new DrawCall(
                        Font.FontSheet,
                        new fbRectangle(
                            Position +
                            Font.CharSize * new Vector2(col++, row),
                            Font.CharSize
                            ),
                        new fbRectangle(fontSpot, Font.CharSize),
                        Depth,
                        Coloring
                        )
                    );
            }
        }
コード例 #17
0
 public GameEventHandler(fbGame fbGame, fbEngine engine)
     : base(fbGame)
 {
     this.engine = engine;
 }
コード例 #18
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);
        }
コード例 #19
0
ファイル: Bite.cs プロジェクト: Koneke/Farbase
 public void Draw(fbEngine engine)
 {
     engine.Draw(this);
 }
コード例 #20
0
 public fbEventHandler Subscribe(fbEngine engine, EventType type)
 {
     engine.Subscribe(this, type);
     return(this);
 }