Пример #1
0
        public static HighlightSettings Default()
        {
            var settings = new HighlightSettings();

            settings.Add(new HighlightSetting { Id = HighlightKeys.Default, Color = "#F5F5F5"  });
            settings.Add(new HighlightSetting { Id = HighlightKeys.Bold, Color = "#FFFF00"  });
            settings.Add(new HighlightSetting { Id = HighlightKeys.RoomName, Color = "#0000FF"  });
            settings.Add(new HighlightSetting { Id = HighlightKeys.Whisper, Color = "#00FFFF"  });

            return settings;
        }
Пример #2
0
        public BoldHighlighter(HighlightSettings settings)
        {
            _settings = settings;

            Modify = (tag, match) => {
                var setting = _settings.Get(HighlightKeys.Bold);
                tag.Text = match.Groups[2].Value;
                tag.Color = setting.Color;
                tag.Mono = setting.Mono;
                tag.Matched = true;
            };
        }
Пример #3
0
        public RoomNameHighlighter(IGameState gameState, HighlightSettings settings)
        {
            _gameState = gameState;
            _settings = settings;

            Matches = (s) => {
                return s == _gameState.Get(ComponentKeys.RoomName) || s == _gameState.Get(ComponentKeys.RoomTitle);
            };
            Modify = (tag) => {
                var setting = _settings.Get(HighlightKeys.RoomName);
                tag.Color = setting.Color;
                tag.Mono = setting.Mono;
                tag.Matched = true;
            };
        }
