예제 #1
0
 private void ScanForServer()
 {
     //Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         IsScanForServerEnabled = false;
         IsProgressBarVisible   = true;
         List <string> servers = WCFProxy.DiscoverHosts();
         ExecuteOnUIThread.Invoke(() =>
         {
             Servers.Clear();
             if (servers == null || !servers.Any())
             {
                 Servers.Add("No server found");
             }
             else
             {
                 foreach (string s in servers)
                 {
                     Servers.Add(s);
                 }
             }
         });
     }
     catch
     {
         ExecuteOnUIThread.Invoke(() => Servers.Add("Error while scanning"));
     }
     finally
     {
         IsProgressBarVisible   = false;
         IsScanForServerEnabled = true;
         //Mouse.OverrideCursor = null;
     }
 }
예제 #2
0
 private void OnGameStarted()
 {
     //_displayDropLocation = ClientOptionsViewModel.Instance.DisplayDropLocation;
     _pieceHint = null; // reset hint
     ExecuteOnUIThread.Invoke(DesactivateContinuousSpecials);
     ExecuteOnUIThread.Invoke(() => PauseText.Visibility = Visibility.Hidden);
 }
예제 #3
0
 private void OnContinuousEffectToggled(Specials special, bool active, double duration)
 {
     if (active)
     {
         ContinuousEffect effect = Effects.FirstOrDefault(x => x.Special == special);
         if (effect != null)
         {
             effect.TotalSeconds = duration;
             ExecuteOnUIThread.Invoke(EffectsView.Refresh);
         }
         else
         {
             effect = new ContinuousEffect
             {
                 Special      = special,
                 TotalSeconds = duration
             };
             Effects.Add(effect);
             ExecuteOnUIThread.Invoke(EffectsView.Refresh);
         }
     }
     else
     {
         ContinuousEffect effect = Effects.FirstOrDefault(x => x.Special == special);
         if (effect != null)
         {
             Effects.Remove(effect);
             ExecuteOnUIThread.Invoke(EffectsView.Refresh);
         }
     }
 }
예제 #4
0
        private void Reset()
        {
            Client.ResetAchievements();
            Settings.Default.Achievements.Save(Client.Achievements.ToList());
            Settings.Default.Save();

            ExecuteOnUIThread.Invoke(() => Achievements = BuildAchievementList(Client.Achievements.ToList()));
        }
예제 #5
0
 private void AddSpectatorEntry(int spectatorId, string spectatorName)
 {
     ExecuteOnUIThread.Invoke(() => SpectatorList.Add(new SpectatorData
     {
         SpectatorId   = spectatorId,
         SpectatorName = spectatorName,
     }));
 }
예제 #6
0
 private void OnGameStarted()
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         SetInventoryLength();
         DrawInventory();
     });
 }
예제 #7
0
 private void ClearEntries()
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         PlayerList.Clear();
         SpectatorList.Clear();
     });
 }
예제 #8
0
 private void SetConnectionResultMessage(ChatColor color, string format, params object[] args)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         ConnectionResult      = String.Format(format, args);
         ConnectionResultColor = color;
     });
 }
예제 #9
0
 private void OnGameStarted()
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         ClearGrid();
         ResetImmunity();
     });
 }
예제 #10
0
 private void AddPlayerEntry(int playerId, string playerName, string team)
 {
     ExecuteOnUIThread.Invoke(() => PlayerList.Add(new PlayerData
     {
         RealPlayerId   = playerId,
         PlayerName     = playerName,
         Team           = team,
         IsServerMaster = false,
     }));
 }
예제 #11
0
 private void SetTeam(int playerId, string team)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         foreach (PlayerData p in PlayerList.Where(x => x.RealPlayerId == playerId))
         {
             p.Team = team;
         }
     });
 }
예제 #12
0
 private void SetServerMaster(int serverMasterId)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         foreach (PlayerData p in PlayerList)
         {
             p.IsServerMaster = p.RealPlayerId == serverMasterId;
         }
     });
 }
