Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/LiveSplit.AutoSplittingRuntime/ASR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public void SettingsMapSetString(string key, string value)
ASRNative.Runtime_settings_map_set_string(ptr, key, value);
}

public bool InvokeSettingsButton(string key)
{
if (ptr == IntPtr.Zero)
{
return false;
}

return ASRNative.Runtime_invoke_settings_button(ptr, key) != 0;
}

public SettingsMap GetSettingsMap()
{
if (ptr == IntPtr.Zero)
Expand Down Expand Up @@ -607,6 +617,7 @@ public string GetType(ulong index)
2 => "title",
3 => "choice",
4 => "file-select",
5 => "button",
_ => "",
};
}
Expand Down Expand Up @@ -749,6 +760,8 @@ LogDelegate log
[DllImport("asr_capi", CallingConvention = CallingConvention.Cdecl)]
public static extern void Runtime_settings_map_set_string(IntPtr self, ASRString key, ASRString value);
[DllImport("asr_capi", CallingConvention = CallingConvention.Cdecl)]
public static extern byte Runtime_invoke_settings_button(IntPtr self, ASRString key);
[DllImport("asr_capi", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr Runtime_get_settings_map(IntPtr self);
[DllImport("asr_capi", CallingConvention = CallingConvention.Cdecl)]
public static extern void Runtime_set_settings_map(IntPtr self, IntPtr settings_map);
Expand Down
47 changes: 47 additions & 0 deletions src/LiveSplit.AutoSplittingRuntime/ComponentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,37 @@ public void BuildTree()
rowIndex++;
break;
}
case "button":
{
if (rowIndex < settingsTable.RowStyles.Count
&& settingsTable.GetControlFromPosition(0, rowIndex) is Button exButton
&& exButton.Tag is string exTag
&& exTag == widgets.GetKey(i)
&& exButton.Text == desc
&& exButton.Margin.Left == margin)
{
toolTip.SetToolTip(exButton, tooltip);
}
else
{
ClearSettingsTableTail(rowIndex);
var button = new Button
{
Tag = widgets.GetKey(i),
Text = desc,
Margin = new Padding(margin, 0, 0, 0),
AutoSize = true,
AutoSizeMode = AutoSizeMode.GrowAndShrink,
};
button.Click += SettingsButton_Click;
toolTip.SetToolTip(button, tooltip);
settingsTable.Controls.Add(button, 0, settingsTable.RowStyles.Count);
settingsTable.RowStyles.Add(new RowStyle(SizeType.Absolute, button.Height));
}

rowIndex++;
break;
}
default:
{
break;
Expand Down Expand Up @@ -434,6 +465,22 @@ private void FileSelect_Click(object sender, EventArgs e)
}
}

private void SettingsButton_Click(object sender, EventArgs e)
{
var button = (Button)sender;
if (button.Tag is not string key || runtime == null)
{
return;
}

runtime.InvokeSettingsButton(key);
// Callback may have mutated the settings map or widgets
SettingsMap prev = previousMap;
previousMap = runtime.GetSettingsMap();
prev?.Dispose();
BuildTree();
}

private class Choice
{
public string key;
Expand Down
Binary file modified src/LiveSplit.AutoSplittingRuntime/x64/asr_capi.dll
Binary file not shown.
Binary file modified src/LiveSplit.AutoSplittingRuntime/x86/asr_capi.dll
Binary file not shown.
25 changes: 25 additions & 0 deletions src/asr-capi/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ pub unsafe extern "C" fn Runtime_settings_map_set_string(
panic!("Index out of bounds")
}

/// # Safety
/// `key` must be a valid NUL-terminated UTF-8 C string (same convention as other Runtime_* key APIs).
#[no_mangle]
pub unsafe extern "C" fn Runtime_invoke_settings_button(
_this: &Runtime,
key: *const u8,
) -> bool {
#[cfg(target_pointer_width = "64")]
{
let key = str(key);
match _this.runtime.invoke_settings_button(key) {
Ok(_) => true,
Err(err) => {
log(
_this.log,
format_args!("{:?}", err.context("Failed executing the auto splitter.")),
);
false
}
}
}
#[cfg(not(target_pointer_width = "64"))]
false
}

#[no_mangle]
pub extern "C" fn Runtime_get_settings_map(_this: &Runtime) -> Box<SettingsMap> {
#[cfg(target_pointer_width = "64")]
Expand Down
1 change: 1 addition & 0 deletions src/asr-capi/src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub extern "C" fn Widgets_get_type(_this: &Widgets, _index: usize) -> usize {
WidgetKind::Title { .. } => 2,
WidgetKind::Choice { .. } => 3,
WidgetKind::FileSelect { .. } => 4,
WidgetKind::Button => 5,
}
}
#[cfg(not(target_pointer_width = "64"))]
Expand Down