Allow linedef flags text to be changed per type (config isn't updated yet)

This commit is contained in:
MascaraSnake 2016-01-14 20:31:27 +01:00
parent 4e988bb61f
commit 6dd3635a38
6 changed files with 76 additions and 32 deletions

View file

@ -1404,6 +1404,10 @@ linedeftypes
{
title = "Teleporter";
prefix = "(412)";
flags2text = "[1] Silent";
flags64text = "[6] Retain angle";
flags256text = "[8] Relative, silent";
flags512text = "[9] Retain momentum";
}
425

View file

@ -592,7 +592,7 @@ namespace CodeImp.DoomBuilder.Config
ac = cats[cde.Key.ToString()];
else
{
ac = new LinedefActionCategory(cde.Key.ToString(), cattitle);
ac = new LinedefActionCategory(cde.Key.ToString(), cattitle,cfg,linedefflags);
cats.Add(cde.Key.ToString(), ac);
}
@ -610,7 +610,7 @@ namespace CodeImp.DoomBuilder.Config
if(de.Value is IDictionary)
{
// Make the line type
LinedefActionInfo ai = new LinedefActionInfo(actionnumber, cfg, cde.Key.ToString(), enums);
LinedefActionInfo ai = new LinedefActionInfo(actionnumber, cfg, ac, enums);
// Add action to category and sorted list
sortedlinedefactions.Add(ai);

View file

@ -16,6 +16,7 @@
#region ================== Namespaces
using CodeImp.DoomBuilder.IO;
using System;
using System.Collections.Generic;
@ -34,9 +35,10 @@ namespace CodeImp.DoomBuilder.Config
// Category properties
private string name;
private string title;
private IDictionary<string, string> flags;
// Actions
private List<LinedefActionInfo> actions;
// Actions
private List<LinedefActionInfo> actions;
// Disposing
private bool isdisposed;
@ -47,7 +49,8 @@ namespace CodeImp.DoomBuilder.Config
public string Name { get { return name; } }
public string Title { get { return title; } }
public List<LinedefActionInfo> Actions { get { return actions; } }
public IDictionary<string, string> Flags { get { return flags; } }
public List<LinedefActionInfo> Actions { get { return actions; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
@ -55,15 +58,17 @@ namespace CodeImp.DoomBuilder.Config
#region ================== Constructor / Disposer
// Constructor
internal LinedefActionCategory(string name, string title)
internal LinedefActionCategory(string name, string title, Configuration cfg, IDictionary<string, string> flags)
{
// Initialize
this.name = name;
this.title = title;
this.actions = new List<LinedefActionInfo>();
this.flags = new Dictionary<string, string>(flags);
ReadCategorySpecificFlags(cfg);
// We have no destructor
GC.SuppressFinalize(this);
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
@ -101,7 +106,17 @@ namespace CodeImp.DoomBuilder.Config
public override string ToString()
{
return title;
}
}
private void ReadCategorySpecificFlags(Configuration cfg)
{
Dictionary<string, string> newflags = new Dictionary<string, string>(flags);
foreach (KeyValuePair<string, string> p in flags)
{
newflags[p.Key] = cfg.ReadSetting("thingtypes." + name + ".flags" + p.Key + "text", p.Value);
}
flags = newflags;
}
#endregion
}

View file

@ -45,12 +45,13 @@ namespace CodeImp.DoomBuilder.Config
private readonly bool isgeneralized;
private readonly bool isknown;
private readonly bool requiresactivation; //mxd
#endregion
private IDictionary<string, string> flags;
#region ================== Properties
#endregion
public int Index { get { return index; } }
#region ================== Properties
public int Index { get { return index; } }
public string Prefix { get { return prefix; } }
public string Category { get { return category; } }
public string Name { get { return name; } }
@ -61,19 +62,20 @@ namespace CodeImp.DoomBuilder.Config
public bool IsNull { get { return (index == 0); } }
public bool RequiresActivation { get { return requiresactivation; } } //mxd
public ArgumentInfo[] Args { get { return args; } }
public IDictionary<string, string> Flags { get { return flags; } }
#endregion
#endregion
#region ================== Constructor / Disposer
#region ================== Constructor / Disposer
// Constructor
internal LinedefActionInfo(int index, Configuration cfg, string categoryname, IDictionary<string, EnumList> enums)
// Constructor
internal LinedefActionInfo(int index, Configuration cfg, LinedefActionCategory ac, IDictionary<string, EnumList> enums)
{
string actionsetting = "linedeftypes." + categoryname + "." + index.ToString(CultureInfo.InvariantCulture);
string actionsetting = "linedeftypes." + ac.Name + "." + index.ToString(CultureInfo.InvariantCulture);
// Initialize
this.index = index;
this.category = categoryname;
this.category = ac.Name;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
this.isgeneralized = false;
this.isknown = true;
@ -85,9 +87,11 @@ namespace CodeImp.DoomBuilder.Config
this.requiresactivation = cfg.ReadSetting(actionsetting + ".requiresactivation", true); //mxd
this.title = this.prefix + " " + this.name;
this.title = this.title.Trim();
this.flags = new Dictionary<string, string>(ac.Flags);
ReadLinedefSpecificFlags(cfg);
// Read the args
for(int i = 0; i < Linedef.NUM_ARGS; i++)
// Read the args
for (int i = 0; i < Linedef.NUM_ARGS; i++)
this.args[i] = new ArgumentInfo(cfg, actionsetting, i, enums);
// We have no destructor
@ -102,7 +106,8 @@ namespace CodeImp.DoomBuilder.Config
this.isknown = isknown;
this.requiresactivation = true; //mxd. Unused, set for consistency sake.
this.title = title;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
this.flags = new Dictionary<string, string>();
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
for(int i = 0; i < Linedef.NUM_ARGS; i++)
this.args[i] = new ArgumentInfo(i);
}
@ -123,8 +128,19 @@ namespace CodeImp.DoomBuilder.Config
if(this.index < other.index) return -1;
else if(this.index > other.index) return 1;
else return 0;
}
}
#endregion
}
private void ReadLinedefSpecificFlags(Configuration cfg)
{
Dictionary<string, string> newflags = new Dictionary<string, string>(flags);
string key = index.ToString(CultureInfo.InvariantCulture);
foreach (KeyValuePair<string, string> p in flags)
{
newflags[p.Key] = cfg.ReadSetting("linedeftypes." + category + "." + key + ".flags" + p.Key + "text", p.Value);
}
flags = newflags;
}
#endregion
}
}

