More cheat window improvements.

This commit is contained in:
Brandon Wright 2018-06-05 19:17:17 -05:00
parent 96b49634f2
commit 6b738e496e
3 changed files with 204 additions and 67 deletions

View File

@ -35,6 +35,18 @@ event_add_code (GtkButton *button, gpointer data)
((Snes9xCheats *) data)->add_code (); ((Snes9xCheats *) data)->add_code ();
} }
static void
event_update_code (GtkButton *button, gpointer data)
{
((Snes9xCheats *) data)->update_code ();
}
static void
event_disable_all (GtkButton *button, gpointer data)
{
((Snes9xCheats *) data)->disable_all ();
}
static void static void
event_remove_code (GtkButton *button, gpointer data) event_remove_code (GtkButton *button, gpointer data)
{ {
@ -114,8 +126,10 @@ Snes9xCheats::Snes9xCheats (void)
GtkBuilderWindowCallbacks callbacks[] = GtkBuilderWindowCallbacks callbacks[] =
{ {
{ "add_code", G_CALLBACK (event_add_code) }, { "add_code", G_CALLBACK (event_add_code) },
{ "update_code", G_CALLBACK (event_update_code) },
{ "remove_code", G_CALLBACK (event_remove_code) }, { "remove_code", G_CALLBACK (event_remove_code) },
{ "search_database", G_CALLBACK (event_search_database) }, { "search_database", G_CALLBACK (event_search_database) },
{ "disable_all", G_CALLBACK (event_disable_all) },
{ "delete_all_cheats", G_CALLBACK (event_delete_all_cheats) }, { "delete_all_cheats", G_CALLBACK (event_delete_all_cheats) },
{ NULL, NULL} { NULL, NULL}
}; };
@ -342,6 +356,7 @@ Snes9xCheats::refresh_tree_view (void)
-1); -1);
delete[] str; delete[] str;
} }
enable_dnd (true); enable_dnd (true);
return; return;
@ -358,12 +373,31 @@ Snes9xCheats::add_code (void)
description = _("No description"); description = _("No description");
if (S9xAddCheatGroup (description, code) < 0) if (S9xAddCheatGroup (description, code) < 0)
{
display_errorbox (_("Couldn't find any cheat codes in input.")); display_errorbox (_("Couldn't find any cheat codes in input."));
return;
}
code = (const gchar *) S9xCheatGroupToText (Cheat.g.size () - 1);
set_entry_text ("code_entry", code);
delete[] code;
gtk_widget_grab_focus (get_widget ("code_entry")); gtk_widget_grab_focus (get_widget ("code_entry"));
refresh_tree_view (); refresh_tree_view ();
while (gtk_events_pending ())
gtk_main_iteration ();
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (get_widget ("cheat_treeview")));
GtkTreePath *path = gtk_tree_path_new_from_indices (Cheat.g.size () - 1, -1);
gtk_tree_selection_select_path (selection, path);
gtk_tree_path_free (path);
GtkScrolledWindow *scroll = GTK_SCROLLED_WINDOW (get_widget ("cheat_scrolledwindow"));
GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (scroll);
gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));
return; return;
} }
@ -505,6 +539,52 @@ Snes9xCheats::toggle_code (const gchar *path, int enabled)
else else
S9xDisableCheatGroup (index); S9xDisableCheatGroup (index);
return;
}
void
Snes9xCheats::update_code (void)
{
int index = get_selected_index ();
if (index < 0)
return;
const char *description;
char *code = (char *) get_entry_text ("code_entry");
description = get_entry_text ("description_entry");
if (description[0] == '\0')
description = _("No description");
code = S9xCheatValidate (code);
if (!code)
{
display_errorbox (_("Couldn't find any cheat codes in input."));
return;
}
S9xModifyCheatGroup (index, description, code);
set_entry_text ("code_entry", code);
delete[] code;
gtk_widget_grab_focus (get_widget ("code_entry"));
refresh_tree_view ();
return;
}
void
Snes9xCheats::disable_all (void)
{
for (unsigned int i = 0; i < Cheat.g.size(); i++)
{
if (Cheat.g[i].enabled)
S9xDisableCheatGroup (i);
}
refresh_tree_view ();
return; return;
} }

View File

@ -23,6 +23,8 @@ class Snes9xCheats : public GtkBuilderWindow
void row_inserted (int row); void row_inserted (int row);
void enable_dnd (bool); void enable_dnd (bool);
void sort_cheats (void); void sort_cheats (void);
void update_code (void);
void disable_all (void);
private: private:
void refresh_tree_view (void); void refresh_tree_view (void);

View File

@ -277,7 +277,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">2</property> <property name="spacing">3</property>
<child internal-child="action_area"> <child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area3"> <object class="GtkHButtonBox" id="dialog-action_area3">
<property name="visible">True</property> <property name="visible">True</property>
@ -319,7 +319,7 @@
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
<property name="shadow_type">in</property> <property name="shadow_type">in</property>
<child> <child>
<object class="GtkScrolledWindow" id="scrolledwindow9"> <object class="GtkScrolledWindow" id="cheat_scrolledwindow">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -350,67 +350,6 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="spacing">5</property> <property name="spacing">5</property>
<child>
<object class="GtkLabel" id="label141">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Code:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="code_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="activates_default">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label140">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Description:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="description_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">1024</property>
<property name="activates_default">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child> <child>
<object class="GtkButton" id="button4"> <object class="GtkButton" id="button4">
<property name="label">gtk-add</property> <property name="label">gtk-add</property>
@ -426,7 +365,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">4</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -442,7 +381,38 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">5</property> <property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="update_button">
<property name="label" translatable="yes">Update Cheat</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<signal name="clicked" handler="update_code" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="disable_all_button">
<property name="label" translatable="yes">Disable All</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="disable_all" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -457,7 +427,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">6</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -472,7 +442,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">7</property> <property name="position">5</property>
</packing> </packing>
</child> </child>
</object> </object>
@ -489,6 +459,91 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<!-- Code and description table -->
<object class="GtkTable" id="code_and_description_table">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">5</property>
<child>
<object class="GtkLabel" id="label141">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Code:</property>
</object>
<packing>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="code_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="activates_default">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL|GTK_EXPAND</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label140">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Description:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="description_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">1024</property>
<property name="activates_default">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL|GTK_EXPAND</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
</child>
</object> </object>
</child> </child>
<action-widgets> <action-widgets>