public void InitializePanels(JoystickConfig config)
        {
            Title = config.Name;

            __CurrentConfig = config;

            var bitscounter = 0;

            for (int i = 0; i < __CurrentConfig.Controls.Count; i++)
            {
                var control = __CurrentConfig.Controls[i];

                if (control is JoystickAxle)
                {
                    AddAxle((JoystickAxle)control, i, bitscounter);
                }
                else if (control is ButtonsCollection)
                {
                    AddButtons((ButtonsCollection)control, i, bitscounter);
                }
                else if (control is HatSwitch)
                {
                    AddHat((HatSwitch)control, i, bitscounter);
                }

                bitscounter += control.Bits();
            }
        }
Beispiel #2
0
        private void createFromBoardCaptureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var dlg = new ParseJoyDialog();

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            var joy = new JoystickConfig();

            try
            {
                var parser = new DescriptionParser(joy);
                var data   = SplitValues(dlg.DescriptorText);
                parser.Parse(data.Select(s => uint.Parse(s, NumberStyles.HexNumber)).GetEnumerator());
                joy.VendorID        = dlg.VendorID;
                joy.ProductID       = dlg.ProductID;
                joy.ReportStructure = dlg.DescriptorText;
            }
            catch (Exception exx)
            {
                ShowError(exx.Message, CommonResources.ParseError);
                return;
            }

            ShowJoystickDialog(joy);
        }
Beispiel #3
0
 void OnJoystickToMapChangedHandler()
 {
     //If there is a Joystick to map
     if (CurrentJoystickBeingMapped != null)
     {
         joystickConfigPanel.SetActive(true);
         Debug.Log("Current joystick being mapped is: " + currentJoystickBeingMapped.name);
     }
     //If there is not, check if there is a Joystick in the queue waiting to be mapped.
     //TODO: Set the current joystick being mapped to null somehow after completely mapped.
     else
     {
         if (queueOfJoysticksToMap.Count > 0)
         {
             JoystickConfig newJoystickToMap = queueOfJoysticksToMap[0];
             queueOfJoysticksToMap.RemoveAt(0);
             joystickConfigPanel.SetActive(false);
             CurrentJoystickBeingMapped = newJoystickToMap;
         }
         else
         {
             joystickConfigPanel.SetActive(false);
         }
     }
 }
Beispiel #4
0
 public CodeGenerator(ProjectSettings settings, JoystickConfig joystick, DesignPanel[] panels, Func <Action, bool> executeStep)
 {
     Settings    = settings;
     JoyInfo     = joystick;
     Panels      = panels;
     ExecuteStep = executeStep;
 }
Beispiel #5
0
 /// <summary>
 /// Detects joystick being attached and detached.
 /// </summary>
 void OnJoystickToggle()
 {
     for (int i = 0; i < Input.GetJoystickNames().Length; i++)
     {
         //A just is attached
         if (Input.GetJoystickNames()[i] != null && Input.GetJoystickNames()[i].Length > 0)
         {
             //A joystick has just been attached
             if (joysticksAttached[i] == null)
             {
                 OnJoystickAttached(i, Input.GetJoystickNames()[i]);
             }
         }
         //A joystick has been detached
         else if (joysticksAttached[i] != null)
         {
             Debug.Log(Input.GetJoystickNames()[i] + " has been detached!");
             joysticksAttached[i] = null;
             if (CurrentJoystickBeingMapped.joystickNumber == i)
             {
                 CurrentJoystickBeingMapped = null;
             }
         }
     }
 }
Beispiel #6
0
        private void ShowJoystickDialog(JoystickConfig joy)
        {
            var dlg = new CreateJoystickDialog();

            dlg.JoystickInfo = joy;

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            if (__JoyInfos.All(j => j.ID != joy.ID))
            {
                __JoyInfos.Add(dlg.JoystickInfo);
            }
            else
            {
                __JoyInfos[__JoyInfos.FindIndex(j => j.ID == joy.ID)] = dlg.JoystickInfo;
            }

            UpdateJoystics();
            foreach (var panel in Panels)
            {
                panel.JoystickUpdated();
            }
            SetChangedState();
        }
Beispiel #7
0
        private void createFromBoardCaptureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var dlg = new ParseJoyDialog();

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            var joy = new JoystickConfig();

            try
            {
                var parser = new DescriptionParser(joy);
                var data   = dlg.DescriptorText.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                parser.Parse(data.Select(s => uint.Parse(s, NumberStyles.HexNumber)).GetEnumerator());
            }
            catch (Exception exx)
            {
                ShowError(exx.Message, "Parsing error");
                return;
            }

            ShowJoystickDialog(joy);
        }