예제 #13
0
        private void OnAchievementEarned(IAchievement achievement, bool firstTime)
        {
            Log.Default.WriteLine(LogLevels.Info, "Achievement: {0} {1} {2:dd/MM/yyyy HH:mm:ss}", achievement.Title, firstTime, achievement.LastTimeAchieved);

            Settings.Default.Achievements.Save(Client.Achievements.ToList());
            Settings.Default.Save();

            ExecuteOnUIThread.Invoke(() => Achievements = BuildAchievementList(Client.Achievements.ToList()));
            //
            RefreshAchievementsStats();
        }
예제 #14
0
 public void AddEntry(InGameChatEntry entry)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         Entries.Add(entry);
         if (Entries.Count > MaxEntries)
         {
             Entries.RemoveAt(0);
         }
     });
 }
예제 #15
0
 protected void AddEntry(ChatEntry entry)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         ChatEntries.Add(entry);
         if (ChatEntries.Count > MaxEntries)
         {
             ChatEntries.RemoveAt(0);
         }
     });
 }
예제 #16
0
 private void OnContinuousEffectToggled(Specials special, bool active, double duration)
 {
     if (special == Specials.Immunity)
     {
         ExecuteOnUIThread.Invoke(() => ActivateImmunity(active));
     }
     else if (special == Specials.Darkness)
     {
         ExecuteOnUIThread.Invoke(() => ActivateDarkness(active));
     }
 }
예제 #17
0
 private void OnGameFinished(GameStatistics statistics)
 {
     //
     RefreshResetEnable();
     //
     ExecuteOnUIThread.Invoke(() => Achievements = BuildAchievementList(Client.Achievements.ToList()));
     //
     Settings.Default.Achievements.Save(Client.Achievements.ToList());
     Settings.Default.Save();
     //
     RefreshAchievementsStats();
 }
예제 #18
0
 private void DeleteSpectatorEntry(int spectatorId, string spectatorName)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         SpectatorData s = SpectatorList.FirstOrDefault(x => x.SpectatorId == spectatorId);
         if (s != null)
         {
             SpectatorList.Remove(s);
         }
         else
         {
             Log.Default.WriteLine(LogLevels.Warning, "Trying to delete unknown spectator {0}[{1}] from spectator list", spectatorId, spectatorName);
         }
     });
 }
예제 #19
0
 private void OnContinuousSpecialFinished(int playerId, Specials special)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         OpponentViewModel vm = DataContext as OpponentViewModel;
         if (vm == null)
         {
             return;
         }
         if (playerId == vm.PlayerId && special == Specials.Immunity)
         {
             ResetImmunity();
         }
     });
 }
예제 #20
0
 private void OnSpecialUsed(int playerId, string playerName, int targetId, string targetName, int specialId, Specials special)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         OpponentViewModel vm = DataContext as OpponentViewModel;
         if (vm == null)
         {
             return;
         }
         if (targetId == vm.PlayerId && special == Specials.Immunity && (vm.Client.IsPlaying || vm.Client.IsSpectator || ClientOptionsViewModel.Instance.DisplayOpponentsFieldEvenWhenNotPlaying))
         {
             SetImmunity();
         }
     });
 }
예제 #21
0
 private void DeletePlayerEntry(int playerId, string playerName)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         PlayerData p = PlayerList.FirstOrDefault(x => x.RealPlayerId == playerId);
         if (p != null)
         {
             PlayerList.Remove(p);
         }
         else
         {
             Log.Default.WriteLine(LogLevels.Warning, "Trying to delete unknown player {0}[{1}] from player list", playerId, playerName);
         }
     });
 }
