/// <summary> /// Initializes a new instance of the <see cref="CommentViewModel"/> class. /// </summary> /// <param name="commentService">The comment service</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="pullRequestId">The pull request id of the comment.</param> /// <param name="commentId">The GraphQL ID of the comment.</param> /// <param name="databaseId">The database id of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="author">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> /// <param name="webUrl"></param> protected CommentViewModel( ICommentService commentService, ICommentThreadViewModel thread, IActorViewModel currentUser, int pullRequestId, string commentId, int databaseId, string body, CommentEditState state, IActorViewModel author, DateTimeOffset updatedAt, Uri webUrl) { this.commentService = commentService; Guard.ArgumentNotNull(thread, nameof(thread)); Guard.ArgumentNotNull(currentUser, nameof(currentUser)); Guard.ArgumentNotNull(author, nameof(author)); Thread = thread; CurrentUser = currentUser; Id = commentId; DatabaseId = databaseId; PullRequestId = pullRequestId; Body = body; EditState = state; Author = author; UpdatedAt = updatedAt; WebUrl = webUrl; var canDeleteObservable = this.WhenAnyValue( x => x.EditState, x => x == CommentEditState.None && author.Login == currentUser.Login); canDelete = canDeleteObservable.ToProperty(this, x => x.CanDelete); Delete = ReactiveCommand.CreateAsyncTask(canDeleteObservable, DoDelete); var canEdit = this.WhenAnyValue( x => x.EditState, x => x == CommentEditState.Placeholder || (x == CommentEditState.None && author.Login == currentUser.Login)); BeginEdit = ReactiveCommand.Create(canEdit); BeginEdit.Subscribe(DoBeginEdit); AddErrorHandler(BeginEdit); CommitEdit = ReactiveCommand.CreateAsyncTask( Observable.CombineLatest( this.WhenAnyValue(x => x.IsReadOnly), this.WhenAnyValue(x => x.Body, x => !string.IsNullOrWhiteSpace(x)), this.WhenAnyObservable(x => x.Thread.PostComment.CanExecuteObservable), (readOnly, hasBody, canPost) => !readOnly && hasBody && canPost), DoCommitEdit); AddErrorHandler(CommitEdit); CancelEdit = ReactiveCommand.Create(CommitEdit.IsExecuting.Select(x => !x)); CancelEdit.Subscribe(DoCancelEdit); AddErrorHandler(CancelEdit); OpenOnGitHub = ReactiveCommand.Create(this.WhenAnyValue(x => x.Id).Select(x => x != null)); }
void ViewModelChanged(DependencyPropertyChangedEventArgs e) { var oldValue = e.OldValue as IActorViewModel; var newValue = e.NewValue as IActorViewModel; if (oldValue != null) { oldValue.PropertyChanged -= ViewModelPropertyChanged; } if (IdleUpdate) { QueueIdleUpdate(); } else { toRender = newValue; if (toRender != null) { toRender.PropertyChanged += ViewModelPropertyChanged; } } InvalidateVisual(); }
void FilterChanged(string filter) { if (users == null) { return; } if (ersatzUser != null) { users.Remove(ersatzUser); ersatzUser = null; } if (!string.IsNullOrWhiteSpace(filter)) { var existing = users.FirstOrDefault(x => x.Login.Equals(filter, StringComparison.CurrentCultureIgnoreCase)); if (existing == null) { ersatzUser = new ActorViewModel(new ActorModel { Login = filter }); users.Add(ersatzUser); } } UsersView.Refresh(); }
private void HandleMainUpdate(IActorViewModel activeActor) { var sectorNodeWithPlayerPerson = GetPlayerSectorNode(_player); if (sectorNodeWithPlayerPerson != null) { var sectorWithPlayerPerson = sectorNodeWithPlayerPerson.Sector; UpdateCurrentSectorOrPerformTransition(sectorWithPlayerPerson, activeActor); } else { // This means the player person is dead (don't exists in any sector). // Or some error occured. if (activeActor.Actor.Person.CheckIsDead()) { _isTransitionPerforming = true; HandleScreenChanging(); TargetScene = new ScoresScreen(Game, _spriteBatch); } else { Debug.Fail("Main screen must load only if the player person is in any sector node."); } } }
private async Task MoveActorImagePath(IActorViewModel actor) { string newActorPath = ActorMetadata.GetActorThumbPath(_path, actor.Name.Value); await _fileSystemService.MoveFile(actor.ThumbPath.Path, newActorPath); actor.ThumbPath.Path = newActorPath; }
private void UpdateCurrentSectorOrPerformTransition(ISector?sectorWithPlayerPerson, IActorViewModel activeActorViewModel) { if (_currentSector == sectorWithPlayerPerson) { _camera.Follow(activeActorViewModel, Game); _personEffectsPanel.Update(); var activePerson = activeActorViewModel.Actor.Person; var activePersonCombatActModule = activePerson.GetModule <ICombatActModule>(); if (!activePersonCombatActModule.IsCombatMode) { _bottomMenu.Update(); } } else if (!_isTransitionPerforming) { LoadTransitionScreen(); } else { Debug.Fail("Unkown situation."); } }
private static bool PropertyIsValid(IActorViewModel actor, string propertyName) { PropertyInfo nameProperty = actor.GetType().GetProperty(propertyName); object value = nameProperty.GetValue(actor); return nameProperty .GetCustomAttributes(true) .OfType<ValidationAttribute>() .All(va => va.IsValid(value)); }
private static bool PropertyIsValid(IActorViewModel actor, string propertyName) { PropertyInfo nameProperty = actor.GetType().GetProperty(propertyName); object value = nameProperty.GetValue(actor); return(nameProperty .GetCustomAttributes(true) .OfType <ValidationAttribute>() .All(va => va.IsValid(value))); }
private void UpdateTargetPosition(IActorViewModel target) { var playerActorWorldCoords = HexHelper.ConvertToWorld(((HexNode)target.Actor.Node).OffsetCoords); var hexSize = MapMetrics.UnitSize / 2; var actorPosition = new Vector2( (float)(playerActorWorldCoords[0] * hexSize * Math.Sqrt(3)), playerActorWorldCoords[1] * hexSize * 2 / 2 ); _targetPosition = actorPosition; }
void OnIdle(object sender, EventArgs e) { toRender = ViewModel; if (toRender != null) { toRender.PropertyChanged += ViewModelPropertyChanged; } InvalidateVisual(); ComponentDispatcher.ThreadIdle -= OnIdle; }
/// <summary> /// Creates a placeholder comment which can be used to add a new comment to a thread. /// </summary> /// <param name="session">The pull request session.</param> /// <param name="thread">The comment thread.</param> /// <param name="currentUser">The current user.</param> /// <returns>THe placeholder comment.</returns> public static CommentViewModel CreatePlaceholder( IPullRequestSession session, ICommentThreadViewModel thread, IActorViewModel currentUser) { return(new PullRequestReviewCommentViewModel( session, thread, currentUser, null, string.Empty, CommentEditState.Placeholder, currentUser, DateTimeOffset.MinValue, false, null)); }
/// <summary> /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class. /// </summary> /// <param name="session">The pull request session.</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="model">The comment model.</param> public PullRequestReviewCommentViewModel( IPullRequestSession session, ICommentThreadViewModel thread, IActorViewModel currentUser, PullRequestReviewModel review, PullRequestReviewCommentModel model) : this( session, thread, currentUser, model.Id, model.Body, CommentEditState.None, new ActorViewModel(model.Author), model.CreatedAt, review.State == PullRequestReviewState.Pending, model.Url != null ? new Uri(model.Url) : null) { }
/// <summary> /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class. /// </summary> /// <param name="session">The pull request session.</param> /// <param name="commentService">The comment service</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="pullRequestId">The pull request id of the comment.</param> /// <param name="commentId">The GraphQL ID of the comment.</param> /// <param name="databaseId">The database id of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="author">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> /// <param name="isPending">Whether this is a pending comment.</param> /// <param name="webUrl"></param> public PullRequestReviewCommentViewModel( IPullRequestSession session, ICommentService commentService, ICommentThreadViewModel thread, IActorViewModel currentUser, int pullRequestId, string commentId, int databaseId, string body, CommentEditState state, IActorViewModel author, DateTimeOffset updatedAt, bool isPending, Uri webUrl) : base(commentService, thread, currentUser, pullRequestId, commentId, databaseId, body, state, author, updatedAt, webUrl) { Guard.ArgumentNotNull(session, nameof(session)); this.session = session; IsPending = isPending; var pendingReviewAndIdObservable = Observable.CombineLatest( session.WhenAnyValue(x => x.HasPendingReview, x => !x), this.WhenAnyValue(model => model.Id).Select(i => i == null), (hasPendingReview, isNewComment) => new { hasPendingReview, isNewComment }); canStartReview = pendingReviewAndIdObservable .Select(arg => arg.hasPendingReview && arg.isNewComment) .ToProperty(this, x => x.CanStartReview); commitCaption = pendingReviewAndIdObservable .Select(arg => !arg.isNewComment ? Resources.UpdateComment : arg.hasPendingReview ? Resources.AddSingleComment : Resources.AddReviewComment) .ToProperty(this, x => x.CommitCaption); StartReview = ReactiveCommand.CreateAsyncTask( CommitEdit.CanExecuteObservable, DoStartReview); AddErrorHandler(StartReview); }
public void Follow(IActorViewModel target, Game game) { var playerActorWorldCoords = HexHelper.ConvertToWorld(((HexNode)target.Actor.Node).OffsetCoords); var hexSize = MapMetrics.UnitSize / 2; var actorPosition = new Vector2( (float)(playerActorWorldCoords[0] * hexSize * Math.Sqrt(3)), playerActorWorldCoords[1] * hexSize * 2 / 2 ); var position = Matrix.CreateTranslation( -actorPosition.X, -actorPosition.Y, 0); var offset = Matrix.CreateTranslation( (float)game.GraphicsDevice.Viewport.Width / 2, (float)game.GraphicsDevice.Viewport.Height / 2, 0); Transform = position * offset; }
private void DrawMonsterInfo(IActorViewModel actorViewModel, SpriteBatch spriteBatch, int viewPortWidth, int viewPortHeight) { if (actorViewModel.Actor.Person is not MonsterPerson monsterPerson) { return; } var position = new Vector2(viewPortWidth - 100, viewPortHeight - 100); spriteBatch.DrawString(_uiContentStorage.GetAuxTextFont(), MonsterHelper.GetPerkHintText(monsterPerson), position, Color.White); var isNumbersShow = false; #if SHOW_NUMS isNumbersShow = true; #endif if (isNumbersShow) { var stats = monsterPerson.GetModule <ISurvivalModule>().Stats; var monsterCombatActModule = monsterPerson.GetModule <ICombatActModule>(); var defaultAct = monsterCombatActModule.GetCurrentCombatActs().First(); spriteBatch.DrawString(_uiContentStorage.GetAuxTextFont(), GetRollAsString(defaultAct.Efficient), position + new Vector2(0, 16), Color.White); for (var statIndex = 0; statIndex < stats.Length; statIndex++) { var stat = stats[statIndex]; var offsetY = statIndex * 16; var statPosition = new Vector2(0, 32 + offsetY); var statText = $"{stat.Type} - {stat.Value} ({stat.ValueShare:0.##})"; spriteBatch.DrawString(_uiContentStorage.GetAuxTextFont(), statText, position + statPosition, Color.White); } } }
private static bool ActorIsValid(IActorViewModel actor) { return(PropertyIsValid(actor, "Name") && PropertyIsValid(actor, "Role")); }
void QueueIdleUpdate() { toRender = null; ComponentDispatcher.ThreadIdle += OnIdle; }
public void Follow(IActorViewModel target, Game game, GameTime gameTime) { UpdateTargetPosition(target); UpdateTransform(game, gameTime); }
private static bool ActorIsValid(IActorViewModel actor) { return PropertyIsValid(actor, "Name") && PropertyIsValid(actor, "Role"); }
private async Task MoveActorImagePath(IActorViewModel actor) { string newActorPath = ActorMetadata.GetActorThumbPath(_path, actor.Name.Value); await _fileSystemService.MoveFile(actor.ThumbPath.Path, newActorPath); actor.ThumbPath.Path = newActorPath; }