Skip to content

Commit

Permalink
Enhancments to Saving/Loading configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Icydeath committed Jul 14, 2020
1 parent 837935f commit 9ece2ee
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 118 deletions.
2 changes: 1 addition & 1 deletion HealbotConfigurator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mc:Ignorable="d"
SaveWindowPosition="True"
ResizeMode="CanMinimize"
Title="Healbot Configurator 1.1" Height="450" Width="1095" IsMaxRestoreButtonEnabled="False" MinWidth="1095" MinHeight="450" WindowStartupLocation="CenterScreen" Closing="MetroWindow_Closing">
Title="Healbot Configurator 1.2" Height="450" Width="1095" IsMaxRestoreButtonEnabled="False" MinWidth="1095" MinHeight="450" WindowStartupLocation="CenterScreen" Closing="MetroWindow_Closing">

<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands>
Expand Down
267 changes: 150 additions & 117 deletions HealbotConfigurator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public partial class MainWindow : MetroWindow
public static EliteAPI _ELITEAPI;
public static string AppPath;
public static string ConfigPath;
public WindowerRes _Res;

public MainWindow()
{
InitializeComponent();

AppPath = AppDomain.CurrentDomain.BaseDirectory;
ConfigPath = System.IO.Path.Combine(AppPath, "Configs");
ConfigPath = Path.Combine(AppPath, "Configs");
if (!Directory.Exists(ConfigPath))
{
Directory.CreateDirectory(ConfigPath);
Expand Down Expand Up @@ -108,16 +110,16 @@ private void FillLists(bool clearLists = false)
Select_DebuffSpell.Items.Clear();
}

var res = new WindowerRes(Settings.Default.WindowerPath, _ELITEAPI);
foreach (var ws in res.Weaponskills)
_Res = new WindowerRes(Settings.Default.WindowerPath, _ELITEAPI);
foreach (var ws in _Res.Weaponskills)
{
Select_Weaponskill.Items.Add(ws);
}
foreach (var spell in res.Spells)
foreach (var spell in _Res.Spells)
{
Select_SpamSpell.Items.Add(spell);
}
foreach (var spell in res.BuffSpells)
foreach (var spell in _Res.BuffSpells)
{
Select_BuffSpell.Items.Add(spell);
Select_DebuffSpell.Items.Add(spell);
Expand All @@ -126,17 +128,39 @@ private void FillLists(bool clearLists = false)

private void SetupDefaults()
{
Toggle_Buffs.IsOn = true;
Toggle_Curing.IsOn = true;
Toggle_Curaga.IsOn = true;
Toggle_Debuffs.IsOn = true;
Toggle_Erase.IsOn = true;
Toggle_Na.IsOn = true;
SendCommand("lua load healbot");

var fname = string.Empty;
if (_ELITEAPI != null)
{
fname = _ELITEAPI.Player.Name + "_" + _Res.Jobs[_ELITEAPI.Player.MainJob] + "_" + _Res.Jobs[_ELITEAPI.Player.SubJob];
}

Toggle_Follow.IsOn = false;
Toggle_Spam.IsOn = false;
Toggle_Weaponskill.IsOn = false;
Toggle_Weaponskill_Waitfor.IsOn = false;
var file = Path.Combine(ConfigPath, fname + ".txt");
if (File.Exists(file))
{
LoadSettingsFromConfig(file);
}
else if (File.Exists(Path.Combine(ConfigPath, "default.txt")))
{
LoadSettingsFromConfig(Path.Combine(ConfigPath, "default.txt"));
}
else
{
Toggle_Buffs.IsOn = true;
Toggle_Curing.IsOn = true;
Toggle_Curaga.IsOn = true;
Toggle_Debuffs.IsOn = true;
Toggle_Erase.IsOn = true;
Toggle_Na.IsOn = true;

Toggle_Follow.IsOn = false;
Toggle_Spam.IsOn = false;
Toggle_Weaponskill.IsOn = false;
Toggle_Weaponskill_Waitfor.IsOn = false;

SaveSettingsToFile("default.txt");
}
}

private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -268,69 +292,78 @@ private void Button_LaunchWindowerPathDialog_Click(object sender, RoutedEventArg

private void SaveSettings()
{
var inputDialog = new CustomInputDialog("Save as...", "default");
if (inputDialog.ShowDialog() == true)
var fname = "default";
if (_ELITEAPI != null)
{
var fileName = inputDialog.DialogValue.Replace(".txt", "") + ".txt";
if (string.IsNullOrEmpty(fileName))
fileName = "default.txt";

var config = new Configuration();
config["Features"]["Curing"].BoolValue = Toggle_Curing.IsOn;
config["Features"]["Curaga"].BoolValue = Toggle_Curaga.IsOn;
config["Features"]["Na"].BoolValue = Toggle_Na.IsOn;
config["Features"]["Erase"].BoolValue = Toggle_Erase.IsOn;
config["Features"]["Buffs"].BoolValue = Toggle_Buffs.IsOn;
config["Features"]["Enfeebling"].BoolValue = Toggle_Debuffs.IsOn;
config["Features"]["IgnoreTrusts"].BoolValue = Toggle_IgnoreTrusts.IsOn;
config["Features"]["Mincure"].IntValue = int.Parse(Num_Mincure.Value.ToString());

config["Follow"]["FollowPlayer"].StringValue = Select_FollowPlayer.SelectedItem != null ? ((ComboboxItem)Select_FollowPlayer.SelectedItem).Text : !string.IsNullOrEmpty(Select_FollowPlayer.Text) ? Select_FollowPlayer.Text : string.Empty;
config["Follow"]["FollowDistance"].FloatValue = float.Parse(Num_Follow.Value.ToString());

var list = new List<string>();
foreach(var b in Lb_Buffs.Items)
{
list.Add(b.ToString());
}
config["Buffs"]["BuffSpells"].StringValueArray = list.ToArray();
fname = _ELITEAPI.Player.Name + "_" + _Res.Jobs[_ELITEAPI.Player.MainJob] + "_" + _Res.Jobs[_ELITEAPI.Player.SubJob];
}

list = new List<string>();
foreach (var b in Lb_Debuffs.Items)
{
list.Add(b.ToString());
}
config["Enfeebling"]["EnfeeblingSpells"].StringValueArray = list.ToArray();
var inputDialog = new CustomInputDialog("Save as...", fname);
if (inputDialog.ShowDialog() == true)
{
SaveSettingsToFile(inputDialog.DialogValue.Replace(".txt", "") + ".txt");
}
}

list = new List<string>();
foreach (var b in Lb_MonitorPlayer.Items)
{
list.Add(b.ToString());
}
config["Monitor"]["MonitorPlayers"].StringValueArray = list.ToArray();
private void SaveSettingsToFile(string fileName)
{
if (string.IsNullOrEmpty(fileName))
fileName = "default.txt";

list = new List<string>();
foreach (var b in Lb_IgnorePlayer.Items)
{
list.Add(b.ToString());
}
config["Ignore"]["IgnorePlayers"].StringValueArray = list.ToArray();
var config = new Configuration();
config["Features"]["Curing"].BoolValue = Toggle_Curing.IsOn;
config["Features"]["Curaga"].BoolValue = Toggle_Curaga.IsOn;
config["Features"]["Na"].BoolValue = Toggle_Na.IsOn;
config["Features"]["Erase"].BoolValue = Toggle_Erase.IsOn;
config["Features"]["Buffs"].BoolValue = Toggle_Buffs.IsOn;
config["Features"]["Enfeebling"].BoolValue = Toggle_Debuffs.IsOn;
config["Features"]["IgnoreTrusts"].BoolValue = Toggle_IgnoreTrusts.IsOn;
config["Features"]["Mincure"].IntValue = int.Parse(Num_Mincure.Value.ToString());

config["Follow"]["FollowPlayer"].StringValue = Select_FollowPlayer.SelectedItem != null ? ((ComboboxItem)Select_FollowPlayer.SelectedItem).Text : !string.IsNullOrEmpty(Select_FollowPlayer.Text) ? Select_FollowPlayer.Text : string.Empty;
config["Follow"]["FollowDistance"].FloatValue = float.Parse(Num_Follow.Value.ToString());

config["Assist"]["AssistPlayer"].StringValue = Select_AssistPlayer.SelectedItem != null ? ((ComboboxItem)Select_AssistPlayer.SelectedItem).Text : !string.IsNullOrEmpty(Select_AssistPlayer.Text) ? Select_AssistPlayer.Text : string.Empty;
config["Assist"]["EngageTarget"].BoolValue = Toggle_Attack.IsOn;
var list = new List<string>();
foreach (var b in Lb_Buffs.Items)
{
list.Add(b.ToString());
}
config["Buffs"]["BuffSpells"].StringValueArray = list.ToArray();

config["Weaponskill"]["WS"].StringValue = Select_Weaponskill.SelectedItem != null ? ((ComboboxItem)Select_Weaponskill.SelectedItem).Text : !string.IsNullOrEmpty(Select_Weaponskill.Text) ? Select_Weaponskill.Text : string.Empty;
config["Weaponskill"]["TargetHP"].IntValue = int.Parse(Num_Weaponskill_Percent.Value.ToString());
config["Weaponskill"]["HPOperator"].StringValue = Select_Weaponskill_Operator.SelectedItem.ToString();
config["Weaponskill"]["WaitForPlayer"].StringValue = Select_Weaponskill_Waitfor.SelectedItem != null ? ((ComboboxItem)Select_Weaponskill_Waitfor.SelectedItem).Text : !string.IsNullOrEmpty(Select_Weaponskill_Waitfor.Text) ? Select_Weaponskill_Waitfor.Text : string.Empty;
config["Weaponskill"]["WaitForTP"].IntValue = int.Parse(Num_Weaponskill_Waitfor.Value.ToString());
list = new List<string>();
foreach (var b in Lb_Debuffs.Items)
{
list.Add(b.ToString());
}
config["Enfeebling"]["EnfeeblingSpells"].StringValueArray = list.ToArray();

config["Spam"]["SpamSpell"].StringValue = Select_SpamSpell.SelectedItem != null ? ((ComboboxItem)Select_SpamSpell.SelectedItem).Text : !string.IsNullOrEmpty(Select_SpamSpell.Text) ? Select_SpamSpell.Text : string.Empty;
list = new List<string>();
foreach (var b in Lb_MonitorPlayer.Items)
{
list.Add(b.ToString());
}
config["Monitor"]["MonitorPlayers"].StringValueArray = list.ToArray();

config.SaveToFile(System.IO.Path.Combine(ConfigPath, fileName));
list = new List<string>();
foreach (var b in Lb_IgnorePlayer.Items)
{
list.Add(b.ToString());
}
config["Ignore"]["IgnorePlayers"].StringValueArray = list.ToArray();


config["Assist"]["AssistPlayer"].StringValue = Select_AssistPlayer.SelectedItem != null ? ((ComboboxItem)Select_AssistPlayer.SelectedItem).Text : !string.IsNullOrEmpty(Select_AssistPlayer.Text) ? Select_AssistPlayer.Text : string.Empty;
config["Assist"]["EngageTarget"].BoolValue = Toggle_Attack.IsOn;

config["Weaponskill"]["WS"].StringValue = Select_Weaponskill.SelectedItem != null ? ((ComboboxItem)Select_Weaponskill.SelectedItem).Text : !string.IsNullOrEmpty(Select_Weaponskill.Text) ? Select_Weaponskill.Text : string.Empty;
config["Weaponskill"]["TargetHP"].IntValue = int.Parse(Num_Weaponskill_Percent.Value.ToString());
config["Weaponskill"]["HPOperator"].StringValue = Select_Weaponskill_Operator.SelectedItem.ToString();
config["Weaponskill"]["WaitForPlayer"].StringValue = Select_Weaponskill_Waitfor.SelectedItem != null ? ((ComboboxItem)Select_Weaponskill_Waitfor.SelectedItem).Text : !string.IsNullOrEmpty(Select_Weaponskill_Waitfor.Text) ? Select_Weaponskill_Waitfor.Text : string.Empty;
config["Weaponskill"]["WaitForTP"].IntValue = int.Parse(Num_Weaponskill_Waitfor.Value.ToString());

config["Spam"]["SpamSpell"].StringValue = Select_SpamSpell.SelectedItem != null ? ((ComboboxItem)Select_SpamSpell.SelectedItem).Text : !string.IsNullOrEmpty(Select_SpamSpell.Text) ? Select_SpamSpell.Text : string.Empty;

config.SaveToFile(Path.Combine(ConfigPath, fileName));
}

private void LoadSettings()
Expand Down Expand Up @@ -362,73 +395,73 @@ private void LoadSettings()
Toggle_Debuffs.IsOn = false;
Toggle_IgnoreTrusts.IsOn = false;

var config = Configuration.LoadFromFile(openFileDialog.FileName);
LoadSettingsFromConfig(openFileDialog.FileName);
}
}

Num_Mincure.Value = config["Features"]["Mincure"].IntValue;
private void LoadSettingsFromConfig(string filename)
{
var config = Configuration.LoadFromFile(filename);

Select_FollowPlayer.Text = config["Follow"]["FollowPlayer"].StringValue;
Num_Follow.Value = config["Follow"]["FollowDistance"].FloatValue;
Num_Mincure.Value = config["Features"]["Mincure"].IntValue;
SendCommand("hb mincure " + Num_Mincure.Value);

Lb_Buffs.Items.Clear();
foreach (var txt in config["Buffs"]["BuffSpells"].StringValueArray)
{
Lb_Buffs.Items.Add(txt);
SendCommand("hb buff " + txt);
}
Select_FollowPlayer.Text = config["Follow"]["FollowPlayer"].StringValue;
Num_Follow.Value = config["Follow"]["FollowDistance"].FloatValue;

Lb_Debuffs.Items.Clear();
foreach (var txt in config["Enfeebling"]["EnfeeblingSpells"].StringValueArray)
{
Lb_Debuffs.Items.Add(txt);
SendCommand("hb debuff " + txt);
}
Lb_Buffs.Items.Clear();
foreach (var txt in config["Buffs"]["BuffSpells"].StringValueArray)
{
Lb_Buffs.Items.Add(txt);
SendCommand("hb buff " + txt);
}

Lb_MonitorPlayer.Items.Clear();
foreach (var txt in config["Monitor"]["MonitorPlayers"].StringValueArray)
{
Lb_MonitorPlayer.Items.Add(txt);
SendCommand("hb watch " + txt);
}
Lb_Debuffs.Items.Clear();
foreach (var txt in config["Enfeebling"]["EnfeeblingSpells"].StringValueArray)
{
Lb_Debuffs.Items.Add(txt);
SendCommand("hb debuff " + txt);
}

Lb_IgnorePlayer.Items.Clear();
foreach (var txt in config["Ignore"]["IgnorePlayers"].StringValueArray)
{
Lb_IgnorePlayer.Items.Add(txt);
SendCommand("hb ignore " + txt);
}
Lb_MonitorPlayer.Items.Clear();
foreach (var txt in config["Monitor"]["MonitorPlayers"].StringValueArray)
{
Lb_MonitorPlayer.Items.Add(txt);
SendCommand("hb watch " + txt);
}

Select_AssistPlayer.Text = config["Assist"]["AssistPlayer"].StringValue;
Select_Weaponskill.Text = config["Weaponskill"]["WS"].StringValue;
Num_Weaponskill_Percent.Value = config["Weaponskill"]["TargetHP"].IntValue;
Select_Weaponskill_Operator.Text = config["Weaponskill"]["HPOperator"].StringValue;
Select_Weaponskill_Waitfor.Text = config["Weaponskill"]["WaitForPlayer"].StringValue;
Num_Weaponskill_Waitfor.Value = config["Weaponskill"]["WaitForTP"].IntValue;
Lb_IgnorePlayer.Items.Clear();
foreach (var txt in config["Ignore"]["IgnorePlayers"].StringValueArray)
{
Lb_IgnorePlayer.Items.Add(txt);
SendCommand("hb ignore " + txt);
}

Select_SpamSpell.Text = config["Spam"]["SpamSpell"].StringValue;
Select_AssistPlayer.Text = config["Assist"]["AssistPlayer"].StringValue;
Select_Weaponskill.Text = config["Weaponskill"]["WS"].StringValue;
Num_Weaponskill_Percent.Value = config["Weaponskill"]["TargetHP"].IntValue;
Select_Weaponskill_Operator.Text = config["Weaponskill"]["HPOperator"].StringValue;
Select_Weaponskill_Waitfor.Text = config["Weaponskill"]["WaitForPlayer"].StringValue;
Num_Weaponskill_Waitfor.Value = config["Weaponskill"]["WaitForTP"].IntValue;

Toggle_Attack.IsOn = config["Assist"]["EngageTarget"].BoolValue;
Toggle_Curing.IsOn = config["Features"]["Curing"].BoolValue;
Toggle_Curaga.IsOn = config["Features"]["Curaga"].BoolValue;
Toggle_Na.IsOn = config["Features"]["Na"].BoolValue;
Toggle_Erase.IsOn = config["Features"]["Erase"].BoolValue;
Toggle_Buffs.IsOn = config["Features"]["Buffs"].BoolValue;
Toggle_Debuffs.IsOn = config["Features"]["Enfeebling"].BoolValue;
Toggle_IgnoreTrusts.IsOn = config["Features"]["IgnoreTrusts"].BoolValue;
}
Select_SpamSpell.Text = config["Spam"]["SpamSpell"].StringValue;

Toggle_Attack.IsOn = config["Assist"]["EngageTarget"].BoolValue;
Toggle_Curing.IsOn = config["Features"]["Curing"].BoolValue;
Toggle_Curaga.IsOn = config["Features"]["Curaga"].BoolValue;
Toggle_Na.IsOn = config["Features"]["Na"].BoolValue;
Toggle_Erase.IsOn = config["Features"]["Erase"].BoolValue;
Toggle_Buffs.IsOn = config["Features"]["Buffs"].BoolValue;
Toggle_Debuffs.IsOn = config["Features"]["Enfeebling"].BoolValue;
Toggle_IgnoreTrusts.IsOn = config["Features"]["IgnoreTrusts"].BoolValue;
}

