public void CreateNew(Lifetime clientLifetime, Action <Lifetime> init) { balloonLifetimes.Next(balloonLifetime => { balloonWindow = new BalloonWindow(); balloonWindow.ButtonClicked += OnButtonClicked; balloonWindow.OptionClicked += OnBalloonOptionClicked; host = new BalloonWindowHost(balloonWindow); // If the client wants to hide the balloon, they can terminate clientLifetime // If another client calls CreateNew, balloonLifetimes.Next terminates // balloonLifetime. Whichever lifetime terminates first will cause // combinedLifetime to terminate, closing the window. var combinedLifetime = Lifetimes.CreateIntersection2(clientLifetime, balloonLifetime).Lifetime; combinedLifetime.AddAction(() => { if (host != null) { host.Close(); host = null; balloonWindow = null; } }); init(combinedLifetime); }); }
private CharacterContext(Character character) { // いもうとの定義 Character = character; // ルートディレクトリ BaseDirectory = character.Directory; // プロファイルを読み込む Profile = Profile.LoadFrom(Path.Combine(BaseDirectory, "profile.yml")) ?? new Profile { Age = Character.Age, TsundereLevel = Character.TsundereLevel }; // バルーン読み込み Balloon = BalloonManager.GetValueOrDefault(Profile.LastBalloon); // ルートからイメージ用ディレクトリを作る SurfaceLoader = new SurfaceLoader(Path.Combine(BaseDirectory, "images")); // ウィンドウを作成する BalloonWindow = new BalloonWindow { Context = this, Balloon = Balloon, LocationOffset = Profile.BalloonOffset }; CharacterWindow = new CharacterWindow { Context = this, BalloonWindow = BalloonWindow }; // メニューのコマンドを定義する var contextMenu = CharacterWindow.ContextMenu; contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Character, CharacterCommand_Executed, CharacterCommand_CanExecute)); contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Balloon, BalloonCommand_Executed, BalloonCommand_CanExecute)); contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Option, OptionCommand_Executed)); contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Version, VersionCommand_Executed)); contextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, CloseCommand_Executed)); // スクリプトエンジンを作成する ScriptEngine = new ScriptEngine(Path.Combine(BaseDirectory, "scripts")); InitializeScriptEngine(); // スクリプトプレイヤーを作成 ScriptPlayer = new ScriptPlayer(this); RemoteConnectionManager = new RemoteConnectionManager(); RemoteCommandManager = new RemoteCommandManager(Character, RemoteConnectionManager); }