/// <summary> /// Change Weak to Strong /// </summary> public bool MakeStrong() { if (StrongRef != null) { return(true); } T strong = null; WeakRef?.TryGetTarget(out strong); StrongRef = strong; WeakRef = null; return(StrongRef != null); }
void WeakEventHandlersShootTargets(Gun gun, List <string> collected, List <string> hit) { Target?bob = new Target("bob", collected, hit); gun.Firing += WeakRef.MakeWeak(bob.OnFiring, eh => gun.Firing -= eh); gun.Bang += WeakRef.MakeWeak <Gun>(bob.OnHit, eh => gun.Bang -= eh); gun.Fired += WeakRef.MakeWeak <Gun.FiredArgs>(bob.OnFired, eh => gun.Fired -= eh); gun.Shoot(); Assert.True(hit.Contains("Don't Shoot")); Assert.True(hit.Contains("bob")); Assert.True(hit.Contains("Bang!")); hit.Clear(); bob = null; }
void WeakActionsShootTargets(Gun gun, List <string> collected, List <string> hit) { Target?bob = new Target("bob", collected, hit); Target?fred = new Target("fred", collected, hit); gun.Bang += WeakRef.MakeWeak <Gun>(bob.OnHit, h => gun.Bang -= h); gun.Bang += fred.OnHit; gun.Shoot(); Assert.True(hit.Contains("bob")); Assert.True(hit.Contains("fred")); hit.Clear(); bob = null; fred = null; }
public MDReplicatedMember(MemberInfo Member, bool Reliable, MDReplicatedType ReplicatedType, WeakRef NodeRef, MDReplicatedSetting[] Settings) { MDLog.AddLogCategoryProperties(LOG_CAT, new MDLogProperties(MDLogLevel.Info)); GameSession = MDStatics.GetGameSession(); Replicator = GameSession.Replicator; GameClock = GameSession.GetGameClock(); GameSynchronizer = GameSession.GetGameSynchronizer(); this.Member = Member; this.Reliable = Reliable; this.ReplicatedType = ReplicatedType; this.NodeRef = NodeRef; ParseSettings(MDReplicator.ParseParameters(typeof(Settings), Settings)); CheckIfShouldReplicate(); }
void WeakEventPropChangedHandlersShootTargets(Gun gun, List <string> collected, List <string> hit, List <string> prop_change) { Target?bob = new Target("bob", collected, hit); bob.PropertyChanged += WeakRef.MakeWeak(HandlePropChanged, h => bob.PropertyChanged -= h); void HandlePropChanged(object sender, PropertyChangedEventArgs e) => prop_change.Add($"{bob?.Name} {e.PropertyName}"); gun.Bang += WeakRef.MakeWeak <Gun>(bob.OnHit, eh => gun.Bang -= eh); gun.Shoot(); Assert.True(hit.Contains("bob")); Assert.True(prop_change.Contains("bob Dead")); hit.Clear(); prop_change.Clear(); bob = null; }
static void Main(string[] args) { var i = "http://data.10jqka.com.cn/ifmarket/getnewlh/code/000000/date/2017-11-22/rid/7/".Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); ///扩展方法 Base1 b = new Base1(); b.Base1_Method2(); ///弱引用样例 WeakRef r = new WeakRef(); r.Run(); ///可选参数 可选参数 k = new 可选参数(); k.Run(); k.Run("顺序一致字符串", 6, 22.22f); k.Run(i: 9, f: 77.77f, str: "顺序不一致字符串"); ///匿名对象 匿名对象 n = new 匿名对象(); n.Run(); ///动态对象 动态对象 d = new 动态对象(); d.Run(); ///异步方法 异步方法 y = new 异步方法(); y.Run(); Console.ReadKey(); }
public MDReplicatedCommandReplicator(MemberInfo Member, bool Reliable, MDReplicatedType ReplicatedType, WeakRef NodeRef, MDReplicatedSetting[] Settings) : base(Member, true, ReplicatedType, NodeRef, Settings) { GameSession = MDStatics.GetGameSession(); Replicator = GameSession.Replicator; GameClock = GameSession.GetGameClock(); Node node = NodeRef.GetRef() as Node; IMDCommandReplicator CommandReplicator = InitializeCommandReplicator(Member, node); CommandReplicator.MDSetSettings(Settings); }
public void OnCommand(GameClient client, string[] args) { if (IsSpammingCommand(client.Player, "duel")) { return; } switch (client.Player.CurrentRegionID) { case 10: case 101: case 201: { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.SafeZone")); return; } } WeakRef weak = null; GamePlayer duelStarter = null; GamePlayer duelTarget = null; if (args.Length > 1) { switch (args[1].ToLower()) { case "challenge": { GamePlayer target = client.Player.TargetObject as GamePlayer; if (target == null || target == client.Player) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.NeedTarget"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } if (!CheckDuelStart(client.Player, target)) { return; } lock (client.Player.TempProperties) { weak = client.Player.TempProperties.getProperty <object>(CHALLENGE_TARGET_WEAK, null) as WeakRef; if (weak != null && (duelTarget = weak.Target as GamePlayer) != null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouAlreadyChallenging", duelTarget.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } weak = client.Player.TempProperties.getProperty <object>(DUEL_STARTER_WEAK, null) as WeakRef; if (weak != null && (duelStarter = weak.Target as GamePlayer) != null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouAlreadyConsidering", duelStarter.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } } lock (target.TempProperties) { if (target.TempProperties.getProperty <object>(DUEL_STARTER_WEAK, null) != null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.TargetAlreadyConsidering", target.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } if (target.TempProperties.getProperty <object>(CHALLENGE_TARGET_WEAK, null) != null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.TargetAlreadyChallenging", target.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } target.TempProperties.setProperty(DUEL_STARTER_WEAK, new WeakRef(client.Player)); } lock (client.Player.TempProperties) { client.Player.TempProperties.setProperty(CHALLENGE_TARGET_WEAK, new WeakRef(target)); } client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouChallenge", target.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); target.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.ChallengesYou", client.Player.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } case "accept": { lock (client.Player.TempProperties) { weak = client.Player.TempProperties.getProperty <object>(DUEL_STARTER_WEAK, null) as WeakRef; } if (weak == null || (duelStarter = weak.Target as GamePlayer) == null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.ConsideringDuel"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } if (!CheckDuelStart(client.Player, duelStarter)) { return; } client.Player.DuelStart(duelStarter); duelStarter.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.TargetAccept", client.Player.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); client.Player.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouAccept"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); lock (client.Player.TempProperties) { client.Player.TempProperties.removeProperty(DUEL_STARTER_WEAK); } lock (duelStarter.TempProperties) { duelStarter.TempProperties.removeProperty(CHALLENGE_TARGET_WEAK); } return; } case "decline": { lock (client.Player.TempProperties) { weak = client.Player.TempProperties.getProperty <object>(DUEL_STARTER_WEAK, null) as WeakRef; client.Player.TempProperties.removeProperty(DUEL_STARTER_WEAK); } if (weak == null || (duelStarter = weak.Target as GamePlayer) == null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.NotInDuel"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } lock (duelStarter.TempProperties) { duelStarter.TempProperties.removeProperty(CHALLENGE_TARGET_WEAK); } duelStarter.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.TargetDeclines", client.Player.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouDecline", duelStarter.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } case "cancel": { lock (client.Player.TempProperties) { weak = client.Player.TempProperties.getProperty <object>(CHALLENGE_TARGET_WEAK, null) as WeakRef; client.Player.TempProperties.removeProperty(CHALLENGE_TARGET_WEAK); } if (weak == null || (duelTarget = weak.Target as GamePlayer) == null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouHaventChallenged"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } lock (duelTarget.TempProperties) { duelTarget.TempProperties.removeProperty(DUEL_STARTER_WEAK); } duelTarget.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.TargetCancel", client.Player.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouCancel"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } case "surrender": { GamePlayer target = client.Player.DuelTarget; if (target == null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.NotInDuel"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); return; } client.Player.DuelStop(); client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.YouSurrender", target.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); target.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.TargetSurrender", client.Player.Name), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); Message.SystemToArea(client.Player, LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.PlayerVsPlayer", client.Player.Name, target.Name), eChatType.CT_Emote, client.Player, target); return; } } } client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Duel.DuelOptions"), eChatType.CT_Emote, eChatLoc.CL_SystemWindow); }
public override void EnablePlugin() { base.EnablePlugin(); if (Instance != null) { throw new InvalidOperationException(); } Instance = this; var editorInterface = GetEditorInterface(); var editorBaseControl = editorInterface.GetBaseControl(); editorSettings = editorInterface.GetEditorSettings(); errorDialog = new AcceptDialog(); editorBaseControl.AddChild(errorDialog); BottomPanel = new BottomPanel(); bottomPanelBtn = AddControlToBottomPanel(BottomPanel, "Mono".TTR()); AddChild(new HotReloadAssemblyWatcher { Name = "HotReloadAssemblyWatcher" }); menuPopup = new PopupMenu(); menuPopup.Hide(); AddToolSubmenuItem("Mono", menuPopup); // TODO: Remove or edit this info dialog once Mono support is no longer in alpha { menuPopup.AddItem("About C# support".TTR(), (int)MenuOptions.AboutCSharp); aboutDialog = new AcceptDialog(); editorBaseControl.AddChild(aboutDialog); aboutDialog.Title = "Important: C# support is not feature-complete"; // We don't use DialogText as the default AcceptDialog Label doesn't play well with the TextureRect and CheckBox // we'll add. Instead we add containers and a new autowrapped Label inside. // Main VBoxContainer (icon + label on top, checkbox at bottom) var aboutVBox = new VBoxContainer(); aboutDialog.AddChild(aboutVBox); // HBoxContainer for icon + label var aboutHBox = new HBoxContainer(); aboutVBox.AddChild(aboutHBox); var aboutIcon = new TextureRect(); aboutIcon.Texture = aboutIcon.GetThemeIcon("NodeWarning", "EditorIcons"); aboutHBox.AddChild(aboutIcon); var aboutLabel = new Label(); aboutHBox.AddChild(aboutLabel); aboutLabel.RectMinSize = new Vector2(600, 150) * EditorScale; aboutLabel.SizeFlagsVertical = (int)Control.SizeFlags.ExpandFill; aboutLabel.Autowrap = true; aboutLabel.Text = "C# support in Godot Engine is in late alpha stage and, while already usable, " + "it is not meant for use in production.\n\n" + "Projects can be exported to Linux, macOS, Windows, Android, iOS and HTML5, but not yet to UWP. " + "Bugs and usability issues will be addressed gradually over future releases, " + "potentially including compatibility breaking changes as new features are implemented for a better overall C# experience.\n\n" + "If you experience issues with this Mono build, please report them on Godot's issue tracker with details about your system, MSBuild version, IDE, etc.:\n\n" + " https://github.com/godotengine/godot/issues\n\n" + "Your critical feedback at this stage will play a great role in shaping the C# support in future releases, so thank you!"; EditorDef("mono/editor/show_info_on_start", true); // CheckBox in main container aboutDialogCheckBox = new CheckBox { Text = "Show this warning when starting the editor" }; aboutDialogCheckBox.Toggled += enabled => { bool showOnStart = (bool)editorSettings.GetSetting("mono/editor/show_info_on_start"); if (showOnStart != enabled) { editorSettings.SetSetting("mono/editor/show_info_on_start", enabled); } }; aboutVBox.AddChild(aboutDialogCheckBox); } if (File.Exists(GodotSharpDirs.ProjectSlnPath) && File.Exists(GodotSharpDirs.ProjectCsProjPath)) { try { // Migrate solution from old configuration names to: Debug, ExportDebug and ExportRelease DotNetSolution.MigrateFromOldConfigNames(GodotSharpDirs.ProjectSlnPath); var msbuildProject = ProjectUtils.Open(GodotSharpDirs.ProjectCsProjPath) ?? throw new Exception("Cannot open C# project"); // NOTE: The order in which changes are made to the project is important // Migrate csproj from old configuration names to: Debug, ExportDebug and ExportRelease ProjectUtils.MigrateFromOldConfigNames(msbuildProject); // Apply the other fixes only after configurations have been migrated // Make sure the existing project has the ProjectTypeGuids property (for VisualStudio) ProjectUtils.EnsureHasProjectTypeGuids(msbuildProject); // Make sure the existing project has Api assembly references configured correctly ProjectUtils.FixApiHintPath(msbuildProject); // Make sure the existing project references the Microsoft.NETFramework.ReferenceAssemblies nuget package ProjectUtils.EnsureHasNugetNetFrameworkRefAssemblies(msbuildProject); if (msbuildProject.HasUnsavedChanges) { // Save a copy of the project before replacing it FileUtils.SaveBackupCopy(GodotSharpDirs.ProjectCsProjPath); msbuildProject.Save(); } } catch (Exception e) { GD.PushError(e.ToString()); } } else { bottomPanelBtn.Hide(); menuPopup.AddItem("Create C# solution".TTR(), (int)MenuOptions.CreateSln); } menuPopup.IdPressed += _MenuOptionPressed; var buildButton = new Button { Text = "Build", HintTooltip = "Build solution", FocusMode = Control.FocusModeEnum.None }; buildButton.PressedSignal += _BuildSolutionPressed; AddControlToContainer(CustomControlContainer.Toolbar, buildButton); // External editor settings EditorDef("mono/editor/external_editor", ExternalEditorId.None); string settingsHintStr = "Disabled"; if (OS.IsWindows) { settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudio}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsOSX) { settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsUnixLike) { settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary { ["type"] = Variant.Type.Int, ["name"] = "mono/editor/external_editor", ["hint"] = PropertyHint.Enum, ["hint_string"] = settingsHintStr }); // Export plugin var exportPlugin = new ExportPlugin(); AddExportPlugin(exportPlugin); exportPlugin.RegisterExportSettings(); exportPluginWeak = WeakRef(exportPlugin); BuildManager.Initialize(); RiderPathManager.Initialize(); GodotIdeManager = new GodotIdeManager(); AddChild(GodotIdeManager); }
protected Pooled(IObjectPool pool) { _weakPool = new WeakRef <IObjectPool>(pool); }
public RewardResult(RawNode node, IContext context) { type = node.GetString("type"); _weakContext = new WeakRef <IContext>(context); }
public override void EnablePlugin() { base.EnablePlugin(); if (Instance != null) { throw new InvalidOperationException(); } Instance = this; var editorInterface = GetEditorInterface(); var editorBaseControl = editorInterface.GetBaseControl(); editorSettings = editorInterface.GetEditorSettings(); errorDialog = new AcceptDialog(); editorBaseControl.AddChild(errorDialog); BottomPanel = new BottomPanel(); bottomPanelBtn = AddControlToBottomPanel(BottomPanel, "Mono".TTR()); AddChild(new HotReloadAssemblyWatcher { Name = "HotReloadAssemblyWatcher" }); menuPopup = new PopupMenu(); menuPopup.Hide(); menuPopup.SetAsToplevel(true); AddToolSubmenuItem("Mono", menuPopup); // TODO: Remove or edit this info dialog once Mono support is no longer in alpha { menuPopup.AddItem("About C# support".TTR(), (int)MenuOptions.AboutCSharp); aboutDialog = new AcceptDialog(); editorBaseControl.AddChild(aboutDialog); aboutDialog.WindowTitle = "Important: C# support is not feature-complete"; // We don't use DialogText as the default AcceptDialog Label doesn't play well with the TextureRect and CheckBox // we'll add. Instead we add containers and a new autowrapped Label inside. // Main VBoxContainer (icon + label on top, checkbox at bottom) var aboutVBox = new VBoxContainer(); aboutDialog.AddChild(aboutVBox); // HBoxContainer for icon + label var aboutHBox = new HBoxContainer(); aboutVBox.AddChild(aboutHBox); var aboutIcon = new TextureRect(); aboutIcon.Texture = aboutIcon.GetIcon("NodeWarning", "EditorIcons"); aboutHBox.AddChild(aboutIcon); var aboutLabel = new Label(); aboutHBox.AddChild(aboutLabel); aboutLabel.RectMinSize = new Vector2(600, 150) * EditorScale; aboutLabel.SizeFlagsVertical = (int)Control.SizeFlags.ExpandFill; aboutLabel.Autowrap = true; aboutLabel.Text = "C# support in Godot Engine is in late alpha stage and, while already usable, " + "it is not meant for use in production.\n\n" + "Projects can be exported to Linux, macOS, Windows and Android, but not yet to iOS, HTML5 or UWP. " + "Bugs and usability issues will be addressed gradually over future releases, " + "potentially including compatibility breaking changes as new features are implemented for a better overall C# experience.\n\n" + "If you experience issues with this Mono build, please report them on Godot's issue tracker with details about your system, MSBuild version, IDE, etc.:\n\n" + " https://github.com/godotengine/godot/issues\n\n" + "Your critical feedback at this stage will play a great role in shaping the C# support in future releases, so thank you!"; EditorDef("mono/editor/show_info_on_start", true); // CheckBox in main container aboutDialogCheckBox = new CheckBox { Text = "Show this warning when starting the editor" }; aboutDialogCheckBox.Connect("toggled", this, nameof(_ToggleAboutDialogOnStart)); aboutVBox.AddChild(aboutDialogCheckBox); } if (File.Exists(GodotSharpDirs.ProjectSlnPath) && File.Exists(GodotSharpDirs.ProjectCsProjPath)) { // Make sure the existing project has Api assembly references configured correctly CsProjOperations.FixApiHintPath(GodotSharpDirs.ProjectCsProjPath); } else { bottomPanelBtn.Hide(); menuPopup.AddItem("Create C# solution".TTR(), (int)MenuOptions.CreateSln); } menuPopup.Connect("id_pressed", this, nameof(_MenuOptionPressed)); var buildButton = new ToolButton { Text = "Build", HintTooltip = "Build solution", FocusMode = Control.FocusModeEnum.None }; buildButton.Connect("pressed", this, nameof(_BuildSolutionPressed)); AddControlToContainer(CustomControlContainer.Toolbar, buildButton); // External editor settings EditorDef("mono/editor/external_editor", ExternalEditorId.None); string settingsHintStr = "Disabled"; if (OS.IsWindows) { settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsOSX) { settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsUnixLike()) { settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary { ["type"] = Variant.Type.Int, ["name"] = "mono/editor/external_editor", ["hint"] = PropertyHint.Enum, ["hint_string"] = settingsHintStr }); // Export plugin var exportPlugin = new ExportPlugin(); AddExportPlugin(exportPlugin); exportPlugin.RegisterExportSettings(); exportPluginWeak = WeakRef(exportPlugin); BuildManager.Initialize(); RiderPathManager.Initialize(); GodotIdeManager = new GodotIdeManager(); AddChild(GodotIdeManager); }
public static bool IsFreed(this Node node) { var wr = WeakRef.WeakRef(node); return(wr.GetRef() == null); }
// Notes: // - TextAnchor references an offset (a position between two characters). It automatically updates // when text is inserted/removed in the document. // - TextAnchor only adds a weak reference to document.Change so unsubscribing isn't needed and // anchors wont keep a Document from being collected. // - To track a segment, use AnchorSegment which implements ISegment using two text anchors. // - Use TextDocument.CreateAnchor to create an anchor from an offset. // - Anchor movement is ambiguous if text is inserted exactly at the anchor's location. Does the anchor // stay before the inserted text, or does it move after it? The property MovementType is used to determine // which of these options the anchor will choose. // // Example: // auto anchor = document.CreateAnchor(offset); // ChangeMyDocument(); // int newOffset = anchor.Offset; internal TextAnchor(TextDocument document, int offset, AnchorMapping.EMove move) { Offset = offset; Movement = move; document.ChangeInternal += WeakRef.MakeWeak <DocumentChangeEventArgs>(HandleDocChanged, h => document.ChangeInternal -= h); void HandleDocChanged(object?sender, DocumentChangeEventArgs e) { if (!(sender is TextDocument doc)) { throw new Exception("sender should be a TextDocument"); } if (e.After && !IsDeleted) { // If the anchor is before the change, ignore if (Offset < e.Offset) { } // If the anchor is after the removed text, adjust by the difference in inserted - removed else if (Offset >= e.Offset + e.TextRemoved.Length) { Offset += e.TextInserted.Length - e.TextRemoved.Length; } // Otherwise, the anchor is within the removed text else { switch (Movement) { case AnchorMapping.EMove.Default: { // If the anchor is at the insertion offset, move to after the inserted text if (Offset == e.Offset) { Offset += e.TextInserted.Length - e.TextRemoved.Length; } // Otherwise, delete the anchor else { Delete(); } break; } case AnchorMapping.EMove.BeforeInsertion: { // Move the anchor to the insertion offset Offset += e.Offset; break; } case AnchorMapping.EMove.AfterInsertion: { // Move the anchor to after the insertion Offset += e.TextInserted.Length - e.TextRemoved.Length; break; } default: { throw new Exception("Unknown anchor movement type"); } } } } } }
public override void _EnablePlugin() { base._EnablePlugin(); if (Instance != null) { throw new InvalidOperationException(); } Instance = this; var editorInterface = GetEditorInterface(); var editorBaseControl = editorInterface.GetBaseControl(); _editorSettings = editorInterface.GetEditorSettings(); _errorDialog = new AcceptDialog(); editorBaseControl.AddChild(_errorDialog); MSBuildPanel = new MSBuildPanel(); _bottomPanelBtn = AddControlToBottomPanel(MSBuildPanel, "MSBuild".TTR()); AddChild(new HotReloadAssemblyWatcher { Name = "HotReloadAssemblyWatcher" }); _menuPopup = new PopupMenu(); _menuPopup.Hide(); AddToolSubmenuItem("C#", _menuPopup); var buildSolutionShortcut = (Shortcut)EditorShortcut("mono/build_solution"); _toolBarBuildButton = new Button { Text = "Build", HintTooltip = "Build Solution".TTR(), FocusMode = Control.FocusModeEnum.None, Shortcut = buildSolutionShortcut, ShortcutInTooltip = true }; _toolBarBuildButton.PressedSignal += BuildSolutionPressed; AddControlToContainer(CustomControlContainer.Toolbar, _toolBarBuildButton); if (File.Exists(GodotSharpDirs.ProjectSlnPath) && File.Exists(GodotSharpDirs.ProjectCsProjPath)) { ApplyNecessaryChangesToSolution(); } else { _bottomPanelBtn.Hide(); _toolBarBuildButton.Hide(); _menuPopup.AddItem("Create C# solution".TTR(), (int)MenuOptions.CreateSln); } _menuPopup.IdPressed += _MenuOptionPressed; // External editor settings EditorDef("mono/editor/external_editor", ExternalEditorId.None); string settingsHintStr = "Disabled"; if (OS.IsWindows) { settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudio}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsMacOS) { settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsUnixLike) { settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } _editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary { ["type"] = Variant.Type.Int, ["name"] = "mono/editor/external_editor", ["hint"] = PropertyHint.Enum, ["hint_string"] = settingsHintStr }); // Export plugin var exportPlugin = new ExportPlugin(); AddExportPlugin(exportPlugin); exportPlugin.RegisterExportSettings(); _exportPluginWeak = WeakRef(exportPlugin); try { // At startup we make sure NuGet.Config files have our Godot NuGet fallback folder included NuGetUtils.AddFallbackFolderToUserNuGetConfigs(NuGetUtils.GodotFallbackFolderName, NuGetUtils.GodotFallbackFolderPath); } catch (Exception e) { GD.PushError("Failed to add Godot NuGet Offline Packages to NuGet.Config: " + e.Message); } BuildManager.Initialize(); RiderPathManager.Initialize(); GodotIdeManager = new GodotIdeManager(); AddChild(GodotIdeManager); }
public override void EnablePlugin() { base.EnablePlugin(); if (Instance != null) { throw new InvalidOperationException(); } Instance = this; var editorInterface = GetEditorInterface(); var editorBaseControl = editorInterface.GetBaseControl(); _editorSettings = editorInterface.GetEditorSettings(); _errorDialog = new AcceptDialog(); editorBaseControl.AddChild(_errorDialog); MSBuildPanel = new MSBuildPanel(); _bottomPanelBtn = AddControlToBottomPanel(MSBuildPanel, "MSBuild".TTR()); AddChild(new HotReloadAssemblyWatcher { Name = "HotReloadAssemblyWatcher" }); _menuPopup = new PopupMenu(); _menuPopup.Hide(); _menuPopup.SetAsToplevel(true); AddToolSubmenuItem("C#", _menuPopup); var buildSolutionShortcut = (ShortCut)EditorShortcut("mono/build_solution"); _toolBarButton = new ToolButton { Text = "Build", HintTooltip = "Build Solution".TTR(), FocusMode = Control.FocusModeEnum.None, Shortcut = buildSolutionShortcut, ShortcutInTooltip = true }; _toolBarButton.Connect("pressed", this, nameof(BuildSolutionPressed)); AddControlToContainer(CustomControlContainer.Toolbar, _toolBarButton); if (File.Exists(GodotSharpDirs.ProjectSlnPath) && File.Exists(GodotSharpDirs.ProjectCsProjPath)) { ApplyNecessaryChangesToSolution(); } else { _bottomPanelBtn.Hide(); _toolBarButton.Hide(); _menuPopup.AddItem("Create C# solution".TTR(), (int)MenuOptions.CreateSln); } _menuPopup.Connect("id_pressed", this, nameof(_MenuOptionPressed)); // External editor settings EditorDef("mono/editor/external_editor", ExternalEditorId.None); string settingsHintStr = "Disabled"; if (OS.IsWindows) { settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudio}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsOSX) { settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } else if (OS.IsUnixLike) { settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code:{(int)ExternalEditorId.VsCode}" + $",JetBrains Rider:{(int)ExternalEditorId.Rider}"; } _editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary { ["type"] = Variant.Type.Int, ["name"] = "mono/editor/external_editor", ["hint"] = PropertyHint.Enum, ["hint_string"] = settingsHintStr }); // Export plugin var exportPlugin = new ExportPlugin(); AddExportPlugin(exportPlugin); exportPlugin.RegisterExportSettings(); _exportPluginWeak = WeakRef(exportPlugin); BuildManager.Initialize(); RiderPathManager.Initialize(); GodotIdeManager = new GodotIdeManager(); AddChild(GodotIdeManager); }
protected override void Context() { _objectToBeReferenced = new AnImplementation(); sut = new WeakRef <IAnInterface>(_objectToBeReferenced); }
public AddObservedDataToActiveSimulationUICommand For(DataRepository observedData) { _observedDataReference = new WeakRef <DataRepository>(observedData); return(this); }
// TODO: jogar para interface. public abstract void FireProjectile(WeakRef target);
public MDCRMInterpolatedValue(MemberInfo Member, bool Reliable, MDReplicatedType ReplicatedType, WeakRef NodeRef, MDReplicatedSetting[] Settings) : base(Member, Reliable, ReplicatedType, NodeRef, Settings) { }
public void RemoveEnemy(WeakRef enemy) { CloseEnemies.RemoveAll(e => e.GetRef() == enemy.GetRef()); }