(b63c9bf0c) Fixed OpenFileDialog not closing on Linux

This commit is contained in:
Joonas Rikkonen
2019-05-23 17:04:30 +03:00
parent 834ee2947b
commit 304db988b1
5 changed files with 80 additions and 4 deletions

View File

@@ -223,6 +223,7 @@
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\MathUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\OpenFileDialog.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\TextureLoader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\ToolBox.cs" />
</ItemGroup>

View File

@@ -967,7 +967,7 @@ namespace Barotrauma
{
try
{
OpenFileDialog ofd = new OpenFileDialog()
Barotrauma.OpenFileDialog ofd = new Barotrauma.OpenFileDialog()
{
Multiselect = true,
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
@@ -1078,7 +1078,7 @@ namespace Barotrauma
{
try
{
OpenFileDialog ofd = new OpenFileDialog()
Barotrauma.OpenFileDialog ofd = new Barotrauma.OpenFileDialog()
{
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
Title = TextManager.Get("workshopitemaddfiles"),

View File

@@ -1074,7 +1074,7 @@ namespace Barotrauma
{
OnClicked = (btn, userdata) =>
{
OpenFileDialog ofd = new OpenFileDialog()
Barotrauma.OpenFileDialog ofd = new Barotrauma.OpenFileDialog()
{
InitialDirectory = Path.GetFullPath(Submarine.SavePath),
Filter = "PNG file|*.png",

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Barotrauma
{
public class OpenFileDialog
{
private System.Windows.Forms.OpenFileDialog ofd;
public bool Multiselect;
public string InitialDirectory;
public string Filter;
public string Title;
public string FileName { get; private set; }
public string[] FileNames { get; private set; }
public OpenFileDialog()
{
ofd = new System.Windows.Forms.OpenFileDialog();
}
public System.Windows.Forms.DialogResult ShowDialog()
{
ofd.Multiselect = Multiselect;
ofd.InitialDirectory = InitialDirectory;
ofd.Filter = Filter;
ofd.Title = Title;
#if LINUX
var wrapperForm = new WrapperForm(ofd);
System.Windows.Forms.Application.Run(wrapperForm);
System.Windows.Forms.Application.Exit();
FileName = wrapperForm.FileName;
FileNames = wrapperForm.FileNames;
return wrapperForm.Result;
#else
var result = ofd.ShowDialog();
FileName = ofd.FileName;
FileNames = ofd.FileNames;
return result;
#endif
}
#if LINUX
private class WrapperForm : System.Windows.Forms.Form
{
private System.Windows.Forms.OpenFileDialog ofd;
public System.Windows.Forms.DialogResult Result { get; private set; }
public string FileName { get; private set; }
public string[] FileNames { get; private set; }
public WrapperForm(System.Windows.Forms.OpenFileDialog dialog)
{
ofd = dialog;
Load += WrapperForm_Load;
}
private void WrapperForm_Load(object sender, EventArgs e)
{
Result = ofd.ShowDialog();
FileName = ofd.FileName;
FileNames = ofd.FileNames;
System.Threading.Thread.Sleep(100);
this.Close();
}
}
#endif
}
}

View File

@@ -122,8 +122,9 @@ namespace Barotrauma
goToObjective = null;
}
TryAddSubObjective(ref goToObjective,
constructor: () => new AIObjectiveGoTo(currentSafeHull, character, objectiveManager, getDivingGearIfNeeded: true)
constructor: () => new AIObjectiveGoTo(currentSafeHull, character, objectiveManager, getDivingGearIfNeeded: false)
{
// If we need diving gear, we should already have it, if possible.
AllowGoingOutside = HumanAIController.HasDivingSuit(character)
},
onAbandon: () => unreachable.Add(goToObjective.Target as Hull));