Пример #1
0
    //protected int wiimoteTimeout = 0, numWiimotesConnected = 0;
    //protected IDictionary<int, int> wiiButtonMap = new Dictionary<int, int>();
    //protected IDictionary<int, int> ps3ButtonMap = new Dictionary<int, int>();

    //protected bool running = true;
    //protected Thread sdlThread = null, wiimoteThread = null;

    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();

        // Set up controls
        spinButtonMaxPlayers.Adjustment.Upper = Images.GetPlayerImageCount();

        iconViewPlayers.Model        = playerStore;
        iconViewPlayers.MarkupColumn = 1;
        iconViewPlayers.PixbufColumn = 2;
        iconViewPlayers.ModifyBase(StateType.Normal, new Gdk.Color(0, 0, 0));
        iconViewPlayers.ModifyText(StateType.Normal, new Gdk.Color(255, 255, 255));

        treeViewGames.Model = gameStore;
        treeViewGames.AppendColumn("Run", new CellRendererToggle(), "active", 0);
        treeViewGames.AppendColumn("Game", new CellRendererText(), "text", 1);
        treeViewGames.AppendColumn("Description", new CellRendererText(), "text", 2);

        RefreshSerialPortNames();

        HITTServer.Start();
        labelNetworkAddress.Markup = string.Format("<span weight=\"bold\" color=\"#333333\">IP Address</span>: {0}", HITTServer.Address);
        labelNetworkPort.Markup    = string.Format("<span weight=\"bold\" color=\"#333333\">Port</span>: {0}", HITTServer.Port);
        baseStation.KeyReceived   += baseStation_OnKeyReceived;

        //Wiimotes.ButtonClicked += wiimotes_OnButtonClicked;

        //ps3ButtonMap[(int)PS3Buttons.Up] = 3;
        //ps3ButtonMap[(int)PS3Buttons.Down] = 4;
        //ps3ButtonMap[(int)PS3Buttons.Left] = 5;
        //ps3ButtonMap[(int)PS3Buttons.Right] = 10;
        //sdlThread = new Thread(SDLMain);
        //sdlThread.Start();

        LoadSettings();

        logger.Debug("Initialization complete");

        if (Nexus.Settings.Default.HITTAutoConnect)
        {
            if (!ConnectToBaseStation())
            {
                notebook1.Page = 2;
            }
        }

        // Load manual
        using (var manualReader = new StreamReader(System.IO.Path.Combine(basePath, "etc/manual.md")))
        {
            Markdown.LoadIntoBuffer(textViewManual.Buffer, manualReader);
        }

        textViewManual.LeftMargin = 5;
        textViewManual.WrapMode   = WrapMode.Word;
        textViewManual.Editable   = false;
    }
Пример #2
0
    protected void HandlePlayerButton(string playerId, int button)
    {
        int  playerIndex = -1;
        bool playerAdded = false;

        // Check if player is already registered
        lock (playerIds)
        {
            if (playerIds.Contains(playerId))
            {
                playerIndex = playerIds.IndexOf(playerId);
            }
            else
            {
                playerIds.Add(playerId);
                playerIndex = playerIds.Count - 1;
                playerAdded = true;
            }
        }

        if (playerAdded)
        {
            // Add player to store
            Application.Invoke(delegate
            {
                playerStore.AppendValues(playerId, GetPlayerString(playerId, button),
                                         Images.GetPlayerImage(playerIndex));
            });
        }
        else
        {
            // Send button press to clients
            HITTServer.SendToAll(new byte[] { (byte)playerIndex, (byte)button });

            if (!isInGame)
            {
                // Update players display
                Application.Invoke(delegate
                {
                    TreeIter iter;

                    if (playerStore.IterNthChild(out iter, playerIndex))
                    {
                        playerStore.SetValue(iter, 1, GetPlayerString(playerId, button));
                    }
                });
            }
        }
    }
Пример #3
0
    protected void OnDeleteEvent(object sender, DeleteEventArgs e)
    {
        logger.Info("Shutting down");

        try
        {
            SaveSettings();

            if (baseStation.IsConnected)
            {
                baseStation.Disconnect();
            }

            HITTServer.Stop();

            // Wiimotes
            //if (wiimoteThread != null) {
            //Wiimotes.DisconnectAll();
            //wiimoteThread.Join();
            //}

            // Joysticks
            //running = false;

            //if (sdlThread != null) {
            //sdlThread.Join();
            //}
        }
        catch (Exception ex)
        {
            logger.WarnFormat("Cleanup error: {0}", ex.Message);
        }

        Application.Quit();
        e.RetVal = true;
    }