Skip to content

Commit

Permalink
Улучшил настройки
Browse files Browse the repository at this point in the history
  • Loading branch information
VaIeroK committed Oct 20, 2022
1 parent efc1fb1 commit 4d3bfd1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 38 deletions.
2 changes: 1 addition & 1 deletion OGF tool/Forms/OgfEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public OGF_Editor()
File.Delete(file_path);
Settings settings = new Settings(pSettings);
settings.Settings_Load(null, null); // Load defaults
settings.SaveParams(null, null); // Save defaults
settings.SaveParams(); // Save defaults
}

pSettings.LoadText("GameMtlPath", ref gamemtl);
Expand Down
17 changes: 16 additions & 1 deletion OGF tool/Forms/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 66 additions & 16 deletions OGF tool/Forms/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

Expand All @@ -21,7 +16,7 @@ public Settings(EditorSettings settings)
pSettings = settings;
}

public void SaveParams(object sender, FormClosingEventArgs e)
public void SaveParams()
{
pSettings.SaveVersion();
pSettings.Save(GameMtlPath);
Expand Down Expand Up @@ -75,16 +70,6 @@ private string GetFSPath(string filename, string key)
return null;
}

private bool IsTextCorrect(string text)
{
foreach (char ch in text)
{
if (ch > 0x1F && ch != 0x20)
return true;
}
return false;
}

private string GetCorrectString(string text)
{
string ret_text = "", symbols = "";
Expand Down Expand Up @@ -205,6 +190,8 @@ private void FindObjectEditor(object sender, EventArgs e)

private void FsPathTextChanged(object sender, EventArgs e)
{
BoxTextChanged(sender, e);

if (Path.GetExtension(FSLtxPath.Text) == ".ltx" && File.Exists(FSLtxPath.Text))
{
string FileName = FSLtxPath.Text;
Expand All @@ -229,5 +216,68 @@ private void FsPathTextChanged(object sender, EventArgs e)
}
}
}

private void BoxTextChanged(object sender, EventArgs e)
{
TextBox textBox = sender as TextBox;

bool file_or_folder = false;

switch (textBox.Name)
{
case "ImagePath":
file_or_folder = false;
break;
case "FSLtxPath":
file_or_folder = true;
break;
case "TexturesPath":
file_or_folder = false;
break;
case "GameMtlPath":
file_or_folder = true;
break;
case "OmfEditorPath":
file_or_folder = true;
break;
case "ObjectEditorPath":
file_or_folder = true;
break;
}

if (file_or_folder)
{
if (File.Exists(textBox.Text))
textBox.BackColor = SystemColors.Window;
else
textBox.BackColor = Color.FromArgb(255, 255, 128, 128);
}
else
{
if (Directory.Exists(textBox.Text))
textBox.BackColor = SystemColors.Window;
else
textBox.BackColor = Color.FromArgb(255, 255, 128, 128);

int temp = textBox.SelectionStart;

int slash_idx = textBox.Text.LastIndexOf('\\');
if (slash_idx == textBox.Text.Count() - 1)
{
textBox.Text = textBox.Text.Substring(0, textBox.Text.LastIndexOf('\\'));

if (textBox.SelectionStart < 1)
textBox.SelectionStart = textBox.Text.Length;

textBox.SelectionStart = temp - 1 >= 0 ? temp - 1 : 0;
}
}
}

private void ApplyButton_Click(object sender, EventArgs e)
{
SaveParams();
Close();
}
}
}
Loading

0 comments on commit 4d3bfd1

Please sign in to comment.