View file

@ -470,8 +470,9 @@ namespace CodeImp.DoomBuilder.Controls
flags.Items.Add(new ListViewItem(ai.Title) { Checked = true, ForeColor = SystemColors.HotTrack });
}
// And flags
foreach(KeyValuePair<string, string> group in General.Map.Config.LinedefFlags)
// And flags
IDictionary<string, string> flagList = (act == null || act.Flags.Count == 0) ? General.Map.Config.LinedefFlags : act.Flags;
foreach (KeyValuePair<string, string> group in flagList)
{
if(l.Flags.ContainsKey(group.Key) && l.Flags[group.Key])
flags.Items.Add(new ListViewItem(group.Value) { Checked = true });

View file

@ -173,9 +173,13 @@ namespace CodeImp.DoomBuilder.Windows
// Get first line
Linedef fl = General.GetByIndex(lines, 0);
// Flags
foreach(CheckBox c in flags.Checkboxes)
// Flags
LinedefActionInfo li = General.Map.Config.GetLinedefActionInfo(fl.Action);
IDictionary<string, string> newFlags = (li == null || li.Flags.Count == 0) ? General.Map.Config.LinedefFlags : li.Flags;
flags.UpdateCheckboxes(newFlags);
foreach (CheckBox c in flags.Checkboxes)
if(fl.Flags.ContainsKey(c.Tag.ToString())) c.Checked = fl.Flags[c.Tag.ToString()];
// Activations
@ -514,8 +518,12 @@ namespace CodeImp.DoomBuilder.Windows
//mxd. Update what must be updated
argscontrol.UpdateScriptControls();
actionhelp.UpdateAction(showaction);
}
}
LinedefActionInfo li = General.Map.Config.GetLinedefActionInfo(action.Value);
IDictionary<string, string> newFlags = (li == null || li.Flags.Count == 0) ? General.Map.Config.LinedefFlags : li.Flags;
flags.UpdateCheckboxes(newFlags);
}
}
// Browse Action clicked
private void browseaction_Click(object sender, EventArgs e)