Skip to content

Commit

Permalink
Added very versatile support for mod-specific settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zzattack committed Sep 27, 2013
1 parent 4cedc5e commit 85ff2b2
Show file tree
Hide file tree
Showing 41 changed files with 5,155 additions and 527 deletions.
22 changes: 22 additions & 0 deletions CNCMaps GUI/CNCMaps GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.XML" />
Expand Down Expand Up @@ -91,12 +92,27 @@
<Compile Include="..\CNCMaps\Utility\Option.cs">
<Link>Option.cs</Link>
</Compile>
<Compile Include="DynamicTypeDescription\CustomComponentModel.cs" />
<Compile Include="DynamicTypeDescription\DynamicTypeDescriptor.cs" />
<Compile Include="DynamicTypeDescription\StandardValueEditorUI.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="DynamicTypeDescription\StandardValueEditorUI.Designer.cs">
<DependentUpon>StandardValueEditorUI.cs</DependentUpon>
</Compile>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="ModConfig.cs" />
<Compile Include="ModConfigEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ModConfigEditor.Designer.cs">
<DependentUpon>ModConfigEditor.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UpdateChecker.cs" />
Expand All @@ -105,10 +121,16 @@
<Content Include="ra2mapicon.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="DynamicTypeDescription\StandardValueEditorUI.resx">
<DependentUpon>StandardValueEditorUI.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ModConfigEditor.resx">
<DependentUpon>ModConfigEditor.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
Expand Down
146 changes: 146 additions & 0 deletions CNCMaps GUI/DynamicTypeDescription/CustomComponentModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#region copyright notice
// Code obtained from http://www.codeproject.com/Articles/23242/Property-Grid-Dynamic-List-ComboBox-Validation-and
// Written by Dave Elliott
// Licensed under The Code Project Open License (CPOL) - http://www.codeproject.com/info/cpol10.aspx
#endregion


using System;
using System.Collections.Generic;
using System.Drawing.Design;
using System.Collections;
using System.ComponentModel;

namespace DynamicTypeDescriptor {
internal class PropertyValueUIService : IPropertyValueUIService {
private PropertyValueUIHandler m_ValueUIHandler;
private EventHandler m_NotifyHandler;

public PropertyValueUIService() {
}

/// <summary>
/// Adds or removes an event handler that will be invoked
/// when the global list of PropertyValueUIItems is modified.
/// </summary>
event EventHandler IPropertyValueUIService.PropertyUIValueItemsChanged {
add {
lock (this)
this.m_NotifyHandler += value;
}
remove {
lock (this)
this.m_NotifyHandler -= value;
}
}

/// <summary>
/// Tell the IPropertyValueUIService implementation that the global list of PropertyValueUIItems has been modified.
/// </summary>
void IPropertyValueUIService.NotifyPropertyValueUIItemsChanged() {
if (this.m_NotifyHandler != null) {
this.m_NotifyHandler(this, EventArgs.Empty);
}
}

/// <summary>
/// Adds a PropertyValueUIHandler to this service. When GetPropertyUIValueItems is
/// called, each handler added to this service will be called and given the opportunity
/// to add an icon to the specified property.
/// </summary>
/// <param name="newHandler"></param>
void IPropertyValueUIService.AddPropertyValueUIHandler(PropertyValueUIHandler newHandler) {
if (newHandler == null) {
throw new ArgumentNullException("newHandler");
}
lock (this)
this.m_ValueUIHandler = (PropertyValueUIHandler)Delegate.Combine(this.m_ValueUIHandler, newHandler);
}

/// <summary>
/// Removes a PropertyValueUIHandler to this service. When GetPropertyUIValueItems is
/// called, each handler added to this service will be called and given the opportunity
/// to add an icon to the specified property.
/// </summary>
/// <param name="newHandler"></param>
void IPropertyValueUIService.RemovePropertyValueUIHandler(PropertyValueUIHandler newHandler) {
if (newHandler == null) {
throw new ArgumentNullException("newHandler");
}

this.m_ValueUIHandler = (PropertyValueUIHandler)Delegate.Remove(this.m_ValueUIHandler, newHandler);
}

/// <summary>
/// Gets all the PropertyValueUIItems that should be displayed on the given property.
/// For each item returned, a glyph icon will be aded to the property.
/// </summary>
/// <param name="context"></param>
/// <param name="propDesc"></param>
/// <returns></returns>
PropertyValueUIItem[] IPropertyValueUIService.GetPropertyUIValueItems(ITypeDescriptorContext context, PropertyDescriptor propDesc) {

if (propDesc == null) {
throw new ArgumentNullException("propDesc");
}

if (this.m_ValueUIHandler == null) {
return new PropertyValueUIItem[0];
}


lock (this) {
ArrayList result = new ArrayList();

this.m_ValueUIHandler(context, propDesc, result);

return (PropertyValueUIItem[])result.ToArray(typeof(PropertyValueUIItem));
}

}
}


internal sealed class SimpleSite : ISite, IServiceProvider {
public IComponent Component {
get;
set;
}
private readonly IContainer container = new Container();
IContainer ISite.Container {
get {
return container;
}
}
public bool DesignMode {
get;
set;
}
public string Name {
get;
set;
}
private Dictionary<Type, object> services;
public void AddService<T>(T service) where T : class {
if (services == null)
services = new Dictionary<Type, object>();
services[typeof(T)] = service;
}
public void RemoveService<T>() where T : class {
if (services != null)
services.Remove(typeof(T));
}
object IServiceProvider.GetService(Type serviceType) {
object service;
if (services != null && services.TryGetValue(serviceType, out service)) {
return service;
}
return null;
}
}





}
Loading

0 comments on commit 85ff2b2

Please sign in to comment.