Exemplo n.º 1
0
        public bool AddOrReplaceScript(string name, string script)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            var coreCtrl = luaCoreCtrls
                           .FirstOrDefault(c => c.name == name);

            if (coreCtrl != null)
            {
                coreCtrl.ReplaceScript(script);
                return(true);
            }

            var coreState = new Models.Data.LuaCoreSetting
            {
                name   = name,
                script = script,
            };

            settings.GetLuaCoreSettings().Add(coreState);

            coreCtrl = new Controllers.LuaCoreCtrl();
            luaCoreCtrls.Add(coreCtrl);
            coreCtrl.Run(settings, coreState, luaApis);
            Save();
            InvokeOnLuaCoreCtrlListChangeIgnoreError();
            return(true);
        }
Exemplo n.º 2
0
        public void Run(
            VgcApis.Models.IServices.IApiService api,
            Services.Settings settings,
            Services.LuaServer luaServer)
        {
            this.api        = api;
            this.configMgr  = api.GetConfigMgrService();
            this.vgcServers = api.GetServersService();

            this.settings    = settings;
            this.luaServer   = luaServer;
            this.luaCoreCtrl = CreateLuaCoreCtrl(
                settings, api);

            InitControls();
            BindEvents();

            ReloadScriptName();
            if (cboxScriptName.Items.Count > 0)
            {
                cboxScriptName.SelectedIndex = 0;
            }

            updateOutputTimer.Tick += UpdateOutput;
            updateOutputTimer.Start();
        }
Exemplo n.º 3
0
        public static void ShowForm(Controllers.LuaCoreCtrl luaCoreCtrl)
        {
            FormLuaCoreSettings f = null;

            if (_instant == null || _instant.IsDisposed)
            {
                VgcApis.Misc.UI.Invoke(() =>
                {
                    f = new FormLuaCoreSettings();
                });
            }

            lock (formInstanLocker)
            {
                if (_instant == null || _instant.IsDisposed)
                {
                    _instant = f;
                    f        = null;
                }
            }

            VgcApis.Misc.UI.Invoke(() =>
            {
                f?.Close();
                var inst = _instant;
                if (inst != null)
                {
                    inst.InitControls(luaCoreCtrl);
                    inst.Show();
                    inst.Activate();
                }
            });
        }
Exemplo n.º 4
0
 void BindEvent(Controllers.LuaCoreCtrl ctrl)
 {
     if (ctrl == null)
     {
         return;
     }
     ctrl.OnStateChange += OnLuaCoreStateChangeHandler;
 }
Exemplo n.º 5
0
        void AddNewLuaCoreCtrl(Models.Data.LuaCoreSetting coreState)
        {
            var coreCtrl = new Controllers.LuaCoreCtrl(false);

            luaCoreCtrls.Add(coreCtrl);
            coreCtrl.Run(settings, coreState, luaApis);
            coreCtrl.OnStateChange += OnRequireMenuUpdateHandler;
        }
Exemplo n.º 6
0
 void ReleaseEvent(Controllers.LuaCoreCtrl ctrl)
 {
     if (ctrl == null)
     {
         return;
     }
     ctrl.OnStateChange -= OnLuaCoreStateChangeHandler;
 }
Exemplo n.º 7
0
 public LuaUI(
     Services.LuaServer luaServer,
     Controllers.LuaCoreCtrl luaCoreCtrl)
 {
     this.luaCoreCtrl = luaCoreCtrl;
     this.luaServer   = luaServer;
     InitializeComponent();
 }
Exemplo n.º 8
0
        void RemoveCoreCtrl(Controllers.LuaCoreCtrl coreCtrl)
        {
            var name = coreCtrl.name;

            coreCtrl.OnStateChange -= OnRequireMenuUpdateHandler;
            coreCtrl.Abort();
            luaCoreCtrls.Remove(coreCtrl);
            settings.GetLuaCoreSettings().RemoveAll(s => s.name == name);
        }
Exemplo n.º 9
0
 public LuaUI(
     Services.LuaServer luaServer,
     Services.FormMgrSvc formMgrSvc,
     Controllers.LuaCoreCtrl luaCoreCtrl)
 {
     this.luaCoreCtrl = luaCoreCtrl;
     this.luaServer   = luaServer;
     this.formMgrSvc  = formMgrSvc;
     InitializeComponent();
 }
