private void toggleItem(T value, bool active) { if (active) { Current.Add(value); } else { Current.Remove(value); } }
public void AddLanguage(CultureInfo cultureInfo) { if (Languages.Contains(cultureInfo)) { return; } changeHandler?.BeginChange(); Languages.Add(cultureInfo); changeHandler?.EndChange(); }
private void AddWords(IEnumerable <WordViewModel> words) { foreach (WordViewModel word in words) { if (word.Segments.Any(s => s.IsSelected)) { _selectedSegmentWords.Add(word); } word.PropertyChanged += word_PropertyChanged; } }
Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state) { if (!playingUsers.Contains(userId)) { playingUsers.Add(userId); } OnUserBeganPlaying?.Invoke(userId, state); return(Task.CompletedTask); }
private void beatmapUpdated(ValueChangedEvent <WeakReference <BeatmapSetInfo> > weakSet) { if (weakSet.NewValue.TryGetTarget(out var set)) { Schedule(() => { beatmapSets.Remove(set); beatmapSets.Add(set); }); } }
internal bool FindNext(FindField field, string str) { if (_words.Count == 0) { ResetSearch(); return(false); } if (_selectedWords.Count == 0) { _startWord = _wordsView.Cast <WordViewModel>().Last(); } else if (_startWord == null) { _startWord = _selectedWords[0]; } else if (_selectedWords.Contains(_startWord)) { ResetSearch(); return(false); } List <WordViewModel> words = _wordsView.Cast <WordViewModel>().ToList(); WordViewModel curWord = _selectedWords.Count == 0 ? _startWord : _selectedWords[0]; int wordIndex = words.IndexOf(curWord); do { wordIndex = (wordIndex + 1) % words.Count; curWord = words[wordIndex]; bool match = false; switch (field) { case FindField.Form: match = curWord.StrRep.Contains(str); break; case FindField.Gloss: match = curWord.Meaning.Gloss.Contains(str); break; } if (match) { using (_selectedWordsMonitor.Enter()) { _selectedWords.Clear(); _selectedWords.Add(curWord); } return(true); } }while (_startWord != curWord); ResetSearch(); return(false); }
private void AddFeature() { FeatureViewModel feature = _selectedAvailableFeature; _availableFeatures.Remove(feature); if (feature.Values.Count > 0) { feature.SelectedValue = feature.Values[0]; } _activeFeatures.Add(feature); SelectedActiveFeature = feature; }
private void load(OsuColour colours) { linkColour = colours.Blue; var chatManager = new ChannelManager(); BindableList <Channel> availableChannels = (BindableList <Channel>)chatManager.AvailableChannels; availableChannels.Add(new Channel { Name = "#english" }); availableChannels.Add(new Channel { Name = "#japanese" }); Dependencies.Cache(chatManager); Dependencies.Cache(new ChatOverlay()); Dependencies.Cache(dialogOverlay); testLinksGeneral(); testEcho(); }
private void load(LyricEditorColourProvider colourProvider, ILyricEditorState state) { hoveredBackground.Colour = colourHover = colourProvider.Background1(LyricEditorMode.CreateTimeTag); colourSelected = colourProvider.Colour3(LyricEditorMode.CreateTimeTag); // update selected state by bindable. selectedTimeTags = state.SelectedTimeTags.GetBoundCopy(); selectedTimeTags.BindCollectionChanged((a, b) => { selected = selectedTimeTags.Contains(timeTag); updateState(); }); Action = () => { // navigate to current lyric. switch (state.Mode) { case LyricEditorMode.CreateTimeTag: state.BindableCaretPosition.Value = new TimeTagIndexCaretPosition(lyric, timeTag?.Index ?? new TextIndex()); break; case LyricEditorMode.RecordTimeTag: state.BindableCaretPosition.Value = new TimeTagCaretPosition(lyric, timeTag); break; case LyricEditorMode.AdjustTimeTag: state.BindableCaretPosition.Value = new NavigateCaretPosition(lyric); break; default: throw new IndexOutOfRangeException(nameof(state.Mode)); } // set current time-tag as selected. selectedTimeTags.Clear(); if (timeTag == null) { return; } // select time-tag is not null. selectedTimeTags.Add(timeTag); if (timeTag.Time == null) { return; } // seek to target time-tag time if time-tag has time. clock.Seek(timeTag.Time.Value); }; }
/// <summary> /// Adds a <see cref="Room"/> to the list of available rooms. /// </summary> /// <param name="room">The <see cref="Room"/> to add.<</param> private void addRoom(Room room) { var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value); if (existing == null) { rooms.Add(room); } else { existing.CopyFrom(room); } }
private void beatmapAdded(ValueChangedEvent <WeakReference <BeatmapSetInfo> > weakSet) { if (weakSet.NewValue.TryGetTarget(out var set)) { Schedule(() => { if (!beatmapSets.Contains(set)) { beatmapSets.Add(set); } }); } }
public ThemeManager(Scheduler scheduler, UserResources resources, VignetteConfigManager config) { this.scheduler = scheduler; UseableThemes.Add(Theme.Light); UseableThemes.Add(Theme.Dark); store = resources.Themes; store.FileCreated += onFileCreated; store.FileDeleted += onFileDeleted; store.FileUpdated += onFileUpdated; store.FileRenamed += onFileRenamed; loadExistingThemes(); themeConfig = config.GetBindable <string>(VignetteSetting.Theme); themeConfig.BindValueChanged(e => { if (e.NewValue == Current.Value.Name) { return; } Current.Value = UseableThemes.FirstOrDefault(t => t.Name == e.NewValue) ?? Theme.Light; SourceChanged?.Invoke(); }, true); Current.BindValueChanged(e => { if (themeConfig.Value == e.NewValue.Name) { return; } themeConfig.Value = e.NewValue.Name; SourceChanged?.Invoke(); }, true); }
public void AddElement(ProjectElement element) { if (element.ID == 0) { element.ID = latestElementID++; } else if (element.ID >= latestElementID) { latestElementID = element.ID + 1; } projectElements.Add(element); }
public void Add(ControlPoint point) { var existing = controlPoints.FirstOrDefault(p => p.GetType() == point.GetType()); if (existing != null) { Remove(existing); } point.AttachGroup(this); controlPoints.Add(point); ItemAdded?.Invoke(point); }
BindableList <Row> CreateDataSource() { var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); var list = new BindableList <Row>(); foreach (var culture in cultures) { list.Add(new Row { Culture = culture }); } return(list); }
public void AddItemsTest() { // add some before applying the watcher.., they must be in the remaining items WatchedList.Add(new Bindable <int>().Set(10)); WatchedList.Add(new Bindable <int>().Set(20)); // now add the items we will be testing against WatchedList.AddRange(new[] { new Bindable <int>().Set(30), new Bindable <int>().Set(40), new Bindable <int>().Set(50), }); // 30, 40, 50 should be added Assert.That(new[] { 30, 40, 50 }, Is.EquivalentTo(ToListOfValues(AddedItemsList))); // 10, 20 should be remaining Assert.That(new[] { 10, 20 }, Is.EquivalentTo(ToListOfValues(RemainingItemsList))); // none should be deleted Assert.That(new int[] {}, Is.EquivalentTo(ToListOfValues(RemovedItemsList))); }
public void Add(ISkinnableDrawable component) { if (content == null) { throw new NotSupportedException("Attempting to add a new component to a target container which is not supported by the current skin."); } if (!(component is Drawable drawable)) { throw new ArgumentException($"Provided argument must be of type {nameof(Drawable)}.", nameof(component)); } content.Add(drawable); components.Add(component); }
private void LoadSegments() { var segments = new BindableList <WordSegmentViewModel>(); if (_word.Shape != null && _word.Shape.Count > 0) { Annotation <ShapeNode> prefixAnn = _word.Prefix; if (prefixAnn != null) { segments.AddRange(GetSegments(prefixAnn)); } segments.Add(new WordSegmentViewModel("|")); segments.AddRange(GetSegments(_word.Stem)); segments.Add(new WordSegmentViewModel("|")); Annotation <ShapeNode> suffixAnn = _word.Suffix; if (suffixAnn != null) { segments.AddRange(GetSegments(suffixAnn)); } } segments.CollectionChanged += SegmentsChanged; Set("Segments", ref _segments, segments); IsValid = _word.Shape != null && _word.Shape.Count > 0; }
public void TestBindViaBindTarget() { BindableList <int> parentBindable = new BindableList <int>(); BindableList <int> bindable1 = new BindableList <int>(); IBindableList <int> bindable2 = new BindableList <int>(); bindable1.BindTarget = parentBindable; bindable2.BindTarget = parentBindable; parentBindable.Add(5); Assert.That(bindable1[0], Is.EqualTo(5)); Assert.That(bindable2[0], Is.EqualTo(5)); }
public virtual void SetUpSteps() { AddStep("reset counts", () => { spectatorClient.Invocations.Clear(); lastHeaders.Clear(); }); AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = new APIUser { Id = 1, }); AddStep("populate users", () => { MultiplayerUsers.Clear(); for (int i = 0; i < total_users; i++) { MultiplayerUsers.Add(CreateUser(i)); } }); AddStep("create leaderboard", () => { Leaderboard?.Expire(); Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value); var playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value); OsuScoreProcessor scoreProcessor = new OsuScoreProcessor(); scoreProcessor.ApplyBeatmap(playableBeatmap); Child = scoreProcessor; LoadComponentAsync(Leaderboard = CreateLeaderboard(scoreProcessor), Add); }); AddUntilStep("wait for load", () => Leaderboard.IsLoaded); AddStep("check watch requests were sent", () => { foreach (var user in MultiplayerUsers) { spectatorClient.Verify(s => s.WatchUser(user.UserID), Times.Once); } }); }
public EditNaturalClassViewModel(FeatureSystem featSys, IEnumerable<SoundClass> soundClasses, NaturalClass naturalClass) : base("Edit Feature-based Class", soundClasses, naturalClass) { _type = naturalClass.Type == CogFeatureSystem.ConsonantType ? SoundType.Consonant : SoundType.Vowel; _availableFeatures = new BindableList<FeatureViewModel>(); _activeFeatures = new BindableList<FeatureViewModel>(); foreach (SymbolicFeature feature in featSys.OfType<SymbolicFeature>()) { SymbolicFeatureValue sfv; if (naturalClass.FeatureStruct.TryGetValue(feature, out sfv)) _activeFeatures.Add(new FeatureViewModel(feature, (FeatureSymbol) sfv)); else _availableFeatures.Add(new FeatureViewModel(feature)); } _addCommand = new RelayCommand(AddFeature, CanAddFeature); _removeCommand = new RelayCommand(RemoveFeature, CanRemoveFeature); }
public void TestClearNotifiesBoundBindable() { var bindableList = new BindableList <string>(); bindableList.BindTo(bindableStringList); for (int i = 0; i < 5; i++) { bindableStringList.Add("testA"); } for (int i = 0; i < 5; i++) { bindableList.Add("testA"); } bindableStringList.Clear(); Assert.IsEmpty(bindableList); }
/// <summary> /// Find an existing channel instance for the provided channel. Lookup is performed basd on ID. /// The provided channel may be used if an existing instance is not found. /// </summary> /// <param name="lookup">A candidate channel to be used for lookup or permanently on lookup failure.</param> /// <param name="addToAvailable">Whether the channel should be added to <see cref="AvailableChannels"/> if not already.</param> /// <param name="addToJoined">Whether the channel should be added to <see cref="JoinedChannels"/> if not already.</param> /// <returns>The found channel.</returns> private Channel getChannel(Channel lookup, bool addToAvailable = false, bool addToJoined = false) { Channel found = null; bool lookupCondition(Channel ch) => lookup.Id > 0 ? ch.Id == lookup.Id : lookup.Name == ch.Name; var available = AvailableChannels.FirstOrDefault(lookupCondition); if (available != null) { found = available; } var joined = JoinedChannels.FirstOrDefault(lookupCondition); if (found == null && joined != null) { found = joined; } if (found == null) { found = lookup; // if we're using a channel object from the server, we want to remove ourselves from the users list. // this is because we check the first user in the channel to display a name/icon on tabs for now. var foundSelf = found.Users.FirstOrDefault(u => u.Id == api.LocalUser.Value.Id); if (foundSelf != null) { found.Users.Remove(foundSelf); } } if (joined == null && addToJoined) { joinedChannels.Add(found); } if (available == null && addToAvailable) { availableChannels.Add(found); } return(found); }
private void updateUserPlayingState(int userId, MultiplayerUserState state) { bool wasPlaying = PlayingUserIds.Contains(userId); bool isPlaying = state >= MultiplayerUserState.WaitingForLoad && state <= MultiplayerUserState.FinishedPlay; if (isPlaying == wasPlaying) { return; } if (isPlaying) { PlayingUserIds.Add(userId); } else { PlayingUserIds.Remove(userId); } }
Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state) { Schedule(() => { if (!playingUsers.Contains(userId)) { playingUsers.Add(userId); } if (watchedUsers.Contains(userId)) { watchedUserStates[userId] = state; } OnUserBeganPlaying?.Invoke(userId, state); }); return(Task.CompletedTask); }
private void load() { Dependencies.Cache(config = new OsuConfigManager(LocalStorage)); Dependencies.CacheAs(spectatorClient.Object); Dependencies.CacheAs(multiplayerClient.Object); // To emulate `MultiplayerClient.CurrentMatchPlayingUserIds` we need a bindable list of *only IDs*. // This tracks the list of users 1:1. MultiplayerUsers.BindCollectionChanged((c, e) => { switch (e.Action) { case NotifyCollectionChangedAction.Add: Debug.Assert(e.NewItems != null); foreach (var user in e.NewItems.OfType <MultiplayerRoomUser>()) { multiplayerUserIds.Add(user.UserID); } break; case NotifyCollectionChangedAction.Remove: Debug.Assert(e.OldItems != null); foreach (var user in e.OldItems.OfType <MultiplayerRoomUser>()) { multiplayerUserIds.Remove(user.UserID); } break; case NotifyCollectionChangedAction.Reset: multiplayerUserIds.Clear(); break; } }); multiplayerClient.SetupGet(c => c.CurrentMatchPlayingUserIds) .Returns(() => multiplayerUserIds); spectatorClient.SetupGet(c => c.WatchedUserStates) .Returns(() => watchedUserStates); }
private void importCollections(List <BeatmapCollection> newCollections) { foreach (var newCol in newCollections) { var existing = Collections.FirstOrDefault(c => c.Name == newCol.Name); if (existing == null) { Collections.Add(existing = new BeatmapCollection { Name = { Value = newCol.Name.Value } }); } foreach (var newBeatmap in newCol.Beatmaps) { if (!existing.Beatmaps.Contains(newBeatmap)) { existing.Beatmaps.Add(newBeatmap); } } } }
public EditNaturalClassViewModel(FeatureSystem featSys, IEnumerable <SoundClass> soundClasses, NaturalClass naturalClass) : base("Edit Feature-based Class", soundClasses, naturalClass) { _type = naturalClass.Type == CogFeatureSystem.ConsonantType ? SoundType.Consonant : SoundType.Vowel; _availableFeatures = new BindableList <FeatureViewModel>(); _activeFeatures = new BindableList <FeatureViewModel>(); foreach (SymbolicFeature feature in featSys.OfType <SymbolicFeature>()) { SymbolicFeatureValue sfv; if (naturalClass.FeatureStruct.TryGetValue(feature, out sfv)) { _activeFeatures.Add(new FeatureViewModel(feature, (FeatureSymbol)sfv)); } else { _availableFeatures.Add(new FeatureViewModel(feature)); } } _addCommand = new RelayCommand(AddFeature, CanAddFeature); _removeCommand = new RelayCommand(RemoveFeature, CanRemoveFeature); }
Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state) { Schedule(() => { if (!playingUsers.Contains(userId)) { playingUsers.Add(userId); } // UserBeganPlaying() is called by the server regardless of whether the local user is watching the remote user, and is called a further time when the remote user is watched. // This may be a temporary thing (see: https://github.com/ppy/osu-server-spectator/blob/2273778e02cfdb4a9c6a934f2a46a8459cb5d29c/osu.Server.Spectator/Hubs/SpectatorHub.cs#L28-L29). // We don't want the user states to update unless the player is being watched, otherwise calling BindUserBeganPlaying() can lead to double invocations. if (watchingUsers.Contains(userId)) { playingUserStates[userId] = state; } OnUserBeganPlaying?.Invoke(userId, state); }); return(Task.CompletedTask); }
private Task importCollections(List <BeatmapCollection> newCollections) { var tcs = new TaskCompletionSource <bool>(); Schedule(() => { try { foreach (var newCol in newCollections) { var existing = Collections.FirstOrDefault(c => c.Name.Value == newCol.Name.Value); if (existing == null) { Collections.Add(existing = new BeatmapCollection { Name = { Value = newCol.Name.Value } }); } foreach (string newBeatmap in newCol.BeatmapHashes) { if (!existing.BeatmapHashes.Contains(newBeatmap)) { existing.BeatmapHashes.Add(newBeatmap); } } } tcs.SetResult(true); } catch (Exception e) { Logger.Error(e, "Failed to import collection."); tcs.SetException(e); } }); return(tcs.Task); }
public void AddOrUpdateRoom(Room room) { Debug.Assert(room.RoomID.Value != null); if (ignoredRooms.Contains(room.RoomID.Value.Value)) { return; } room.Position.Value = -room.RoomID.Value.Value; try { foreach (var pi in room.Playlist) { pi.MapObjects(beatmaps, rulesets); } var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value); if (existing == null) { rooms.Add(room); } else { existing.CopyFrom(room); } } catch (Exception ex) { Logger.Error(ex, $"Failed to update room: {room.Name.Value}."); ignoredRooms.Add(room.RoomID.Value.Value); rooms.Remove(room); } notifyRoomsUpdated(); }
private void LoadSegments() { var segments = new BindableList<WordSegmentViewModel>(); if (_word.Shape != null && _word.Shape.Count > 0) { Annotation<ShapeNode> prefixAnn = _word.Prefix; if (prefixAnn != null) segments.AddRange(GetSegments(prefixAnn)); segments.Add(new WordSegmentViewModel("|")); segments.AddRange(GetSegments(_word.Stem)); segments.Add(new WordSegmentViewModel("|")); Annotation<ShapeNode> suffixAnn = _word.Suffix; if (suffixAnn != null) segments.AddRange(GetSegments(suffixAnn)); } segments.CollectionChanged += SegmentsChanged; Set("Segments", ref _segments, segments); IsValid = _word.Shape != null && _word.Shape.Count > 0; }