Esempio n. 1
0
        /// <summary>
        /// Update override to adjust game chat mode.
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Set the chat mode based on our controls focus..
            Terraria.SetMainField("chatMode", this._chatInput.Focused);
        }
Esempio n. 2
0
        /// <summary>
        /// Update override to enforce chatmode block.
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            // Allow base control to update..
            base.Update(gameTime);

            // Locate the console textbox..
            var consoleEdit = this._console.Controls.SingleOrDefault(c => c.GetType() == typeof(TextBox));

            if (consoleEdit == null)
            {
                return;
            }

            // Set the chat mode..
            Terraria.SetMainField("chatMode", consoleEdit.Focused);
        }
Esempio n. 3
0
 void OnTimeCommand(ConsoleCommandArgs args)
 {
     args.Handled = true;
     if (args.Arguments.Count == 2)
     {
         double time;
         if (Double.TryParse(args.Arguments[1], out time))
         {
             Terraria.SetMainField("time", time);
             Console.PrintConsole("Time set!", ConsoleMessageType.About);
         }
         else
         {
             Console.PrintConsole("Invalid time specified!", ConsoleMessageType.Error);
             Console.PrintConsole("Usage: /time <time>", ConsoleMessageType.Normal);
         }
     }
     else
     {
         Console.PrintConsole("No time specified!", ConsoleMessageType.Error);
         Console.PrintConsole("Usage: /time <time>", ConsoleMessageType.Normal);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="manager"></param>
        public DetoxConsole(Manager manager)
            : base(manager)
        {
            // Initialize this control..
            base.Init();
            base.Left      = base.Top = 0;
            base.Name      = "frmConsole";
            base.Width     = Terraria.MainGame.Window.ClientBounds.Width;
            base.Height    = 250;
            base.Alpha     = 255;
            base.Resizable = false;
            //
            //
            //
            this._console = new TomShane.Neoforce.Controls.Console(manager)
            {
                Anchor          = Anchors.All,
                Name            = "DetoxConsole",
                Width           = base.ClientArea.Width,
                Height          = base.ClientArea.Height,
                ChannelsVisible = false,
                MessageFormat   = ConsoleMessageFormats.TimeStamp,
                TextColor       = Color.White
            };
            this._console.Channels.AddRange(new[]
            {
                new ConsoleChannel(0, "About", Color.Chartreuse),
                new ConsoleChannel(1, "Default", Color.White),
                new ConsoleChannel(2, "Warning", Color.Yellow),
                new ConsoleChannel(3, "Error", Color.Red)
            });
            this._console.SelectedChannel = 1;
            this._console.MessageSent    += (sender, e) =>
            {
                // Ensure the command is valid..
                if (string.IsNullOrEmpty(e.Message.Text) || !e.Message.Text.StartsWith("/"))
                {
                    return;
                }

                // Attempt to handle the command..
                e.Handled = ConsoleCommands.ProcessCommand(e.Message.Text);
                if (!e.Handled)
                {
                    this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("Invalid command or command error occurred.", ConsoleMessageType.Error));
                    e.Handled = true;
                }
            };
            this._console.Init();
            //
            //
            //
            base.Add(this._console);
            manager.Add(this);

            // Attach device settings event to resize console..
            manager.DeviceSettingsChanged += args =>
            {
                // Adjust the base panel size..
                base.Width  = Terraria.MainGame.Window.ClientBounds.Width;
                base.Height = 250;

                // Adjust the console size..
                this._console.Width  = base.ClientArea.Width;
                this._console.Height = base.ClientArea.Height;
            };

            // Locate the console textbox..
            var consoleEdit = this._console.Controls.SingleOrDefault(c => c.GetType() == typeof(TextBox));

            if (consoleEdit == null)
            {
                return;
            }

            consoleEdit.KeyDown += (sender, e) =>
            {
                // Prevent tilde from being processed..
                if (e.Key == Keys.OemTilde)
                {
                    e.Handled = true;
                }

                // Force escape to remove focus from the console..
                if (e.Key == Keys.Escape)
                {
                    consoleEdit.Focused = false;
                    e.Handled           = true;
                }
            };
            consoleEdit.KeyPress += (sender, e) =>
            {
                if (e.Key == Keys.OemTilde)
                {
                    e.Handled = true;
                }
            };
            consoleEdit.KeyUp += (sender, e) =>
            {
                if (e.Key == Keys.OemTilde)
                {
                    e.Handled = true;
                }
            };
            consoleEdit.TextChanged += (sender, e) =>
            {
                consoleEdit.Suspended = true;
                consoleEdit.Text      = consoleEdit.Text.Replace("`", "");
                consoleEdit.Suspended = false;
                e.Handled             = true;
            };
            consoleEdit.FocusGained += (sender, e) => Terraria.SetMainField("chatMode", false);
            consoleEdit.FocusLost   += (sender, e) => Terraria.SetMainField("chatMode", false);

            // Subscribe to the API console message event..
            DetoxAPI.Console.PrintConsoleMessage += (sender, e) => this.LogConsoleMessage(e);

            // Register some basic console commands..
            DetoxAPI.ConsoleCommands.AddCommnd(new List <string> {
                "help", "info", "h", "?"
            }, "Prints a list of registered console commands.", OnHelpCommand);
            DetoxAPI.ConsoleCommands.AddCommnd(new List <string> {
                "exit", "close", "terminate"
            }, "Exits Terraria immediately.", args => System.Windows.Forms.Application.Exit());
            DetoxAPI.ConsoleCommands.AddCommnd(new List <string> {
                "plugin", "extension", "p"
            }, "Handles a plugin command.", OnPluginCommand);
        }
Esempio n. 5
0
 /// <summary>
 /// FocusLost callback to disable the Terraria chat mode.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ChatInput_OnFocusLost(object sender, TomShane.Neoforce.Controls.EventArgs e)
 {
     Terraria.SetMainField("chatMode", false);
 }
Esempio n. 6
0
 /// <summary>
 /// FocusGained callback to enable the Terraria chat mode.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ChatInput_OnFocusGained(object sender, TomShane.Neoforce.Controls.EventArgs e)
 {
     this._chatInput.TextColor = Color.White;
     Terraria.SetMainField("chatMode", true);
 }