Skip to content

Instantly share code, notes, and snippets.

@Aerodos12
Created July 29, 2019 15:21
Show Gist options
  • Save Aerodos12/e08666b6a314662e982270327bb0b7fe to your computer and use it in GitHub Desktop.
Save Aerodos12/e08666b6a314662e982270327bb0b7fe to your computer and use it in GitHub Desktop.
CampaignSmith Code (Planning)
<Application x:Class="CampaignSmith.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CampaignSmith"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Generic.xaml" />
</Application.Resources>
</Application>
using CampaignSmith.Services;
using Catel.IoC;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace CampaignSmith
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
var serviceLocator = ServiceLocator.Default;
serviceLocator.RegisterType<ISingleplayerProjectService, SingleplayerProjectService>();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampaignSmith.DocumentTypes
{
class Campaign
{
public Int32 Id { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public List<string> Tags { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampaignSmith.Models
{
using Catel.Data;
using System.Collections.ObjectModel;
public class CampaignModel: ValidatableModelBase
{
public string CampaignName
{
get => GetValue<string>(CampaignNameProperty);
set => SetValue(CampaignNameProperty, value);
}
private readonly PropertyData CampaignNameProperty = RegisterProperty("CampaignName", typeof(string), null);
public string CampaignTitle
{
get => GetValue<string>(CampaignTitleProperty);
set => SetValue(CampaignTitleProperty, value);
}
private readonly PropertyData CampaignTitleProperty = RegisterProperty("CampaignTitle", typeof(string), null);
public string CampaignDescription
{
get => GetValue<string>(CampaignDescriptionProperty);
set => SetValue(CampaignDescriptionProperty, value);
}
private readonly PropertyData CampaignDescriptionProperty = RegisterProperty("CampaignDescription", typeof(string), null);
public ObservableCollection<string> CampaignTags
{
get => GetValue<ObservableCollection<string>>(CampaignTagsProperty);
set => SetValue(CampaignTagsProperty, value);
}
private readonly PropertyData CampaignTagsProperty = RegisterProperty("CampaignTags", typeof(ObservableCollection<string>), () => new ObservableCollection<string>());
public override string ToString()
{
return CampaignName;
}
}
}
using CampaignSmith.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampaignSmith.Services
{
public interface ISingleplayerProjectService
{
IEnumerable<SingleplayerProjectModel> LoadProjects();
void SaveProjects(IEnumerable<SingleplayerProjectModel> singleplayerProjects);
}
}
<catel:DataWindow
x:Class="CampaignSmith.MainWindow"
xmlns:Fluent="urn:fluent-ribbon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:catel="http://schemas.catelproject.com"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:CampaignSmith"
mc:Ignorable="d"
ResizeMode="CanResize"
Title="Campaign Smith" x:Name="CPSmithShellWindow" Height="450" Width="800" WindowState="Maximized" SizeToContent="WidthAndHeight">
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="131*"/>
<ColumnDefinition Width="611*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Fluent:RibbonTitleBar x:Name="_titleBar">
<DataTemplate>
<TextBlock Text="{Binding Title}"></TextBlock>
</DataTemplate>
</Fluent:RibbonTitleBar>
<Fluent:Ribbon Grid.Row="0" Grid.ColumnSpan="3">
<Fluent:Ribbon.Menu>
<Fluent:Backstage>
<Fluent:BackstageTabControl>
<Fluent:BackstageTabItem Header="New">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Vertical">
<Label
FontSize="36"
Foreground="{DynamicResource Fluent.Ribbon.Brushes.IdealForegroundColorBrush}"
>
Project Level
</Label>
<Fluent:Button
Header="Singleplayer Project"
></Fluent:Button>
</StackPanel>
</StackPanel>
</Fluent:BackstageTabItem>
</Fluent:BackstageTabControl>
</Fluent:Backstage>
</Fluent:Ribbon.Menu>
<Fluent:RibbonTabItem Header="Home">
</Fluent:RibbonTabItem>
<Fluent:RibbonTabItem Header="Create">
<Fluent:RibbonGroupBox Header="Project Level">
<Fluent:Button Header="Singleplayer Project"></Fluent:Button>
<Fluent:Button Header="Cooperative (Co-op) Project"></Fluent:Button>
</Fluent:RibbonGroupBox>
<Fluent:RibbonGroupBox Header="Campaign Level">
<Fluent:Button Header="Campaign"></Fluent:Button>
<Fluent:DropDownButton Header="Specialized Campaign">
<Fluent:MenuItem Header="Deuteragonistic"></Fluent:MenuItem>
<Fluent:MenuItem Header="Primary"></Fluent:MenuItem>
<Fluent:MenuItem Header="Prequel"></Fluent:MenuItem>
<Fluent:MenuItem Header="Other"></Fluent:MenuItem>
</Fluent:DropDownButton>
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
<Fluent:Ribbon.StartScreen>
<Fluent:StartScreen IsOpen="True">
<Fluent:StartScreenTabControl>
<Fluent:StartScreenTabControl.LeftContent>
<StackPanel Orientation="Vertical">
<Label Foreground="{DynamicResource Fluent.Ribbon.Brushes.IdealForegroundColorBrush}" FontSize="36">
Campaign Smith v0.1
</Label>
</StackPanel>
</Fluent:StartScreenTabControl.LeftContent>
<Fluent:StartScreenTabControl.RightContent>
<StackPanel Orientation="Vertical">
<Fluent:Button HorizontalAlignment="Center"
IsDefinitive="True">New Project</Fluent:Button>
</StackPanel>
</Fluent:StartScreenTabControl.RightContent>
</Fluent:StartScreenTabControl>
</Fluent:StartScreen>
</Fluent:Ribbon.StartScreen>
</Fluent:Ribbon>
<xcad:DockingManager Grid.Row="1" Grid.ColumnSpan="3"
BorderBrush="Black"
BorderThickness="1">
<xcad:DockingManager.DocumentHeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Title}"></Label>
</StackPanel>
</DataTemplate>
</xcad:DockingManager.DocumentHeaderTemplate>
<xcad:LayoutRoot x:Name="_campaignWorkspace">
<xcad:LayoutPanel>
<xcad:LayoutDocumentPaneGroup DockWidth="2.75*">
<xcad:LayoutDocumentPane>
<xcad:LayoutDocument ContentId="projectStart" Title="Project 1: Start">
</xcad:LayoutDocument>
</xcad:LayoutDocumentPane>
</xcad:LayoutDocumentPaneGroup>
<xcad:LayoutAnchorablePane DockWidth="*">
<xcad:LayoutAnchorable ContentId="u_properties" Title="Properties">
<xctk:PropertyGrid>
</xctk:PropertyGrid>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutPanel>
</xcad:LayoutRoot>
</xcad:DockingManager>
<Fluent:StatusBar Grid.Row="2">
</Fluent:StatusBar>
</Grid>
</catel:DataWindow>
using CampaignSmith.Models;
using CampaignSmith.Services;
using Catel;
using Catel.Data;
using Catel.MVVM;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampaignSmith.ViewModels
{
public class MainWindowViewModel: ViewModelBase
{
private readonly ISingleplayerProjectService projectService;
public override string Title { get => "Campaign Smith - " + base.Title; protected set => base.Title = value; }
public ObservableCollection<SingleplayerProjectModel> SingleplayerProjects
{
get => GetValue<ObservableCollection<SingleplayerProjectModel>>(SingleplayerProjectsProperty);
set => SetValue(SingleplayerProjectsProperty, value);
}
public static readonly PropertyData SingleplayerProjectsProperty = RegisterProperty("SingleplayerProjects", typeof(ObservableCollection<SingleplayerProjectModel>), null);
public MainWindowViewModel(ISingleplayerProjectService _projectService)
{
Argument.IsNotNull(() => _projectService);
projectService = _projectService;
}
protected override Task InitializeAsync()
{
var projects = projectService.LoadProjects();
SingleplayerProjects = new ObservableCollection<SingleplayerProjectModel>(projects);
return Task.CompletedTask;
}
protected override Task CloseAsync()
{
projectService.SaveProjects(SingleplayerProjects);
return Task.CompletedTask;
}
}
}
<UserControl x:Class="CampaignSmith.Views.NewSingleplayerProjectWizard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CampaignSmith.Views"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<xctk:Wizard FinishButtonClosesWindow="True"
NextButtonContent="Move on"
BackButtonContent="Move back">
<xctk:WizardPage x:Name="IntroPage" Title="Create New Singleplayer Project"
Description="This wizard will guide you in the process of creating a new singleplayer project." NextPage="{Binding NextPage, ElementName=Basics}">
</xctk:WizardPage>
<xctk:WizardPage x:Name="Basics" PageType="Interior" Title="General Information" Description="A good project usuaully has a name and tags associated with it." PreviousPage="{Binding PreviousPage, ElementName=IntroPage}" NextPage="{Binding NextPage, ElementName=Description}">
</xctk:WizardPage>
<xctk:WizardPage x:Name="Description" PageType="Interior" Title="Narrative Summary" Description="Summarize your project to understand what it is all about." PreviousPage="{Binding PreviousPage, ElementName=Description}" ></xctk:WizardPage>
<xctk:WizardPage x:Name="Finished" Title="Project Creation Completed" Description="You have now finished setting up your project. You can now either go back to review your project details, or proceed to adding campaigns by clicking Finish." PageType="Interior" CanFinish="True" PreviousPage="{Binding PreviousPage, ElementName=Description}"></xctk:WizardPage>
</xctk:Wizard>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CampaignSmith.Views
{
/// <summary>
/// Interaction logic for NewSingleplayerProjectWizard.xaml
/// </summary>
public partial class NewSingleplayerProjectWizard : UserControl
{
public NewSingleplayerProjectWizard()
{
InitializeComponent();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampaignSmith.Models
{
using Catel.Data;
using System.Collections.ObjectModel;
class SettingsModel: SavableModelBase<SettingsModel>
{
public ObservableCollection<SingleplayerProjectModel> SingleplayerProjects
{
get => GetValue<ObservableCollection<SingleplayerProjectModel>>(SingleplayerProjectsProperty);
set => SetValue(SingleplayerProjectsProperty, value);
}
public static readonly PropertyData SingleplayerProjectsProperty = RegisterProperty("SingleplayerProjects", typeof(ObservableCollection<SingleplayerProjectModel>), () => new ObservableCollection<SingleplayerProjectModel>());
}
}
using LiteDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampaignSmith.DocumentTypes
{
class SingleplayerProject
{
public Int32 Id { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string[] Tags { get; set; }
[BsonRef("campaigns")]
public List<Campaign> Campaigns { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampaignSmith.Models
{
using Catel.Data;
using System.Collections.ObjectModel;
public class SingleplayerProjectModel: ValidatableModelBase
{
public Int32 ProjectId
{
get => GetValue<Int32>(ProjectIdProperty);
set => SetValue(ProjectIdProperty, value);
}
private readonly PropertyData ProjectIdProperty = RegisterProperty("ProjectId", typeof(Int32), null);
public string ProjectName
{
get => GetValue<string>(ProjectNameProperty);
set => SetValue(ProjectNameProperty, value);
}
private readonly PropertyData ProjectNameProperty = RegisterProperty("ProjectName", typeof(string), null);
public string ProjectTitle
{
get => GetValue<string>(ProjectTitleProperty);
set => SetValue(ProjectTitleProperty, value);
}
private readonly PropertyData ProjectTitleProperty = RegisterProperty("ProjectTitle", typeof(string), null);
public string ProjectDescription
{
get => GetValue<string>(ProjectDescriptionProperty);
set => SetValue(ProjectDescriptionProperty, value);
}
private readonly PropertyData ProjectDescriptionProperty = RegisterProperty("ProjectDescription", typeof(string), null);
public ObservableCollection<string> ProjectTags
{
get => GetValue<ObservableCollection<string>>(ProjectTagsProperty);
set => SetValue(ProjectTagsProperty, value);
}
private readonly PropertyData ProjectTagsProperty = RegisterProperty("ProjectDescription", typeof(ObservableCollection<string>), () => new ObservableCollection<string>());
public ObservableCollection<CampaignModel> Campaigns
{
get => GetValue<ObservableCollection<CampaignModel>>(CampaignsProperty);
set => SetValue(CampaignsProperty, value);
}
private readonly PropertyData CampaignsProperty = RegisterProperty("Campaigns", typeof(ObservableCollection<CampaignModel>), () => new ObservableCollection<CampaignModel>());
public override string ToString()
{
return ProjectName;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LiteDB;
using System.Reflection;
using CampaignSmith.DocumentTypes;
using CampaignSmith.Models;
namespace CampaignSmith.Services
{
class SingleplayerProjectService: ISingleplayerProjectService
{
private LiteDatabase dataSource;
private LiteCollection<SingleplayerProject> projects;
public SingleplayerProjectService()
{
this.dataSource = new LiteDatabase(@"CPSmithDB.db");
this.projects = dataSource.GetCollection<SingleplayerProject>("projects");
}
public LiteDatabase DataSource { get => dataSource; set => dataSource = value; }
public IEnumerable<SingleplayerProjectModel> LoadProjects()
{
List<SingleplayerProjectModel> projects_M = new List<SingleplayerProjectModel>() { };
projects = dataSource.GetCollection<SingleplayerProject>("projects");
foreach(SingleplayerProject proj in projects.FindAll())
{
SingleplayerProjectModel spProject = new SingleplayerProjectModel
{
ProjectTitle = proj.Title,
ProjectName = proj.Name,
ProjectDescription = proj.Description,
};
foreach(string tag in proj.Tags)
{
spProject.ProjectTags.Add(tag);
}
foreach(Campaign campaign in proj.Campaigns)
{
CampaignModel cp = new CampaignModel
{
CampaignTitle = campaign.Title,
CampaignName = campaign.Name,
CampaignDescription = campaign.Description,
};
foreach(string tag in campaign.Tags)
{
cp.CampaignTags.Add(tag);
}
spProject.Campaigns.Add(cp);
}
projects_M.Add(spProject);
}
return projects_M;
}
public void SaveProjects(IEnumerable<SingleplayerProjectModel> singleplayerProjects)
{
foreach(SingleplayerProjectModel spm in singleplayerProjects.ToList())
{
SingleplayerProject proj = projects.FindOne(proj1 => proj1.Id.Equals(spm.ProjectId));
if(spm.ProjectName != proj.Name)
{
proj.Name = spm.ProjectName;
}
if(spm.ProjectTitle != proj.Title)
{
proj.Title = spm.ProjectTitle;
}
if (spm.ProjectDescription != proj.Description)
{
proj.Description = spm.ProjectDescription;
}
proj.Tags = spm.ProjectTags.ToArray<string>();
_ = projects.Update(proj);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment