Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdminUI #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Meridian59.DebugUI/AdminController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

13 changes: 13 additions & 0 deletions Meridian59.DebugUI/CustomDataGridColumns/TagColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Meridian59.DebugUI.CustomDataGridColumns
{
class TagCell : DataGridViewTextBoxCell

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this class have any purpose yet or is it a preparation for something you have in mind ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a placeholder. I want to have a custom column for the "Tag/Blakserv DataType" column in the ObjectEditor form.

{

}
}
469 changes: 253 additions & 216 deletions Meridian59.DebugUI/DebugForm.Designer.cs

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions Meridian59.DebugUI/DebugForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ You should have received a copy of the GNU General Public License along with "Me
*/

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Meridian59.Data;
using Meridian59.DebugUI.Events;
using Meridian59.Protocol.Events;
using Meridian59.Protocol.GameMessages;
using Meridian59.Common.Enums;
using Meridian59.Data.Models;
using Meridian59.Data.Models.AdminData;
using Meridian59.Files;

namespace Meridian59.DebugUI
{


public partial class DebugForm : Form
{
public event GameMessageEventHandler PacketSend;
Expand Down Expand Up @@ -63,9 +68,36 @@ public DataController DataController
roomInfoView.DataSource = dataController.RoomInformation;
lightShadingView.DataSource = dataController.LightShading;
backgroundMusicView.DataSource = dataController.BackgroundMusic;
DataController.AdminData.AdminObjectAdded += AdminInfoOnAdminObjectAdded;
DataController.AdminData.PacketSend += AdminData_PacketSend;
DataController.AdminData.LogAdminMessage += AdminData_LogAdminMessage;
}
}

void AdminData_LogAdminMessage(LogAdminMessageEventHandlerArgs e)
{
txtAdminOutput.Text = e.AdminMessage + txtAdminOutput.Text;
}

void AdminData_PacketSend(object sender, GameMessageEventArgs e)
{
if (PacketSend != null)
PacketSend(this, e);
}

private void AdminInfoOnAdminObjectAdded(object sender, AddTrackedAdminObjectEventHandlerArgs args)
{
ObjectEditor oe = new ObjectEditor(args.AdminObject);
oe.Closing += oe_Closing;
oe.Show();
}

void oe_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
ObjectEditor oe = (ObjectEditor) sender;
DataController.AdminData.UntrackAdminObject(oe.GetTrackedObject());
}

private ResourceManager resourceManager;
public ResourceManager ResourceManager
{
Expand Down Expand Up @@ -160,5 +192,21 @@ private void btnDisbandGuild_Click(object sender, EventArgs e)
if (PacketSend != null)
PacketSend(this, new GameMessageEventArgs(new UserCommandMessage(new UserCommandGuildDisband(), null)));
}

private void txtAdminCommand_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (PacketSend != null)
PacketSend(this, new GameMessageEventArgs(new ReqAdminMessage(txtAdminCommand.Text)));
txtAdminCommand.Text = "";
}
}

}





}
3 changes: 3 additions & 0 deletions Meridian59.DebugUI/Events/EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with "Me
*/

using System;
using System.Windows.Forms;
using Meridian59.Protocol.GameMessages;

namespace Meridian59.DebugUI.Events
{
Expand Down Expand Up @@ -53,4 +55,5 @@ public PacketLogChangeEventArgs(bool LogOutgoing, bool LogIncoming, bool LogPing
this.LogPings = LogPings;
}
}

}
12 changes: 12 additions & 0 deletions Meridian59.DebugUI/Meridian59.DebugUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AdminController.cs" />
<Compile Include="BaseGridView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CustomDataGridColumns\TagColumn.cs" />
<Compile Include="ObjectEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ObjectEditor.Designer.cs">
<DependentUpon>ObjectEditor.cs</DependentUpon>
</Compile>
<Compile Include="Viewers\BackgroundMusicView.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down Expand Up @@ -186,6 +195,9 @@
<EmbeddedResource Include="DebugForm.resx">
<DependentUpon>DebugForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="ObjectEditor.resx">
<DependentUpon>ObjectEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Viewers\BackgroundMusicView.resx">
<DependentUpon>BackgroundMusicView.cs</DependentUpon>
</EmbeddedResource>
Expand Down
85 changes: 85 additions & 0 deletions Meridian59.DebugUI/ObjectEditor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Meridian59.DebugUI/ObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Meridian59.Data.Models.AdminData;

namespace Meridian59.DebugUI
{
public partial class ObjectEditor : Form

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually the classname of all views refers to the model name that is shown in the view, e.g.:

  • Models.RoomInfo --> RoomInfoView
  • Models.ObjectBase --> ObjectBaseView

It looks like a proper name would be "AdminObjectView", because this class seems to display the data of the "AdminObject" model.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

{
private BindingSource dataBindingSource;
private AdminObject trackedObject;

public ObjectEditor(AdminObject obj)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not pass the datasource as a constructor parameter.

Instead define a property "DataSource" on your UI (view), according to MVC pattern the type of this property of course would be the one of the according underlying model providing the data for the view (your "AdminData" class for example if you need all of it - or in this case probably just "AdminObject")

Please have a look at "RoomInfoView.cs" or "RoomObjectsView.cs" for examples for "DataSource" property.
You can adopt their definition of a "DataSource" property. Don't forget the [DesignerSerialization...] attributes above the signature.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not completed yet. There are a lof of ways I can work better within your design/architecture. I'll work on that slowly. I feel like now that I have AdminData class in Meridian59 I might need an AdminUIController in DebugUI that handles talking to AdminData.

I probably need to define some Interfaces for AdminObject and AdminProperty, INotifyProeprtyChanged is probably not going to work in the long run.

{
InitializeComponent();
Text = String.Format("{0} {1}", obj.ObjectNumber, obj.ClassName);
dataBindingSource = new BindingSource();
dataBindingSource.DataSource = obj.Properties;
dataGridView1.DataSource = dataBindingSource;
dataGridView1.Columns[0].ReadOnly = true;
obj.PropertyChanged += TrackedObject_OnPropertyChanged;
trackedObject = obj;
}

private void TrackedObject_OnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
{
RefreshData();
ResetBindings();
}

public void RefreshData()
{
dataBindingSource.Clear();
dataBindingSource.DataSource = null;
dataGridView1.DataSource = null;
dataBindingSource.DataSource = trackedObject.Properties;
dataGridView1.DataSource = dataBindingSource;
dataGridView1.Refresh();
}

public AdminObject GetTrackedObject()
{
return trackedObject;
}
}
}
Loading