예제 #22
0
 private void OnRedrawBoard(int playerId, IBoard board)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         OpponentViewModel vm = DataContext as OpponentViewModel; // <-- this may cause cross-thread exception
         if (vm == null)
         {
             return;
         }
         if (playerId == vm.PlayerId && (vm.Client.IsPlaying || vm.Client.IsSpectator || ClientOptionsViewModel.Instance.DisplayOpponentsFieldEvenWhenNotPlaying))
         {
             DrawGrid(board);
         }
     });
 }
예제 #23
0
 private void OnPlayerUnregistered()
 {
     ExecuteOnUIThread.Invoke(ResetImmunity);
 }
예제 #24
0
 private void ClearEntries()
 {
     ExecuteOnUIThread.Invoke(Entries.Clear);
 }
예제 #25
0
 public void AddServerToLatest(string address)
 {
     ExecuteOnUIThread.Invoke(() => AddServerToLatestInner(address));
 }
예제 #26
0
 private void OnInventoryChanged()
 {
     ExecuteOnUIThread.Invoke(DrawInventory);
 }
예제 #27
0
        protected override void OnStartup(StartupEventArgs e)
        {
            //
            ExecuteOnUIThread.Initialize();

            // Initialize Log
            string logFilename = "WPF_" + Guid.NewGuid().ToString().Substring(0, 5) + ".log";

            Log.Default.Initialize(ConfigurationManager.AppSettings["logpath"], logFilename);

            //// Log user settings path
            //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
            //Log.Default.WriteLine(LogLevels.Info, "Local user config path: {0}", config.FilePath);

            //// TODO: if PortableSettingsProvider file doesn't exist, copy config.FilePath to PortableSettingsProvider path

            if (!Directory.Exists(PortableSettingsProvider.SettingsPath))
            {
                Directory.CreateDirectory(PortableSettingsProvider.SettingsPath);
            }
            // If new config file doesn't exist, rename user.config or copy old one
            try
            {
                string newPath = Path.Combine(PortableSettingsProvider.SettingsPath, PortableSettingsProvider.SettingsFilename);
                if (!File.Exists(newPath))
                {
                    //
                    string oldPath = Path.Combine(PortableSettingsProvider.SettingsPath, "user.config");
                    if (File.Exists(oldPath))
                    {
                        Log.Default.WriteLine(LogLevels.Info, @"User settings file not found. Rename {0} to {1}", oldPath, newPath);
                        File.Move(oldPath, newPath);
                    }
                    else
                    {
                        // Original config file path
                        Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
                        if (File.Exists(config.FilePath))
                        {
                            Log.Default.WriteLine(LogLevels.Info, "User settings file not found. Copy {0} to {1}", config.FilePath, newPath);
                            File.Copy(config.FilePath, newPath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Default.WriteLine(LogLevels.Error, "Error while creating new config file from old one. Exception: {0}", ex.ToString());
            }


            //ExtractTetrinetTextures();

            // Get textures
            string textureFilepath = ConfigurationManager.AppSettings["texture"];
            bool   isDirectory     = false;

            try
            {
                FileAttributes attr = File.GetAttributes(textureFilepath);
                isDirectory = (attr & FileAttributes.Directory) == FileAttributes.Directory;
            }
            catch
            {
            }
            if (isDirectory)
            {
                TextureManager.TextureManager.Instance.ReadFromPath(textureFilepath);
            }
            else
            {
                TextureManager.TextureManager.Instance.ReadFromFile(textureFilepath);
            }

            //
            base.OnStartup(e);
        }
예제 #28
0
 private void OnPieceMoved()
 {
     ExecuteOnUIThread.Invoke(DrawInventory);
 }
예제 #29
0
 private void OnGameFinished(GameStatistics statistics)
 {
     SelectedPlayer = null; // reset
     ExecuteOnUIThread.Invoke(() => AddStatistics(statistics));
     SelectedGameStatistics = statistics;
 }
예제 #30
0
 private void OnConnectionLost(ConnectionLostReasons reason)
 {
     ExecuteOnUIThread.Invoke(ResetImmunity);
 }