Esempio n. 1
0
 public void DeselectAll()
 {
     foreach (IVIStar star in selection_star_system.Root.Children)
     {
         IVIStar star_in_src_sys = null;
         selection_sys_to_src_sys.TryGetValue(star, out star_in_src_sys);
         if (star_in_src_sys != null)
         {
             star_in_src_sys.NotifyDeselected();
         }
         Destroy(star.gameObject);
     }
     selection_star_system.Root.Children.Clear();
     selection_sys_to_src_sys.Clear();
 }
Esempio n. 2
0
    // ToggleSelect(star) remplace Select(star).
    // "Select(star)" ne communique pas l'intention de déselectionner une Star
    // si elle est déjà sélectionnée.
    public void ToggleSelect(IVIStar candidate)
    {
        // Pour chaque star déjà dans la sélection
        foreach (IVIStar present in selection_star_system.Root.Children)
        {
            // Test si la star ne provient pas du star_system du clipboard même
            // (égalité de références)
            if (candidate == present)
            {
                Debug.Log("[Clipboard]: Ignored " + candidate.Entry.FullPath);
                return;
            }

            // Si la candidate est déjà présente, on la désélectionne.
            if (candidate.Entry.FullPath.Equals(present.Entry.FullPath))
            {
                selection_star_system.Root.Children.Remove(present);
                selection_sys_to_src_sys.Remove(present);
                Destroy(present);
                candidate.NotifyDeselected();
                Debug.Log("[Clipboard]: Deselected " + candidate.Entry.FullPath);
                OnSelectionStarSystemChanged();
                // C'est mauvais d'appeler Remove() pendant qu'on itère sur la collection,
                // mais on est sauvés par le return.
                return;
            }

            // Test si un supérieur/inférieur de star est déjà dans la sélection
            if (candidate.Entry.FullPath.StartsWith(present.Entry.FullPath) ||
                present.Entry.FullPath.StartsWith(candidate.Entry.FullPath))
            {
                Debug.Log("[Clipboard]: Replaced `" + present.Entry.FullPath
                          + "` by `" + candidate.Entry.FullPath + "` ");
                IVIStar present_in_src_sys;
                selection_sys_to_src_sys.TryGetValue(present, out present_in_src_sys);
                present_in_src_sys.NotifyDeselected();
                candidate.NotifySelected();
                var candidate_copy = Instantiate(candidate, selection_star_system.transform).GetComponent <IVIStar> ();
                candidate_copy.Parent = selection_star_system.Root;
                candidate_copy.Entry  = candidate.Entry;                // Nécessaire
                selection_star_system.Root.Children.Add(candidate_copy);
                selection_star_system.Root.Children.Remove(present);
                Destroy(present);
                selection_sys_to_src_sys.Add(candidate_copy, candidate);
                selection_sys_to_src_sys.Remove(present);
                OnSelectionStarSystemChanged();
                // C'est mauvais d'appeler Remove() pendant qu'on itère sur la collection,
                // mais on est sauvés par le return.
                return;
            }
        }

        candidate.NotifySelected();
        var candidate_cpy = Instantiate(candidate, selection_star_system.transform).GetComponent <IVIStar> ();

        candidate_cpy.Parent = selection_star_system.Root;
        candidate_cpy.Entry  = candidate.Entry;        // OK, c'est nécessaire !
        selection_star_system.Root.Children.Add(candidate_cpy);
        selection_sys_to_src_sys.Add(candidate_cpy, candidate);
        Debug.Log("[Clipboard]: Selected " + candidate.Entry.FullPath);
        OnSelectionStarSystemChanged();
    }