Exemplo n.º 10
0
        void UpdateNameLabel(Controllers.LuaCoreCtrl ctrl)
        {
            var n = ctrl.name;

            if (lbName.Text != n)
            {
                lbName.Text = n;
                toolTip1.SetToolTip(lbName, n);
            }
        }
Exemplo n.º 11
0
        List <Controllers.LuaCoreCtrl> InitLuaCores(
            Settings settings,
            Models.Apis.LuaApis luaApis)
        {
            var cores = new List <Controllers.LuaCoreCtrl>();

            foreach (var luaCoreState in settings.GetLuaCoreSettings())
            {
                var luaCtrl = new Controllers.LuaCoreCtrl();
                luaCtrl.Run(settings, luaCoreState, luaApis);
                cores.Add(luaCtrl);
            }
            return(cores);
        }
Exemplo n.º 12
0
        void UpdateRunningState(Controllers.LuaCoreCtrl ctrl)
        {
            var isRunning = ctrl.isRunning;
            var text      = isRunning ? "ON" : "OFF";
            var color     = isRunning ? Color.DarkOrange : Color.Green;

            if (lbRunningState.Text != text)
            {
                lbRunningState.Text = text;
            }
            if (lbRunningState.ForeColor != color)
            {
                lbRunningState.ForeColor = color;
            }
        }
Exemplo n.º 13
0
        public void Reload(
            Services.LuaServer luaServerSvc,
            Services.FormMgrSvc formMgrSvc,

            Controllers.LuaCoreCtrl luaCoreCtrl)
        {
            this.luaServerSvc = luaServerSvc;
            this.formMgrSvc   = formMgrSvc;

            var org = this.luaCoreCtrl;

            this.luaCoreCtrl = luaCoreCtrl;
            ReleaseEvent(org);
            BindEvent(luaCoreCtrl);
            UpdateUiLater();
        }
Exemplo n.º 14
0
        void UpdateOptionsLabel(Controllers.LuaCoreCtrl ctrl)
        {
            var a    = ctrl.isAutoRun ? "A" : @"";
            var h    = ctrl.isHidden ? "H" : "";
            var c    = ctrl.isLoadClr ? "C" : "";
            var text = $"{a}{c}{h}";

            if (string.IsNullOrEmpty(text))
            {
                text = I18N.LuaCtrlOptionNone;
            }

            if (rlbOptions.Text != text)
            {
                rlbOptions.Text = text;
            }
        }
Exemplo n.º 15
0
        public static void ShowForm(Controllers.LuaCoreCtrl luaCoreCtrl)
        {
            lock (formInstanLocker)
            {
                if (_instant == null || _instant.IsDisposed)
                {
                    VgcApis.Misc.UI.Invoke(() =>
                    {
                        _instant = new FormLuaCoreSettings();
                    });
                }

                VgcApis.Misc.UI.Invoke(() =>
                {
                    _instant.InitControls(luaCoreCtrl);
                    _instant.Show();
                    _instant.Activate();
                });
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// true: require refresh false: not need refresh
        /// </summary>
        /// <param name="name"></param>
        /// <param name="script"></param>
        /// <returns></returns>
        bool AddOrReplaceScriptQuiet(string name, string script)
        {
            var coreCtrl = luaCoreCtrls.FirstOrDefault(c => c.name == name);

            if (coreCtrl != null)
            {
                coreCtrl.ReplaceScript(script);
                return(false);
            }

            var coreState = new Models.Data.LuaCoreSetting
            {
                name   = name,
                script = script,
            };

            settings.GetLuaCoreSettings().Add(coreState);
            coreCtrl = new Controllers.LuaCoreCtrl();
            luaCoreCtrls.Add(coreCtrl);
            coreCtrl.Run(settings, coreState, luaApis);
            return(true);
        }
Exemplo n.º 17
0
 void InitControls(Controllers.LuaCoreCtrl luaCoreCtrl)
 {
     this.luaCoreCtrl = luaCoreCtrl;
     UpdateUi();
 }
Exemplo n.º 18
0
 public LuaUI(Controllers.LuaCoreCtrl luaCoreCtrl)
 {
     this.luaCoreCtrl = luaCoreCtrl;
     InitializeComponent();
 }