Example #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;
     }
 }
Example #2
0
 private void OnGameStarted()
 {
     //_displayDropLocation = ClientOptionsViewModel.Instance.DisplayDropLocation;
     _pieceHint = null; // reset hint
     ExecuteOnUIThread.Invoke(DesactivateContinuousSpecials);
     ExecuteOnUIThread.Invoke(() => PauseText.Visibility = Visibility.Hidden);
 }
Example #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);
         }
     }
 }
Example #4
0
        private void Reset()
        {
            Client.ResetAchievements();
            Settings.Default.Achievements.Save(Client.Achievements.ToList());
            Settings.Default.Save();

            ExecuteOnUIThread.Invoke(() => Achievements = BuildAchievementList(Client.Achievements.ToList()));
        }
Example #5
0
 private void AddSpectatorEntry(int spectatorId, string spectatorName)
 {
     ExecuteOnUIThread.Invoke(() => SpectatorList.Add(new SpectatorData
     {
         SpectatorId   = spectatorId,
         SpectatorName = spectatorName,
     }));
 }
Example #6
0
 private void OnGameStarted()
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         SetInventoryLength();
         DrawInventory();
     });
 }
Example #7
0
 private void ClearEntries()
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         PlayerList.Clear();
         SpectatorList.Clear();
     });
 }
Example #8
0
 private void SetConnectionResultMessage(ChatColor color, string format, params object[] args)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         ConnectionResult      = String.Format(format, args);
         ConnectionResultColor = color;
     });
 }
Example #9
0
 private void OnGameStarted()
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         ClearGrid();
         ResetImmunity();
     });
 }
Example #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,
     }));
 }
Example #11
0
 private void SetTeam(int playerId, string team)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         foreach (PlayerData p in PlayerList.Where(x => x.RealPlayerId == playerId))
         {
             p.Team = team;
         }
     });
 }
Example #12
0
 private void SetServerMaster(int serverMasterId)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         foreach (PlayerData p in PlayerList)
         {
             p.IsServerMaster = p.RealPlayerId == serverMasterId;
         }
     });
 }
Example #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();
        }
Example #14
0
 public void AddEntry(InGameChatEntry entry)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         Entries.Add(entry);
         if (Entries.Count > MaxEntries)
         {
             Entries.RemoveAt(0);
         }
     });
 }
Example #15
0
 protected void AddEntry(ChatEntry entry)
 {
     ExecuteOnUIThread.Invoke(() =>
     {
         ChatEntries.Add(entry);
         if (ChatEntries.Count > MaxEntries)
         {
             ChatEntries.RemoveAt(0);
         }
     });
 }
Example #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));
     }
 }
Example #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();
 }
Example #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);
         }
     });
 }
Example #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();
         }
     });
 }
Example #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();
         }
     });
 }
Example #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);
         }
     });
 }
Example #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);
         }
     });
 }
Example #23
0
 private void OnPlayerUnregistered()
 {
     ExecuteOnUIThread.Invoke(ResetImmunity);
 }
Example #24
0
 private void ClearEntries()
 {
     ExecuteOnUIThread.Invoke(Entries.Clear);
 }
Example #25
0
 public void AddServerToLatest(string address)
 {
     ExecuteOnUIThread.Invoke(() => AddServerToLatestInner(address));
 }
Example #26
0
 private void OnInventoryChanged()
 {
     ExecuteOnUIThread.Invoke(DrawInventory);
 }
Example #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);
        }
Example #28
0
 private void OnPieceMoved()
 {
     ExecuteOnUIThread.Invoke(DrawInventory);
 }
Example #29
0
 private void OnGameFinished(GameStatistics statistics)
 {
     SelectedPlayer = null; // reset
     ExecuteOnUIThread.Invoke(() => AddStatistics(statistics));
     SelectedGameStatistics = statistics;
 }
Example #30
0
 private void OnConnectionLost(ConnectionLostReasons reason)
 {
     ExecuteOnUIThread.Invoke(ResetImmunity);
 }