diff --git a/Makefile b/Makefile index d79c5f4..2d89e7e 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ endif # for internal functions, so let's "ignore" it. CFLAGS+=-Wno-error=deprecated-declarations -VERSION:=0.10.0-rc1 +VERSION:=0.10.1 .PHONY: ./build/gmcpil diff --git a/src/callbacks.c b/src/callbacks.c index 2a2aa78..ea00bde 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -151,18 +151,24 @@ void settings_cb(__attribute__((unused)) GtkWidget* button, __attribute__((unuse { const char* username; const char* distance; - GtkEntryBuffer* gtk_buff; + const char* hud; + GtkEntryBuffer* username_buff; + GtkEntryBuffer* hud_buff; - gtk_buff = gtk_entry_get_buffer(GTK_ENTRY(settings_box.username_entry)); + username_buff = gtk_entry_get_buffer(GTK_ENTRY(settings_box.username_entry)); + hud_buff = gtk_entry_get_buffer(GTK_ENTRY(settings_box.hud_entry)); - username = gtk_entry_buffer_get_text(gtk_buff); + username = gtk_entry_buffer_get_text(username_buff); distance = gtk_combo_box_text_get_active_text(settings_box.distance_combo); + hud = gtk_entry_buffer_get_text(hud_buff); setenv("MCPI_USERNAME", username, 1); setenv("MCPI_RENDER_DISTANCE", distance, 1); + setenv("GALLIUM_HUD", hud, 1); mcpil_config_set_username(config, username); mcpil_config_set_distance(config, distance); + mcpil_config_set_hud(config, hud); mcpil_config_save(config); return; } diff --git a/src/config.c b/src/config.c index 80f9126..eea71df 100644 --- a/src/config.c +++ b/src/config.c @@ -28,15 +28,16 @@ #include #include -struct MCPILConfigPrivate +struct __attribute__((packed)) MCPILConfigPrivate { gchar* ip; gchar* port; gchar* username; gchar* features; gchar* distance; - gchar* filename; gchar* last_profile; + gchar* hud; + gchar* filename; }; enum @@ -47,7 +48,9 @@ enum PROP_USERNAME, PROP_FEATURES, PROP_DISTANCE, - PROP_LAST_PROFILE + PROP_LAST_PROFILE, + PROP_HUD, + PROP_LAST }; G_DEFINE_TYPE_WITH_CODE(MCPILConfig, mcpil_config, G_TYPE_OBJECT, G_ADD_PRIVATE(MCPILConfig)) @@ -83,57 +86,42 @@ static void mcpil_config_class_init(MCPILConfigClass* klass) pspec = g_param_spec_string("last_profile", "Last profile", "Last selected profile", NULL, G_PARAM_READWRITE); g_object_class_install_property(gobject_class, PROP_LAST_PROFILE, pspec); + + pspec = g_param_spec_string("hud", "Gallium HUD", "Gallium HUD options", NULL, G_PARAM_READWRITE); + g_object_class_install_property(gobject_class, PROP_HUD, pspec); return; } static void mcpil_config_init(MCPILConfig* self) { + int i = 0; MCPILConfigPrivate* private = MCPIL_CONFIG_PRIVATE(self); + gchar** private_gchar = (gchar**)(private); - private->ip = NULL; - private->port = 0; - private->username = NULL; - private->features = NULL; - private->distance = NULL; - private->last_profile = NULL; + while (i < PROP_LAST - 1) + { + private_gchar[i] = NULL; + i++; + } return; } static void mcpil_config_finalize(GObject* obj) { + int i = 0; MCPILConfig* self = MCPIL_CONFIG(obj); MCPILConfigPrivate* private = MCPIL_CONFIG_PRIVATE(self); GObjectClass* parent_class = G_OBJECT_CLASS(mcpil_config_parent_class); + gchar** private_gchar = (gchar**)(private); - if (private->ip != NULL) - { - g_free(private->ip); - } - if (private->port != NULL) - { - g_free(private->port); - } - if (private->username != NULL) - { - g_free(private->username); - } - if (private->features != NULL) - { - g_free(private->features); - } - if (private->distance != NULL) + while (i < PROP_LAST - 1) { - g_free(private->distance); + if (private_gchar[i] != NULL) + { + g_free(private_gchar[i]); + } + i++; } - if (private->filename != NULL) - { - g_free(private->filename); - } - if (private->last_profile != NULL) - { - g_free(private->last_profile); - } - (*parent_class->finalize)(obj); return; } @@ -144,34 +132,20 @@ GETTER_SETTER(gchar*, username); GETTER_SETTER(gchar*, features); GETTER_SETTER(gchar*, distance); GETTER_SETTER(gchar*, last_profile); +GETTER_SETTER(gchar*, hud); static void mcpil_config_set_property(GObject* obj, guint prop_id, const GValue* value, GParamSpec* pspec) { MCPILConfig* self = MCPIL_CONFIG(obj); + MCPILConfigPrivate* private = MCPIL_CONFIG_PRIVATE(self); + gchar** private_gchar = (gchar**)(private); - switch (prop_id) + if (prop_id <= PROP_LAST) { - case PROP_IP: - mcpil_config_set_ip(self, g_value_get_string(value)); - break; - case PROP_PORT: - mcpil_config_set_port(self, g_value_get_string(value)); - break; - case PROP_USERNAME: - mcpil_config_set_username(self, g_value_get_string(value)); - break; - case PROP_FEATURES: - mcpil_config_set_features(self, g_value_get_string(value)); - break; - case PROP_DISTANCE: - mcpil_config_set_distance(self, g_value_get_string(value)); - break; - case PROP_LAST_PROFILE: - mcpil_config_set_last_profile(self, g_value_get_string(value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); - break; + private_gchar[prop_id - 1] = g_strdup((gchar*)g_value_get_string(value)); + } else + { + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); } return; } @@ -180,29 +154,15 @@ static void mcpil_config_get_property(GObject* obj, guint prop_id, GValue* value { MCPILConfig* self = MCPIL_CONFIG(obj); - switch (prop_id) + MCPILConfigPrivate* private = MCPIL_CONFIG_PRIVATE(self); + gchar** private_gchar = (gchar**)(private); + + if (prop_id <= PROP_LAST) + { + g_value_set_string(value, private_gchar[prop_id - 1]); + } else { - case PROP_IP: - g_value_set_string(value, mcpil_config_get_ip(self)); - break; - case PROP_PORT: - g_value_set_string(value, mcpil_config_get_port(self)); - break; - case PROP_USERNAME: - g_value_set_string(value, mcpil_config_get_username(self)); - break; - case PROP_FEATURES: - g_value_set_string(value, mcpil_config_get_features(self)); - break; - case PROP_DISTANCE: - g_value_set_string(value, mcpil_config_get_distance(self)); - break; - case PROP_LAST_PROFILE: - g_value_set_string(value, mcpil_config_get_last_profile(self)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); - break; + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); } return; } diff --git a/src/include/config.h b/src/include/config.h index c16cc04..1820bc0 100644 --- a/src/include/config.h +++ b/src/include/config.h @@ -76,6 +76,7 @@ void mcpil_config_set_username(MCPILConfig* self, const gchar* username); void mcpil_config_set_features(MCPILConfig* self, const gchar* features); void mcpil_config_set_distance(MCPILConfig* self, const gchar* distance); void mcpil_config_set_last_profile(MCPILConfig* self, const gchar* profile); +void mcpil_config_set_hud(MCPILConfig* self, const gchar* hud); gchar* mcpil_config_get_ip(MCPILConfig* self); gchar* mcpil_config_get_port(MCPILConfig* self); @@ -83,6 +84,7 @@ gchar* mcpil_config_get_username(MCPILConfig* self); gchar* mcpil_config_get_features(MCPILConfig* self); gchar* mcpil_config_get_distance(MCPILConfig* self); gchar* mcpil_config_get_last_profile(MCPILConfig* self); +gchar* mcpil_config_get_hud(MCPILConfig* self); int mcpil_config_save(MCPILConfig* self); diff --git a/src/include/mcpil.h b/src/include/mcpil.h index f331164..e0baecf 100644 --- a/src/include/mcpil.h +++ b/src/include/mcpil.h @@ -27,10 +27,10 @@ #include #include -#define MCPIL_MAJOR 0 -#define MCPIL_MINOR 10 -#define MCPIL_PATCH 0 -#define MCPIL_VERSION "v0.10.0" +#define GMCPIL_MAJOR 0 +#define GMCPIL_MINOR 10 +#define GMCPIL_PATCH 0 +#define GMCPIL_VERSION "v0.10.0" #define STR(str) #str #define SAFE_ATOI(str) strtol(str ? str : "", NULL, 10) @@ -68,9 +68,10 @@ typedef void* feature_t[2]; typedef struct settings_box_t { - GtkWidget* ip_entry; - GtkWidget* port_entry; + GtkEntry* ip_entry; + GtkEntry* port_entry; GtkEntry* username_entry; + GtkEntry* hud_entry; GtkComboBoxText* distance_combo; char* buff; } settings_box_t; @@ -113,7 +114,6 @@ GtkWidget* Features_tab(GtkWidget* notebook); GtkWidget* Multiplayer_tab(GtkWidget* notebook); GtkWidget* Settings_tab(GtkWidget* notebook); GtkWidget* About_tab(GtkWidget* notebook); -GtkWidget* advanced_settings(GtkWidget* parent); /* Variable declarations */ GtkWidget* window; diff --git a/src/tabs.c b/src/tabs.c index 01e2087..f362a87 100644 --- a/src/tabs.c +++ b/src/tabs.c @@ -181,12 +181,15 @@ TAB(Multiplayer, "Multiplayer", "Save", multiplayer_cb, { } ip_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - ip_label = gtk_label_new("IP Address:"); + ip_label = gtk_label_new("IP Address"); ip_entry = gtk_entry_new_with_buffer(gtk_entry_buffer_new(default_ip, strlen(default_ip))); + gtk_entry_set_width_chars(GTK_ENTRY(ip_entry), 25); port_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - port_label = gtk_label_new("Port:"); + port_label = gtk_label_new("Port"); port_entry = gtk_entry_new_with_buffer(gtk_entry_buffer_new(default_port, strlen(default_port))); + gtk_entry_set_width_chars(GTK_ENTRY(port_entry), 25); + gtk_entry_set_input_purpose(GTK_ENTRY(port_entry), GTK_INPUT_PURPOSE_DIGITS); gtk_box_pack_start(GTK_BOX(ip_hbox), ip_label, FALSE, FALSE, 10); gtk_box_pack_end(GTK_BOX(ip_hbox), ip_entry, FALSE, FALSE, 10); @@ -203,8 +206,8 @@ TAB(Multiplayer, "Multiplayer", "Save", multiplayer_cb, { gtk_box_pack_start(GTK_BOX(tab), port_hbox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(tab), notice_label, FALSE, FALSE, 10); - settings_box.ip_entry = ip_entry; - settings_box.port_entry = port_entry; + settings_box.ip_entry = GTK_ENTRY(ip_entry); + settings_box.port_entry = GTK_ENTRY(port_entry); setenv("GMCPIL_SERVER_IP", default_ip, 1); setenv("GMCPIL_SERVER_PORT", default_port, 1); }); @@ -214,15 +217,20 @@ TAB(Settings, "Settings", "Save", settings_cb, { int distance_int; char* default_username; char* default_distance; + char* default_hud; GtkWidget* username_hbox; GtkWidget* username_label; GtkWidget* username_entry; GtkWidget* distance_hbox; GtkWidget* distance_label; GtkWidget* distance_combo; + GtkWidget* hud_hbox; + GtkWidget* hud_label; + GtkWidget* hud_entry; default_distance = mcpil_config_get_distance(config); default_username = mcpil_config_get_username(config); + default_hud = mcpil_config_get_hud(config); if (default_distance == NULL) { default_distance = "Normal"; @@ -233,19 +241,22 @@ TAB(Settings, "Settings", "Save", settings_cb, { default_username = "StevePi"; mcpil_config_set_username(config, default_username); } + if (default_hud == NULL) + { + default_hud = "simple,fps"; + mcpil_config_set_username(config, default_hud); + } distance_int = get_distance(default_distance); username_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - username_label = gtk_label_new("Username:"); - + username_label = gtk_label_new("Username"); username_entry = gtk_entry_new_with_buffer(gtk_entry_buffer_new(default_username, strlen(default_username))); + gtk_entry_set_width_chars(GTK_ENTRY(username_entry), 25); distance_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - distance_label = gtk_label_new("Rendering distance:"); - + distance_label = gtk_label_new("Rendering distance"); distance_combo = gtk_combo_box_text_new(); - while (i < 4) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(distance_combo), distances[i]); @@ -253,20 +264,31 @@ TAB(Settings, "Settings", "Save", settings_cb, { } gtk_combo_box_set_active(GTK_COMBO_BOX(distance_combo), distance_int); + hud_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + hud_label = gtk_label_new("Gallium HUD options"); + hud_entry = gtk_entry_new_with_buffer(gtk_entry_buffer_new(default_hud, strlen(default_hud))); + gtk_entry_set_width_chars(GTK_ENTRY(hud_entry), 25); + gtk_box_pack_start(GTK_BOX(username_hbox), username_label, FALSE, FALSE, 10); - gtk_box_pack_start(GTK_BOX(username_hbox), username_entry, TRUE, TRUE, 10); + gtk_box_pack_end(GTK_BOX(username_hbox), username_entry, FALSE, FALSE, 10); gtk_box_pack_start(GTK_BOX(distance_hbox), distance_label, FALSE, FALSE, 10); - gtk_box_pack_start(GTK_BOX(distance_hbox), distance_combo, TRUE, TRUE, 10); + gtk_box_pack_end(GTK_BOX(distance_hbox), distance_combo, FALSE, FALSE, 10); + + gtk_box_pack_start(GTK_BOX(hud_hbox), hud_label, FALSE, FALSE, 10); + gtk_box_pack_end(GTK_BOX(hud_hbox), hud_entry, FALSE, FALSE, 10); gtk_box_pack_start(GTK_BOX(tab), username_hbox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(tab), distance_hbox, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(tab), hud_hbox, FALSE, FALSE, 0); settings_box.username_entry = GTK_ENTRY(username_entry); settings_box.distance_combo = GTK_COMBO_BOX_TEXT(distance_combo); + settings_box.hud_entry = GTK_ENTRY(hud_entry); setenv("MCPI_USERNAME", default_username, 1); setenv("MCPI_RENDER_DISTANCE", distances[distance_int], 1); + setenv("GALLIUM_HUD", default_hud, 1); }); TAB(About, "Minecraft Pi Launcher", "Help", about_cb, { @@ -293,7 +315,7 @@ TAB(About, "Minecraft Pi Launcher", "Help", about_cb, { } info_label = gtk_label_new(NULL); - gtk_label_set_markup(GTK_LABEL(info_label), "" MCPIL_VERSION "\nby all its contributors"); + gtk_label_set_markup(GTK_LABEL(info_label), "" GMCPIL_VERSION "\nby all its contributors"); gtk_label_set_justify(GTK_LABEL(info_label), GTK_JUSTIFY_CENTER); link = gtk_link_button_new_with_label(MCPIL_REPO_URL, MCPIL_REPO_URL);