Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Work on the level sets tab
Browse files Browse the repository at this point in the history
  • Loading branch information
REHERC committed Jan 22, 2021
1 parent e1a432f commit 62a82aa
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 29 deletions.
2 changes: 1 addition & 1 deletion App.AdventureMaker.Core/Commands/ProjectFolderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ProjectFolderCommand(IEditor<CampaignFile> editor_)

Enabled = false;

editor.OnFileLoaded += (_) =>
editor.OnLoaded += (_) =>
{
Enabled = editor.CurrentFile != null;
};
Expand Down
2 changes: 1 addition & 1 deletion App.AdventureMaker.Core/Commands/SaveFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SaveFileCommand(IEditor<CampaignFile> editor_)

Enabled = false;

editor.OnFileLoaded += (_) =>
editor.OnLoaded += (_) =>
{
Enabled = editor.CurrentFile != null;
};
Expand Down
2 changes: 2 additions & 0 deletions App.AdventureMaker.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public static class Constants

public const string DIALOG_MESSAGE_REMOVE_PLAYLIST = "Are you sure you want to remove the following playlist: \"{0}\" ?";
public const string DIALOG_CAPTION_REMOVE_PLAYLIST = "Remove playlist";

public const string PLAYLIST_NO_NAME = "(No playlist name)";
}
}
13 changes: 12 additions & 1 deletion App.AdventureMaker.Core/Controls/TextBoxWithButton.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
using Eto.Forms;
using System;

namespace App.AdventureMaker.Core.Controls
{
public class TextBoxWithButton : ControlWithButtonBase<TextBox>
{
public event EventHandler<EventArgs> TextChanged;

public string Text
{
get => Control.Text;
set => Control.Text = value;
set
{
Control.Text = value;
TextChanged?.Invoke(this, new EventArgs());
}
}

public TextBoxWithButton() : base(new TextBox())
{
Button.Text = "...";
Control.TextChanged += (sender, e) =>
{
Text = Control.Text;
};
}
}
}
2 changes: 1 addition & 1 deletion App.AdventureMaker.Core/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private void InitializeComponent()
ToolBar = new MainToolbar(mainView);
Menu = new MainMenu(this, mainView);

mainView.OnFileModified += (editor) =>
mainView.OnModified += (editor) =>
{
UpdateTitle();
};
Expand Down
6 changes: 3 additions & 3 deletions App.AdventureMaker.Core/Interfaces/IEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace App.AdventureMaker.Core.Interfaces
{
public interface IEditor<DATA>
{
public event Action<IEditor<DATA>> OnFileLoaded;
public event Action<IEditor<DATA>> OnFileModified;
public event Action<IEditor<DATA>> OnLoaded;

public event Action<IEditor<DATA>> OnModified;

public FileInfo CurrentFile { get; set; }

Expand Down
9 changes: 9 additions & 0 deletions App.AdventureMaker.Core/Interfaces/IModifiedNotifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace App.AdventureMaker.Core.Interfaces
{
public interface IModifiedNotifier<DATA>
{
public event Action<DATA> OnModified;
}
}
10 changes: 5 additions & 5 deletions App.AdventureMaker.Core/Views/MainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace App.AdventureMaker.Core.Views
public class MainView : Panel, IEditor<CampaignFile>
{
#region Interface Events and Members
public event Action<IEditor<CampaignFile>> OnFileLoaded;
public event Action<IEditor<CampaignFile>> OnLoaded;

public event Action<IEditor<CampaignFile>> OnFileModified;
public event Action<IEditor<CampaignFile>> OnModified;

public FileInfo CurrentFile { get; set; } = null;

Expand All @@ -22,7 +22,7 @@ public bool Modified
set
{
modified_ = value;
OnFileModified?.Invoke(this);
OnModified?.Invoke(this);
}
}
#endregion
Expand All @@ -33,7 +33,7 @@ public MainView()
{
Content = editor = new EditorTabView(this);

OnFileLoaded += (_) =>
OnLoaded += (_) =>
{
editor.Visible = CurrentFile != null;
};
Expand Down Expand Up @@ -70,7 +70,7 @@ public void LoadFile(FileInfo file)
}

Modified = false;
OnFileLoaded?.Invoke(this);
OnLoaded?.Invoke(this);
}
}
}
32 changes: 28 additions & 4 deletions App.AdventureMaker.Core/Views/Pages/LevelSets/LevelSetsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace App.AdventureMaker.Core.Views
{
public class LevelSetsPage : TableLayout, ISaveLoad<CampaignFile>
{
public readonly ExtendedTabControl tabs;
public readonly ReorderableListBox listBox;
public readonly LevelSetsPropertiesView properties;
private readonly ExtendedTabControl tabs;
private readonly ReorderableListBox listBox;
private readonly LevelSetsPropertiesView properties;
private readonly IEditor<CampaignFile> editor;

public LevelSetsPage(IEditor<CampaignFile> editor_)
{
editor = editor_;

tabs = new ExtendedTabControl();
tabs.AddPage("Properties", properties = new LevelSetsPropertiesView(), scrollable: true);
tabs.AddPage("Properties", properties = new LevelSetsPropertiesView(editor), scrollable: true);
tabs.AddPage("Levels", new Panel(), scrollable: true);

TableRow row = new TableRow()
Expand All @@ -35,11 +35,23 @@ public LevelSetsPage(IEditor<CampaignFile> editor_)
listBox.ItemsReordered += (_, __) => editor.Modified = true;

listBox.RemoveItem += RemovePlaylist;
listBox.AddItem += AddPlaylist;

properties.OnModified += (playlist) =>
{
properties.SaveData(listBox.SelectedValue as CampaignPlaylist);
listBox.ListControl.UpdateBindings();
listBox.ListControl.Invalidate();
editor.Modified = true;
};
}

private void SelectPlaylist(object sender, EventArgs e)
{
tabs.Enabled = listBox.SelectedIndex != -1;
properties.LoadData(listBox.SelectedValue as CampaignPlaylist);
}

private void RemovePlaylist(object sender, EventArgs e)
Expand All @@ -51,6 +63,18 @@ private void RemovePlaylist(object sender, EventArgs e)
}
}

