コード例 #1
0
        public void RegisterCmdHandler <T>(TypedCmdEventHandler <T> callback) where T : MessageCmdData
        {
            string name = MessageCmdDataNameDB.GetCmdName(typeof(T));

            if (name == null)
            {
                throw new System.InvalidOperationException("no CmdNameAttribute on " + typeof(T).Name);
            }
            CmdConverter <T> converter = new CmdConverter <T>(callback);

            m_handlers[name] = converter.Callback;
            m_mcdc.RegisterCreator(typeof(T));
        }
コード例 #2
0
        public static Bitmap Get(string path, int scaleRatio, Brush brush, SmoothingMode mode = SmoothingMode.HighQuality)
        {
            int        svgPathSize = 8;
            int        width       = svgPathSize * scaleRatio + 1;
            int        height      = svgPathSize * scaleRatio + 1;
            List <Cmd> cmds;

            cmds = CmdParser.Parse(path);
            CmdValidator.ValidateCmds(cmds);
            cmds = CmdConverter.ExtractToSingleAndAbsolutePositionCmds(cmds);
            cmds = CmdScaler.Scale(cmds, scaleRatio);
            return(CmdDrawer.Draw(cmds, width, height, brush, mode));
        }
コード例 #3
0
        private void DrawImage(List <Cmd> cmd)
        {
            InitBrushIfNeeded();
            int scale = (int)nudScale.Value;
            int @base = (int)nudBase.Value;

            // process commands
            List <Cmd> processedCmds = cmd;

            processedCmds = CmdConverter.ExtractToSingleAndAbsolutePositionCmds(processedCmds);
            processedCmds = CmdScaler.Scale(processedCmds, scale);

            // display drawned into text box
            var cmdText = new StringBuilder();

            processedCmds.ForEach(cm => cmdText.Append(cm.ToString()));
            txtParsedCmds.Text = cmdText.ToString();

            // draw image into preview
            pbPreview.Image = CmdDrawer.Draw(processedCmds, @base * scale, @base * scale, br);
        }
コード例 #4
0
        private void Preview()
        {
            try
            {
                lblError.Text = string.Empty;
                //
                int scale = (int)nudScale.Value;
                _cmds = CmdParser.Parse(txtSVGPath.Text);
                List <Cmd> processedCmds = _cmds;
                processedCmds = CmdConverter.ExtractToSingleAndAbsolutePositionCmds(processedCmds);
                processedCmds = CmdScaler.Scale(processedCmds, scale);
                // load parse command into listview
                lbParsedCmds.SelectedIndexChanged -= lbParsedCmds_SelectedIndexChanged;
                lbParsedCmds.Items.Clear();
                lbParsedCmds.Items.AddRange(
                    _cmds
                    .Select(i => i.ToString())
                    .ToArray());
                lbParsedCmds.SelectedIndexChanged += lbParsedCmds_SelectedIndexChanged;

                // select last events
                lbParsedCmds.SelectedIndex = lbParsedCmds.Items.Count - 1;
            }
            catch (InvalidSvgCharacterException isce)
            {
                pbPreview.Image = null;
                lblError.Text   = "Error: " + isce.Message;
            }
            catch (InvalidCmdException invalidCmdEx)
            {
                pbPreview.Image            = null;
                lbParsedCmds.SelectedIndex = invalidCmdEx.Index;
                lblError.Text = "Error: " + invalidCmdEx.Message;
            }
            catch (Exception ex)
            {
                lblError.Text = "Error: " + ex.Message;
            }
        }
コード例 #5
0
        public void RegisterCmdHandler <T>(string name, TypedCmdEventHandler <T> callback)
        {
            CmdConverter <T> converter = new CmdConverter <T>(log_, callback);

            messageHandlers_[name] = converter.Callback;
        }
コード例 #6
0
        /// <summary>
        /// Lets you register a command to be called when the game is directly sent a message.
        /// </summary>
        /// <example>
        /// <code>
        /// private class MessageColor {
        ///     public string color = "";    // in CSS format rgb(r,g,b)
        /// };
        ///
        /// ...
        /// gameServer.RegisterCmdHandler("color", OnColor);
        /// ...
        /// void OnColor(MessageColor) {
        ///   Debug.Log("received msg with color: " + color);
        /// }
        /// </code>
        /// </example>
        /// <param name="name">command to call callback for</param>
        /// <param name="callback">Typed callback</param>
        public void RegisterCmdHandler <T>(string name, TypedCmdEventHandler <T> callback)
        {
            CmdConverter <T> converter = new CmdConverter <T>(callback);

            m_handlers[name] = converter.Callback;
        }
コード例 #7
0
ファイル: NetPlayer.cs プロジェクト: aaronyuen2/earthDefender
        private void RegisterInternalCmdHandler <T>(string name, TypedCmdEventHandler <T> callback)
        {
            CmdConverter <T> converter = new CmdConverter <T>(callback);

            m_internalHandlers[name] = converter.Callback;
        }