Skip to content

Commit

Permalink
Added door functionality
Browse files Browse the repository at this point in the history
Basic door functionality, the program can add doors to rooms. Modifying the doors in each room currently doesn't work
  • Loading branch information
crispyricepc committed Mar 19, 2019
1 parent 1f5f8ab commit 522524c
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 52 deletions.
1 change: 0 additions & 1 deletion SkeletonGameMaker/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public partial class App : Application
private void Application_Startup(object sender, StartupEventArgs e)
{
bool closed = false;
StringColors.Initialise();
do
{
MainWindow window = new MainWindow();
Expand Down
8 changes: 4 additions & 4 deletions SkeletonGameMaker/DoorMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:SkeletonGameMaker"
mc:Ignorable="d"
MaxWidth="1024"
MaxHeight="1024">
MaxHeight="1024" IsVisibleChanged="UserControl_IsVisibleChanged">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="72"/>
Expand All @@ -20,9 +20,9 @@
<Label x:Name="LbDoorName" Content="DoorName" Margin="5,5,5,0" VerticalAlignment="Top" Grid.ColumnSpan="2" HorizontalAlignment="Center"/>
<Label x:Name="LbDoorStatus" Content="Status" Margin="5,36,5,0" VerticalAlignment="Top" Height="26" Width="42"/>
<ComboBox x:Name="CbDoorStatus" Grid.Column="1" Margin="5,40,10,0" VerticalAlignment="Top">
<ComboBoxItem x:Name="CbiDoorOpen" Content="Open" HorizontalAlignment="Left"/>
<ComboBoxItem x:Name="CbiDoorClose" Content="Closed" HorizontalAlignment="Left"/>
<ComboBoxItem x:Name="CbiDoorLocked" Content="Locked" HorizontalAlignment="Left"/>
<ComboBoxItem x:Name="CbiDoorOpen" Content="Open" HorizontalAlignment="Left" Width="{Binding ActualWidth, ElementName=CbDoorStatus, Mode=OneWay}"/>
<ComboBoxItem x:Name="CbiDoorClose" Content="Close" HorizontalAlignment="Left" Width="{Binding ActualWidth, ElementName=CbDoorStatus, Mode=OneWay}"/>
<ComboBoxItem x:Name="CbiDoorLocked" Content="Locked" HorizontalAlignment="Left" Width="{Binding ActualWidth, ElementName=CbDoorStatus, Mode=OneWay}"/>
</ComboBox>

</Grid>
Expand Down
77 changes: 71 additions & 6 deletions SkeletonGameMaker/DoorMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;

namespace SkeletonGameMaker
{
Expand All @@ -20,6 +21,38 @@ namespace SkeletonGameMaker
/// </summary>
public partial class DoorMenu : UserControl
{
static class StringColors
{
public static List<string> ColorsList = new List<string>();
public static bool IsInitialized = false;

public static void Initialise()
{
IsInitialized = true;
Type colorType = typeof(System.Drawing.Color);
PropertyInfo[] propInfos = colorType.GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);
foreach (PropertyInfo propInfo in propInfos)
{
ColorsList.Add(AddSpacesToSentence(propInfo.Name));
}
}

private static string AddSpacesToSentence(string text)
{
if (string.IsNullOrWhiteSpace(text))
return "";
StringBuilder newText = new StringBuilder(text.Length * 2);
newText.Append(text[0]);
for (int i = 1; i < text.Length; i++)
{
if (char.IsUpper(text[i]) && text[i - 1] != ' ')
newText.Append(' ');
newText.Append(text[i]);
}
return newText.ToString();
}
}

public int RoomID, TargetRoomID;
public LocationDirection PrimaryRoomDirection;
public LocationDirection SecondaryRoomDirection
Expand All @@ -36,6 +69,19 @@ public DoorMenu()
InitializeComponent();
}

private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!StringColors.IsInitialized)
{
StringColors.Initialise();
}
LvDoorColours.Items.Clear();
foreach (string color in StringColors.ColorsList)
{
LvDoorColours.Items.Add(color);
}
}