private void SendCommand(string cmd)
{
if (_ELITEAPI != null)
{
_ELITEAPI.ThirdParty.SendString(@"//" + cmd);
//_ELITEAPI.ThirdParty.SendString(@"/echo " + cmd);
}
//else
//{
// var msg = new CustomMessageDialog("ERROR", "Player instance not found. Unable to send command:" + Environment.NewLine + cmd);
// msg.ShowDialog();
//}
}

private void Button_SaveSettings_Click(object sender, RoutedEventArgs e)
Expand Down
18 changes: 18 additions & 0 deletions HealbotConfigurator/WindowerRes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class WindowerRes
public List<ComboboxItem> BuffSpells { get; set; }
public List<ComboboxItem> BuffAbilities { get; set; }

public Dictionary<byte, string> Jobs { get; set; }

public WindowerRes(string windowerpath, EliteAPI api)
{
if (string.IsNullOrEmpty(windowerpath) || api == null)
Expand All @@ -36,6 +38,22 @@ private void SetupResources()
SetupWeaponskills();
SetupSpells();
SetupBuffAbilities();
SetupJobs();
}

private void SetupJobs()
{
Jobs = new Dictionary<byte, string>();
var path = Path.Combine(WindowerPath, "res\\jobs.lua");
string luaItems = File.ReadAllText(path);
Script script = new Script();
DynValue res = script.DoString(luaItems);
foreach (DynValue dv in res.ToScalar().Table.Values)
{
var id = (double)dv.Table["id"];
var job = (string)dv.Table["ens"];
Jobs.Add((byte)id, job);
}
}

private void SetupWeaponskills()
Expand Down

0 comments on commit 9ece2ee

Please sign in to comment.