public static string CapitalizedString(this PersonAttribute attr) { string[] words = attr.ToString().Split(new [] { '-', '_' }, System.StringSplitOptions.RemoveEmptyEntries); var capitalizedWords = words.Select(word => char.ToUpper(word[0]) + word.Substring(1).ToLower()).ToArray(); return(System.String.Join(" ", capitalizedWords)); }
// TODO: use profession.GetColor() to color profession in GodDemand description/cost, and Person public static Color32 GetColor(this PersonAttribute attr) { switch (attr) { case PersonAttribute.FARMER: return(new Color32(60, 99, 60, 255)); case PersonAttribute.WARRIOR: return(new Color32(225, 0, 0, 255)); case PersonAttribute.CIVILIAN: return(new Color32(23, 19, 102, 255)); case PersonAttribute.SCRIBE: return(new Color32(166, 0, 226, 255)); case PersonAttribute.WITCH_DOCTOR: return(new Color32(239, 96, 13, 255)); case PersonAttribute.NONE: return(new Color32(29, 29, 29, 255)); default: Debug.Log("WARNING: " + attr.ToString() + " has no associated color"); return(Color.white); } }
// TODO: add an option to choose between 16px and 32px variants public Sprite GetSprite(PersonAttribute attribute) { if (attribute == PersonAttribute.NONE) { return(null); } return(GetSprite(attribute.ToString())); }
public XpBuff(PersonAttribute profession) : base("", "") { mProfession = profession; string professionString = profession.CapitalizedString(); mName = string.Format("Level {0} {1}s", GameState.GetLevelCap(mProfession) + 1, professionString); mDescription = professionString + "s gain +1 xp/s. +1 max level."; mIcon = profession.ToString(); }
private static void CreateDateTextBox(PersonAttribute attribute, string cssClass, Control parentContainer, bool setValue, bool enabled) { DynamicDateTextBox dtb = new DynamicDateTextBox(); parentContainer.Controls.Add(dtb); dtb.ID = GetControlID(attribute); dtb.CssClass = cssClass; dtb.Enabled = enabled; if (setValue) { dtb.Text = attribute.ToString(true); } }
public void SetProfession(PersonAttribute profession) { mProfession = profession; this.name = mProfession.ToString(); // Update visuals transform.Find("Top bar/Icon").GetComponent <Image>().sprite = Utilities.GetSpriteManager().GetSprite(mProfession); Color32 profColor = mProfession.GetColor(); // Color the background based on the profession's associated color GetComponent <Image>().color = new Color32(profColor.r, profColor.g, profColor.b, 30); // TODO: use the associated profession's color for icon color once the icons are white //transform.Find("Top bar/Icon").GetComponent<Image>().color = ; string labelString = string.Format( "{0} ({1} + {2}/lvl)", mProfession.GetDescription(), mProfession.GetEfficiencyBase(), mProfession.GetEfficiencyPerLevel()); transform.Find("Top bar/Text").GetComponent <Text>().text = labelString; }
public override bool PerformAction(DataUpdate dataUpdate) { // Create objects based on setting Arena.Core.Attribute attribute = new Arena.Core.Attribute((Convert.ToInt32(AttributeIdSetting))); // Add primary key to 'Before' dataset so that it can be searched if (dataUpdate.DataBefore != null) { DataColumn[] primaryKey = new DataColumn[2]; primaryKey[0] = dataUpdate.DataBefore.Columns["person_id"]; primaryKey[1] = dataUpdate.DataBefore.Columns["attribute_id"]; dataUpdate.DataBefore.PrimaryKey = primaryKey; } // Loop through each new row if (dataUpdate.DataAfter != null) { foreach (DataRow newRow in dataUpdate.DataAfter.Rows) { // If this update is for the attribute type we care about if (Convert.ToInt32(newRow["attribute_id"].ToString()) == attribute.AttributeId) { // Load New Person Attribute PersonAttribute newPA = new PersonAttribute(attribute.AttributeId); newPA.PersonID = Convert.ToInt32(newRow["person_id"].ToString()); if (newRow["int_value"] != DBNull.Value) { newPA.IntValue = Convert.ToInt32(newRow["int_value"].ToString()); } if (newRow["decimal_value"] != DBNull.Value) { newPA.DecimalValue = Convert.ToDecimal(newRow["decimal_value"].ToString()); } if (newRow["varchar_value"] != DBNull.Value) { newPA.StringValue = newRow["varchar_value"].ToString(); } if (newRow["datetime_value"] != DBNull.Value) { newPA.DateValue = Convert.ToDateTime(newRow["datetime_value"].ToString()); } // If this is a date attribute and the ignore date setting is set, make sure the date setting is not too old if (IgnoreDateDaysSetting == "-1" || newPA.AttributeType != Arena.Enums.DataType.DateTime || newPA.DateValue.AddDays(Convert.ToInt32(IgnoreDateDaysSetting)).CompareTo(DateTime.Today) >= 0) { // If we don't need a specific value or the value is equal to our test value if (SpecificValueSetting == string.Empty || newPA.ToString().Trim().ToLower() == SpecificValueSetting.Trim().ToLower()) { // Look for the previous version of this row DataRow oldRow = null; if (dataUpdate.DataBefore != null) { object[] key = new object[2]; key[0] = newPA.PersonID; key[1] = newPA.AttributeId; oldRow = dataUpdate.DataBefore.Rows.Find(key); } string title = string.Empty; string description = string.Empty; // If a previous version doesn't exist (was an add) if (oldRow == null) { title = attribute.AttributeName + " Value Added"; description = string.Format("{0} was updated to '{1}' on {2} at {3}.", attribute.AttributeName, newPA.ToString(), dataUpdate.UpdateDateTime.ToShortDateString(), dataUpdate.UpdateDateTime.ToShortTimeString()); } else { // Load Old Person Attribute PersonAttribute oldPA = new PersonAttribute(attribute.AttributeId); oldPA.PersonID = Convert.ToInt32(oldRow["person_id"].ToString()); if (oldRow["int_value"] != DBNull.Value) { oldPA.IntValue = Convert.ToInt32(oldRow["int_value"].ToString()); } if (oldRow["decimal_value"] != DBNull.Value) { oldPA.DecimalValue = Convert.ToDecimal(oldRow["decimal_value"].ToString()); } if (oldRow["varchar_value"] != DBNull.Value) { oldPA.StringValue = oldRow["varchar_value"].ToString(); } if (oldRow["datetime_value"] != DBNull.Value) { oldPA.DateValue = Convert.ToDateTime(oldRow["datetime_value"].ToString()); } // Or it was different (was an update) if (newPA.ToString() != oldPA.ToString()) { title = attribute.AttributeName + " Value Updated"; description = string.Format("{0} was updated from '{1}' to '{2}' on {3} at {4}.", attribute.AttributeName, oldPA.ToString(), newPA.ToString(), dataUpdate.UpdateDateTime.ToShortDateString(), dataUpdate.UpdateDateTime.ToShortTimeString()); } } // Create a new assignment if (title != string.Empty) { AssignmentType assignmentType = new AssignmentType((Convert.ToInt32(AssignmentTypeIdSetting))); Assignment assignment = new Assignment(); assignment.AssignmentTypeId = assignmentType.AssignmentTypeId; assignment.Title = title; assignment.Description = description; assignment.RequesterPersonId = Convert.ToInt32(newRow["person_id"].ToString()); assignment.PriorityId = assignmentType.DefaultPriorityId; assignment.SubmitAssignmentEntry(null, "PersonAttributeDataChange"); } } } } } } return(true); }
/// <summary> /// This (factory) method will create controls based on the given PersonAttribute object and add them to the /// container control that's passed in. This allows the dynamic control to participate in ViewState. /// </summary> /// <param name="attribute"><see cref="Arena.Core.PersonAttribute">PersonAttribute</see> to represent</param> /// <param name="cssClass">CSS class to append to the dynamic control</param> /// <param name="parentContainer">Parent Control to add the control to</param> /// <param name="setValue">Boolean indicating whether or not to set the value of the control</param> /// <param name="enabled">Boolean indicating whether the control will be enabled</param> public static void CreateControl(PersonAttribute attribute, string cssClass, Control parentContainer, bool setValue, bool enabled) { if (attribute.Visible && attribute.Permissions.Allowed(OperationType.View, ArenaContext.Current.User)) { bool canEdit = (enabled && attribute.Permissions.Allowed(OperationType.Edit, ArenaContext.Current.User)); switch (attribute.AttributeType) { case DataType.Currency: case DataType.Decimal: CreateTextBox(attribute, cssClass, parentContainer, setValue, canEdit, attribute.ToString()); break; case DataType.Int: CreateTextBox(attribute, cssClass, parentContainer, setValue, canEdit, attribute.ToString()); break; case DataType.DateTime: CreateDateTextBox(attribute, cssClass, parentContainer, canEdit, enabled); break; case DataType.String: case DataType.Guid: case DataType.Url: CreateTextBox(attribute, cssClass, parentContainer, canEdit, enabled, attribute.ToString()); break; case DataType.Lookup: CreateDropDownList(attribute, cssClass, parentContainer, canEdit, enabled); break; case DataType.YesNo: CreateCheckBox(attribute, cssClass, parentContainer, canEdit, enabled); break; case DataType.Document: CreateDocumentPicker(attribute, cssClass, parentContainer, canEdit, enabled); break; default: break; } if (attribute.Required) { CreateValidator(attribute, cssClass, parentContainer); } } }
private string CreateStaffXML() { StringBuilder sbMessages = new StringBuilder(); AttributeGroup StaffDetailsGroup = new AttributeGroup(StaffDetailsAttributeGroupID); Arena.Core.Attribute departmentAttribute = new Arena.Core.Attribute(DepartmentAttributeID); LookupType departments = new LookupType(Convert.ToInt32(departmentAttribute.TypeQualifier)); List <StaffMember> staff = new List <StaffMember>(); PersonCollection people = new PersonCollection(); people.LoadStaffMembers(); foreach (Person person in people) { string title = string.Empty; Lookup department = null; Lookup departmentPosition = null; PersonAttribute pa = (PersonAttribute)person.Attributes.FindByID(PositionAttributeID); if (pa != null) { title = pa.StringValue; } pa = (PersonAttribute)person.Attributes.FindByID(DepartmentAttributeID); if (pa != null && pa.IntValue != -1) { department = new Lookup(pa.IntValue); } pa = (PersonAttribute)person.Attributes.FindByID(DepartmentPositionAttributeID); if (pa != null && pa.IntValue != -1) { departmentPosition = new Lookup(pa.IntValue); } if (department != null && departmentPosition != null) { staff.Add(new StaffMember( person.PersonID, person.PersonGUID, person.NickName, person.LastName, person.Blob != null ? person.Blob.GUID : Guid.Empty, person.Emails.FirstActive, title, department, departmentPosition)); } } staff.Sort(); // Delete any existing department XML files in the staff folder DirectoryInfo staffFolder = new DirectoryInfo(Path.Combine(XMLFolderPath, "Staff")); if (staffFolder.Exists) { foreach (FileInfo fi in staffFolder.GetFiles()) { try { fi.Delete(); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not delete {0} file: {1}\n", fi.FullName, ex.Message); } } } else { staffFolder.Create(); } if (staff.Count > 0) { LookupCollection activeDepartments = new LookupCollection(); Lookup currentDepartment = new Lookup(); XmlDocument xdoc = null; XmlNode departmentNode = null; foreach (StaffMember StaffMember in staff) { if (currentDepartment.LookupID != StaffMember.Department.LookupID) { if (xdoc != null) { string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml"); try { xdoc.Save(path); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message); } } currentDepartment = StaffMember.Department; activeDepartments.Add(currentDepartment); xdoc = new XmlDocument(); departmentNode = xdoc.CreateNode(XmlNodeType.Element, "department", xdoc.NamespaceURI); XmlAttribute xattr = xdoc.CreateAttribute("", "name", xdoc.NamespaceURI); xattr.Value = currentDepartment.Value; departmentNode.Attributes.Append(xattr); xdoc.AppendChild(departmentNode); } departmentNode.AppendChild(StaffMember.XMLNode(xdoc)); if (StaffMember.DepartmentPosition.Qualifier2 == "1") { XmlDocument xdocStaff = new XmlDocument(); XmlNode xnodeStaff = StaffMember.XMLNode(xdocStaff); xdocStaff.AppendChild(xnodeStaff); if (_assistantTypeID != -1) { RelationshipCollection relationships = new RelationshipCollection(StaffMember.ID); foreach (Relationship relationship in relationships) { if (relationship.RelationshipTypeId == _assistantTypeID) { XmlNode xnodeAssistant = xdocStaff.CreateNode(XmlNodeType.Element, "assistant", xdocStaff.NamespaceURI); XmlAttribute xattr = xdocStaff.CreateAttribute("", "fn", xdocStaff.NamespaceURI); xattr.Value = relationship.RelatedPerson.NickName; xnodeAssistant.Attributes.Append(xattr); xattr = xdocStaff.CreateAttribute("", "ln", xdocStaff.NamespaceURI); xattr.Value = relationship.RelatedPerson.LastName; xnodeAssistant.Attributes.Append(xattr); xattr = xdocStaff.CreateAttribute("", "email", xdocStaff.NamespaceURI); xattr.Value = relationship.RelatedPerson.Emails.FirstActive; xnodeAssistant.Attributes.Append(xattr); xnodeStaff.AppendChild(xnodeAssistant); break; } } } PersonAttributeCollection pAttributes = new PersonAttributeCollection(); pAttributes.LoadByGroup(StaffDetailsGroup, StaffMember.ID); foreach (PersonAttribute pa in pAttributes) { if (pa.AttributeType == Arena.Enums.DataType.Document) { if (BioDocumentTypeID != -1 && pa.TypeQualifier == BioDocumentTypeID.ToString()) { Arena.Utility.ArenaDataBlob bioDoc = new Arena.Utility.ArenaDataBlob(pa.IntValue); if (bioDoc.FileExtension == "txt") { ASCIIEncoding enc = new ASCIIEncoding(); string bio = enc.GetString(bioDoc.ByteArray); if (bio != string.Empty) { XmlNode xnodeBio = xdocStaff.CreateNode(XmlNodeType.Element, "biography", xdocStaff.NamespaceURI); xnodeBio.AppendChild(xdocStaff.CreateCDataSection(bio)); xnodeStaff.AppendChild(xnodeBio); } } } } else { XmlNode xnodeAttribute = xdocStaff.CreateNode(XmlNodeType.Element, "attribute", xdocStaff.NamespaceURI); XmlAttribute xattr = xdocStaff.CreateAttribute("", "name", xdocStaff.NamespaceURI); xattr.Value = pa.AttributeName; xnodeAttribute.Attributes.Append(xattr); xattr = xdocStaff.CreateAttribute("", "value", xdocStaff.NamespaceURI); xattr.Value = pa.ToString(); xnodeAttribute.Attributes.Append(xattr); xnodeStaff.AppendChild(xnodeAttribute); } } string path = Path.Combine(staffFolder.FullName, StaffMember.Guid.ToString() + ".xml"); try { xdocStaff.Save(path); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message); } } } if (xdoc != null) { string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml"); try { xdoc.Save(path); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message); } } XmlDocument xdocDepartments = new XmlDocument(); XmlNode xnodeDepartments = xdocDepartments.CreateNode(XmlNodeType.Element, "departments", xdocDepartments.NamespaceURI); xdocDepartments.AppendChild(xnodeDepartments); foreach (Lookup activeDepartment in activeDepartments) { XmlNode xnodeDepartment = xdocDepartments.CreateNode(XmlNodeType.Element, "department", xdocDepartments.NamespaceURI); XmlAttribute xattr = xdocDepartments.CreateAttribute("", "guid", xdocDepartments.NamespaceURI); xattr.Value = activeDepartment.Guid.ToString(); xnodeDepartment.Attributes.Append(xattr); xattr = xdocDepartments.CreateAttribute("", "name", xdocDepartments.NamespaceURI); xattr.Value = activeDepartment.Value; xnodeDepartment.Attributes.Append(xattr); XmlNode xnodeDeptDescription = xdocDepartments.CreateNode(XmlNodeType.Element, "description", xdocDepartments.NamespaceURI); xnodeDeptDescription.InnerText = activeDepartment.Qualifier8; xnodeDepartment.AppendChild(xnodeDeptDescription); xnodeDepartments.AppendChild(xnodeDepartment); } try { xdocDepartments.Save(Path.Combine(staffFolder.FullName, "departments.xml")); } catch (System.Exception ex) { sbMessages.AppendFormat("Could not save {0} file: {1}\n", Path.Combine(staffFolder.FullName, "departments.xml"), ex.Message); } } return(sbMessages.ToString()); }