Skip to content

Commit

Permalink
ストーリー作成タブを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Apr 18, 2024
1 parent 6dd9ce6 commit 1e75a39
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 0 deletions.
8 changes: 8 additions & 0 deletions KoeBook.Core/Contracts/Services/IStoryCreatorService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using KoeBook.Core.Models;

namespace KoeBook.Core.Contracts.Services;

public interface IStoryCreaterService
{
public ValueTask<string> CreateStoryAsync(StoryGenre genre, string intruction, CancellationToken cancellationToken);
}
4 changes: 4 additions & 0 deletions KoeBook.Core/Models/StoryGenre.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace KoeBook.Core.Models;

public record class StoryGenre(string Genre, string Description);

2 changes: 2 additions & 0 deletions KoeBook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public App()
services.AddTransient<ShellPage>();
services.AddTransient<ShellViewModel>();
services.AddTransient<EditDetailsViewModel>();
services.AddTransient<CreateStoryPage>();
services.AddTransient<CreateStoryViewModel>();

// Configuration
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
Expand Down
10 changes: 10 additions & 0 deletions KoeBook/KoeBook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<None Remove="Components\Dialog\DialogContentControl.xaml" />
<None Remove="Components\Dialog\SharedContentDialog.xaml" />
<None Remove="Components\StateProgressBar.xaml" />
<None Remove="Views\CreateStoryPage.xaml" />
<None Remove="Views\EditDetailsTab.xaml" />
</ItemGroup>

Expand All @@ -28,6 +29,7 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Markdown" Version="7.1.2" />
<PackageReference Include="FastEnum" Version="1.8.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
Expand Down Expand Up @@ -68,4 +70,12 @@
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>

<ItemGroup>
<CustomAdditionalCompileInputs Remove="Views\CreateStoryPage.xaml" />
</ItemGroup>

<ItemGroup>
<Resource Remove="Views\CreateStoryPage.xaml" />
</ItemGroup>
</Project>
67 changes: 67 additions & 0 deletions KoeBook/ViewModels/CreateStoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections.Immutable;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;
using KoeBook.Services;

namespace KoeBook.ViewModels;

public sealed partial class CreateStoryViewModel : ObservableObject
{
private readonly IStoryCreaterService _storyCreaterService;
private readonly GenerationTaskRunnerService _generationTaskRunnerService;

public ImmutableArray<StoryGenre> Genres { get; } = [
new("青春小説", "学校生活、友情、恋愛など、若者の成長物語"),
new("ミステリー・サスペンス", "謎解きや犯罪、真相究明などのスリリングな物語"),
new("SF", "未来、科学技術、宇宙などを題材にした物語"),
new("ホラー", "恐怖や怪奇現象を扱った、読者の恐怖心をくすぐる物語"),
new("ロマンス", "恋愛や結婚、人間関係などを扱った、胸キュンな物語"),
new("コメディ", "ユーモアやギャグ、風刺などを交えた、読者を笑わせる物語"),
new("歴史小説", "過去の出来事や人物を題材にした、歴史の背景が感じられる物語"),
new("ノンフィクション・エッセイ", "実際の経験や知識、考えを綴った、リアルな物語"),
new("詩集", "感情や思考、風景などを言葉で表現した、韻文形式の作品集"),
];

[ObservableProperty]
private StoryGenre _selectedGenre;

[ObservableProperty]
private string _intruction = "";

[ObservableProperty]
private string _storyText = """
# h1
## h2
### h3
1. aaa
2. bbb
3. ccc
---
""";

public CreateStoryViewModel(GenerationTaskRunnerService generationTaskRunnerService)
{
_selectedGenre = Genres[0];
_generationTaskRunnerService = generationTaskRunnerService;
//_storyCreaterService = storyCreaterService;
_storyCreaterService = null!;
}

public bool CanCreateStory => !string.IsNullOrWhiteSpace(Intruction);

[RelayCommand(CanExecute = nameof(CanCreateStory))]
private async Task OnCreateStoryAsync(CancellationToken cancellationToken)
{
StoryText = await _storyCreaterService.CreateStoryAsync(SelectedGenre, Intruction, cancellationToken);
}

[RelayCommand]
private async void OnStartGenerateTask (CancellationToken cancellationToken)
{
}
}

64 changes: 64 additions & 0 deletions KoeBook/Views/CreateStoryPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="KoeBook.Views.CreateStoryPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:KoeBook.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:models="using:KoeBook.Core.Models"
mc:Ignorable="d">

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Spacing="12" Margin="5">
<Button
Content="ストーリーを生成する"/>
<Button
Content="EPUBを生成する" />
</StackPanel>
</StackPanel>

<ScrollView
Grid.Row="1"
ZoomMode="Disabled"
HorizontalScrollMode="Disabled">

<StackPanel Spacing="8">
<TextBlock
Style="{StaticResource TitleTextBlockStyle}"
Text="ストーリーの指針"/>
<ComboBox
Margin="{StaticResource XSmallTopMargin}"
Header="ジャンル"
Width="200"
ItemsSource="{x:Bind ViewModel.Genres}"
SelectedValue="{x:Bind ViewModel.SelectedGenre, Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="models:StoryGenre">
<TextBlock Text="{x:Bind Genre}" ToolTipService.ToolTip="{x:Bind Description}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBox
Header="具体的な指示"
Text="{x:Bind ViewModel.Intruction, Mode=TwoWay}"
Height="256" />
<TextBlock
Style="{StaticResource TitleTextBlockStyle}"
Text="ストーリー"
Margin="{StaticResource SmallTopMargin}" />
<controls:MarkdownTextBlock
Padding="8"
CornerRadius="10"
Text="{x:Bind ViewModel.StoryText, Mode=OneWay}" />
</StackPanel>
</ScrollView>
</Grid>
</Page>
24 changes: 24 additions & 0 deletions KoeBook/Views/CreateStoryPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using KoeBook.ViewModels;
using Microsoft.UI.Xaml.Controls;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace KoeBook.Views;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class CreateStoryPage : Page
{
public static readonly Guid Id = Guid.NewGuid();

public CreateStoryViewModel ViewModel { get; }

public CreateStoryPage()
{
ViewModel = App.GetService<CreateStoryViewModel>();

this.InitializeComponent();
}
}
6 changes: 6 additions & 0 deletions KoeBook/Views/ShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
</TabViewItem.IconSource>
<local:MainPage x:Name="MainPage" Margin="20,10,20,10"/>
</TabViewItem>
<TabViewItem
x:Name="CreateStoryPageTab"
IsClosable="False"
Header="作成">
<local:CreateStoryPage Margin="20,10,20,10" />
</TabViewItem>
</TabView.TabItems>
<TabView.TabStripHeader>
<Button
Expand Down
1 change: 1 addition & 0 deletions KoeBook/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public ShellPage(ShellViewModel viewModel)
InitializeComponent();

TabHelper.SetNavigateTo(MainPageTab, MainPage.Id);
TabHelper.SetNavigateTo(CreateStoryPageTab, CreateStoryPage.Id);

ViewModel.TabViewService.Initialize(MainTabView);
App.MainWindow.ExtendsContentIntoTitleBar = true;
Expand Down

0 comments on commit 1e75a39

Please sign in to comment.