Skip to content

Commit

Permalink
configure_v3: add an hidden setting to choose the shortcut type
Browse files Browse the repository at this point in the history
  • Loading branch information
brliron committed Dec 22, 2024
1 parent 33e544d commit 10c0f97
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions thcrap_configure/src/configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ int TH_CDECL win32_utf8_main(int argc, const char *argv[])
// Other default settings
json_object_set_new(new_cfg, "dat_dump", json_false());
json_object_set_new(new_cfg, "patched_files_dump", json_false());
json_object_set_new(new_cfg, "developper_mode", json_false());

run_cfg_fn = run_cfg_fn_build(sel_stack);
run_cfg_fn = EnterRunCfgFN(run_cfg_fn);
Expand Down
2 changes: 1 addition & 1 deletion thcrap_configure_v3/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<LineBreak />
Click Next to continue, or click "Configure Settings" to change settings.
</TextBlock>
<Button Content="Configure Settings" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="SettingsWindow_Open" />
<Button Content="Configure Settings" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="SettingsWindow_Open" Padding="3,2" />
<TextBlock Name="VersionText" HorizontalAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
</Grid>
</xctk:WizardPage>
Expand Down
11 changes: 10 additions & 1 deletion thcrap_configure_v3/Page5.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
<CheckBox Margin="0,7,0,0" Checked="checkbox_Checked" Unchecked="checkbox_Checked" x:Name="checkboxStartMenu" IsChecked="True">In the Start menu</CheckBox>
<CheckBox Margin="0,7,0,0" Checked="checkbox_Checked" Unchecked="checkbox_Checked" x:Name="checkboxGamesFolder">In the games' folder</CheckBox>
<CheckBox Margin="0,7,0,0" Checked="checkbox_Checked" Unchecked="checkbox_Checked" x:Name="checkboxThcrapFolder">In the thcrap folder</CheckBox>
<StackPanel Margin="0,7,0,0" Orientation="Horizontal" x:Name="warningPanel" Visibility="Hidden">
<StackPanel Margin="0,7,0,0" Orientation="Horizontal" x:Name="warningPanel" Visibility="Collapsed">
<Image x:Name="warningImage" Margin="0,0,7,0" Height="14" />
<TextBlock>You need shortcuts to run the patched games! <TextBlock Foreground="Blue" TextDecorations="Underline" Cursor="Hand" MouseUp="NoShortcutsMoreDetails">More details...</TextBlock></TextBlock>
</StackPanel>
<StackPanel Margin="0,7,0,0" Orientation="Horizontal" x:Name="shortcutTypePanel" Visibility="Hidden">
<TextBlock Margin="0,0,7,0">Shortcut type: </TextBlock>
<ComboBox x:Name="shortcutType">
<ComboBoxItem>Choose automatically (default)</ComboBoxItem>
<ComboBoxItem>Shortcut</ComboBoxItem>
<ComboBoxItem>Wrapper with absolute path</ComboBoxItem>
<ComboBoxItem>Wrapper with realtive path</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
</UserControl>
31 changes: 21 additions & 10 deletions thcrap_configure_v3/Page5.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ShortcutDestinations = thcrap_configure_v3.GlobalConfig.ShortcutDestinations;

namespace thcrap_configure_v3
{
Expand Down Expand Up @@ -42,12 +43,18 @@ public void Enter()
if (config == null)
{
config = new GlobalConfig();
GlobalConfig.ShortcutDestinations dest = config.default_shortcut_destinations;
ShortcutDestinations dest = config.default_shortcut_destinations;

checkboxDesktop.IsChecked = dest.HasFlag(GlobalConfig.ShortcutDestinations.Desktop);
checkboxStartMenu.IsChecked = dest.HasFlag(GlobalConfig.ShortcutDestinations.StartMenu);
checkboxGamesFolder.IsChecked = dest.HasFlag(GlobalConfig.ShortcutDestinations.GamesFolder);
checkboxThcrapFolder.IsChecked = dest.HasFlag(GlobalConfig.ShortcutDestinations.ThcrapFolder);
checkboxDesktop.IsChecked = dest.HasFlag(ShortcutDestinations.Desktop);
checkboxStartMenu.IsChecked = dest.HasFlag(ShortcutDestinations.StartMenu);
checkboxGamesFolder.IsChecked = dest.HasFlag(ShortcutDestinations.GamesFolder);
checkboxThcrapFolder.IsChecked = dest.HasFlag(ShortcutDestinations.ThcrapFolder);
}

if (config.developer_mode)
{
shortcutTypePanel.Visibility = Visibility.Visible;
shortcutType.SelectedIndex = (int)config.shortcuts_type;
}
}

Expand All @@ -61,7 +68,7 @@ private void checkbox_Checked(object sender, RoutedEventArgs e)

if (checkboxDesktop.IsChecked == true || checkboxStartMenu.IsChecked == true ||
checkboxGamesFolder.IsChecked == true || checkboxThcrapFolder.IsChecked == true || isUTLPresent == true)
warningPanel.Visibility = Visibility.Hidden;
warningPanel.Visibility = Visibility.Collapsed;
else
warningPanel.Visibility = Visibility.Visible;
}
Expand Down Expand Up @@ -90,10 +97,14 @@ private void CreateShortcuts(string configName, IEnumerable<ThcrapDll.games_js_e
public void Leave(string configName, IEnumerable<ThcrapDll.games_js_entry> games)
{
config.default_shortcut_destinations =
(checkboxDesktop.IsChecked == true ? GlobalConfig.ShortcutDestinations.Desktop : 0) |
(checkboxStartMenu.IsChecked == true ? GlobalConfig.ShortcutDestinations.StartMenu : 0) |
(checkboxGamesFolder.IsChecked == true ? GlobalConfig.ShortcutDestinations.GamesFolder : 0) |
(checkboxThcrapFolder.IsChecked == true ? GlobalConfig.ShortcutDestinations.ThcrapFolder : 0);
(checkboxDesktop.IsChecked == true ? ShortcutDestinations.Desktop : 0) |
(checkboxStartMenu.IsChecked == true ? ShortcutDestinations.StartMenu : 0) |
(checkboxGamesFolder.IsChecked == true ? ShortcutDestinations.GamesFolder : 0) |
(checkboxThcrapFolder.IsChecked == true ? ShortcutDestinations.ThcrapFolder : 0);
if (config.developer_mode)
{
config.shortcuts_type = (ThcrapDll.ShortcutsType)shortcutType.SelectedIndex;
}
config.Save();

if (checkboxDesktop.IsChecked == true)
Expand Down
3 changes: 3 additions & 0 deletions thcrap_configure_v3/Runconfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum ShortcutDestinations
public bool console { get; set; }
public long exception_detail { get; set; }
public long codepage { get; set; }
public bool developer_mode { get; set; }
public ShortcutDestinations default_shortcut_destinations { get; set; }
public ThcrapDll.ShortcutsType shortcuts_type { get; set; }

Expand All @@ -66,6 +67,7 @@ public GlobalConfig()
console = ThcrapDll.globalconfig_get_boolean("console", false);
exception_detail = ThcrapDll.globalconfig_get_integer("exception_detail", 1);
codepage = ThcrapDll.globalconfig_get_integer("codepage", 932);
developer_mode = ThcrapDll.globalconfig_get_boolean("developer_mode", false);

long _default_shortcut_destinations = ThcrapDll.globalconfig_get_integer("default_shortcut_destinations",
(long)(ShortcutDestinations.Desktop | ShortcutDestinations.StartMenu));
Expand All @@ -89,6 +91,7 @@ public void Save()
ThcrapDll.globalconfig_set_boolean("console", console);
ThcrapDll.globalconfig_set_integer("exception_detail", exception_detail);
ThcrapDll.globalconfig_set_integer("codepage", codepage);
ThcrapDll.globalconfig_set_boolean("developer_mode", developer_mode);

long _default_shortcut_destinations = (long)default_shortcut_destinations | ((long)shortcuts_type << configTypeOffset);
ThcrapDll.globalconfig_set_integer("default_shortcut_destinations", _default_shortcut_destinations);
Expand Down
1 change: 1 addition & 0 deletions thcrap_configure_v3/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<StackPanel Margin="0,10,0,0">
<Label Content="Advanced" />
<CheckBox Name="developer_mode" Content="Developer mode"/>
<CheckBox Name="console" Content="Enable the log console"/>
<CheckBox Name="use_wininet" Content="Use WinInet"/>
<Grid Margin="0,5,0,0">
Expand Down
2 changes: 2 additions & 0 deletions thcrap_configure_v3/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void WindowOpened(object sender, RoutedEventArgs e)
update_at_exit.IsChecked = ThcrapDll.globalconfig_get_boolean("update_at_exit", false);
time_between_updates.Text = ThcrapDll.globalconfig_get_integer("time_between_updates", 5).ToString();

developer_mode.IsChecked = ThcrapDll.globalconfig_get_boolean("developer_mode", false);
console.IsChecked = ThcrapDll.globalconfig_get_boolean("console", false);
use_wininet.IsChecked = ThcrapDll.globalconfig_get_boolean("use_wininet", false);
codepage.Text = ThcrapDll.globalconfig_get_integer("codepage", 932).ToString();
Expand Down Expand Up @@ -111,6 +112,7 @@ private void Settings_Save(object sender, RoutedEventArgs e)
ThcrapDll.globalconfig_set_boolean("update_at_exit", update_at_exit.IsChecked == true);
ThcrapDll.globalconfig_set_integer("time_between_updates", Int32.Parse(time_between_updates.Text));

ThcrapDll.globalconfig_set_boolean("developer_mode", developer_mode.IsChecked == true);
ThcrapDll.globalconfig_set_boolean("console", console.IsChecked == true);
ThcrapDll.globalconfig_set_boolean("use_wininet", use_wininet.IsChecked == true);
ThcrapDll.globalconfig_set_integer("codepage", Int32.Parse(codepage.Text));
Expand Down

0 comments on commit 10c0f97

Please sign in to comment.