private void BuildScriptEventView(ScriptEvent p_Event, Framework.ContextVar p_Parent, bool p_First = false)
        {
            string  l_Name = "";
            var     l_Type = Game.EventTypes.Instance.GetType(p_Event.EventType);

            if (!p_First)
                l_Name = "[EVENT.ID=" + p_Event.ID.ToString() + "][" + l_Type.Name + "] => " + p_Event.Comment.Replace("\\n", " | ");

            Framework.ContextVar l_Var = p_First ? p_Parent : new Framework.ContextVar();

            l_Var.SetValue("Type", l_Type.Name);
            l_Var.SetValue("Chance", p_Event.Chance.ToString() + " %");
            l_Var.SetValue("Phase Mask", p_Event.PhaseMask.ToString());

            string l_Flags = "";

            foreach (var l_Flag in Game.EventFlags.Instance.Flags)
            {
                if ((p_Event.EventFlags & l_Flag.Value) != 0)
                    l_Flags += (l_Flags == "" ? "" : ", ") + l_Flag.Name;
            }

            l_Var.SetValue("Flags", l_Flags);
            l_Var.SetValue("Parameter 1 (" + l_Type.Param1 + ")", p_Event.Params[0].ToString());
            l_Var.SetValue("Parameter 2 (" + l_Type.Param2 + ")", p_Event.Params[1].ToString());
            l_Var.SetValue("Parameter 3 (" + l_Type.Param3 + ")", p_Event.Params[2].ToString());
            l_Var.SetValue("Parameter 4 (" + l_Type.Param4 + ")", p_Event.Params[3].ToString());
            l_Var.SetValue("Comment", p_Event.Comment.Replace("\\n", "\n"));

            l_Var.SetValue("Sub Events", new Framework.ContextVar());
            l_Var.SetValue("Actions", new Framework.ContextVar());

            foreach (var l_SubEvent in p_Event.SubEvents)
                BuildScriptEventView(l_SubEvent, l_Var.Nodes["Sub Events"]);

            foreach (var l_Action in p_Event.Actions)
                BuildScriptActionView(l_Action, l_Var.Nodes["Actions"]);

            if (!p_First)
                p_Parent.SetValue(l_Name, l_Var);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="p_Current"></param>
        /// <param name="p_Creation"></param>
        /// <param name="p_HaveParent"></param>
        /// <param name="p_ParentEvent"></param>
        public EventManager(ScriptEvent p_Current, bool p_Creation, bool p_HaveParent, ScriptEvent p_ParentEvent)
        {
            InitializeComponent();

            InitializationEventTypes();
            InitializationEventFlags();

            Parameter1Description.Text = "";
            Parameter2Description.Text = "";
            Parameter3Description.Text = "";
            Parameter4Description.Text = "";

            m_IsCreation    = p_Creation;
            m_HaveParent    = p_HaveParent;
            m_ParentEvent   = p_ParentEvent;
            m_Current       = p_Current;

            if (!p_Creation && p_Current != null)
            {
                if (p_Current.PhaseMask == 0)
                {
                    AllPhase.Checked = true;
                    AllPhase_CheckedChanged(this, null);
                }
                else
                {
                    for (int l_I = 1; l_I < 32; l_I++)
                    {
                        if ((p_Current.PhaseMask & (1 << l_I)) != 0)
                            PhaseList.Items.Add((1 << l_I).ToString());
                    }
                }

                EventChance.Value = (int)p_Current.Chance;
                EventChance_Scroll(this, null);

                int l_CurrentIndex = 0;
                foreach (var l_Flag in Game.EventFlags.Instance.Flags)
                {
                    if ((p_Current.EventFlags & l_Flag.Value) != 0)
                        EventFlags.SelectedIndices.Add(l_CurrentIndex);

                    l_CurrentIndex++;
                }

                l_CurrentIndex = 0;
                foreach (var l_Type in Game.EventTypes.Instance.Types)
                {
                    if ((p_Current.EventType & l_Type.Value) != 0)
                    {
                        EventType.SelectedIndices.Add(l_CurrentIndex);
                        break;
                    }

                    l_CurrentIndex++;
                }
                EventType_SelectedIndexChanged(this, null);

                Parameter1.Text = p_Current.Params[0].ToString();
                Parameter2.Text = p_Current.Params[1].ToString();
                Parameter3.Text = p_Current.Params[2].ToString();
                Parameter4.Text = p_Current.Params[3].ToString();

                Comment.Text = p_Current.Comment.Replace("\\n", "\n");
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public ActionManager(ScriptAction p_Current, ScriptEvent p_Event, bool p_Create)
        {
            InitializeComponent();

            InitializationActionTypes();
            InitializationTargetTypes();

            TargetParameter1Description.Text = "";
            TargetParameter2Description.Text = "";
            TargetParameter3Description.Text = "";

            ActionParameter1Description.Text = "";
            ActionParameter2Description.Text = "";
            ActionParameter3Description.Text = "";
            ActionParameter4Description.Text = "";
            ActionParameter5Description.Text = "";
            ActionParameter6Description.Text = "";

            m_Current       = p_Current;
            m_Event         = p_Event;
            m_IsCreation    = p_Create;

            if (!p_Create && p_Current != null)
            {
                int l_CurrentIndex = 0;
                foreach (var l_Type in Game.ActionTypes.Instance.Types)
                {
                    if ((p_Current.Type & l_Type.Value) != 0)
                    {
                        ActionType.SelectedIndices.Add(l_CurrentIndex);
                        break;
                    }

                    l_CurrentIndex++;
                }
                ActionType_SelectedIndexChanged(this, null);

                l_CurrentIndex = 0;
                foreach (var l_Type in Game.TargetTypes.Instance.Types)
                {
                    if ((p_Current.Type & l_Type.Value) != 0)
                    {
                        TargetType.SelectedIndices.Add(l_CurrentIndex);
                        break;
                    }

                    l_CurrentIndex++;
                }
                TargetType_SelectedIndexChanged(this, null);

                ActionParameter1.Text = p_Current.Params[0].ToString();
                ActionParameter2.Text = p_Current.Params[1].ToString();
                ActionParameter3.Text = p_Current.Params[2].ToString();
                ActionParameter4.Text = p_Current.Params[3].ToString();
                ActionParameter5.Text = p_Current.Params[4].ToString();
                ActionParameter6.Text = p_Current.Params[5].ToString();

                TargetParameter1.Text = p_Current.TargetParams[0].ToString();
                TargetParameter2.Text = p_Current.TargetParams[1].ToString();
                TargetParameter3.Text = p_Current.TargetParams[2].ToString();

                TargetX.Text = p_Current.TargetX.ToString();
                TargetY.Text = p_Current.TargetY.ToString();
                TargetZ.Text = p_Current.TargetZ.ToString();
                TargetO.Text = p_Current.TargetO.ToString();

                Comment.Text = p_Current.Comment.Replace("\\n", "\n");
            }
        }
        //////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Internal recursive get event
        /// </summary>
        /// <param name="p_ID"></param>
        /// <param name="p_Current"></param>
        /// <param name="p_Found"></param>
        /// <returns></returns>
        private static ScriptEvent _GetEvent(uint p_ID, ScriptEvent p_Current, ref bool p_Found)
        {
            if (p_Current.ID == p_ID)
            {
                p_Found = true;
                return p_Current;
            }

            foreach (var l_SubEvent in p_Current.SubEvents)
            {
                ScriptEvent l_Result = _GetEvent(p_ID, l_SubEvent, ref p_Found);

                if (p_Found)
                    return l_Result;
            }

            return null;
        }
        /// <summary>
        /// Internal recursive delete event
        /// </summary>
        /// <param name="p_ID"></param>
        /// <param name="p_Current"></param>
        /// <param name="p_Found"></param>
        private static void _DeleteEvent(uint p_ID, ScriptEvent p_Current, ref bool p_Found)
        {
            foreach (var l_SubEvent in p_Current.SubEvents)
            {
                if (l_SubEvent.ID == p_ID)
                {
                    p_Current.SubEvents.Remove(l_SubEvent);
                    return;
                }

                _DeleteEvent(p_ID, l_SubEvent, ref p_Found);

                if (p_Found)
                    return;
            }

            return;
        }