private void AddPlaylist(object sender, EventArgs e)
{
// TODO: Implement
var playlist = new CampaignPlaylist()
{
guid = Guid.NewGuid().ToString()
};

listBox.Items.Add(playlist);
listBox.SelectedValue = playlist;
}

public void LoadData(CampaignFile project)
{
listBox.Items.Clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,89 @@
using App.AdventureMaker.Core.Controls;
using Distance.AdventureMaker.Common.Enums;
using Eto.Drawing;
using App.AdventureMaker.Core.Interfaces;
using Distance.AdventureMaker.Common.Models;
using Eto.Forms;
using System;

namespace App.AdventureMaker.Core.Views
{
public class LevelSetsPropertiesView : StackLayout
public class LevelSetsPropertiesView : StackLayout, ISaveLoad<CampaignPlaylist>, IModifiedNotifier<CampaignPlaylist>
{
public event Action<CampaignPlaylist> OnModified;

private bool raiseEvents = true;

private readonly PropertiesListBase properties;
private readonly IEditor<CampaignFile> editor;

private readonly TextBox nameBox;
private readonly TextBox descriptionBox;
private readonly TextBoxWithButton iconBox;
private readonly GuidLabel guidBox;

public LevelSetsPropertiesView()
public LevelSetsPropertiesView(IEditor<CampaignFile> editor_)
{
editor = editor_;

//Style = "no-padding";
Orientation = Orientation.Vertical;
HorizontalContentAlignment = HorizontalAlignment.Stretch;

properties = new PropertiesListBase();

properties.AddRow("Name", new TextBox());
properties.AddRow("Description", new TextBox());
properties.AddRow("Icon", new TextBoxWithButton());
properties.AddRow("Playlist locking", new EnumDropDown<PlaylistUnlock>());
properties.AddRow("Individual level locking", new EnumDropDown<LevelUnlock>());
properties.AddRow("Difficulty rating", new EnumDropDown<Difficulty>());
properties.AddRow("Name", nameBox = new TextBox());
properties.AddRow("Description", descriptionBox = new TextBox());
properties.AddRow("Icon", iconBox = new TextBoxWithButton());
properties.AddRow("Unique ID", guidBox = new GuidLabel());
//properties.AddRow("Playlist locking", new EnumDropDown<PlaylistUnlock>());
//properties.AddRow("Individual level locking", new EnumDropDown<LevelUnlock>());
//properties.AddRow("Difficulty rating", new EnumDropDown<Difficulty>());

properties.CompleteRows();

Items.Add(new StackLayoutItem(properties) { Expand = false });

nameBox.TextChanged += NotifyModified;
descriptionBox.TextChanged += NotifyModified;
iconBox.TextChanged += NotifyModified;
guidBox.TextChanged += NotifyModified;
}

private void NotifyModified(object sender, EventArgs e)
{
if (!raiseEvents) return;

var playlist = new CampaignPlaylist();
SaveData(playlist);
OnModified?.Invoke(playlist);
}

public void LoadData(CampaignPlaylist playlist)
{
if (playlist != null)
{
raiseEvents = false;

nameBox.Text = playlist.name;
descriptionBox.Text = playlist.description;
iconBox.Text = playlist.icon;
guidBox.Text = playlist.guid;

raiseEvents = true;
}
}

public void SaveData(CampaignPlaylist playlist)
{
//raiseEvents = false;

playlist.name = nameBox.Text;
playlist.description = descriptionBox.Text;
playlist.icon = iconBox.Text;
playlist.guid = guidBox.Text;

//raiseEvents = true;

//NotifyModified(null, null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using App.AdventureMaker.Core.Controls;
using App.AdventureMaker.Core.Interfaces;
using Distance.AdventureMaker.Common.Enums;
//using Distance.AdventureMaker.Common.Enums;
using Distance.AdventureMaker.Common.Models;
using Eto.Forms;

Expand Down
8 changes: 6 additions & 2 deletions Distance.AdventureMaker.Common/Models/CampaignPlaylist.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable CS0649

#if APP
using App.AdventureMaker.Core;
using Eto.Forms;
#endif
using Newtonsoft.Json;
Expand All @@ -22,11 +23,14 @@ public class CampaignPlaylist
public string name;

[JsonProperty]
public string descrtiption;
public string description;

[JsonProperty]
public string icon;

[JsonProperty]
public bool display_in_sprint;

[JsonProperty]
public List<CampaignLevel> levels;

Expand All @@ -39,7 +43,7 @@ public CampaignPlaylist()
[JsonIgnore]
public string Text
{
get => name;
get => name?.Length > 0 ? name : Constants.PLAYLIST_NO_NAME;
set => name = value;
}

Expand Down

0 comments on commit 62a82aa

Please sign in to comment.