Пример #1
0
    // Unity Callbacks
    public void Start()
    {
        m_gameServerInstance = this;

        m_logListeners = new List <Logger.LogDelegate>();
        m_logger       = new Logger(this.OnServerLogMessage);

        // Only need to do this once on creation
        InitializeConstants();

        m_state         = eState.stopped;
        m_dbInitRequest = null;
    }
Пример #2
0
    public void OnLocalHostToggled(
        bool hostServerLocally)
    {
        AsyncRPGServer server = AsyncRPGServer.GetInstance();

        Debug.Log("Active: " + server.IsServerActive() + ", Initializing: " + server.IsServerInitializing());
        if (hostServerLocally && !server.IsServerActive() && !server.IsServerInitializing())
        {
            Debug.Log("Start Server!");
            server.StartServer();
        }
        else if (!hostServerLocally && (server.IsServerActive() || server.IsServerInitializing()))
        {
            Debug.Log("Stop Server!");
            server.StopServer();
        }
    }
Пример #3
0
    private void SetServerStatusVisible(bool visible)
    {
        if (!m_serverPanelWidgetGroup.Visible && visible)
        {
            // Hide the login panel
            m_loginPanelWidgetGroup.Visible = false;

            // Reset and show the server status panel
            m_serverStatusText.Text          = "";
            m_serverOkButton.Visible         = false;
            m_serverPanelWidgetGroup.Visible = true;

            // Start listening for log messages
            AsyncRPGServer.GetInstance().AddServerLogListener(this.OnServerLogMessage);
        }
        else if (m_serverPanelWidgetGroup.Visible && !visible)
        {
            m_serverPanelWidgetGroup.Visible = false;
            m_loginPanelWidgetGroup.Visible  = true;

            // Stop listening for log messages
            AsyncRPGServer.GetInstance().RemoveServerLogListener(this.OnServerLogMessage);
        }
    }
Пример #4
0
    // Unity Callbacks
    public void Start()
    {
        m_gameServerInstance = this;

        m_logListeners = new List<Logger.LogDelegate>();
        m_logger = new Logger(this.OnServerLogMessage);

        // Only need to do this once on creation
        InitializeConstants();

        m_state= eState.stopped;
        m_dbInitRequest= null;
    }
Пример #5
0
 public void OnDestroy()
 {
     StopServer();
     m_gameServerInstance = null;
 }
Пример #6
0
    public void Start()
    {
        bool isLocalServerRunning = AsyncRPGServer.GetInstance().IsServerActive();

        Screen.showCursor = true;

        // Create the root widget group
        m_rootWidgetGroup = new WidgetGroup(null, Screen.width, Screen.height, 0.0f, 0.0f);
        m_rootWidgetGroup.SetWidgetEventListener(this);

        m_widgetEventDispatcher = new WidgetEventDispatcher();
        m_widgetEventDispatcher.Start(m_rootWidgetGroup);

        // Create the widget group to hold the login panel
        m_loginPanelWidgetGroup =
            new WidgetGroup(
                m_rootWidgetGroup,
                loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height,
                Screen.width / 2 - loginPanelStyle.gamePanelStyle.Width / 2,
                Screen.height / 2 - loginPanelStyle.gamePanelStyle.Height / 2);

        // Background for the game info
        new ImageWidget(
            m_loginPanelWidgetGroup,
            loginPanelStyle.gamePanelStyle.Width,
            loginPanelStyle.gamePanelStyle.Height,
            loginPanelStyle.gamePanelStyle.Background,
            0.0f, 0.0f);

        // Username and Password - Left Aligned
        {
            WidgetLayoutCursor cursor = new WidgetLayoutCursor(
                loginPanelStyle.gamePanelStyle.BorderWidth
                + loginPanelStyle.gamePanelStyle.WidgetSpacing,
                loginPanelStyle.gamePanelStyle.BorderWidth
                + loginPanelStyle.gamePanelStyle.WidgetSpacing);
            cursor.Kerning = loginPanelStyle.gamePanelStyle.WidgetSpacing;
            cursor.Leading = loginPanelStyle.gamePanelStyle.WidgetSpacing;

            // Server
            cursor.Advance(
                new LabelWidget(
                    m_loginPanelWidgetGroup,
                    loginPanelStyle.labelStyle,
                    cursor.X, cursor.Y,
                    "Server:"));
            m_serverText =
                cursor.Advance(
                    new TextEntryWidget(
                        m_loginPanelWidgetGroup,
                        loginPanelStyle.textEntryStyle,
                        cursor.X, cursor.Y,
                        "localhost"));
            m_serverText.Visible = !isLocalServerRunning;
            m_localHostLabel     =
                new LabelWidget(
                    m_loginPanelWidgetGroup,
                    m_serverText.Width, m_serverText.Height,
                    m_serverText.LocalX, m_serverText.LocalY,
                    "localhost");
            m_localHostLabel.Visible = isLocalServerRunning;
            cursor.NewLine();

            // Local hosted check box
            cursor.Advance(
                new LabelWidget(
                    m_loginPanelWidgetGroup,
                    loginPanelStyle.labelStyle,
                    cursor.X, cursor.Y,
                    "Host Server:"));
            m_localHostCheckBox =
                cursor.Advance(
                    new CheckBoxWidget(
                        m_loginPanelWidgetGroup,
                        loginPanelStyle.checkBoxStyle,
                        cursor.X, cursor.Y));
            m_localHostCheckBox.Enabled = isLocalServerRunning;
            cursor.NewLine();

            // Username
            cursor.Advance(
                new LabelWidget(
                    m_loginPanelWidgetGroup,
                    loginPanelStyle.labelStyle,
                    cursor.X, cursor.Y,
                    "Username:"******"test" : ""));
            cursor.NewLine();

            // Password
            cursor.Advance(
                new LabelWidget(
                    m_loginPanelWidgetGroup,
                    loginPanelStyle.labelStyle,
                    cursor.X, cursor.Y,
                    "Password:"******"password" : ""));
            m_passwordText.IsPassword = true;
            cursor.NewLine();
        }

        // Buttons - Centered along the bottom
        {
            WidgetLayoutCursor cursor = new WidgetLayoutCursor(
                loginPanelStyle.gamePanelStyle.Width / 2
                - loginPanelStyle.gamePanelStyle.WidgetSpacing / 2
                - loginPanelStyle.buttonStyle.Width,
                loginPanelStyle.gamePanelStyle.Height
                - loginPanelStyle.buttonStyle.Height
                - loginPanelStyle.labelStyle.Height
                - loginPanelStyle.gamePanelStyle.BorderWidth
                - loginPanelStyle.gamePanelStyle.WidgetSpacing);

            m_createAccountButton =
                cursor.Advance(
                    new ButtonWidget(
                        m_loginPanelWidgetGroup,
                        loginPanelStyle.buttonStyle,
                        cursor.X, cursor.Y,
                        "New Account"));
            m_createAccountButton.Visible = false;

            m_loginButton =
                cursor.Advance(
                    new ButtonWidget(
                        m_loginPanelWidgetGroup,
                        loginPanelStyle.buttonStyle,
                        cursor.X, cursor.Y,
                        "Login"));
            m_loginButton.Visible = true;

            cursor.NewLine();

            m_loginStatusLabel =
                cursor.Advance(
                    new LabelWidget(
                        m_loginPanelWidgetGroup,
                        loginPanelStyle.gamePanelStyle.Width
                        - 2.0f * loginPanelStyle.gamePanelStyle.BorderWidth,
                        loginPanelStyle.labelStyle.Height,
                        cursor.X, cursor.Y,
                        ""));
        }

        // Server Status Panel
        m_serverPanelWidgetGroup =
            new WidgetGroup(
                m_rootWidgetGroup,
                loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height,
                Screen.width / 2 - loginPanelStyle.gamePanelStyle.Width / 2,
                Screen.height / 2 - loginPanelStyle.gamePanelStyle.Height / 2);
        m_serverPanelWidgetGroup.Visible = false;

        // Background for the game info
        new ImageWidget(
            m_serverPanelWidgetGroup,
            loginPanelStyle.gamePanelStyle.Width,
            loginPanelStyle.gamePanelStyle.Height,
            loginPanelStyle.gamePanelStyle.Background,
            0.0f, 0.0f);

        {
            float contentCenter       = loginPanelStyle.gamePanelStyle.Width / 2.0f;
            WidgetLayoutCursor cursor = new WidgetLayoutCursor(
                0.0f,
                loginPanelStyle.gamePanelStyle.BorderWidth
                + loginPanelStyle.gamePanelStyle.WidgetSpacing);
            cursor.Kerning = loginPanelStyle.gamePanelStyle.WidgetSpacing;
            cursor.Leading = loginPanelStyle.gamePanelStyle.WidgetSpacing;

            LabelWidget topLabel =
                cursor.Advance(
                    new LabelWidget(
                        m_serverPanelWidgetGroup,
                        loginPanelStyle.labelStyle,
                        contentCenter - loginPanelStyle.labelStyle.Width / 2.0f, cursor.Y,
                        "[Server]"));
            topLabel.Alignment = TextAnchor.UpperCenter;
            cursor.NewLine();

            m_serverStatusText =
                cursor.Advance(
                    new ScrollTextWidget(
                        m_serverPanelWidgetGroup,
                        loginPanelStyle.scrollTextStyle,
                        contentCenter - loginPanelStyle.scrollTextStyle.Width / 2.0f, cursor.Y,
                        ""));
            cursor.NewLine();

            m_serverOkButton =
                cursor.Advance(
                    new ButtonWidget(
                        m_serverPanelWidgetGroup,
                        loginPanelStyle.buttonStyle,
                        contentCenter - loginPanelStyle.buttonStyle.Width / 2.0f, cursor.Y,
                        "Ok"));
            m_serverOkButton.Visible = false;
        }
    }
Пример #7
0
 public void OnDestroy()
 {
     StopServer();
     m_gameServerInstance = null;
 }