private void ReactToChangedMember(string changedMember, object oldValue, ElementSave parentElement, InstanceSave instance) { ReactIfChangedMemberIsName(parentElement, instance, changedMember, oldValue); ReactIfChangedMemberIsBaseType(parentElement, changedMember, oldValue); ReactIfChangedMemberIsFont(parentElement, changedMember, oldValue); ReactIfChangedMemberIsCustomFont(parentElement, changedMember, oldValue); ReactIfChangedMemberIsUnitType(parentElement, changedMember, oldValue); ReactIfChangedMemberIsTexture(parentElement, changedMember, oldValue); ReactIfChangedMemberIsTextureAddress(parentElement, changedMember, oldValue); ReactIfChangedMemberIsParent(parentElement, changedMember, oldValue); PluginManager.Self.VariableSet(parentElement, instance, changedMember, oldValue); }
public ElementSave GetElementSave(InstanceSave instance) { return(GetElementSave(instance.BaseType)); }
public void CallInstanceRename(InstanceSave instanceSave, string oldName) { InstanceRename?.Invoke(instanceSave, oldName); }
public object GetValue(string variableName) { ////////////////////Early Out//////////////// if (ParentContainer == null) { return(null); } //////////////////End Early Out////////////// // Check for reserved stuff if (variableName == "Name") { return(ParentContainer.Name); } else if (variableName == "Base Type") { if (string.IsNullOrEmpty(ParentContainer.BaseType)) { return(null); } else { string baseType = ParentContainer.BaseType; StandardElementTypes returnValue; if (Enum.TryParse <StandardElementTypes>(baseType, out returnValue)) { return(returnValue); } else { return(baseType); } } } if (ToolsUtilities.StringFunctions.ContainsNoAlloc(variableName, '.')) { string instanceName = variableName.Substring(0, variableName.IndexOf('.')); ElementSave elementSave = ParentContainer; InstanceSave instanceSave = null; if (elementSave != null) { instanceSave = elementSave.GetInstance(instanceName); } if (instanceSave != null) { // This is a variable on an instance if (variableName.EndsWith(".Name")) { return(instanceSave.Name); } else if (variableName.EndsWith(".Base Type")) { return(instanceSave.BaseType); } else if (variableName.EndsWith(".Locked")) { return(instanceSave.Locked); } } } VariableSave variableState = GetVariableSave(variableName); // If the user hasn't set this variable on this state, it'll be null. So let's just display null // for now. Eventually we'll display a variable plus some kind of indication that it's an unset variable. if (variableState == null || variableState.SetsValue == false) { VariableListSave variableListSave = GetVariableListSave(variableName); if (variableListSave != null) { return(variableListSave.ValueAsIList); } else { return(null); } } else { return(variableState.Value); } }
void HandleCalendarGetCalendar(CalendarGetCalendar calendarGetCalendar) { ObjectGuid guid = GetPlayer().GetGUID(); long currTime = Time.UnixTime; CalendarSendCalendar packet = new CalendarSendCalendar(); packet.ServerTime = currTime; var invites = Global.CalendarMgr.GetPlayerInvites(guid); foreach (var invite in invites) { CalendarSendCalendarInviteInfo inviteInfo = new CalendarSendCalendarInviteInfo(); inviteInfo.EventID = invite.EventId; inviteInfo.InviteID = invite.InviteId; inviteInfo.InviterGuid = invite.SenderGuid; inviteInfo.Status = invite.Status; inviteInfo.Moderator = invite.Rank; CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(invite.EventId); if (calendarEvent != null) { inviteInfo.InviteType = (byte)(calendarEvent.IsGuildEvent() && calendarEvent.GuildId == _player.GetGuildId() ? 1 : 0); } packet.Invites.Add(inviteInfo); } var playerEvents = Global.CalendarMgr.GetPlayerEvents(guid); foreach (var calendarEvent in playerEvents) { CalendarSendCalendarEventInfo eventInfo; eventInfo.EventID = calendarEvent.EventId; eventInfo.Date = calendarEvent.Date; eventInfo.EventClubID = calendarEvent.GuildId; eventInfo.EventName = calendarEvent.Title; eventInfo.EventType = calendarEvent.EventType; eventInfo.Flags = calendarEvent.Flags; eventInfo.OwnerGuid = calendarEvent.OwnerGuid; eventInfo.TextureID = calendarEvent.TextureId; packet.Events.Add(eventInfo); } for (Difficulty i = 0; i < Difficulty.Max; ++i) { var boundInstances = _player.GetBoundInstances(i); if (boundInstances != null) { foreach (var boundInstance in boundInstances.Values) { if (boundInstance.perm) { CalendarSendCalendarRaidLockoutInfo lockoutInfo; InstanceSave save = boundInstance.save; lockoutInfo.MapID = (int)save.GetMapId(); lockoutInfo.DifficultyID = (uint)save.GetDifficultyID(); lockoutInfo.ExpireTime = save.GetResetTime() - currTime; lockoutInfo.InstanceID = save.GetInstanceId(); // instance save id as unique instance copy id packet.RaidLockouts.Add(lockoutInfo); } } } } SendPacket(packet); }
private float ModifyVariable(string baseVariableName, float modificationAmount, InstanceSave instanceSave) { string nameWithInstance; object currentValueAsObject; GetCurrentValueForVariable(baseVariableName, instanceSave, out nameWithInstance, out currentValueAsObject); float currentValue = (float)currentValueAsObject; string unitsVariableName = baseVariableName + " Units"; string unitsNameWithInstance; object unitsVariableAsObject; GetCurrentValueForVariable(unitsVariableName, instanceSave, out unitsNameWithInstance, out unitsVariableAsObject); currentValue = AdjustCurrentValueIfScale(currentValue, baseVariableName, unitsVariableAsObject); modificationAmount = AdjustAmountAccordingToUnitType(baseVariableName, modificationAmount, unitsVariableAsObject); float newValue = currentValue + modificationAmount; SelectedState.Self.SelectedStateSave.SetValue(nameWithInstance, newValue, instanceSave, "float"); return(newValue); }
private List <MemberCategory> GetMemberCategories(ElementSave element, StateSave state, StateSaveCategory stateCategory, InstanceSave instance) { List <MemberCategory> categories = new List <MemberCategory>(); mLastElement = element; mLastState = state; mLastInstance = instance; mLastCategory = stateCategory; var stateSave = SelectedState.Self.SelectedStateSave; if (stateSave != null) { GetMemberCategoriesForState(element, instance, categories, stateSave, stateCategory); } else if (stateCategory != null) { GetMemberCategoriesForStateCategory(element, instance, categories, stateCategory); } return(categories); }
private void AddAndRemoveScreensComponentsAndStandards(TreeNode folderTreeNode) { if (ProjectManager.Self.GumProjectSave == null) { return; } // Save off old selected stuff InstanceSave selectedInstance = SelectedState.Self.SelectedInstance; ElementSave selectedElement = SelectedState.Self.SelectedElement; BehaviorSave selectedBehavior = SelectedState.Self.SelectedBehavior; if (!string.IsNullOrEmpty(ProjectManager.Self.GumProjectSave.FullFileName)) { string currentDirectory = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName); if (folderTreeNode != null) { currentDirectory = folderTreeNode.GetFullFilePath(); } } #region Add nodes that haven't been added yet foreach (ScreenSave screenSave in ProjectManager.Self.GumProjectSave.Screens) { if (GetTreeNodeFor(screenSave) == null) { string fullPath = FileLocations.Self.ScreensFolder + FileManager.GetDirectory(screenSave.Name); TreeNode parentNode = GetTreeNodeFor(fullPath); AddTreeNodeForElement(screenSave, parentNode, ScreenImageIndex); } } foreach (ComponentSave componentSave in ProjectManager.Self.GumProjectSave.Components) { if (GetTreeNodeFor(componentSave) == null) { string fullPath = FileLocations.Self.ComponentsFolder + FileManager.GetDirectory(componentSave.Name); TreeNode parentNode = GetTreeNodeFor(fullPath); if (parentNode == null) { throw new Exception($"Error trying to get parent node for component {fullPath}"); } AddTreeNodeForElement(componentSave, parentNode, ComponentImageIndex); } } foreach (StandardElementSave standardSave in ProjectManager.Self.GumProjectSave.StandardElements) { if (standardSave.Name != "Component") { if (GetTreeNodeFor(standardSave) == null) { AddTreeNodeForElement(standardSave, mStandardElementsTreeNode, StandardElementImageIndex); } } } foreach (BehaviorSave behaviorSave in ProjectManager.Self.GumProjectSave.Behaviors) { if (GetTreeNodeFor(behaviorSave) == null) { string fullPath = FileLocations.Self.BehaviorsFolder + FileManager.GetDirectory(behaviorSave.Name); TreeNode parentNode = GetTreeNodeFor(fullPath); AddTreeNodeForBehavior(behaviorSave, parentNode, BehaviorImageIndex); } } #endregion #region Remove nodes that are no longer needed for (int i = mScreensTreeNode.Nodes.Count - 1; i > -1; i--) { ScreenSave screen = mScreensTreeNode.Nodes[i].Tag as ScreenSave; // If the screen is null, that means that it's a folder TreeNode, so we don't want to remove it if (screen != null) { if (!ProjectManager.Self.GumProjectSave.Screens.Contains(screen)) { mScreensTreeNode.Nodes.RemoveAt(i); } } } for (int i = mComponentsTreeNode.Nodes.Count - 1; i > -1; i--) { ComponentSave component = mComponentsTreeNode.Nodes[i].Tag as ComponentSave; // If the component is null, that means that it's a folder TreeNode, so we don't want to remove it if (component != null) { if (!ProjectManager.Self.GumProjectSave.Components.Contains(component)) { mComponentsTreeNode.Nodes.RemoveAt(i); } } } for (int i = mStandardElementsTreeNode.Nodes.Count - 1; i > -1; i--) { // Do we want to support folders here? StandardElementSave standardElement = mStandardElementsTreeNode.Nodes[i].Tag as StandardElementSave; if (!ProjectManager.Self.GumProjectSave.StandardElements.Contains(standardElement)) { mStandardElementsTreeNode.Nodes.RemoveAt(i); } } for (int i = mBehaviorsTreeNode.Nodes.Count - 1; i > -1; i--) { BehaviorSave behavior = mBehaviorsTreeNode.Nodes[i].Tag as BehaviorSave; if (behavior != null) { if (!ProjectManager.Self.GumProjectSave.Behaviors.Contains(behavior)) { mBehaviorsTreeNode.Nodes.RemoveAt(i); } } } #endregion #region Update the nodes foreach (TreeNode treeNode in mScreensTreeNode.Nodes) { RefreshUi(treeNode); } foreach (TreeNode treeNode in mComponentsTreeNode.Nodes) { RefreshUi(treeNode); } foreach (TreeNode treeNode in mStandardElementsTreeNode.Nodes) { RefreshUi(treeNode); } foreach (TreeNode treeNode in mBehaviorsTreeNode.Nodes) { RefreshUi(treeNode); } #endregion #region Sort everything mScreensTreeNode.Nodes.SortByName(recursive: true); mComponentsTreeNode.Nodes.SortByName(recursive: true); mStandardElementsTreeNode.Nodes.SortByName(recursive: true); mBehaviorsTreeNode.Nodes.SortByName(recursive: true); #endregion #region Re-select whatever was selected before if (selectedInstance != null) { SelectedState.Self.SelectedInstance = selectedInstance; } if (selectedBehavior != null) { SelectedState.Self.SelectedBehavior = selectedBehavior; } #endregion }
public void LoadGroups() { { uint oldMSTime = Time.GetMSTime(); // Delete all groups whose leader does not exist DB.Characters.DirectExecute("DELETE FROM groups WHERE leaderGuid NOT IN (SELECT guid FROM characters)"); // Delete all groups with less than 2 members DB.Characters.DirectExecute("DELETE FROM groups WHERE guid NOT IN (SELECT guid FROM group_member GROUP BY guid HAVING COUNT(guid) > 1)"); // 0 1 2 3 4 5 6 7 8 9 SQLResult result = DB.Characters.Query("SELECT g.leaderGuid, g.lootMethod, g.looterGuid, g.lootThreshold, g.icon1, g.icon2, g.icon3, g.icon4, g.icon5, g.icon6" + // 10 11 12 13 14 15 16 17 18 19 ", g.icon7, g.icon8, g.groupType, g.difficulty, g.raiddifficulty, g.legacyRaidDifficulty, g.masterLooterGuid, g.guid, lfg.dungeon, lfg.state FROM groups g LEFT JOIN lfg_data lfg ON lfg.guid = g.guid ORDER BY g.guid ASC"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 group definitions. DB table `groups` is empty!"); return; } uint count = 0; do { Group group = new(); group.LoadGroupFromDB(result.GetFields()); AddGroup(group); // Get the ID used for storing the group in the database and register it in the pool. uint storageId = group.GetDbStoreId(); RegisterGroupDbStoreId(storageId, group); // Increase the next available storage ID if (storageId == NextGroupDbStoreId) { NextGroupDbStoreId++; } ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} group definitions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } Log.outInfo(LogFilter.ServerLoading, "Loading Group members..."); { uint oldMSTime = Time.GetMSTime(); // Delete all rows from group_member or group_instance with no group DB.Characters.DirectExecute("DELETE FROM group_member WHERE guid NOT IN (SELECT guid FROM groups)"); DB.Characters.DirectExecute("DELETE FROM group_instance WHERE guid NOT IN (SELECT guid FROM groups)"); // Delete all members that does not exist DB.Characters.DirectExecute("DELETE FROM group_member WHERE memberGuid NOT IN (SELECT guid FROM characters)"); // 0 1 2 3 4 SQLResult result = DB.Characters.Query("SELECT guid, memberGuid, memberFlags, subgroup, roles FROM group_member ORDER BY guid"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 group members. DB table `group_member` is empty!"); return; } uint count = 0; do { Group group = GetGroupByDbStoreId(result.Read <uint>(0)); if (group) { group.LoadMemberFromDB(result.Read <uint>(1), result.Read <byte>(2), result.Read <byte>(3), (LfgRoles)result.Read <byte>(4)); } else { Log.outError(LogFilter.Server, "GroupMgr:LoadGroups: Consistency failed, can't find group (storage id: {0})", result.Read <uint>(0)); } ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} group members in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } Log.outInfo(LogFilter.ServerLoading, "Loading Group instance saves..."); { uint oldMSTime = Time.GetMSTime(); // 0 1 2 3 4 5 6 SQLResult result = DB.Characters.Query("SELECT gi.guid, i.map, gi.instance, gi.permanent, i.difficulty, i.resettime, i.entranceId, " + // 7 "(SELECT COUNT(1) FROM character_instance ci LEFT JOIN groups g ON ci.guid = g.leaderGuid WHERE ci.instance = gi.instance AND ci.permanent = 1 LIMIT 1) " + "FROM group_instance gi LEFT JOIN instance i ON gi.instance = i.id ORDER BY guid"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 group-instance saves. DB table `group_instance` is empty!"); return; } uint count = 0; do { Group group = GetGroupByDbStoreId(result.Read <uint>(0)); // group will never be NULL (we have run consistency sql's before loading) MapRecord mapEntry = CliDB.MapStorage.LookupByKey(result.Read <ushort>(1)); if (mapEntry == null || !mapEntry.IsDungeon()) { Log.outError(LogFilter.Sql, "Incorrect entry in group_instance table : no dungeon map {0}", result.Read <ushort>(1)); continue; } uint diff = result.Read <byte>(4); DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(diff); if (difficultyEntry == null || difficultyEntry.InstanceType != mapEntry.InstanceType) { continue; } InstanceSave save = Global.InstanceSaveMgr.AddInstanceSave(mapEntry.Id, result.Read <uint>(2), (Difficulty)diff, result.Read <long>(5), result.Read <uint>(6), result.Read <ulong>(7) == 0, true); group.BindToInstance(save, result.Read <bool>(3), true); ++count; }while (result.NextRow()); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} group-instance saves in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); } }
public EnterState PlayerCannotEnter(uint mapid, Player player, bool loginCheck = false) { MapRecord entry = CliDB.MapStorage.LookupByKey(mapid); if (entry == null) { return(EnterState.CannotEnterNoEntry); } if (!entry.IsDungeon()) { return(EnterState.CanEnter); } InstanceTemplate instance = Global.ObjectMgr.GetInstanceTemplate(mapid); if (instance == null) { return(EnterState.CannotEnterUninstancedDungeon); } Difficulty targetDifficulty = player.GetDifficultyID(entry); // Get the highest available difficulty if current setting is higher than the instance allows MapDifficultyRecord mapDiff = Global.DB2Mgr.GetDownscaledMapDifficultyData(entry.Id, ref targetDifficulty); if (mapDiff == null) { return(EnterState.CannotEnterDifficultyUnavailable); } //Bypass checks for GMs if (player.IsGameMaster()) { return(EnterState.CanEnter); } string mapName = entry.MapName[Global.WorldMgr.GetDefaultDbcLocale()]; Group group = player.GetGroup(); if (entry.IsRaid() && entry.Expansion() >= (Expansion)WorldConfig.GetIntValue(WorldCfg.Expansion)) // can only enter in a raid group but raids from old expansion don't need a group { if ((!group || !group.isRaidGroup()) && WorldConfig.GetBoolValue(WorldCfg.InstanceIgnoreRaid)) { return(EnterState.CannotEnterNotInRaid); } } if (!player.IsAlive()) { if (player.HasCorpse()) { // let enter in ghost mode in instance that connected to inner instance with corpse uint corpseMap = player.GetCorpseLocation().GetMapId(); do { if (corpseMap == mapid) { break; } InstanceTemplate corpseInstance = Global.ObjectMgr.GetInstanceTemplate(corpseMap); corpseMap = corpseInstance != null ? corpseInstance.Parent : 0; } while (corpseMap != 0); if (corpseMap == 0) { return(EnterState.CannotEnterCorpseInDifferentInstance); } Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' has corpse in instance '{1}' and can enter.", player.GetName(), mapName); } else { Log.outDebug(LogFilter.Maps, "Map.CanPlayerEnter - player '{0}' is dead but does not have a corpse!", player.GetName()); } } //Get instance where player's group is bound & its map if (!loginCheck && group) { InstanceBind boundInstance = group.GetBoundInstance(entry); if (boundInstance != null && boundInstance.save != null) { Map boundMap = FindMap(mapid, boundInstance.save.GetInstanceId()); if (boundMap != null) { EnterState denyReason = boundMap.CannotEnter(player); if (denyReason != 0) { return(denyReason); } } } } // players are only allowed to enter 10 instances per hour if (entry.IsDungeon() && (player.GetGroup() == null || (player.GetGroup() != null && !player.GetGroup().isLFGGroup()))) { uint instaceIdToCheck = 0; InstanceSave save = player.GetInstanceSave(mapid); if (save != null) { instaceIdToCheck = save.GetInstanceId(); } // instanceId can never be 0 - will not be found if (!player.CheckInstanceCount(instaceIdToCheck) && !player.IsDead()) { return(EnterState.CannotEnterTooManyInstances); } } //Other requirements if (player.Satisfy(Global.ObjectMgr.GetAccessRequirement(mapid, targetDifficulty), mapid, true)) { return(EnterState.CanEnter); } else { return(EnterState.CannotEnterUnspecifiedReason); } }
private static void RenameAllReferencesTo(ElementSave elementSave, InstanceSave instance, string oldName) { // Tell the GumProjectSave to react to the rename. // This changes the names of the ElementSave references. ProjectManager.Self.GumProjectSave.ReactToRenamed(elementSave, instance, oldName); if (instance == null) { foreach (var screen in ProjectState.Self.GumProjectSave.Screens) { bool shouldSave = false; foreach (var instanceInScreen in screen.Instances) { if (instanceInScreen.BaseType == oldName) { instanceInScreen.BaseType = elementSave.Name; shouldSave = true; } } foreach (var variable in screen.DefaultState.Variables.Where(item => item.GetRootName() == "Contained Type")) { if (variable.Value as string == oldName) { variable.Value = elementSave.Name; } } if (shouldSave) { GumCommands.Self.FileCommands.TryAutoSaveElement(screen); } } foreach (var component in ProjectState.Self.GumProjectSave.Components) { bool shouldSave = false; if (component.BaseType == oldName) { component.BaseType = elementSave.Name; shouldSave = true; } foreach (var instanceInScreen in component.Instances) { if (instanceInScreen.BaseType == oldName) { instanceInScreen.BaseType = elementSave.Name; shouldSave = true; } } foreach (var variable in component.DefaultState.Variables.Where(item => item.GetRootName() == "Contained Type")) { if (variable.Value as string == oldName) { variable.Value = elementSave.Name; } } if (shouldSave) { GumCommands.Self.FileCommands.TryAutoSaveElement(component); } } } if (instance != null) { string newName = SelectedState.Self.SelectedInstance.Name; foreach (StateSave stateSave in SelectedState.Self.SelectedElement.AllStates) { stateSave.ReactToInstanceNameChange(instance, oldName, newName); } foreach (var eventSave in SelectedState.Self.SelectedElement.Events) { if (eventSave.GetSourceObject() == oldName) { eventSave.Name = instance.Name + "." + eventSave.GetRootName(); } } } }
private void HandleInstanceAdd(ElementSave element, InstanceSave instance) { UpdateErrorsForElement(element); }
private void HandleVariableSet(ElementSave element, InstanceSave instance, string variableName, object oldValue) { UpdateErrorsForElement(element); }
private void PastedCopiedInstance(InstanceSave sourceInstance, ElementSave sourceElement, ElementSave targetElement, InstanceSave targetInstance, StateSave copiedState) { targetInstance.Name = StringFunctions.MakeStringUnique(targetInstance.Name, targetElement.Instances.Select(item => item.Name)); targetElement.Instances.Add(targetInstance); // We now have to copy over the states if (targetElement != sourceElement) { if (sourceElement.States.Count != 1) { MessageBox.Show("Only the default state variables will be copied since the source and target elements differ."); } StateSave stateSave = copiedState; // Why do we reverse loop here? for (int i = stateSave.Variables.Count - 1; i > -1; i--) { VariableSave sourceVariable = stateSave.Variables[i]; VariableSave copiedVariable = sourceVariable.Clone(); // Only copy over the variables that apply to the object that was dropped if (sourceVariable.SourceObject == sourceInstance.Name) { copiedVariable.Name = targetInstance.Name + "." + copiedVariable.GetRootName(); // We don't want to copy exposed variables. // If we did, the user would have 2 variables exposed with the same. copiedVariable.ExposedAsName = null; targetElement.DefaultState.Variables.Add(copiedVariable); } } for (int i = 0; i < stateSave.VariableLists.Count; i++) { var sourceVariableList = stateSave.VariableLists[i]; var copiedVariableList = sourceVariableList.Clone(); // Only copy over the variables that apply to the object that was dropped if (sourceVariableList.SourceObject == sourceInstance.Name) { copiedVariableList.Name = targetInstance.Name + "." + copiedVariableList.GetRootName(); copiedVariableList.SourceObject = targetInstance.Name; targetElement.DefaultState.VariableLists.Add(copiedVariableList); } } } else { StateSave stateSave = copiedState; for (int i = stateSave.Variables.Count - 1; i > -1; i--) { // We may have copied over a group of instances. If so // the copied state may have variables for multiple instances. // We only want to apply the variables that work for the selected // object. VariableSave sourceVariable = stateSave.Variables[i]; if (sourceVariable.SourceObject == sourceInstance.Name) { VariableSave copiedVariable = sourceVariable.Clone(); copiedVariable.Name = targetInstance.Name + "." + copiedVariable.GetRootName(); // We don't want to copy exposed variables. // If we did, the user would have 2 variables exposed with the same. copiedVariable.ExposedAsName = null; SelectedState.Self.SelectedStateSave.Variables.Add(copiedVariable); } } // Copy over the VariableLists too for (int i = stateSave.VariableLists.Count - 1; i > -1; i--) { VariableListSave sourceList = stateSave.VariableLists[i]; if (sourceList.SourceObject == sourceInstance.Name) { VariableListSave copiedList = sourceList.Clone(); copiedList.Name = targetInstance.Name + "." + copiedList.GetRootName(); copiedList.SourceObject = targetInstance.Name; SelectedState.Self.SelectedStateSave.VariableLists.Add(copiedList); } } } // This used to be done here when we paste, but now we're // going to remove it when the cut happens - just like text // editors. Undo will handle this if we mess up. // bool shouldSaveSource = false; //if (mIsCtrlXCut) //{ // if (sourceElement.Instances.Contains(sourceInstance)) // { // // Not sure why we weren't just using // // ElementCommands here - maybe an oversight? // // This should improve things like // //sourceElement.Instances.Remove(sourceInstance); // ElementCommands.Self.RemoveInstance(sourceInstance, sourceElement); // shouldSaveSource = true; // } //} targetInstance.ParentContainer = targetElement; // We need to call InstanceAdd before we select the new object - the Undo manager expects it // This includes before other managers refresh PluginManager.Self.InstanceAdd(targetElement, targetInstance); WireframeObjectManager.Self.RefreshAll(true); GumCommands.Self.GuiCommands.RefreshElementTreeView(targetElement); SelectedState.Self.SelectedInstance = targetInstance; GumCommands.Self.FileCommands.TryAutoSaveElement(targetElement); }
private void AdjustCursorChangeValuesForShiftDrag(ref float cursorXChange, ref float cursorYChange, InstanceSave instanceSave, List <ElementWithState> elementStack) { if (InputLibrary.Keyboard.Self.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) || InputLibrary.Keyboard.Self.KeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift)) { bool supportsShift = mSideGrabbed == ResizeSide.TopLeft || mSideGrabbed == ResizeSide.TopRight || mSideGrabbed == ResizeSide.BottomLeft || mSideGrabbed == ResizeSide.BottomRight; if (supportsShift && instanceSave != null) { IPositionedSizedObject ipso = WireframeObjectManager.Self.GetRepresentation(instanceSave, elementStack); Cursor cursor = Cursor.Self; float cursorX = cursor.GetWorldX(); float cursorY = cursor.GetWorldY(); float top = ipso.GetAbsoluteTop(); float bottom = ipso.GetAbsoluteBottom(); float left = ipso.GetAbsoluteLeft(); float right = ipso.GetAbsoluteRight(); float absoluteXDifference = 1; float absoluteYDifference = 1; switch (mSideGrabbed) { case ResizeSide.BottomRight: absoluteXDifference = System.Math.Abs(left - cursorX); absoluteYDifference = System.Math.Abs(top - cursorY); break; case ResizeSide.BottomLeft: absoluteXDifference = System.Math.Abs(right - cursorX); absoluteYDifference = System.Math.Abs(top - cursorY); break; case ResizeSide.TopLeft: absoluteXDifference = System.Math.Abs(right - cursorX); absoluteYDifference = System.Math.Abs(bottom - cursorY); break; case ResizeSide.TopRight: absoluteXDifference = System.Math.Abs(left - cursorX); absoluteYDifference = System.Math.Abs(bottom - cursorY); break; } float aspectRatio = absoluteXDifference / absoluteYDifference; if (aspectRatio > mAspectRatioOnGrab) { float yToUse = 0; // We use the X, but adjust the Y switch (mSideGrabbed) { case ResizeSide.BottomRight: cursorXChange = cursorX - right; yToUse = top + absoluteXDifference / mAspectRatioOnGrab; cursorYChange = yToUse - bottom; break; case ResizeSide.BottomLeft: cursorXChange = cursorX - left; yToUse = top + absoluteXDifference / mAspectRatioOnGrab; cursorYChange = yToUse - bottom; break; case ResizeSide.TopRight: cursorXChange = cursorX - right; yToUse = bottom - absoluteXDifference / mAspectRatioOnGrab; cursorYChange = yToUse - top; break; case ResizeSide.TopLeft: cursorXChange = cursorX - left; yToUse = bottom - absoluteXDifference / mAspectRatioOnGrab; cursorYChange = yToUse - top; break; } } else { float xToUse; // We use the Y, but adjust the X switch (mSideGrabbed) { case ResizeSide.BottomRight: cursorYChange = cursorY - bottom; xToUse = left + absoluteYDifference * mAspectRatioOnGrab; cursorXChange = xToUse - right; break; case ResizeSide.BottomLeft: cursorYChange = cursorY - bottom; xToUse = right - absoluteYDifference * mAspectRatioOnGrab; cursorXChange = xToUse - left; break; case ResizeSide.TopRight: cursorYChange = cursorY - top; xToUse = left + absoluteYDifference * mAspectRatioOnGrab; cursorXChange = xToUse - right; break; case ResizeSide.TopLeft: cursorYChange = cursorY - top; xToUse = right - absoluteYDifference * mAspectRatioOnGrab; cursorXChange = xToUse - left; break; } } } } }
void HandleAreaTrigger(AreaTriggerPkt packet) { Player player = GetPlayer(); if (player.IsInFlight()) { Log.outDebug(LogFilter.Network, "HandleAreaTriggerOpcode: Player '{0}' (GUID: {1}) in flight, ignore Area Trigger ID:{2}", player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID); return; } AreaTriggerRecord atEntry = CliDB.AreaTriggerStorage.LookupByKey(packet.AreaTriggerID); if (atEntry == null) { Log.outDebug(LogFilter.Network, "HandleAreaTriggerOpcode: Player '{0}' (GUID: {1}) send unknown (by DBC) Area Trigger ID:{2}", player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID); return; } if (packet.Entered && !player.IsInAreaTriggerRadius(atEntry)) { Log.outDebug(LogFilter.Network, "HandleAreaTriggerOpcode: Player '{0}' ({1}) too far, ignore Area Trigger ID: {2}", player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID); return; } if (player.isDebugAreaTriggers) { player.SendSysMessage(packet.Entered ? CypherStrings.DebugAreatriggerEntered : CypherStrings.DebugAreatriggerLeft, packet.AreaTriggerID); } if (Global.ScriptMgr.OnAreaTrigger(player, atEntry, packet.Entered)) { return; } if (player.IsAlive()) { List <uint> quests = Global.ObjectMgr.GetQuestsForAreaTrigger(packet.AreaTriggerID); if (quests != null) { foreach (uint questId in quests) { Quest qInfo = Global.ObjectMgr.GetQuestTemplate(questId); if (qInfo != null && player.GetQuestStatus(questId) == QuestStatus.Incomplete) { foreach (QuestObjective obj in qInfo.Objectives) { if (obj.Type == QuestObjectiveType.AreaTrigger && !player.IsQuestObjectiveComplete(obj)) { player.SetQuestObjectiveData(obj, 1); player.SendQuestUpdateAddCreditSimple(obj); break; } } if (player.CanCompleteQuest(questId)) { player.CompleteQuest(questId); } } } } } if (Global.ObjectMgr.IsTavernAreaTrigger(packet.AreaTriggerID)) { // set resting flag we are in the inn player.GetRestMgr().SetRestFlag(RestFlag.Tavern, atEntry.Id); if (Global.WorldMgr.IsFFAPvPRealm()) { player.RemoveByteFlag(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag, UnitBytes2Flags.FFAPvp); } return; } Battleground bg = player.GetBattleground(); if (bg) { bg.HandleAreaTrigger(player, packet.AreaTriggerID, packet.Entered); } OutdoorPvP pvp = player.GetOutdoorPvP(); if (pvp != null) { if (pvp.HandleAreaTrigger(player, packet.AreaTriggerID, packet.Entered)) { return; } } AreaTriggerStruct at = Global.ObjectMgr.GetAreaTrigger(packet.AreaTriggerID); if (at == null) { return; } bool teleported = false; if (player.GetMapId() != at.target_mapId) { EnterState denyReason = Global.MapMgr.PlayerCannotEnter(at.target_mapId, player, false); if (denyReason != 0) { bool reviveAtTrigger = false; // should we revive the player if he is trying to enter the correct instance? switch (denyReason) { case EnterState.CannotEnterNoEntry: Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' attempted to enter map with id {1} which has no entry", player.GetName(), at.target_mapId); break; case EnterState.CannotEnterUninstancedDungeon: Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' attempted to enter dungeon map {1} but no instance template was found", player.GetName(), at.target_mapId); break; case EnterState.CannotEnterDifficultyUnavailable: { Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' attempted to enter instance map {1} but the requested difficulty was not found", player.GetName(), at.target_mapId); MapRecord entry = CliDB.MapStorage.LookupByKey(at.target_mapId); if (entry != null) { player.SendTransferAborted(entry.Id, TransferAbortReason.Difficulty, (byte)player.GetDifficultyID(entry)); } } break; case EnterState.CannotEnterNotInRaid: Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' must be in a raid group to enter map {1}", player.GetName(), at.target_mapId); player.SendRaidGroupOnlyMessage(RaidGroupReason.Only, 0); reviveAtTrigger = true; break; case EnterState.CannotEnterCorpseInDifferentInstance: player.SendPacket(new AreaTriggerNoCorpse()); Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' does not have a corpse in instance map {1} and cannot enter", player.GetName(), at.target_mapId); break; case EnterState.CannotEnterInstanceBindMismatch: { MapRecord entry = CliDB.MapStorage.LookupByKey(at.target_mapId); if (entry != null) { string mapName = entry.MapName[player.GetSession().GetSessionDbcLocale()]; Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' cannot enter instance map '{1}' because their permanent bind is incompatible with their group's", player.GetName(), mapName); // is there a special opcode for this? // @todo figure out how to get player localized difficulty string (e.g. "10 player", "Heroic" etc) player.SendSysMessage(CypherStrings.InstanceBindMismatch, mapName); } reviveAtTrigger = true; } break; case EnterState.CannotEnterTooManyInstances: player.SendTransferAborted(at.target_mapId, TransferAbortReason.TooManyInstances); Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' cannot enter instance map {1} because he has exceeded the maximum number of instances per hour.", player.GetName(), at.target_mapId); reviveAtTrigger = true; break; case EnterState.CannotEnterMaxPlayers: player.SendTransferAborted(at.target_mapId, TransferAbortReason.MaxPlayers); reviveAtTrigger = true; break; case EnterState.CannotEnterZoneInCombat: player.SendTransferAborted(at.target_mapId, TransferAbortReason.ZoneInCombat); reviveAtTrigger = true; break; default: break; } if (reviveAtTrigger) // check if the player is touching the areatrigger leading to the map his corpse is on { if (!player.IsAlive() && player.HasCorpse()) { if (player.GetCorpseLocation().GetMapId() == at.target_mapId) { player.ResurrectPlayer(0.5f); player.SpawnCorpseBones(); } } } return; } Group group = player.GetGroup(); if (group) { if (group.isLFGGroup() && player.GetMap().IsDungeon()) { teleported = player.TeleportToBGEntryPoint(); } } } if (!teleported) { WorldSafeLocsRecord entranceLocation = null; InstanceSave instanceSave = player.GetInstanceSave(at.target_mapId); if (instanceSave != null) { // Check if we can contact the instancescript of the instance for an updated entrance location Map map = Global.MapMgr.FindMap(at.target_mapId, player.GetInstanceSave(at.target_mapId).GetInstanceId()); if (map) { InstanceMap instanceMap = map.ToInstanceMap(); if (instanceMap != null) { InstanceScript instanceScript = instanceMap.GetInstanceScript(); if (instanceScript != null) { entranceLocation = CliDB.WorldSafeLocsStorage.LookupByKey(instanceScript.GetEntranceLocation()); } } } // Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript if (entranceLocation == null) { entranceLocation = CliDB.WorldSafeLocsStorage.LookupByKey(instanceSave.GetEntranceLocation()); } } if (entranceLocation != null) { player.TeleportTo(entranceLocation.MapID, entranceLocation.Loc.X, entranceLocation.Loc.Y, entranceLocation.Loc.Z, (float)(entranceLocation.Facing * Math.PI / 180), TeleportToOptions.NotLeaveTransport); } else { player.TeleportTo(at.target_mapId, at.target_X, at.target_Y, at.target_Z, at.target_Orientation, TeleportToOptions.NotLeaveTransport); } } }
private void CalculateMultipliers(InstanceSave instanceSave, List <ElementWithState> elementStack, out float changeXMultiplier, out float changeYMultiplier, out float widthMultiplier, out float heightMultiplier) { changeXMultiplier = 0; changeYMultiplier = 0; widthMultiplier = 0; heightMultiplier = 0; IPositionedSizedObject ipso = WireframeObjectManager.Self.GetRepresentation(instanceSave, elementStack); if (ipso == null) { ipso = WireframeObjectManager.Self.GetRepresentation(SelectedState.Self.SelectedElement); } switch (this.mSideGrabbed) { case ResizeSide.TopLeft: changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso); widthMultiplier = -1; changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso); heightMultiplier = -1; break; case ResizeSide.Top: changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso); heightMultiplier = -1; break; case ResizeSide.TopRight: changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso); widthMultiplier = 1; changeYMultiplier = GetYMultiplierForTop(instanceSave, ipso); heightMultiplier = -1; break; case ResizeSide.Right: changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso); widthMultiplier = 1; break; case ResizeSide.BottomRight: changeXMultiplier = GetXMultiplierForRight(instanceSave, ipso); changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso); widthMultiplier = 1; heightMultiplier = 1; break; case ResizeSide.Bottom: heightMultiplier = 1; changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso); break; case ResizeSide.BottomLeft: changeYMultiplier = GetYMultiplierForBottom(instanceSave, ipso); changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso); widthMultiplier = -1; heightMultiplier = 1; break; case ResizeSide.Left: changeXMultiplier = GetXMultiplierForLeft(instanceSave, ipso); widthMultiplier = -1; break; } if (SelectionManager.Self.ResizeHandles.Width != 0) { widthMultiplier *= (ipso.Width / SelectionManager.Self.ResizeHandles.Width); } if (SelectionManager.Self.ResizeHandles.Height != 0) { heightMultiplier *= (ipso.Height / SelectionManager.Self.ResizeHandles.Height); } }
public InstanceSave GetInstance(IRenderableIpso representation, ElementSave instanceContainer, string prefix, InstanceFetchType fetchType, List <ElementWithState> elementStack) { if (instanceContainer == null) { return(null); } InstanceSave toReturn = null; string qualifiedName = representation.GetAttachmentQualifiedName(elementStack); // strip off the guide name if it starts with a guide qualifiedName = StripGuideOrParentNameIfNecessaryName(qualifiedName, representation); foreach (InstanceSave instanceSave in instanceContainer.Instances) { if (prefix + instanceSave.Name == qualifiedName) { toReturn = instanceSave; break; } } if (toReturn == null) { foreach (InstanceSave instanceSave in instanceContainer.Instances) { ElementSave instanceElement = instanceSave.GetBaseElementSave(); bool alreadyInStack = elementStack.Any(item => item.Element == instanceElement); if (!alreadyInStack) { var elementWithState = new ElementWithState(instanceElement); elementStack.Add(elementWithState); toReturn = GetInstance(representation, instanceElement, prefix + instanceSave.Name + ".", fetchType, elementStack); if (toReturn != null) { if (fetchType == InstanceFetchType.DeepInstance) { // toReturn will be toReturn, no need to do anything } else // fetchType == InstanceInCurrentElement { toReturn = instanceSave; } break; } elementStack.Remove(elementWithState); } } } return(toReturn); }
/// <summary> /// Refreshes the property grid for the argument element, state, and instance. This will only refresh the grid /// if the element, state, or instance values have changed since the last time this function was called, or if /// force is true. /// </summary> /// <param name="element">The element to display. The properties on this element may not be displayed if the instance is not null.</param> /// <param name="state">The state to display.</param> /// <param name="instance">The instance to display. May be null.</param> /// <param name="force">Whether to refresh even if the element, state, and instance have not changed.</param> private void RefreshDataGrid(ElementSave element, StateSave state, StateSaveCategory category, InstanceSave instance, BehaviorSave behaviorSave, bool force = false) { bool hasChangedObjectShowing = element != mLastElement || instance != mLastInstance || state != mLastState || category != mLastCategory || force; if (hasChangedObjectShowing) { List <MemberCategory> categories = GetMemberCategories(element, state, category, instance); Application.DoEvents(); SimultaneousCalls++; lock (lockObject) { if (SimultaneousCalls > 1) { SimultaneousCalls--; return; } records.Add("in"); mVariablesDataGrid.Instance = SelectedState.Self.SelectedStateSave; mVariablesDataGrid.Visibility = System.Windows.Visibility.Hidden; mVariablesDataGrid.Categories.Clear(); // There's a bug here where drag+dropping a new instance will create // duplicate UI members. I am going to deal with it now because it is foreach (var memberCategory in categories) { // We used to do this: // Application.DoEvents(); // That made things go faster, // but it made the "lock" not work, which could make duplicate UI show up. mVariablesDataGrid.Categories.Add(memberCategory); if (SimultaneousCalls > 1) { SimultaneousCalls--; // EARLY OUT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! return; } } } SimultaneousCalls--; Application.DoEvents(); mVariablesDataGrid.Visibility = System.Windows.Visibility.Visible; } else { // let's see if any variables have been added/removed var categories = GetMemberCategories(element, state, category, instance); foreach (var newCategory in categories) { // let's see if any variables have changed var oldCategory = mVariablesDataGrid.Categories.FirstOrDefault(item => item.Name == newCategory.Name); if (oldCategory != null && DoCategoriesDiffer(oldCategory.Members, newCategory.Members)) { int index = mVariablesDataGrid.Categories.IndexOf(oldCategory); mVariablesDataGrid.Categories.RemoveAt(index); mVariablesDataGrid.Categories.Insert(index, newCategory); } } } RefreshErrors(element); RefreshBehaviorUi(behaviorSave); mVariablesDataGrid.Refresh(); }
private GraphicalUiElement CreateRepresentationForInstance(InstanceSave instance, InstanceSave parentInstance, List <ElementWithState> elementStack, GraphicalUiElement container) { IPositionedSizedObject newIpso = null; GraphicalUiElement graphicalElement = newIpso as GraphicalUiElement; var baseElement = ObjectFinder.Self.GetElementSave(instance.BaseType); string type = instance.BaseType; if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle") { graphicalElement = new GraphicalUiElement(null, container); ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType); graphicalElement.CreateGraphicalComponent(instanceBase, null); graphicalElement.Tag = instance; graphicalElement.Component.Name = instance.Name; graphicalElement.Component.Tag = instance; if (type == "Text") { (graphicalElement.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines; } } else if (instance.IsComponent()) { newIpso = CreateRepresentationsForInstanceFromComponent(instance, elementStack, parentInstance, container, ObjectFinder.Self.GetComponent(instance.BaseType)); } else { // Make sure the base type is valid. // This could be null if a base type changed // its name but the derived wasn't updated, or // if someone screwed with the XML files. Who knows... if (baseElement != null) { graphicalElement = new GraphicalUiElement(null, container); CreateRectangleFor(instance, elementStack, graphicalElement); } } if (newIpso != null && (newIpso is GraphicalUiElement) == false) { graphicalElement = new GraphicalUiElement(newIpso as IRenderable, container); } else if (newIpso is GraphicalUiElement) { graphicalElement = newIpso as GraphicalUiElement; } if (graphicalElement != null) { if (baseElement != null) { graphicalElement.ElementSave = baseElement; foreach (var exposedVariable in baseElement.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName))) { graphicalElement.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name); } } var selectedState = SelectedState.Self.SelectedStateSave; if (selectedState == null) { selectedState = SelectedState.Self.SelectedElement.DefaultState; } RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState); string guide = rvf.GetValue <string>("Guide"); string parent = rvf.GetValue <string>(instance.Name + ".Parent"); SetGuideParent(container, graphicalElement, guide, container == null || parent == AvailableInstancesConverter.ScreenBoundsName); } if (baseElement != null) { graphicalElement.SetStatesAndCategoriesRecursively(baseElement); graphicalElement.SetVariablesRecursively(baseElement, baseElement.DefaultState); } return(graphicalElement); }
// Reset all solo instances and optionally send a message on success for each public void ResetInstances(InstanceResetMethod method, bool isRaid, bool isLegacy) { // method can be INSTANCE_RESET_ALL, INSTANCE_RESET_CHANGE_DIFFICULTY, INSTANCE_RESET_GROUP_JOIN // we assume that when the difficulty changes, all instances that can be reset will be Difficulty difficulty = GetDungeonDifficultyID(); if (isRaid) { if (!isLegacy) { difficulty = GetRaidDifficultyID(); } else { difficulty = GetLegacyRaidDifficultyID(); } } var difficultyDic = m_boundInstances.LookupByKey(difficulty); if (difficultyDic == null) { return; } foreach (var pair in difficultyDic) { InstanceSave p = pair.Value.save; MapRecord entry = CliDB.MapStorage.LookupByKey(difficulty); if (entry == null || entry.IsRaid() != isRaid || !p.CanReset()) { continue; } if (method == InstanceResetMethod.All) { // the "reset all instances" method can only reset normal maps if (entry.InstanceType == MapTypes.Raid || difficulty == Difficulty.Heroic) { continue; } } // if the map is loaded, reset it Map map = Global.MapMgr.FindMap(p.GetMapId(), p.GetInstanceId()); if (map != null && map.IsDungeon()) { if (!map.ToInstanceMap().Reset(method)) { continue; } } // since this is a solo instance there should not be any players inside if (method == InstanceResetMethod.All || method == InstanceResetMethod.ChangeDifficulty) { SendResetInstanceSuccess(p.GetMapId()); } p.DeleteFromDB(); difficultyDic.Remove(pair.Key); // the following should remove the instance save from the manager and delete it as well p.RemovePlayer(this); } }
private GraphicalUiElement CreateRepresentationsForInstanceFromComponent(InstanceSave instance, List <ElementWithState> elementStack, InstanceSave parentInstance, GraphicalUiElement parentIpso, ComponentSave baseComponentSave) { StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(instance); GraphicalUiElement rootIpso = null; if (ses != null) { rootIpso = new GraphicalUiElement(null, parentIpso); string type = ses.Name; if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle") { ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType); rootIpso.CreateGraphicalComponent(instanceBase, null); rootIpso.Tag = instance; rootIpso.Component.Name = instance.Name; rootIpso.Component.Tag = instance; if (type == "Text") { (rootIpso.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines; } } else { CreateRectangleFor(instance, elementStack, rootIpso); } var selectedState = SelectedState.Self.SelectedStateSave; if (selectedState == null) { selectedState = SelectedState.Self.SelectedElement.DefaultState; } RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState); string guide = rvf.GetValue <string>("Guide"); SetGuideParent(parentIpso, rootIpso, guide, false); ElementWithState elementWithState = new ElementWithState(baseComponentSave); var tempRvf = new DataTypes.RecursiveVariableFinder(instance, elementStack); var state = tempRvf.GetValue("State") as string; elementWithState.StateName = state; foreach (var category in baseComponentSave.Categories) { elementWithState.CategorizedStates.Add(category.Name, tempRvf.GetValue <string>(category.Name + "State")); } elementWithState.InstanceName = instance.Name; elementStack.Add(elementWithState); foreach (InstanceSave internalInstance in baseComponentSave.Instances) { GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso); } SetUpParentRelationship(rootIpso.ContainedElements, elementStack, baseComponentSave.Instances); elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == baseComponentSave)); } return(rootIpso); }
/// <summary> /// Perofrms a sequential, cumulative combination of all states along an animation. /// As an animation plays each state (keyframe) combines with the previous /// to create a combined state. As the animation continues, these combined states /// accumulate the changes of all states before them. Therefore, we need to pre-combine /// the keyframes so that when animations are played they can properly interpolate. /// /// </summary> public void RefreshCombinedStates(ElementSave element, bool useDefaultAsStarting = true) { StateSave previous = null; if (useDefaultAsStarting) { previous = element.DefaultState; } foreach (var animatedState in this.Keyframes.Where(item => !string.IsNullOrEmpty(item.StateName))) { var originalState = GetStateFromCategorizedName(animatedState.StateName, element); if (originalState != null) { if (previous == null) { previous = originalState; animatedState.CachedCumulativeState = originalState.Clone(); } else { var combined = previous.Clone(); combined.MergeIntoThis(originalState); combined.Name = originalState.Name; animatedState.CachedCumulativeState = combined; previous = combined; } } } foreach (var subAnimation in this.Keyframes.Where(item => !string.IsNullOrEmpty(item.AnimationName))) { InstanceSave instance = null; string name = subAnimation.AnimationName; if (name.Contains('.')) { int indexOfDot = name.IndexOf('.'); string instanceName = name.Substring(0, indexOfDot); instance = element.Instances.FirstOrDefault(item => item.Name == instanceName); } if (instance == null) { // Null check in case the referenced instance was removed subAnimation.SubAnimationViewModel?.RefreshCombinedStates(element, false); } else { var instanceElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instance); if (instanceElement != null) { subAnimation.SubAnimationViewModel.RefreshCombinedStates(instanceElement, false); } } } }
public static void PasteInstanceSaves(List <InstanceSave> instancesToCopy, StateSave copiedState, ElementSave targetElement) { Dictionary <string, string> oldNewNameDictionary = new Dictionary <string, string>(); List <InstanceSave> newInstances = new List <InstanceSave>(); foreach (var sourceInstance in instancesToCopy) { ElementSave sourceElement = sourceInstance.ParentContainer; InstanceSave newInstance = sourceInstance.Clone(); // the original may have been defined in a base component. The new instance will not be // derived in the base, so let's get rid of that: newInstance.DefinedByBase = false; newInstances.Add(newInstance); if (targetElement != null) { var oldName = newInstance.Name; newInstance.Name = StringFunctions.MakeStringUnique(newInstance.Name, targetElement.Instances.Select(item => item.Name)); var newName = newInstance.Name; oldNewNameDictionary[oldName] = newName; targetElement.Instances.Add(newInstance); } } foreach (var sourceInstance in instancesToCopy) { ElementSave sourceElement = sourceInstance.ParentContainer; var newInstance = newInstances.First(item => item.Name == oldNewNameDictionary[sourceInstance.Name]); if (targetElement != null) { StateSave stateSave = copiedState; StateSave targetState; // We now have to copy over the states if (targetElement != sourceElement) { if (sourceElement.States.Count != 1) { MessageBox.Show("Only the default state variables will be copied since the source and target elements differ."); } targetState = targetElement.DefaultState; } else { targetState = SelectedState.Self.SelectedStateSave; } // why reverse loop? for (int i = stateSave.Variables.Count - 1; i > -1; i--) { // We may have copied over a group of instances. If so // the copied state may have variables for multiple instances. // We only want to apply the variables that work for the selected // object. VariableSave sourceVariable = stateSave.Variables[i]; if (sourceVariable.SourceObject == sourceInstance.Name) { VariableSave copiedVariable = sourceVariable.Clone(); copiedVariable.Name = newInstance.Name + "." + copiedVariable.GetRootName(); var valueAsString = copiedVariable.Value as string; if (copiedVariable.GetRootName() == "Parent" && string.IsNullOrWhiteSpace(valueAsString) == false && oldNewNameDictionary.ContainsKey(valueAsString)) { // this is a parent and it may be attached to a copy, so update the value var newValue = oldNewNameDictionary[valueAsString]; copiedVariable.Value = newValue; } // We don't want to copy exposed variables. // If we did, the user would have 2 variables exposed with the same. copiedVariable.ExposedAsName = null; targetState.Variables.Add(copiedVariable); } } // Copy over the VariableLists too for (int i = stateSave.VariableLists.Count - 1; i > -1; i--) { VariableListSave sourceVariableList = stateSave.VariableLists[i]; if (sourceVariableList.SourceObject == sourceInstance.Name) { VariableListSave copiedList = sourceVariableList.Clone(); copiedList.Name = newInstance.Name + "." + copiedList.GetRootName(); targetState.VariableLists.Add(copiedList); } } // This used to be done here when we paste, but now we're // going to remove it when the cut happens - just like text // editors. Undo will handle this if we mess up. // bool shouldSaveSource = false; //if (mIsCtrlXCut) //{ // if (sourceElement.Instances.Contains(sourceInstance)) // { // // Not sure why we weren't just using // // ElementCommands here - maybe an oversight? // // This should improve things like // //sourceElement.Instances.Remove(sourceInstance); // ElementCommands.Self.RemoveInstance(sourceInstance, sourceElement); // shouldSaveSource = true; // } //} newInstance.ParentContainer = targetElement; // We need to call InstanceAdd before we select the new object - the Undo manager expects it // This includes before other managers refresh PluginManager.Self.InstanceAdd(targetElement, newInstance); } } WireframeObjectManager.Self.RefreshAll(true); GumCommands.Self.GuiCommands.RefreshElementTreeView(targetElement); GumCommands.Self.FileCommands.TryAutoSaveElement(targetElement); SelectedState.Self.SelectedInstances = newInstances; }
public StandardElementSave GetRootStandardElementSave(InstanceSave instanceSave) { return(GetRootStandardElementSave(instanceSave.GetBaseElementSave())); }
public void RefreshPositionsAndScalesForInstance(InstanceSave instance, List <ElementWithState> elementStack) { GraphicalUiElement ipso = WireframeObjectManager.Self.GetRepresentation(instance, elementStack); ipso.UpdateLayout(); }
public InstanceBind BindToInstance(InstanceSave save, bool permanent, BindExtensionState extendState = BindExtensionState.Normal, bool load = false) { if (save != null) { InstanceBind bind = new InstanceBind(); if (m_boundInstances[(int)save.GetDifficultyID()].ContainsKey(save.GetMapId())) { bind = m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()]; } if (extendState == BindExtensionState.Keep) // special flag, keep the player's current extend state when updating for new boss down { if (save == bind.save) { extendState = bind.extendState; } else { extendState = BindExtensionState.Normal; } } if (!load) { PreparedStatement stmt; if (bind.save != null) { // update the save when the group kills a boss if (permanent != bind.perm || save != bind.save || extendState != bind.extendState) { stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHAR_INSTANCE); stmt.AddValue(0, save.GetInstanceId()); stmt.AddValue(1, permanent); stmt.AddValue(2, extendState); stmt.AddValue(3, GetGUID().GetCounter()); stmt.AddValue(4, bind.save.GetInstanceId()); DB.Characters.Execute(stmt); } } else { stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHAR_INSTANCE); stmt.AddValue(0, GetGUID().GetCounter()); stmt.AddValue(1, save.GetInstanceId()); stmt.AddValue(2, permanent); stmt.AddValue(3, extendState); DB.Characters.Execute(stmt); } } if (bind.save != save) { if (bind.save != null) { bind.save.RemovePlayer(this); } save.AddPlayer(this); } if (permanent) { save.SetCanReset(false); } bind.save = save; bind.perm = permanent; bind.extendState = extendState; if (!load) { Log.outDebug(LogFilter.Maps, "Player.BindToInstance: Player '{0}' ({1}) is now bound to map (ID: {2}, Instance {3}, Difficulty {4})", GetName(), GetGUID().ToString(), save.GetMapId(), save.GetInstanceId(), save.GetDifficultyID()); } Global.ScriptMgr.OnPlayerBindToInstance(this, save.GetDifficultyID(), save.GetMapId(), permanent, extendState); m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()] = bind; return(bind); } return(null); }
private bool SideGrabbingActivityForInstanceSave(float cursorXChange, float cursorYChange, InstanceSave instanceSave, List <ElementWithState> elementStack) { float changeXMultiplier; float changeYMultiplier; float widthMultiplier; float heightMultiplier; CalculateMultipliers(instanceSave, elementStack, out changeXMultiplier, out changeYMultiplier, out widthMultiplier, out heightMultiplier); AdjustCursorChangeValuesForShiftDrag(ref cursorXChange, ref cursorYChange, instanceSave, elementStack); bool hasChangeOccurred = false; if (changeXMultiplier != 0 && cursorXChange != 0) { hasChangeOccurred = true; float value = ModifyVariable("X", cursorXChange * changeXMultiplier, instanceSave); } if (changeYMultiplier != 0 && cursorYChange != 0) { hasChangeOccurred = true; float value = ModifyVariable("Y", cursorYChange * changeYMultiplier, instanceSave); } if (heightMultiplier != 0 && cursorYChange != 0) { hasChangeOccurred = true; float value = ModifyVariable("Height", cursorYChange * heightMultiplier, instanceSave); } if (widthMultiplier != 0 && cursorXChange != 0) { hasChangeOccurred = true; float value = ModifyVariable("Width", cursorXChange * widthMultiplier, instanceSave); } return(hasChangeOccurred); }
public void CallInstanceReordered(InstanceSave instance) { InstanceReordered?.Invoke(instance); }
private void ReactIfChangedMemberIsUnitType(ElementSave parentElement, string changedMember, object oldValue) { StateSave stateSave = SelectedState.Self.SelectedStateSave; IPositionedSizedObject currentIpso = WireframeObjectManager.Self.GetSelectedRepresentation(); float parentWidth = ObjectFinder.Self.GumProjectSave.DefaultCanvasWidth; float parentHeight = ObjectFinder.Self.GumProjectSave.DefaultCanvasHeight; float fileWidth = 0; float fileHeight = 0; if (currentIpso != null) { currentIpso.GetFileWidthAndHeight(out fileWidth, out fileHeight); if (currentIpso.Parent != null) { parentWidth = currentIpso.Parent.Width; parentHeight = currentIpso.Parent.Height; } } float outX = 0; float outY = 0; float valueToSet = 0; string variableToSet = null; bool isWidthOrHeight = false; bool wasAnythingSet = false; if (changedMember == "X Units" || changedMember == "Y Units" || changedMember == "Width Units" || changedMember == "Height Units") { object unitType = EditingManager.GetCurrentValueForVariable(changedMember, SelectedState.Self.SelectedInstance); XOrY xOrY = XOrY.X; if (changedMember == "X Units") { variableToSet = "X"; xOrY = XOrY.X; } else if (changedMember == "Y Units") { variableToSet = "Y"; xOrY = XOrY.Y; } else if (changedMember == "Width Units") { variableToSet = "Width"; isWidthOrHeight = true; xOrY = XOrY.X; } else if (changedMember == "Height Units") { variableToSet = "Height"; isWidthOrHeight = true; xOrY = XOrY.Y; } float valueOnObject = 0; if (stateSave.TryGetValue <float>(GetQualifiedName(variableToSet), out valueOnObject)) { if (xOrY == XOrY.X) { UnitConverter.Self.ConvertToPixelCoordinates( valueOnObject, 0, oldValue, null, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out outY); UnitConverter.Self.ConvertToUnitTypeCoordinates( outX, outY, unitType, null, parentWidth, parentHeight, fileWidth, fileHeight, out valueToSet, out outY); } else { UnitConverter.Self.ConvertToPixelCoordinates( 0, valueOnObject, null, oldValue, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out outY); UnitConverter.Self.ConvertToUnitTypeCoordinates( outX, outY, null, unitType, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out valueToSet); } wasAnythingSet = true; } } if (wasAnythingSet) { InstanceSave instanceSave = SelectedState.Self.SelectedInstance; if (SelectedState.Self.SelectedInstance != null) { variableToSet = SelectedState.Self.SelectedInstance.Name + "." + variableToSet; } stateSave.SetValue(variableToSet, valueToSet, instanceSave); } }