private void BtnDoorCreate_Click(object sender, RoutedEventArgs e)
{
string errorMessage = "";
Expand All @@ -54,29 +100,48 @@ private void BtnDoorCreate_Click(object sender, RoutedEventArgs e)
}
else
{
// Create the primary door
Item primaryDoor = new Item();
Item secondaryDoor = new Item();
primaryDoor.ID = Saves.FindFreeID(2001, 9999, Saves.Items.GetIDs());
primaryDoor.Name = ((ListViewItem)LvDoorColours.SelectedItem).Content.ToString().ToLower() + " door";
primaryDoor.Name = LvDoorColours.SelectedItem.ToString().ToLower() + " door";
primaryDoor.Description = "It is a " + primaryDoor.Name;
primaryDoor.Location = RoomID;
primaryDoor.Status = ((ComboBoxItem)CbDoorStatus.SelectedItem).Content.ToString().ToLower();
primaryDoor.Commands = "open,close";
primaryDoor.Results = nameof(PrimaryRoomDirection).ToLower() + "," + TargetRoomID.ToString() +
";" + nameof(PrimaryRoomDirection).ToLower() + ",0";

primaryDoor.Results = PrimaryRoomDirection.LocToString().ToLower() + "," + TargetRoomID.ToString() +
";" + PrimaryRoomDirection.LocToString().ToLower() + ",0";
// Create the secondary door
secondaryDoor.ID = primaryDoor.ID + 10000;
secondaryDoor.Name = primaryDoor.Name;
secondaryDoor.Description = "It is a " + secondaryDoor.Name;
secondaryDoor.Location = TargetRoomID;
secondaryDoor.Status = primaryDoor.Status;
secondaryDoor.Commands = primaryDoor.Commands;
secondaryDoor.Results = nameof(SecondaryRoomDirection).ToLower() + "," + RoomID.ToString() +
";" + nameof(SecondaryRoomDirection).ToLower() + ",0";
secondaryDoor.Results = SecondaryRoomDirection.LocToString().ToLower() + "," + RoomID.ToString() +
";" + SecondaryRoomDirection.LocToString().ToLower() + ",0";

Saves.Items.Add(primaryDoor);
Saves.Items.Add(secondaryDoor);

switch (((ComboBoxItem)CbDoorStatus.SelectedItem).Content.ToString().ToLower())
{
case "open":
Saves.Places[Saves.Places.GetIndexFromID(RoomID)].SetDirection(PrimaryRoomDirection, TargetRoomID);
Saves.Places[Saves.Places.GetIndexFromID(TargetRoomID)].SetDirection(SecondaryRoomDirection, RoomID);
break;
case "close":
Saves.Places[Saves.Places.GetIndexFromID(RoomID)].SetDirection(PrimaryRoomDirection, 0);
Saves.Places[Saves.Places.GetIndexFromID(TargetRoomID)].SetDirection(SecondaryRoomDirection, 0);
break;
case "locked":
Saves.Places[Saves.Places.GetIndexFromID(RoomID)].SetDirection(PrimaryRoomDirection, 0);
Saves.Places[Saves.Places.GetIndexFromID(TargetRoomID)].SetDirection(SecondaryRoomDirection, 0);
break;
default:
throw new InputException(((ComboBoxItem)CbDoorStatus.SelectedItem).Content.ToString().ToLower() + " is not a valid status");
}

OnDoorCreation?.Invoke(sender, EventArgs.Empty);
}
}
Expand Down
27 changes: 27 additions & 0 deletions SkeletonGameMaker/Place.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,32 @@ public void AddDoor(string name, string description, LocationDirection direction
int thisSideId = Saves.FindFreeID(2000, 9999, idList);
int otherSideId = thisSideId + 10000;
}

public void SetDirection(LocationDirection direction, int targetId)
{
switch (direction)
{
case LocationDirection.North:
North = targetId;
break;
case LocationDirection.South:
South = targetId;
break;
case LocationDirection.East:
East = targetId;
break;
case LocationDirection.West:
West = targetId;
break;
case LocationDirection.Up:
Up = targetId;
break;
case LocationDirection.Down:
Down = targetId;
break;
default:
throw new Exception("Location invalid");
}
}
}
}
10 changes: 10 additions & 0 deletions SkeletonGameMaker/RoomsMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,33 @@ private void BtnNewDoor_Click(object sender, RoutedEventArgs e)
Button btn = sender as Button;

LocationDirection direction;
int targetid;

switch (btn.Name)
{
case "BtnNorthDoor":
direction = LocationDirection.North;
targetid = North;
break;
case "BtnSouthDoor":
direction = LocationDirection.South;
targetid = South;
break;
case "BtnEastDoor":
direction = LocationDirection.East;
targetid = East;
break;
case "BtnWestDoor":
direction = LocationDirection.West;
targetid = West;
break;
case "BtnUpDoor":
direction = LocationDirection.Up;
targetid = Up;
break;
case "BtnDownDoor":
direction = LocationDirection.Down;
targetid = Down;
break;
default:
throw new Exception("Can't find button name");
Expand All @@ -128,6 +135,9 @@ private void BtnNewDoor_Click(object sender, RoutedEventArgs e)
if (btn.Content.ToString().ToLower().Contains("create"))
{
LvItemsList.Visibility = Visibility.Collapsed;
UcDoorMenu.PrimaryRoomDirection = direction;
UcDoorMenu.RoomID = Room.id;
UcDoorMenu.TargetRoomID = targetid;
UcDoorMenu.Visibility = Visibility.Visible;
}
else if (btn.Content.ToString().ToLower().Contains("modify"))
Expand Down
20 changes: 20 additions & 0 deletions SkeletonGameMaker/Saves.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ public static LocationDirection GetOpposite(this LocationDirection direction)
throw new Exception("Not a valid direction");
}
}
public static string LocToString(this LocationDirection direction)
{
switch (direction)
{
case LocationDirection.North:
return "north";
case LocationDirection.South:
return "south";
case LocationDirection.East:
return "east";
case LocationDirection.West:
return "west";
case LocationDirection.Up:
return "up";
case LocationDirection.Down:
return "down";
default:
throw new Exception("Not a valid direction");
}
}
}

public static class LocalConvert
Expand Down
1 change: 0 additions & 1 deletion SkeletonGameMaker/SkeletonGameMaker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
<DependentUpon>RoomsMenu.xaml</DependentUpon>
</Compile>
<Compile Include="Saves.cs" />
<Compile Include="StringColors.cs" />
<Compile Include="ValueConverters.cs" />
<Page Include="DoorMenu.xaml">
<SubType>Designer</SubType>
Expand Down
40 changes: 0 additions & 40 deletions SkeletonGameMaker/StringColors.cs

This file was deleted.

0 comments on commit 522524c

Please sign in to comment.