Пример #4
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            InitializeVitalsAndRTBars();

            Window.Title = "Outlander";

            _gameServer = _bootStrapper.Build();
            _services = _bootStrapper.ServiceLocator();

            var appSettings = _services.Get<AppSettings>();
            var homeDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Documents/Outlander");
            appSettings.HomeDirectory = homeDir;

            _services.Get<IAppDirectoriesBuilder>().Build();
            _services.Get<IAppSettingsLoader>().Load();

            UpdateImages();

            _commandProcessor = _services.Get<ICommandProcessor>();
            _scriptLog = _services.Get<IScriptLog>();
            _services.Get<IRoundtimeHandler>().Changed += (sender, e) => {
                SetRoundtime(e);
            };

            _highlightSettings = _services.Get<HighlightSettings>();
            _mainTextViewWrapper = new TextViewWrapper(MainTextView, _highlightSettings);

            _scriptLog.Info += (sender, e) => {
                string log;
                if(e.LineNumber > -1)
                {
                    log = "[{0}({1})]:  {2}\n".ToFormat(e.Name, e.LineNumber, e.Data);
                }
                else
                {
                    log = "[{0}]:  {1}\n".ToFormat(e.Name, e.Data);
                }

                BeginInvokeOnMainThread(()=> {

                    var hasLineFeed = MainTextView.TextStorage.Value.EndsWith("\n");

                    if(!hasLineFeed)
                        log = "\n" + log;

                    var tag = TextTag.For(log, "#0066CC");

                    _mainTextViewWrapper.Append(tag);
                });
            };

            _scriptLog.NotifyStarted += (sender, e) => {

                var log = "[{0}]: {1} - script started\n".ToFormat(e.Name, e.Started.ToString("G"));

                BeginInvokeOnMainThread(()=> {

                    var hasLineFeed = MainTextView.TextStorage.Value.EndsWith("\n");

                    if(!hasLineFeed)
                        log = "\n" + log;

                    var tag = TextTag.For(log, "ADFF2F");
                    _mainTextViewWrapper.Append(tag);
                });
            };

            _scriptLog.NotifyAborted += (sender, e) => {
                var log = "[{0}]: total runtime {1:hh\\:mm\\:ss} - {2} seconds\n".ToFormat(e.Name, e.Runtime, Math.Round(e.Runtime.TotalSeconds, 2));

                BeginInvokeOnMainThread(()=> {

                    var hasLineFeed = MainTextView.TextStorage.Value.EndsWith("\n");

                    if(!hasLineFeed)
                        log = "\n" + log;

                    var tag = TextTag.For(log, "ADFF2F");
                    _mainTextViewWrapper.Append(tag);
                });
            };

            var notifyLogger = new NotificationLogger();
            notifyLogger.OnError = (err) => {
                BeginInvokeOnMainThread(()=> {
                    LogSystem(err.Message + "\n\n");
                });
            };

            var compositeLogger = _services.Get<ILog>().As<CompositeLog>();
            compositeLogger.Add(notifyLogger);

            _gameServer.GameState.Tags = (tags) => {
                tags.Apply(t => {
                    t.As<AppTag>().IfNotNull(appInfo => {
                        BeginInvokeOnMainThread(() => {
                            Window.Title = string.Format("{0}: {1} - {2}", appInfo.Game, appInfo.Character, "Outlander");
                        });
                    });

                    t.As<StreamTag>().IfNotNull(streamTag => {
                        if(!string.IsNullOrWhiteSpace(streamTag.Id) && streamTag.Id.Equals("logons")) {

                            var text = "[{0}]{1}".ToFormat(DateTime.Now.ToString("HH:mm"), streamTag.Text);
                            var highlights = _services.Get<Highlights>().For(TextTag.For(text));

                            BeginInvokeOnMainThread(()=> {
                                highlights.Apply(h => {
                                    h.Mono = true;
                                    Append(h, ArrivalsTextView);
                                });
                            });
                        }

                        if(!string.IsNullOrWhiteSpace(streamTag.Id) && streamTag.Id.Equals("thoughts")) {

                            var text = "[{0}]: {1}".ToFormat(DateTime.Now.ToString("HH:mm"), streamTag.Text);
                            var highlights = _services.Get<Highlights>().For(TextTag.For(text));

                            BeginInvokeOnMainThread(()=> {
                                highlights.Apply(h => {
                                    Append(h, ThoughtsTextView);
                                });
                            });
                        }

                        if(!string.IsNullOrWhiteSpace(streamTag.Id) && streamTag.Id.Equals("death")) {

                            var text = "[{0}]{1}".ToFormat(DateTime.Now.ToString("HH:mm"), streamTag.Text);
                            var highlights = _services.Get<Highlights>().For(TextTag.For(text));

                            BeginInvokeOnMainThread(()=> {
                                highlights.Apply(h => {
                                    Append(h, DeathsTextView);
                                });
                            });
                        }
                    });

                    t.As<SpellTag>().IfNotNull(s => {
                        BeginInvokeOnMainThread(() => {
                            _spell = s.Spell;
                            _count = 0;
                            SpellLabel.StringValue = "S: {0}".ToFormat(s.Spell);

                            if(!string.Equals(_spell, "None"))
                            {
                                _gameServer.GameState.Set(ComponentKeys.SpellTime, "0");
                                _spellTimer.Start();
                            }
                            else
                            {
                                _spellTimer.Stop();
                                _gameServer.GameState.Set(ComponentKeys.SpellTime, "0");
                            }
                        });
                    });

                    t.As<VitalsTag>().IfNotNull(v => {
                        UpdateVitals();
                    });

                    var ids = new string[]
                    {
                        ComponentKeys.RoomTitle,
                        ComponentKeys.RoomDescription,
                        ComponentKeys.RoomObjects,
                        ComponentKeys.RoomPlayers,
                        ComponentKeys.RoomExists
                    };

                    t.As<ComponentTag>().IfNotNull(c => {
                        if(!ids.Contains(c.Id))
                            return;
                        var builder = new StringBuilder();
                        _gameServer.GameState.Get(ComponentKeys.RoomTitle).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomDescription).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomObjectsH).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomPlayers).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomExists).IfNotNullOrEmpty(s=>builder.AppendLine(s));

                        BeginInvokeOnMainThread(()=> {
                            LogRoom(builder.ToString(), RoomTextView);
                        });
                    });

                    BeginInvokeOnMainThread(()=> {
                        UpdateImages();

                        LeftHandLabel.StringValue = string.Format("L: {0}", _gameServer.GameState.Get(ComponentKeys.LeftHand));
                        RightHandLabel.StringValue = string.Format("R: {0}", _gameServer.GameState.Get(ComponentKeys.RightHand));
                    });

                    _services.Get<IAppSettingsLoader>().SaveVariables();
                });
            };

            _gameServer.GameState.Exp = (exp) => {

                _expTracker.Update(exp);

                var skills = _expTracker.SkillsWithExp().ToList();
                var tags = skills
                        .OrderBy(x => x.Name)
                        .Select(x =>
                        {
                            var color = x.IsNew ? _highlightSettings.Get(HighlightKeys.Whisper).Color : string.Empty;
                            return TextTag.For(x.Display() + "\n", color, true);
                        }).ToList();
                var now = DateTime.Now;
                tags.Add(TextTag.For("Last updated: {0:hh\\:mm\\:ss tt}\n".ToFormat(now), string.Empty, true));
                if(_expTracker.StartedTracking.HasValue)
                    tags.Add(TextTag.For("Tracking for: {0:hh\\:mm\\:ss}\n".ToFormat(now - _expTracker.StartedTracking.Value), string.Empty, true));

                BeginInvokeOnMainThread(()=> {
                    ReplaceText(tags, ExpTextView);
                });
            };

            _gameStream = _services.Get<IGameStream>();
            _gameStreamListener = new GameStreamListener(tag => {
                BeginInvokeOnMainThread(()=>{
                    if(tag.Filtered)
                        return;
                    Log(tag);
                });
            });
            _gameStreamListener.Subscribe(_gameStream);
        }
Пример #5
0
 public TextViewWrapper(NSTextView textView, HighlightSettings highlightSettings)
 {
     _textView = textView;
     _highlightSettings = highlightSettings;
 }