using System.Collections.Generic;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
using MLEM.Misc;
namespace MLEM.Formatting.Codes {
///
/// An instance of a formatting code that can be used for a .
/// To add a new formatting code, see
///
public class Code : GenericDataHolder {
///
/// The regex that this code was created from
///
public readonly Regex Regex;
///
/// The match that this code encompasses
///
public readonly Match Match;
///
/// The tokens that this formatting code is a part of.
/// Note that this array only has multiple entries if additional tokens have to be started while this code is still applied.
///
public IList Tokens { get; internal set; }
///
/// Creates a new formatting code based on a formatting code regex and its match.
///
/// The match
/// The regex
protected Code(Match match, Regex regex) {
this.Match = match;
this.Regex = regex;
}
///
/// Returns whether this formatting code should end when the passed formatting code starts.
/// If this method returns true, a new is started at its position.
/// This is the opposite version of .
///
/// The code that is started here.
/// If this code should end here.
public virtual bool EndsHere(Code other) {
return other.GetType() == this.GetType();
}
///
/// Returns whether the should end when this formatting code starts.
/// If this method returns true, a new is started at this code's position.
/// This is the opposite version of .
///
/// The code that could end here.
/// Whether the code should end here.
public virtual bool EndsOther(Code other) {
return false;
}
///
public virtual Color? GetColor(Color defaultPick) {
return null;
}
///
public virtual GenericFont GetFont(GenericFont defaultPick) {
return null;
}
///
/// Update this formatting code's animations etc.
///
/// The game's time
public virtual void Update(GameTime time) {}
///
/// Returns the string that this formatting code should be replaced with.
/// Usually, you'll just want an empty string here, but some formatting codes (like ) require their space to be filled by spaces.
///
/// The font that is used
/// The replacement string for this formatting code
public virtual string GetReplacementString(GenericFont font) {
return string.Empty;
}
///
public virtual bool DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, Token token, int indexInToken, ref Vector2 pos, GenericFont font, ref Color color, ref float scale, float depth) {
return false;
}
///
public virtual void DrawSelf(GameTime time, SpriteBatch batch, Token token, Vector2 pos, GenericFont font, Color color, float scale, float depth) {}
///
/// Creates a new formatting code from the given regex and regex match.
///
///
/// The text formatter that created this code
/// The match for the code's regex
/// The regex used to create this code
public delegate Code Constructor(TextFormatter formatter, Match match, Regex regex);
}
}