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

Commit

Permalink
Implementation of some settings in the level properties window
Browse files Browse the repository at this point in the history
  • Loading branch information
REHERC committed Mar 26, 2021
1 parent 3c22c64 commit 3fd4d17
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 24 deletions.
143 changes: 125 additions & 18 deletions App.AdventureMaker.Core/Forms/LevelPropertiesWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,38 @@
using Eto.Drawing;
using System;
using App.AdventureMaker.Core.Controls;
using Distance.AdventureMaker.Common.Enums;
using App.AdventureMaker.Core.Interfaces;

namespace App.AdventureMaker.Core.Forms
{
public class LevelPropertiesWindow : Dialog<CampaignLevel>
{
private CampaignLevel Data { get; }

private readonly IEditor<CampaignFile> editor;

private readonly ExtendedTabControl tabs;
private readonly DynamicLayout generalProperties;
private readonly DynamicLayout loadingScreenProperties;
private readonly DynamicLayout introSequenceProperties;
private readonly DynamicLayout gameplayProperties;

public LevelPropertiesWindow(CampaignLevel level)
private readonly GuidLabel propLevelGuid;
private readonly TextBox propLevelName;
private readonly ResourceSelector propLevelFile;
private readonly ResourceSelector propLoadingBackground;
private readonly BooleanSelector propLoadingOverwriteText;
private readonly TextBox propLoadingText;
private readonly ResourceSelector propLoadingBackgroundIcon;
private readonly EnumDropDown<LevelTransitionType> propIntroType;
private readonly TextBox propIntroLine1;
private readonly TextBox propIntroLine2;

public LevelPropertiesWindow(IEditor<CampaignFile> editor, CampaignLevel level)
{
this.editor = editor;

Data = level.CloneObject()
?? new CampaignLevel()
{
Expand Down Expand Up @@ -65,30 +82,119 @@ public LevelPropertiesWindow(CampaignLevel level)
#region General Tab
tabs.AddPage("General", generalProperties = new DynamicLayout());

generalProperties.BeginScrollable();

for (int groupID = 1; groupID < 10; ++groupID)
{
DynamicGroup dynGP = null;
CheckBox dynGPenabled;
generalProperties.AddSeparateRow($"Enable group #{groupID}", dynGPenabled = new CheckBox());

dynGPenabled.CheckedChanged += (sender, e) => dynGP.GroupBox.Enabled = dynGPenabled.Checked == true;
generalProperties.BeginScrollable(BorderType.None);
generalProperties.BeginVertical();

dynGP = generalProperties.BeginGroup($"Group #{groupID}");
for (int propID = 1; propID < 10; ++propID)
{
generalProperties.AddRow($"Property {groupID}.{propID}", new TextBox());
}
generalProperties.EndGroup();
}
generalProperties.AddRow("Unique ID", propLevelGuid = new GuidLabel());
generalProperties.AddRow("Level file", propLevelFile = new ResourceSelector(editor, ResourceType.Level));
generalProperties.AddRow("Level name", propLevelName = new TextBox());

generalProperties.EndVertical();
generalProperties.AddSpace();
generalProperties.EndScrollable();
#endregion

tabs.AddPage("Gameplay", gameplayProperties = new DynamicLayout());
//tabs.AddPage("Gameplay", gameplayProperties = new DynamicLayout());

#region Loading Screen Tab
tabs.AddPage("Loading screen", loadingScreenProperties = new DynamicLayout());

loadingScreenProperties.BeginScrollable(BorderType.None);
loadingScreenProperties.BeginVertical();

loadingScreenProperties.AddRow("Background image", propLoadingBackground = new ResourceSelector(editor, ResourceType.Texture));
loadingScreenProperties.AddRow("Overwrite loading text", propLoadingOverwriteText = new BooleanSelector());
loadingScreenProperties.AddRow("Loading text", propLoadingText = new TextBox());
loadingScreenProperties.AddRow("Progress indicator icon", propLoadingBackgroundIcon = new ResourceSelector(editor, ResourceType.Texture));

loadingScreenProperties.EndVertical();
loadingScreenProperties.AddSpace();
loadingScreenProperties.EndScrollable();
#endregion

#region Intro Sequence Tab
tabs.AddPage("Intro sequence", introSequenceProperties = new DynamicLayout());

introSequenceProperties.BeginScrollable(BorderType.None);
introSequenceProperties.BeginVertical();

// Set whether or not to show the intro, the intro style and text values

introSequenceProperties.AddRow("Intro type", propIntroType = new EnumDropDown<LevelTransitionType>());
introSequenceProperties.AddRow("First line", propIntroLine1 = new TextBox());
introSequenceProperties.AddRow("Second line", propIntroLine2 = new TextBox());

introSequenceProperties.EndVertical();
introSequenceProperties.AddSpace();
introSequenceProperties.EndScrollable();
#endregion

#region Event Subscribing
propLoadingOverwriteText.ValueChanged += OnOverwriteLoadingTextChanged;
propIntroType.SelectedValueChanged += OnTransitionTypeChanged;
#endregion

LoadData(Data);
}

private void OnOverwriteLoadingTextChanged(object sender, EventArgs e)
{
propLoadingText.Enabled = propLoadingOverwriteText.Value;
}

private void OnTransitionTypeChanged(object sender, EventArgs e)
{
switch (propIntroType.SelectedValue)
{
case LevelTransitionType.None:
propIntroLine1.Enabled = false;
propIntroLine2.Enabled = false;
break;
case LevelTransitionType.Default:
propIntroLine1.Enabled = true;
propIntroLine2.Enabled = true;
break;
case LevelTransitionType.LostToEchoes:
case LevelTransitionType.EarlyAccess:
propIntroLine1.Enabled = true;
propIntroLine2.Enabled = false;
break;
}
}

private void LoadData(CampaignLevel level)
{
propLevelGuid.Text = level.Guid;
propLevelFile.Resource = editor.Document.GetResource(level.ResourceId, ResourceType.Level);
propLevelName.Text = level.Name;

propLoadingBackground.Resource = editor.Document.GetResource(level.LoadingBackground, ResourceType.Texture);
propLoadingBackgroundIcon.Resource = editor.Document.GetResource(level.LoadingBackgroundIcon, ResourceType.Texture);
propLoadingText.Text = level.LoadingText;
propLoadingOverwriteText.Value = level.OverrideLoadingText;
OnOverwriteLoadingTextChanged(propLoadingOverwriteText, EventArgs.Empty);

propIntroType.SelectedValue = level.Transition;
propIntroLine1.Text = level.Title;
propIntroLine2.Text = level.TitleSmall;
}

private void SaveData(CampaignLevel level)
{
level.Guid = propLevelGuid.Text;
level.ResourceId = propLevelFile.Resource?.guid;
level.Name = propLevelName.Text;


level.LoadingBackground = propLoadingBackground.Resource?.guid;
level.LoadingBackgroundIcon = propLoadingBackgroundIcon.Resource?.guid;

level.OverrideLoadingText = propLoadingOverwriteText.Value;
level.LoadingText = propLoadingText.Text;

level.Transition = propIntroType.SelectedValue;
level.Title = propIntroLine1.Text;
level.TitleSmall = propIntroLine2.Text;
}

private void OnCancel(object sender, EventArgs e)
Expand All @@ -98,6 +204,7 @@ private void OnCancel(object sender, EventArgs e)

private void OnConfirm(object sender, EventArgs e)
{
SaveData(Data);
Close(Data);
}
}
Expand Down
9 changes: 9 additions & 0 deletions App.AdventureMaker.Core/Styles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public static void ApplyAll()
Style.Add<TableLayout>(null, item => item.Spacing = new Size(4, 8));
Style.Add<Scrollable>(null, item => item.Border = BorderType.None);

Style.Add<Scrollable>(null, (item) => {
item.Border = BorderType.None;
});

Style.Add<Button>("icon", item =>
{
Size size = new Size(32, 32);
Expand All @@ -33,6 +37,11 @@ public static void ApplyAll()
item.Orientation = Orientation.Horizontal;
item.VerticalContentAlignment = VerticalAlignment.Stretch;
});

Style.Add<Label>(null, (item) =>
{
item.VerticalAlignment = VerticalAlignment.Center;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void SelectionChanged(object sender, EventArgs e)

private void AddLevel(object sender, EventArgs e)
{
CampaignLevel level = new LevelPropertiesWindow(null).ShowModal();
CampaignLevel level = new LevelPropertiesWindow(editor, null).ShowModal();

if (!Equals(level, null))
{
Expand All @@ -268,7 +268,7 @@ private void EditLevel(object sender, EventArgs e)
{
int index = levelList.SelectedRow;

level = new LevelPropertiesWindow(level).ShowModal();
level = new LevelPropertiesWindow(editor, level).ShowModal();

if (!Equals(level, null))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ public void LoadData(CampaignPlaylist playlist, bool resetUI)
nameBox.Text = playlist.Name;
descriptionBox.Text = playlist.Description;

var resourceQuery = editor.Document.Data.Resources.Where(res => Equals(res.guid, playlist.Icon));
iconBox.Resource = resourceQuery.FirstOrDefault();
//var resourceQuery = editor.Document.Data.Resources.Where(res => Equals(res.guid, playlist.Icon));
//iconBox.Resource = resourceQuery.FirstOrDefault();

iconBox.Resource = editor.Document.GetResource(playlist.Icon, ResourceType.Texture);

guidBox.Text = playlist.Guid;
sprintDisplayBox.Value = playlist.DisplayInSprint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Models\Resources\Level.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Resources\Texture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\UI\ProjectCreateData.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\CampaignFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Validation\IValidator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Validation\Validator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Validation\ValidationItem.cs" />
Expand Down
3 changes: 2 additions & 1 deletion Common.Distance.AdventureMaker/Enums/LevelTransitionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ namespace Distance.AdventureMaker.Common.Enums
[Flags]
public enum LevelTransitionType : byte
{
None,
Default,
LostToEchoes,
DistanceEarlyAccess
EarlyAccess
}
}
5 changes: 4 additions & 1 deletion Common.Distance.AdventureMaker/Models/CampaignLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CampaignLevel : INotifyPropertyChanged
public string Guid { get; set; }

[JsonProperty("name")]
public string Name;
public string Name { get; set; }

[JsonProperty("resource_id")]
public string ResourceId { get; set; }
Expand All @@ -35,6 +35,9 @@ public class CampaignLevel : INotifyPropertyChanged
[JsonProperty("loading_background")]
public string LoadingBackground { get; set; }

[JsonProperty("loading_background_icon")]
public string LoadingBackgroundIcon { get; set; }

[JsonProperty("override_loading_text")]
public bool OverrideLoadingText { get; set; }

Expand Down
13 changes: 13 additions & 0 deletions Common.Distance.AdventureMaker/Utilities/CampaignFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Distance.AdventureMaker.Common.Enums;
using Distance.AdventureMaker.Common.Models.Resources;

namespace Distance.AdventureMaker.Common.Models
{
public partial class CampaignFile
{
public CampaignResource GetResource(string guid, ResourceType type)
{
return Data.Resources.Find((res) => Equals(res.guid, guid) && Equals(res.resource_type, type));
}
}
}

0 comments on commit 3fd4d17

Please sign in to comment.