feat: implement availability
This commit is contained in:
parent
84d0be81e6
commit
178950bee9
|
@ -28,6 +28,16 @@ namespace XIVChat_Desktop {
|
|||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
public string? CurrentChannel { get; private set; }
|
||||
|
||||
private bool available;
|
||||
|
||||
public bool Available {
|
||||
get => this.available;
|
||||
private set {
|
||||
this.available = value;
|
||||
this.OnPropertyChanged(nameof(this.Available));
|
||||
}
|
||||
}
|
||||
|
||||
public Connection(App app, string host, ushort port) {
|
||||
this.app = app;
|
||||
|
||||
|
@ -195,6 +205,9 @@ namespace XIVChat_Desktop {
|
|||
// remove player data
|
||||
this.SetPlayerData(null);
|
||||
|
||||
// set availability
|
||||
this.Available = false;
|
||||
|
||||
// at this point, we are disconnected, so log it
|
||||
this.app.Dispatch(() => {
|
||||
this.app.Window.AddSystemMessage("Disconnected");
|
||||
|
@ -234,6 +247,9 @@ namespace XIVChat_Desktop {
|
|||
this.SetPlayerData(playerData);
|
||||
break;
|
||||
case ServerOperation.Availability:
|
||||
var availability = Availability.Decode(payload);
|
||||
|
||||
this.Available = availability.available;
|
||||
break;
|
||||
case ServerOperation.Channel:
|
||||
var channel = ServerChannel.Decode(payload);
|
||||
|
@ -287,5 +303,22 @@ namespace XIVChat_Desktop {
|
|||
window.Location.Visibility = visibility;
|
||||
});
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(string prop) {
|
||||
Action action;
|
||||
|
||||
if (prop == nameof(this.Available)) {
|
||||
action = () => {
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Available)));
|
||||
this.app.Window.OnPropertyChanged(nameof(MainWindow.InputPlaceholder));
|
||||
};
|
||||
} else {
|
||||
action = () => {
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
|
||||
};
|
||||
}
|
||||
|
||||
this.app.Dispatch(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,12 +97,14 @@
|
|||
Grid.Row="1"
|
||||
Text="{Binding App.Connection.CurrentChannel, ElementName=Main, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<TextBox ui:ControlHelper.PlaceholderText="Send a message..."
|
||||
Grid.Row="2"
|
||||
Margin="0,0,0,8"
|
||||
TextWrapping="Wrap"
|
||||
SpellCheck.IsEnabled="True"
|
||||
KeyDown="Input_Submit" />
|
||||
<TextBox
|
||||
ui:ControlHelper.PlaceholderText="{Binding InputPlaceholder, ElementName=Main, UpdateSourceTrigger=PropertyChanged}"
|
||||
IsEnabled="{Binding App.Connection.Available, ElementName=Main, UpdateSourceTrigger=PropertyChanged, FallbackValue=False}"
|
||||
Grid.Row="2"
|
||||
Margin="0,0,0,8"
|
||||
TextWrapping="Wrap"
|
||||
SpellCheck.IsEnabled="True"
|
||||
KeyDown="Input_Submit" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</TabControl.ContentTemplate>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
@ -12,11 +13,13 @@ namespace XIVChat_Desktop {
|
|||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow {
|
||||
public partial class MainWindow : INotifyPropertyChanged {
|
||||
public App App => (App)Application.Current;
|
||||
|
||||
public List<ServerMessage> Messages { get; } = new List<ServerMessage>();
|
||||
|
||||
public string InputPlaceholder => this.App.Connection?.Available == true ? "Send a message..." : "Chat is currently unavailable";
|
||||
|
||||
public MainWindow() {
|
||||
this.InitializeComponent();
|
||||
this.DataContext = this;
|
||||
|
@ -162,5 +165,11 @@ namespace XIVChat_Desktop {
|
|||
private void Scan_Click(object sender, RoutedEventArgs e) {
|
||||
new ServerScan(this).Show();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
internal virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) {
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue