public override void OnInspectorGUI() { //base.OnInspectorGUI(); IntRangeVariable intVariable = (IntRangeVariable)target; intVariable.Descending = EditorGUILayout.Toggle("Descending", intVariable.Descending); if (intVariable.Descending) { intVariable.MaxValue = EditorGUILayout.IntField("Max Value", (int)intVariable.MaxValue); intVariable.MinValue = EditorGUILayout.IntField("Min Value", (int)intVariable.MinValue); intVariable.InitialValue = (int)EditorGUILayout.Slider("Initial Value", intVariable.InitialValue, intVariable.MaxValue, intVariable.MinValue); } else { intVariable.MinValue = EditorGUILayout.IntField("Min Value", (int)intVariable.MinValue); intVariable.MaxValue = EditorGUILayout.IntField("Max Value", (int)intVariable.MaxValue); intVariable.InitialValue = (int)EditorGUILayout.Slider("Initial Value", intVariable.InitialValue, intVariable.MinValue, intVariable.MaxValue); } if (Application.isPlaying) { intVariable.RuntimeValue = EditorGUILayout.IntField("Runtime Value", intVariable.RuntimeValue); } GUILayout.Label("Runtime Value: " + intVariable.RuntimeValue.ToString()); }
// *** INITIALIZATION *** // #region SetGameVariables public override void SetGameVariables() { base.SetGameVariables(); PositionNumber = new IntRangeVariable(1, 960); Array = null; Castling.Choices.Add("FRC"); Castling.Choices.Add("Chess480"); }
private string getCurrentValue(Game game, GameVariableAttribute gva, PropertyInfo pi) { if (pi.PropertyType == typeof(bool)) { bool val = (bool)pi.GetValue(game); return(val ? "true" : "false"); } else if (pi.PropertyType == typeof(string)) { string val = (string)pi.GetValue(game); if (val == null) { return("<i>dynamic</i>"); } else { return("\"" + val + "\""); } } else if (pi.PropertyType == typeof(int)) { int val = (int)pi.GetValue(game); return(val.ToString()); } else if (pi.PropertyType == typeof(ChoiceVariable)) { ChoiceVariable val = (ChoiceVariable)pi.GetValue(game); return(val.Value); } else if (pi.PropertyType == typeof(IntRangeVariable)) { IntRangeVariable val = (IntRangeVariable)pi.GetValue(game); return("<i>integer</i> between " + val.MinValue.ToString() + " and " + val.MaxValue.ToString()); } else if (pi.PropertyType == typeof(PieceType)) { PieceType pt = (PieceType)pi.GetValue(game); if (pt != null) { return(pt.Name + (pt.Name != pt.InternalName ? " (" + pt.InternalName + ")" : "")); } else { return("null"); } } return(""); }
private void btnOK_Click(object sender, EventArgs e) { int intPropertyNumber = 0; try { if (intProperty1 != null) { intPropertyNumber = 1; ((IntRangeVariable)intProperty1.GetValue(game, null)).Value = Convert.ToInt32(txtVariable1.Text); } if (intProperty2 != null) { intPropertyNumber = 2; ((IntRangeVariable)intProperty2.GetValue(game, null)).Value = Convert.ToInt32(txtVariable2.Text); } if (choiceProperty1 != null) { ((ChoiceVariable)choiceProperty1.GetValue(game, null)).Value = (string)pickVariable1.SelectedItem; } if (choiceProperty2 != null) { ((ChoiceVariable)choiceProperty2.GetValue(game, null)).Value = (string)pickVariable2.SelectedItem; } } catch { PropertyInfo property = intPropertyNumber == 1 ? intProperty1 : intProperty2; IntRangeVariable variable = (IntRangeVariable)property.GetValue(game, null); string displayName = ConvertVariableNameToDisplay(property.Name); MessageBox.Show("Parameter '" + displayName.Substring(0, displayName.Length - 1) + "' must be between " + variable.MinValue.ToString() + " and " + variable.MaxValue.ToString()); DialogResult = DialogResult.None; return; } Close(); }
// *** INITIALIZATION *** // #region SetGameVariables public override void SetGameVariables() { base.SetGameVariables(); PositionNumber = new IntRangeVariable(1, 256); Array = "rnbqkbnr/#{BlackPawns}/8/8/#{WhitePawns}/RNBQKBNR"; }
// *** INITIALIZATION *** // #region SetGameVariables public override void SetGameVariables() { base.SetGameVariables(); PositionNumber = new IntRangeVariable(1, 18); }
private string getPotentialValues(Game game, GameVariableAttribute gva, PropertyInfo pi, out bool paragraph, bool fullDescription = false) { paragraph = false; if (pi.PropertyType == typeof(bool)) { return("<i>boolean</i>"); } else if (pi.PropertyType == typeof(string)) { string val = (string)pi.GetValue(game); if (val == null) { return("<i>dynamic</i>"); } else { return("<i>string</i>"); //"\"" + val + "\""; } } else if (pi.PropertyType == typeof(int)) { return("<i>integer</i>"); } else if (pi.PropertyType == typeof(ChoiceVariable)) { ChoiceVariable val = (ChoiceVariable)pi.GetValue(game); if (val.HasDescriptions) { paragraph = true; string s = "choice of: <blockquote><ul>"; foreach (string choice in val.Choices) { s += "<li><b>" + choice + "</b>"; string desc = val.DescribeChoice(choice); if (desc != null) { s += ": " + desc; } s += "</li>"; } s += "</ul></blockquote>"; return(s); } else { string s = "choice of { "; bool first = true; foreach (string choice in val.Choices) { if (first) { first = false; } else { s += ", "; } s += choice; } s += " }"; if (val.DefaultValue != null) { s += " default: " + val.DefaultValue; } return(s); } } else if (pi.PropertyType == typeof(PieceType)) { return("<i>PieceType</i>"); } else if (pi.PropertyType == typeof(IntRangeVariable)) { IntRangeVariable val = (IntRangeVariable)pi.GetValue(game); return("<i>integer</i> between " + val.MinValue.ToString() + " and " + val.MaxValue.ToString()); } return(""); }
protected void PreviewHelper(Game game, object helperObject) { int unassignedCount = 0; PropertyInfo[] properties = game.GetType().GetProperties(); foreach (PropertyInfo property in properties) { object[] attributes = property.GetCustomAttributes(typeof(GameVariableAttribute), false); if (attributes.Length > 0) { if (property.PropertyType == typeof(ChoiceVariable)) { ChoiceVariable choice = (ChoiceVariable)property.GetValue(game, null); if (choice.Choices.Count > 0 && choice.Value == null) { // this property is unassigned if (unassignedCount == 0) { choice.Value = (string)pickVariable1.SelectedItem; } else if (unassignedCount == 1) { choice.Value = (string)pickVariable2.SelectedItem; } unassignedCount++; } } else if (property.PropertyType == typeof(IntRangeVariable)) { IntRangeVariable val = (IntRangeVariable)property.GetValue(game, null); if (val.Value == null) { // this property is unassigned if (unassignedCount == 0) { int textvalue; val.Value = null; if (Int32.TryParse(txtVariable1.Text, out textvalue)) { if (textvalue >= val.MinValue && textvalue <= val.MaxValue) { val.Value = textvalue; } } } else if (unassignedCount == 1) { int textvalue; val.Value = null; if (Int32.TryParse(txtVariable2.Text, out textvalue)) { if (textvalue >= val.MinValue && textvalue <= val.MaxValue) { val.Value = textvalue; } } } unassignedCount++; } } } } }
private void GameVariablesForm_Load(object sender, EventArgs e) { // Determine background color - this is typically the // first square color (light square color) but if that // color isn't light enough, we will scale it up to make // it lighter. Things look bad if the backgrounds for // all the tool windows aren't fairly light Theme theme = ThemeFactory.CreateTheme(game); Color WindowBackgroundColor = theme.ColorScheme.SquareColors[0]; int brightness = (WindowBackgroundColor.R + WindowBackgroundColor.G + WindowBackgroundColor.B) / 3; if (brightness < 250) { double scaleFactor = 250.0 / (double)brightness; WindowBackgroundColor = Color.FromArgb( (int)(WindowBackgroundColor.R + ((255 - WindowBackgroundColor.R) * (scaleFactor - 1.0))), (int)(WindowBackgroundColor.G + ((255 - WindowBackgroundColor.G) * (scaleFactor - 1.0))), (int)(WindowBackgroundColor.B + ((255 - WindowBackgroundColor.B) * (scaleFactor - 1.0)))); } BackColor = WindowBackgroundColor; int unassignedCount = 0; PropertyInfo[] properties = game.GetType().GetProperties(); foreach (PropertyInfo property in properties) { object[] attributes = property.GetCustomAttributes(typeof(GameVariableAttribute), false); if (attributes.Length > 0) { if (property.PropertyType == typeof(ChoiceVariable)) { ChoiceVariable choice = (ChoiceVariable)property.GetValue(game, null); if (choice.Choices.Count > 0 && choice.Value == null) { // this property is unassigned if (unassignedCount == 0) { choiceProperty1 = property; lblGameVariable1.Visible = true; lblGameVariable1.Text = ConvertVariableNameToDisplay(property.Name); pickVariable1.Visible = true; foreach (string choicename in choice.Choices) { pickVariable1.Items.Add(choicename); } if (choice.DefaultValue != null) { pickVariable1.SelectedItem = choice.DefaultValue; } else { pickVariable1.SelectedIndex = Program.Random.Next(pickVariable1.Items.Count); } } else if (unassignedCount == 1) { choiceProperty2 = property; lblGameVariable2.Visible = true; lblGameVariable2.Text = ConvertVariableNameToDisplay(property.Name); pickVariable2.Visible = true; foreach (string choicename in choice.Choices) { pickVariable2.Items.Add(choicename); } if (choice.DefaultValue != null) { pickVariable2.SelectedItem = choice.DefaultValue; } else { pickVariable2.SelectedIndex = Program.Random.Next(pickVariable2.Items.Count); } } else { throw new Exception("Not supported - too many unassigned variables"); } unassignedCount++; } } else if (property.PropertyType == typeof(IntRangeVariable)) { IntRangeVariable val = (IntRangeVariable)property.GetValue(game, null); if (val.Value == null) { // this property is unassigned if (unassignedCount == 0) { intProperty1 = property; lblGameVariable1.Visible = true; lblGameVariable1.Text = ConvertVariableNameToDisplay(property.Name); txtVariable1.Visible = true; val.Value = Program.Random.Next((int)val.MaxValue - (int)val.MinValue + 1) + (int)val.MinValue; txtVariable1.Text = val.Value.ToString(); unassignedCount++; } } } } } if (unassignedCount == 1) { lblGameVariable1.Location = new Point(lblGameVariable1.Location.X, lblGameVariable1.Location.Y + 18); txtVariable1.Location = new Point(txtVariable1.Location.X, txtVariable1.Location.Y + 18); pickVariable1.Location = new Point(pickVariable1.Location.X, pickVariable1.Location.Y + 18); } finishedLoading = true; UpdatePreviewImage(); }