Beispiel #8
0
 public override void FillJoyInfo(JoystickConfig joy)
 {
     joy.Controls.Add(new LevelingBits
     {
         Length = int.Parse(tbSize.Text),
         Name   = "DMMY"
     });
 }
Beispiel #9
0
    public InputHandler(Character c, Locomotion l, int n)
    {
        character  = c;
        locomotion = l;
        locomotion.Init();

        controller = new JoystickConfig(n);
        SwitchStates(0);
    }
Beispiel #10
0
        // -----------------
        public TouchJoystick() : base()
        {
            this.joyStateBinding = new JoystickStateBinding();
            this.pressBinding    = new DigitalBinding();

            this.centerWhenFollowing = false;

            this.config = new JoystickConfig();
            this.state  = new JoystickState(this.config);
        }
Beispiel #11
0
        private bool CheckJoystick()
        {
            var valid =
                __Panels.Count > 0 &&
                __Panels.Aggregate(true, (current, panel) => current & panel.Check());

            valid = valid &
                    ValidateControl(tbName, () => !string.IsNullOrWhiteSpace(tbName.Text));


            UInt16 v = 0;
            UInt16 p = 0;

            valid = valid & ValidateControl(tbVendorProduct, () =>
            {
                string[] vs = tbVendorProduct.Text.Split(':');
                if (vs.Length != 2)
                {
                    return(false);
                }

                return(UInt16.TryParse(vs[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out v) &
                       UInt16.TryParse(vs[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out p));
            });

            if (!valid)
            {
                return(false);
            }

            _joystickInfo = new JoystickConfig
            {
                Code            = wrex.Replace(tbName.Text, "").ToUpper(),
                Name            = tbName.Text,
                ProductID       = p,
                VendorID        = v,
                ReportStructure = __RepoprtStructure,
                ID = __ID != Guid.Empty ? __ID : Guid.NewGuid()
            };

            foreach (var panel in __Panels)
            {
                panel.FillJoyInfo(_joystickInfo);
            }

            if (_joystickInfo.Bits() % 8 != 0)
            {
                MessageBox.Show(this, "Wrong total bits number, must be multiple of 8", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            return(true);
        }
Beispiel #12
0
 public override void FillJoyInfo(JoystickConfig joy)
 {
     joy.Controls.Add(
         new ButtonsCollection()
     {
         Name             = tbName.Text,
         ConstantName     = tbCName.Text,
         ButtonsCount     = int.Parse(tbCount.Text),
         ButtonsStateBits = int.Parse(tbSize.Text)
     }
         );
 }
Beispiel #13
0
 public override void FillJoyInfo(JoystickConfig joy)
 {
     joy.Controls.Add(
         new JoystickAxle
     {
         Name     = tbName.Text,
         CName    = tbCName.Text,
         Length   = int.Parse(cbLength.Text),
         MinValue = int.Parse(tbMin.Text),
         MaxValue = int.Parse(tbMax.Text)
     });
 }
Beispiel #14
0
        private void LoadFile(string fname)
        {
            if (!File.Exists(fname))
            {
                return;
            }

            XDocument file;

            using (var reader = File.OpenText(fname))
            {
                file = XDocument.Load(reader);
            }

            modelsTabSwitch.TabPages.Clear();
            FRAMMapper.Clear();
            __JoyInfos.Clear();

            __JoyInfos.AddRange(JoystickConfig.LoadFromXML(file));
            __Settings = ProjectSettings.LoadFromXML(file) ?? new ProjectSettings();

            if (file.Root != null)
            {
                var xmodels = file.Root.Element("Models");

                if (xmodels != null)
                {
                    foreach (var xElement in xmodels.Elements())
                    {
                        var panel = new DesignPanel();
                        panel.Deserialize(xElement);
                        AddModelPanel(panel);
                    }

                    foreach (var panel in Panels)
                    {
                        panel.Link();
                    }
                }
            }

            CurrentFileName = fname;

            AddFileToLastFiles(fname);
            SaveLastList();
            SetFileState();
            SetSavedState();
            UpdateJoystics();
        }
Beispiel #15
0
    public void OnJoystickAttached(int joyNum, string joyName)
    {
        //Check if a profile for the joystick already exists
        if (availableJoysticks != null)
        {
            for (int i = 0; i < availableJoysticks.Length; i++)
            {
                JoystickConfig j = availableJoysticks[i];
                if (j != null && j.name == joyName)
                {
                    if (j.platform == Application.platform.ToString() && j.joystickNumber == joyNum)
                    {
                        Debug.Log(availableJoysticks[i].name + " has been plugged in has player " + (joyNum + 1) + "(LOADED)");
                        joysticksAttached[joyNum] = j;
                        if (CurrentJoystickBeingMapped == null)
                        {
                            CurrentJoystickBeingMapped = joysticksAttached[joyNum];
                        }
                        else
                        {
                            queueOfJoysticksToMap.Add(joysticksAttached[joyNum]);
                        }
                        return;
                    }
                }
            }
        }

        //Otherwise creates a new profile
        JoystickConfig newJoystick = new JoystickConfig(joyName, Application.platform.ToString(), joyNum);

        newUnknownJoysticks.Add(newJoystick);
        joysticksAttached[joyNum] = newJoystick;

        if (CurrentJoystickBeingMapped == null)
        {
            CurrentJoystickBeingMapped = newJoystick;
        }
        else
        {
            queueOfJoysticksToMap.Add(newJoystick);
        }
        Debug.Log(Input.GetJoystickNames()[joyNum] + " has been plugged in has player " + (joyNum + 1) + "(NEW)");
    }
Beispiel #16
0
        // -------------------
        public void DrawGUI(AnalogConfig target)
        {
            EditorGUILayout.BeginVertical();

            if (!string.IsNullOrEmpty(this.titleContent.text))
            {
//EditorGUILayout.LabelField("Fodable: " + this.isFoldable  + " Folded:" + this.isFoldedOut);

                if (this.isFoldable)
                {
                    InspectorUtils.DrawSectionHeader(this.titleContent, ref this.isFoldedOut);
                }
                else
                {
                    EditorGUILayout.LabelField(this.titleContent, CFEditorStyles.Inst.boldText, GUILayout.ExpandWidth(true), GUILayout.MinWidth(30));
                    this.isFoldedOut = true;
                }
            }
            else
            {
                this.isFoldedOut = true;
            }


            if (this.isFoldedOut)
            {
                CFGUI.BeginIndentedVertical(CFEditorStyles.Inst.transpSunkenBG);

                JoystickConfig joyConfig = target as JoystickConfig;
                if (joyConfig != null)
                {
                    this.DrawJoystickConfigGUI(joyConfig);
                }

                this.DrawAnalogConfigGUI(target);

                CFGUI.EndIndentedVertical();
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }
    private bool GetJoystickAxisPressed()
    {
        JoystickConfig currentJoystick = UniversalJoystickMapper.CurrentJoystickBeingMapped;
        int            joyNum          = currentJoystick.joystickNumber + 1;
        int            axisN           = 1; // start at axis 1

        for (int i = 0; i < 28; i++)
        {
            string sourceString = "JoystickAxis " + axisN;
            // Log any key press
            if (Input.GetAxis(sourceString) > 0)
            {
                UniversalJoystickMapper.CurrentJoystickBeingMapped.sourceAxisNames[(int)axis] = sourceString;
                Debug.Log(UniversalJoystickMapper.CurrentJoystickBeingMapped.name + " Joystick " +
                          UniversalJoystickMapper.CurrentJoystickBeingMapped.joystickNumber + " axis " + (axisN) + " @ " + Time.time);
                return(true);
            }
            axisN++;
        }
        return(false);
    }
Beispiel #18
0
        private void ShowJoystickDialog(JoystickConfig config)
        {
            var dlg = new CreateJoystickDialog();

            if (config != null)
            {
                dlg.JoystickInfo = config;
            }

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            __JoyInfo = dlg.JoystickInfo;

            foreach (var panel in Panels)
            {
                panel.JoystickUpdated();
            }
            SetChangedState();
        }
Beispiel #19
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (ofdImport.ShowDialog(this.ParentForm) != DialogResult.OK)
            {
                return;
            }

            using (var ofr = new StreamReader(ofdImport.FileName, Encoding.UTF8))
            {
                try
                {
                    var cstr = ofr.ReadToEnd();
                    var xjoy = XDocument.Parse(cstr);
                    JoystickInfo = new JoystickConfig(xjoy.Root);

                    CheckJoystick();
                }
                catch (Exception exx)
                {
                    MessageBox.Show(this, exx.Message, "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #20
0
        private void FillPanels(JoystickConfig joystickInfo)
        {
            foreach (var control in joystickInfo.Controls)
            {
                BaseControlPanel panel;

                if (control is JoystickAxle)
                {
                    panel = new AxlePanel();
                    panel.FillFromJoyInfo(control);
                }
                else if (control is ButtonsCollection)
                {
                    panel = new ButtonsPanel();
                    panel.FillFromJoyInfo(control);
                }
                else if (control is HatSwitch)
                {
                    panel = new HatPanel();
                    panel.FillFromJoyInfo(control);
                }
                else if (control is LevelingBits)
                {
                    panel = new DummyPanel();
                    panel.FillFromJoyInfo(control);
                }
                else
                {
                    continue;
                }

                AddPanel(panel);
            }

            tbName.Text          = joystickInfo.Name;
            tbVendorProduct.Text = string.Format("{0:X4}:{1:X4}", joystickInfo.VendorID, joystickInfo.ProductID);
        }
Beispiel #21
0
        private void FillPanels(JoystickConfig joystickInfo)
        {
            foreach (var control in joystickInfo.Controls)
            {
                BaseControlPanel panel;

                if (control is JoystickAxle)
                {
                    panel = new AxlePanel();
                    panel.FillFromJoyInfo(control);
                }
                else if (control is ButtonsCollection)
                {
                    panel = new ButtonsPanel();
                    panel.FillFromJoyInfo(control);
                }
                else if (control is HatSwitch)
                {
                    panel = new HatPanel();
                    panel.FillFromJoyInfo(control);
                }
                else if (control is LevelingBits)
                {
                    panel = new DummyPanel();
                    panel.FillFromJoyInfo(control);
                }
                else
                {
                    continue;
                }

                AddPanel(panel);
            }

            tbName.Text  = joystickInfo.Name;
            tbCName.Text = joystickInfo.Code;
        }
Beispiel #22
0
        private bool CheckJoystick()
        {
            var valid =
                __Panels.Count > 0 &&
                __Panels.Aggregate(true, (current, panel) => current & panel.Check());

            valid = valid &
                    ValidateControl(tbName, () => !string.IsNullOrWhiteSpace(tbName.Text)) &
                    ValidateControl(tbCName, () => checkRex.IsMatch(tbCName.Text));

            if (!valid)
            {
                return(false);
            }

            _joystickInfo = new JoystickConfig
            {
                Code = tbCName.Text,
                Name = tbName.Text
            };

            foreach (var panel in __Panels)
            {
                panel.FillJoyInfo(_joystickInfo);
            }

            if (_joystickInfo.Bits() % 8 != 0)
            {
                MessageBox.Show(this, "Wrong total bits number, must be multiple of 8", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            return(true);
        }
Beispiel #23
0
        private static void MapGenerator()
        {
            Timeline   timeline = new Timeline();
            MessageBus mainBus  = new MessageBus();

            IMapGenerator         generator       = new MapGenerator(timeline, mainBus);
            IEnumerator <MapInfo> generationSteps = generator.GenerationSteps(60, 40, SingletonRandom.DefaultRNG.Next() + "").GetEnumerator();

            generationSteps.MoveNext();


            MapInfo mapInfo = generationSteps.Current;
            Map     map     = mapInfo.Map;
            Spawner spawner = new Spawner(map);

            JoystickConfig joystickConfig = new JoystickConfig
            {
                DownCode  = Terminal.TK_S,
                LeftCode  = Terminal.TK_A,
                RightCode = Terminal.TK_D,
                UpCode    = Terminal.TK_W,
                MapUp     = Terminal.TK_UP,
                MapDown   = Terminal.TK_DOWN,
                MapRight  = Terminal.TK_RIGHT,
                MapLeft   = Terminal.TK_LEFT,
                Inventory = Terminal.TK_I,
                Equip     = Terminal.TK_E
            };

            MapViewPane viewPane = new MapViewPane(mainBus, joystickConfig, null, false);

            viewPane.Map      = map;
            viewPane.LightMap = mapInfo.LightMap;

            map.ObjectRemoved += (sender, eventArgs) => viewPane.SetDirty();
            map.ObjectMoved   += (sender, eventArgs) => viewPane.SetDirty();
            map.ObjectAdded   += (sender, eventArgs) => viewPane.SetDirty();

            TextPane descriptionPane = new TextPane("");

            Describer describer = new Describer(descriptionPane);

            describer.Map = map;
            mainBus.RegisterSubscriber(describer);

            StackPane mapAndConsole = new StackPane(StackPane.StackDirection.Vertical);

            mapAndConsole.AddChild(descriptionPane, 1);
            mapAndConsole.AddChild(viewPane, 1);

            Window rootWindow = new Window(mapAndConsole, new Rectangle(0, 0, 120, 41), 0);

            BearTermRenderer renderer = new BearTermRenderer(rootWindow, "window.title='Spell Sword'; window.size=120x41; window.resizeable=true; input.filter=[keyboard+, mouse+, arrows+]");

            mainBus.RegisterSubscriber <ParticleEvent>(renderer);
            mainBus.RegisterSubscriber <WindowEvent>(renderer);

            GameControlConsumer gameControlConsumer = new GameControlConsumer(joystickConfig, mainBus, viewPane);

            BearTermInputRouter inputRouter = new BearTermInputRouter(gameControlConsumer);

            mainBus.RegisterSubscriber(inputRouter);
            inputRouter.Handle(WindowEvent.Open(mapAndConsole, new Rectangle(0, 0, 120, 41)));

            Terminal.Refresh();


            int lastFrame = Environment.TickCount;

            Stopwatch timer = new Stopwatch();

            timer.Start();

            int frames = 0;

            while (generationSteps.MoveNext())
            {
                inputRouter.HandleInput();

                renderer.Refresh();

                // Artificially slow generation process
                while (Environment.TickCount - lastFrame < 50)
                {
                }

                lastFrame = Environment.TickCount;
                frames   += 1;
            }

            double duration = timer.Elapsed.TotalSeconds;
            double fps      = frames / duration;

            Console.WriteLine($"Generation and rendering took: {duration} seconds");
            Console.WriteLine($"Rendering took place at: {fps} fps");

            while (true)
            {
                inputRouter.HandleInput();
                renderer.Refresh();
            }

            //Console.ReadKey();
        }
Beispiel #24
0
        private static void StartGameDungeon()
        {
            // 1D446841
            MessageBus gameBus = new MessageBus();
            string     seed    = SingletonRandom.DefaultRNG.Next().ToString("X");

            Console.WriteLine($"Generating dungeon with seed: {seed}");

            Dungeon dungeon = new Dungeon(gameBus, new Rectangle(0, 0, 60, 40), Source.From <GenerationContext, IBiome>(Biomes.TestBiome), seed);


            JoystickConfig joystickConfig = new JoystickConfig
            {
                DownCode  = Terminal.TK_S,
                LeftCode  = Terminal.TK_A,
                RightCode = Terminal.TK_D,
                UpCode    = Terminal.TK_W,
                MapUp     = Terminal.TK_UP,
                MapDown   = Terminal.TK_DOWN,
                MapRight  = Terminal.TK_RIGHT,
                MapLeft   = Terminal.TK_LEFT,
                Inventory = Terminal.TK_I,
                Equip     = Terminal.TK_E
            };

            Floor initialFloor = dungeon.Floors[0];

            // Creating Player
            GameObject player = new UpdatingGameObject(new Coord(20, 20), Layers.Main, null, initialFloor.Timeline);

            Being playerBeing = new Being(new SelectedAttributes(new AttributeSet(6, 7, 7, 8, 8)), Alignment.PlayerAlignment, new EquipmentSlotSet(), 10, "You");

            playerBeing.Equipment.Equip(new MeleeWeapon(new Damage(10)), EquipmentSlot.RightHandEquip);

            UserControlAgent control = new UserControlAgent(joystickConfig);

            gameBus.RegisterSubscriber <MouseMoveEvent>(control);
            gameBus.RegisterSubscriber <KeyEvent>(control);

            Actor playerActor = new Actor(playerBeing, control, gameBus);

            player.AddComponent(playerActor);
            player.AddComponent(new GlyphComponent(new Glyph(Characters.AT, Color.Aqua)));
            player.AddComponent(new LightSourceComponent(initialFloor.MapInfo.LightMap, new Light(Color.Aqua, Coord.NONE, 4, 5)));
            player.AddComponent(new FOVExplorerComponent());
            player.AddComponent(new NameComponent(new Title("the", "Hero")));

            EffectTargetComponent playerEffectTarget = new EffectTargetComponent();

            playerEffectTarget.EffectTarget.AddEffectReceiver(playerActor);
            player.AddComponent(playerEffectTarget);

            playerEffectTarget.EffectTarget.ApplyEffect(new StaminaEffect(1, EffectKind.Repeating, new EventTimerTiming(25, 25)));

            Logger logger = new Logger();

            gameBus.RegisterSubscriber(logger);

            MapViewPane mapViewPane = new MapViewPane(gameBus, joystickConfig, new InventoryDisplayPane(playerBeing.Equipment, playerBeing.Inventory, joystickConfig, gameBus), useFOV: true);

            EventHandler <ItemEventArgs <IGameObject> >      mapChangeDirty = (sender, eventArgs) => mapViewPane.SetDirty();
            EventHandler <ItemMovedEventArgs <IGameObject> > MapMoveDirty   = (sender, eventArgs) => mapViewPane.SetDirty();

            dungeon.OnFloorChange += (previousFloor, newFloor) =>
            {
                mapViewPane.Map      = newFloor.MapInfo.Map;
                mapViewPane.LightMap = newFloor.MapInfo.LightMap;

                if (previousFloor != null)
                {
                    previousFloor.MapInfo.Map.ObjectRemoved -= mapChangeDirty;
                    previousFloor.MapInfo.Map.ObjectMoved   -= MapMoveDirty;
                    previousFloor.MapInfo.Map.ObjectAdded   -= mapChangeDirty;
                }

                newFloor.MapInfo.Map.ObjectRemoved += mapChangeDirty;
                newFloor.MapInfo.Map.ObjectMoved   += MapMoveDirty;
                newFloor.MapInfo.Map.ObjectAdded   += mapChangeDirty;

                mapViewPane.SetDirty();
            };



            TextPane descriptionPane = new TextPane("TEST TEXT");

            Describer describer = new Describer(descriptionPane);

            describer.Map          = initialFloor.MapInfo.Map;
            dungeon.OnFloorChange += (previousFloor, newFloor) => describer.Map = newFloor.MapInfo.Map;

            gameBus.RegisterSubscriber(describer);

            LogPane logPane = new LogPane(logger);

            StackPane mapAndConsole = new StackPane(StackPane.StackDirection.Vertical);

            mapAndConsole.AddChild(descriptionPane, 1);
            mapAndConsole.AddChild(mapViewPane, 5);
            mapAndConsole.AddChild(logPane, 1);

            StackPane statusBars = new StackPane(StackPane.StackDirection.Vertical);

            statusBars.AddChild(new FillBarPane(playerBeing.Health, "Health", Color.Red, Color.DarkRed), 1);
            statusBars.AddChild(new FillBarPane(playerBeing.Mana, "Mana", Color.Aqua, Color.DarkBlue), 1);
            statusBars.AddChild(new FillBarPane(playerBeing.Stamina, "Stamina", Color.Yellow, Color.DarkGoldenrod), 1);

            StackPane root = new StackPane(StackPane.StackDirection.Horizontal);

            root.AddChild(mapAndConsole, 4);
            root.AddChild(statusBars, 1);

            Window rootWindow = new Window(root, new Rectangle(0, 0, 160, 50), 0);

            BearTermRenderer renderer = new BearTermRenderer(rootWindow, "window.title='Spell Sword'; window.size=160x50; window.resizeable=true; input.filter=[keyboard+, mouse+, arrows+]");

            gameBus.RegisterSubscriber <ParticleEvent>(renderer);
            gameBus.RegisterSubscriber <WindowEvent>(renderer);

            //WindowRouter windowRouter = new WindowRouter();
            //windowRouter.Handle(WindowEvent.Open(root, new Rectangle(0, 0, 160, 50)));
            //mainBus.RegisterSubscriber(windowRouter);

            GameControlConsumer gameControlConsumer = new GameControlConsumer(joystickConfig, gameBus, mapViewPane);

            BearTermInputRouter inputRouter = new BearTermInputRouter(gameControlConsumer);

            gameBus.RegisterSubscriber(inputRouter);
            inputRouter.Handle(WindowEvent.Open(root, new Rectangle(0, 0, 160, 50)));



            for (int i = 1; i < 5; i++)
            {
                //GameObject goblin = TestUtil.CreateGoblin((5 + i, 5 + i % 2 + 1), playerActor, initialFloor.Timeline, initialFloor.GoalMapStore, initialFloor.MessageBus);
                //initialFloor.MapInfo.Map.AddEntity(goblin);
            }

            initialFloor.MapInfo.Map.AddEntity(player);

            dungeon.Handle(new FloorTransitionEvent(player, 0, 1));
            dungeon.Handle(new FloorTransitionEvent(player, 1, 0));

            Terminal.Refresh();

            int lastFrame = Environment.TickCount;

            while (true)
            {
                inputRouter.HandleInput();
                //control.VisualizeAim(playerActor);

                if (!control.WaitingForInput)
                {
                    dungeon.Tick();
                }

                if (Environment.TickCount - lastFrame > 20)
                {
                    renderer.Refresh();
                    lastFrame = Environment.TickCount;
                }
            }
        }
Beispiel #25
0
        private static void StartGame()
        {
            //Dungeon dungeon = new Dungeon();
            // dungeon.Enter();

            MessageBus mainBus = new MessageBus();

            Timeline timeline = new Timeline();
            MapInfo  mapInfo  = new MapGenerator(timeline, mainBus).Generate(120, 40, "helloseed");
            Map      map      = mapInfo.Map;
            LightMap lightMap = mapInfo.LightMap;


            Spawner spawner = new Spawner(map);

            mainBus.RegisterSubscriber(spawner);

            JoystickConfig joystickConfig = new JoystickConfig
            {
                DownCode  = Terminal.TK_S,
                LeftCode  = Terminal.TK_A,
                RightCode = Terminal.TK_D,
                UpCode    = Terminal.TK_W,
                MapUp     = Terminal.TK_UP,
                MapDown   = Terminal.TK_DOWN,
                MapRight  = Terminal.TK_RIGHT,
                MapLeft   = Terminal.TK_LEFT,
                Inventory = Terminal.TK_I,
                Equip     = Terminal.TK_E
            };

            //lightMap.AddLight(new Light(Color.AntiqueWhite, new Coord(1, 1), 15, 5));
            lightMap.AddLight(new Light(Color.Wheat, new Coord(8, 8), 20, 10000));

            // Creating Player
            GameObject player = new UpdatingGameObject(new Coord(20, 20), Layers.Main, null, timeline);

            Being playerBeing = new Being(new SelectedAttributes(new AttributeSet(10, 10, 10, 10, 10)), Alignment.PlayerAlignment, new EquipmentSlotSet(), 5, "You");

            playerBeing.Equipment.Equip(new MeleeWeapon(new Damage(10)), EquipmentSlot.RightHandEquip);

            UserControlAgent control = new UserControlAgent(joystickConfig);

            mainBus.RegisterSubscriber <MouseMoveEvent>(control);
            mainBus.RegisterSubscriber <KeyEvent>(control);

            Actor playerActor = new Actor(playerBeing, control, mainBus);

            player.AddComponent(playerActor);
            player.AddComponent(new GlyphComponent(new Glyph(Characters.AT, Color.Aqua)));
            player.AddComponent(new LightSourceComponent(lightMap, new Light(Color.Aqua, Coord.NONE, 4, 8)));
            player.AddComponent(new FOVExplorerComponent());
            player.AddComponent(new NameComponent(new Title("the", "Hero")));

            EffectTargetComponent playerEffectTarget = new EffectTargetComponent();

            playerEffectTarget.EffectTarget.AddEffectReceiver(playerActor);
            player.AddComponent(playerEffectTarget);

            playerEffectTarget.EffectTarget.ApplyEffect(new StaminaEffect(1, EffectKind.Repeating, new EventTimerTiming(25, 25)));

            Logger logger = new Logger();

            mainBus.RegisterSubscriber(logger);

            MapViewPane viewPane = new MapViewPane(mainBus, joystickConfig, new InventoryDisplayPane(playerBeing.Equipment, playerBeing.Inventory, joystickConfig, mainBus));

            viewPane.Map      = map;
            viewPane.LightMap = lightMap;

            map.ObjectRemoved += (sender, eventArgs) => viewPane.SetDirty();
            map.ObjectMoved   += (sender, eventArgs) => viewPane.SetDirty();
            map.ObjectAdded   += (sender, eventArgs) => viewPane.SetDirty();


            TextPane descriptionPane = new TextPane("TEST TEXT");

            Describer describer = new Describer(descriptionPane);

            describer.Map = map;

            mainBus.RegisterSubscriber(describer);

            LogPane logPane = new LogPane(logger);

            StackPane mapAndConsole = new StackPane(StackPane.StackDirection.Vertical);

            mapAndConsole.AddChild(descriptionPane, 1);
            mapAndConsole.AddChild(viewPane, 5);
            mapAndConsole.AddChild(logPane, 1);

            StackPane statusBars = new StackPane(StackPane.StackDirection.Vertical);

            statusBars.AddChild(new FillBarPane(playerBeing.Health, "Health", Color.Red, Color.DarkRed), 1);
            statusBars.AddChild(new FillBarPane(playerBeing.Mana, "Mana", Color.Aqua, Color.DarkBlue), 1);
            statusBars.AddChild(new FillBarPane(playerBeing.Stamina, "Stamina", Color.Yellow, Color.DarkGoldenrod), 1);

            StackPane root = new StackPane(StackPane.StackDirection.Horizontal);

            root.AddChild(mapAndConsole, 4);
            root.AddChild(statusBars, 1);

            Window rootWindow = new Window(root, new Rectangle(0, 0, 160, 50), 0);

            BearTermRenderer renderer = new BearTermRenderer(rootWindow, "window.title='Spell Sword'; window.size=160x50; window.resizeable=true; input.filter=[keyboard+, mouse+, arrows+]");

            mainBus.RegisterSubscriber <ParticleEvent>(renderer);
            mainBus.RegisterSubscriber <WindowEvent>(renderer);

            //WindowRouter windowRouter = new WindowRouter();
            //windowRouter.Handle(WindowEvent.Open(root, new Rectangle(0, 0, 160, 50)));
            //mainBus.RegisterSubscriber(windowRouter);

            GameControlConsumer gameControlConsumer = new GameControlConsumer(joystickConfig, mainBus, viewPane);

            BearTermInputRouter inputRouter = new BearTermInputRouter(gameControlConsumer);

            mainBus.RegisterSubscriber(inputRouter);
            inputRouter.Handle(WindowEvent.Open(root, new Rectangle(0, 0, 160, 50)));


            GoalMapStore goalMapStore = new GoalMapStore(map);

            for (int i = 1; i < 5; i++)
            {
                //GameObject goblin = TestUtil.CreateGoblin((5 + i, 5 + i % 2 + 1), playerActor, timeline, goalMapStore, mainBus);
                //map.AddEntity(goblin);
            }

            map.AddEntity(player);

            Terminal.Refresh();


            int lastFrame = Environment.TickCount;

            while (true)
            {
                inputRouter.HandleInput();
                //control.VisualizeAim(playerActor);

                if (!control.WaitingForInput)
                {
                    timeline.Advance(1);
                    goalMapStore.UpdateMaps();
                }

                if (Environment.TickCount - lastFrame > 20)
                {
                    renderer.Refresh();
                    lastFrame = Environment.TickCount;
                }
            }
        }
Beispiel #26
0
//private float buttonHeight = 40;
        // ---------------------
        protected void DrawJoystickConfigGUI(JoystickConfig target)
        {
            bool
                blockX           = target.blockX,
                blockY           = target.blockY,
                perAxisDeadzones = target.perAxisDeadzones;

            JoystickConfig.ClampMode
                clampMode = target.clampMode;
            //circularClamp	= target.circularClamp;
            JoystickConfig.StickMode
                stickMode = target.stickMode;
            DirectionState.OriginalDirResetMode
                originalDirResetMode = target.originalDirResetMode;
            JoystickConfig.DigitalDetectionMode
                digitalDetectionMode = target.digitalDetectionMode;

            float
                angularMagnet = target.angularMagnet;



            stickMode = (JoystickConfig.StickMode)CFGUI.EnumPopup(new GUIContent("Mode", "Joystick mode"), stickMode, 120);             // GUILayout.MinWidth(30));

            clampMode = (JoystickConfig.ClampMode)CFGUI.EnumPopup(new GUIContent("Vector Range", "Vector Range Mode"), clampMode, 120); //GUILayout.MinWidth(30));

            digitalDetectionMode = (JoystickConfig.DigitalDetectionMode)CFGUI.EnumPopup(new GUIContent("Digi. Detect. Mode", "Digital Detection Mode"),
                                                                                        digitalDetectionMode, 120);

            angularMagnet = CFGUI.Slider(new GUIContent("Digi. Angular Magnet", "Angular Magnet Strength used when changing digital direction. Higher value will make changing direction harder, which is recommended for Touch Digital Detection Mode."),
                                         angularMagnet, 0f, 1f, 100);



            if (stickMode == JoystickConfig.StickMode.Analog)
            {
                perAxisDeadzones = EditorGUILayout.ToggleLeft(new GUIContent("Per-Axis Analog Range", "Per-Axis deadzone, endzone and ramp transformations."),
                                                              perAxisDeadzones, GUILayout.MinWidth(30));
            }

            blockX = EditorGUILayout.ToggleLeft(new GUIContent("Block X"), blockX, GUILayout.MinWidth(30));
            blockY = EditorGUILayout.ToggleLeft(new GUIContent("Block Y"), blockY, GUILayout.MinWidth(30));

            originalDirResetMode = (DirectionState.OriginalDirResetMode)CFGUI.EnumPopup(new GUIContent("Dir. Reset Mode", "Original Direction Reset Mode - choose when original stick direction will be reset. This option is used mainly by the Direction Binding..."),
                                                                                        originalDirResetMode, 120); // GUILayout.MinWidth(30));



            if ((blockX != target.blockX) ||
                (blockY != target.blockY) ||
                (perAxisDeadzones != target.perAxisDeadzones) ||
                (clampMode != target.clampMode) ||
                (originalDirResetMode != target.originalDirResetMode) ||
                (digitalDetectionMode != target.digitalDetectionMode) ||
                (stickMode != target.stickMode) ||
                (angularMagnet != target.angularMagnet))
            {
                CFGUI.CreateUndo("Joy Config modification", this.undoObject);


                target.perAxisDeadzones = perAxisDeadzones;
                target.blockX           = blockX;
                target.blockY           = blockY;
                //target.circularClamp		= circularClamp;
                target.clampMode            = clampMode;
                target.stickMode            = stickMode;
                target.originalDirResetMode = originalDirResetMode;
                target.angularMagnet        = angularMagnet;
                target.digitalDetectionMode = digitalDetectionMode;

                CFGUI.EndUndo(this.undoObject);
            }
        }
Beispiel #27
0
 public virtual void FillJoyInfo(JoystickConfig joy)
 {
     throw new NotImplementedException();
 }
 public override bool CheckJoystickInUse(JoystickConfig joystickConfig)
 {
     return(__CurrentConfig != null && joystickConfig != null && joystickConfig.ID == __CurrentConfig.ID);
 }
Beispiel #29
0
 public bool CheckJoystickInUse(JoystickConfig joystickConfig)
 {
     return(__Elements.Any(el => el.CheckJoystickInUse(joystickConfig)));
 }
Beispiel #30
0
        private void Joystick_Click(object sender, RoutedEventArgs e)
        {
            var jc = new JoystickConfig();

            jc.ShowDialog();
        }