SanAndreasUnity/Assets/Scripts/UI/ChangePathToGTAWindow.cs

88 lines
1.6 KiB
C#
Raw Normal View History

2020-05-31 17:07:22 +00:00
using System.Collections.Generic;
using UnityEngine;
using SanAndreasUnity.Behaviours;
using SanAndreasUnity.Utilities;
namespace SanAndreasUnity.UI {
public class ChangePathToGTAWindow : PauseMenuWindow {
FileBrowser m_fileBrowser = null;
ChangePathToGTAWindow()
{
// set default parameters
this.windowName = "Change path to GTA";
}
void Start ()
{
// adjust rect
2019-07-28 21:08:34 +00:00
this.windowRect = GUIUtils.GetCenteredRect( FileBrowser.GetRecommendedSize() );
2020-05-31 17:07:22 +00:00
}
protected override void OnWindowOpened ()
{
// create file browser
if (null == m_fileBrowser)
{
2021-02-06 22:06:43 +00:00
m_fileBrowser = new FileBrowser (new Rect (new Vector2 (8, 30), new Vector2(this.WindowSize.x - 16, this.WindowSize.y - 30 - 10)), "", this.OnSelectedPath) {
2020-05-31 17:07:22 +00:00
BrowserType = FileBrowserType.Directory
};
}
// set current directory to game directory
string currentGameDir = Config.GetPath (Config.const_game_dir);
if (!string.IsNullOrEmpty (currentGameDir))
{
m_fileBrowser.CurrentDirectory = currentGameDir;
}
else
{
// path is not set
m_fileBrowser.CurrentDirectory = System.IO.Directory.GetCurrentDirectory ();
}
}
void OnSelectedPath (string path)
{
if (string.IsNullOrEmpty (path))
{
// canceled
this.IsOpened = false;
return;
}
// save new path
Config.SetString (Config.const_game_dir, path);
Config.SaveUserConfigSafe ();
this.IsOpened = false;
}
protected override void OnWindowGUI ()
{
if (m_fileBrowser != null)
{
m_fileBrowser.OnGUI ();
}
}
}
}