Exemplo n.º 1
0
static int write_pref(lua_State*L)
{
  const char *script = luaL_checkstring(L,1);
  const char *name = luaL_checkstring(L,2);
  const char* type_name = luaL_checkstring(L,3);
  int i;
  for (i=0; pref_type_name[i]; i++)
    if (strcmp(pref_type_name[i], type_name) == 0)
    {
      break;
    }
  if(!pref_type_name[i]) luaL_argerror(L,3,NULL);

  char pref_name[1024];
  get_pref_name(pref_name,1024,script,name);
  switch(i)
  {
    case pref_string:
      dt_conf_set_string(pref_name,luaL_checkstring(L,4));
      break;
    case pref_bool:
      luaL_checktype(L,4,LUA_TBOOLEAN);
      dt_conf_set_bool(pref_name,lua_toboolean(L,4));
      break;
    case pref_int:
      dt_conf_set_int(pref_name,luaL_checkinteger(L,4));
      break;
  }
  return 0;
}
Exemplo n.º 2
0
static int read_pref(lua_State*L)
{
  const char *script = luaL_checkstring(L,1);
  const char *name = luaL_checkstring(L,2);
  const char* type_name = luaL_checkstring(L,3);
  int i;
  for (i=0; pref_type_name[i]; i++)
    if (strcmp(pref_type_name[i], type_name) == 0)
    {
      break;
    }
  if(!pref_type_name[i]) luaL_argerror(L,3,NULL);

  char pref_name[1024];
  get_pref_name(pref_name,1024,script,name);
  switch(i)
  {
    case pref_string:
      lua_pushstring(L,dt_conf_get_string(pref_name));
      break;
    case pref_bool:
      lua_pushboolean(L,dt_conf_get_bool(pref_name));
      break;
    case pref_int:
      lua_pushnumber(L,dt_conf_get_int(pref_name));
      break;
  }
  return 1;
}
Exemplo n.º 3
0
static void response_callback_int(GtkDialog *dialog, gint response_id, pref_element* cur_elt)
{
  if(response_id == GTK_RESPONSE_ACCEPT)
  {
    char pref_name[1024];
    get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
    dt_conf_set_int(pref_name, gtk_spin_button_get_value(GTK_SPIN_BUTTON(cur_elt->widget)));
  }
}
Exemplo n.º 4
0
static void response_callback_bool(GtkDialog *dialog, gint response_id, pref_element* cur_elt)
{
  if(response_id == GTK_RESPONSE_ACCEPT)
  {
    char pref_name[1024];
    get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
    dt_conf_set_bool(pref_name, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cur_elt->widget)));
  }
}
Exemplo n.º 5
0
static void response_callback_string(GtkDialog *dialog, gint response_id, pref_element* cur_elt)
{
  if(response_id == GTK_RESPONSE_ACCEPT)
  {
    char pref_name[1024];
    get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
    dt_conf_set_string(pref_name,gtk_entry_get_text(GTK_ENTRY(cur_elt->widget)));
  }
}
Exemplo n.º 6
0
static gboolean reset_widget_int (GtkWidget *label, GdkEventButton *event, pref_element*cur_elt)
{
  if(event->type == GDK_2BUTTON_PRESS)
  {
    char pref_name[1024];
    get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(cur_elt->widget), cur_elt->int_data.default_value);
    return TRUE;
  }
  return FALSE;
}
Exemplo n.º 7
0
static gboolean reset_widget_string (GtkWidget *label, GdkEventButton *event, pref_element*cur_elt)
{
  if(event->type == GDK_2BUTTON_PRESS)
  {
    char pref_name[1024];
    get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
    gtk_entry_set_text(GTK_ENTRY(cur_elt->widget), cur_elt->string_data.default_value);
    return TRUE;
  }
  return FALSE;
}
Exemplo n.º 8
0
void dump_autoinscriptions(ang_file *f) {
	int i;
	for (i = 1; i < z_info->k_max; i++) {
		struct object_kind *k = &k_info[i];
		char name[120];
		const char *note;

		if (!k->name || !k->tval) continue;
		note = get_autoinscription(k);
		if (note) {
			get_pref_name(name, sizeof name, k->name);
			file_putf(f, "inscribe:%s:%s:%s\n", tval_find_name(k->tval), name, note);
		}
	}
}
Exemplo n.º 9
0
/* Dump objects */
void dump_objects(ang_file *fff)
{
	int i;

	file_putf(fff, "# Objects\n");

	for (i = 1; i < z_info->k_max; i++)
	{
		object_kind *k_ptr = &k_info[i];
		char name[120] = "";

		if (!k_ptr->name || !k_ptr->tval) continue;

		get_pref_name(name, sizeof name, k_ptr->name);
		file_putf(fff, "K:%s:%s:%d:%d\n", tval_find_name(k_ptr->tval),
				name, k_ptr->x_attr, k_ptr->x_char);
	}
}
Exemplo n.º 10
0
static int register_pref(lua_State*L)
{
  // to avoid leaks, we need to first get all params (which could raise errors) then alloc and fill the struct
  // this is complicated, but needed
  pref_element * built_elt = malloc(sizeof(pref_element));
  memset(built_elt,0,sizeof(pref_element));
  int cur_param =1;

  if(!lua_isstring(L,cur_param)) goto error;
  built_elt->script = strdup(lua_tostring(L,cur_param));
  cur_param++;

  if(!lua_isstring(L,cur_param)) goto error;
  built_elt->name = strdup(lua_tostring(L,cur_param));
  cur_param++;

  int i;
  const char* type_name = lua_tostring(L,cur_param);
  if(!type_name) goto error;
  for (i=0; pref_type_name[i]; i++)
    if (strcmp(pref_type_name[i], type_name) == 0)
    {
      built_elt->type =i;
      break;
    }
  if(!pref_type_name[i]) goto error;
  cur_param++;

  if(!lua_isstring(L,cur_param)) goto error;
  built_elt->label = strdup(lua_tostring(L,cur_param));
  cur_param++;

  if(!lua_isstring(L,cur_param)) goto error;
  built_elt->tooltip = strdup(lua_tostring(L,cur_param));
  cur_param++;

  char pref_name[1024];
  get_pref_name(pref_name,1024,built_elt->script,built_elt->name);
  switch(built_elt->type)
  {
    case pref_string:
      if(!lua_isstring(L,cur_param)) goto error;
      built_elt->string_data.default_value = strdup(lua_tostring(L,cur_param));
      cur_param++;

      if(!dt_conf_key_exists(pref_name)) dt_conf_set_string(pref_name,built_elt->string_data.default_value);
      break;
    case pref_bool:
      if(!lua_isboolean(L,cur_param)) goto error;
      built_elt->bool_data.default_value = lua_toboolean(L,cur_param);
      cur_param++;

      if(!dt_conf_key_exists(pref_name)) dt_conf_set_bool(pref_name,built_elt->bool_data.default_value);
      break;
    case pref_int:
      if(!lua_isnumber(L,cur_param)) goto error;
      built_elt->int_data.default_value = lua_tointeger(L,cur_param);
      cur_param++;

      if(!lua_isnumber(L,cur_param)) goto error;
      built_elt->int_data.min = lua_tointeger(L,cur_param);
      cur_param++;

      if(!lua_isnumber(L,cur_param)) goto error;
      built_elt->int_data.max = lua_tointeger(L,cur_param);
      cur_param++;

      if(!dt_conf_key_exists(pref_name)) dt_conf_set_int(pref_name,built_elt->int_data.default_value);
      break;
  }


  built_elt->next = pref_list;
  pref_list = built_elt;
  return 0;
error:
  destroy_pref_element(built_elt);
  return luaL_argerror(L,cur_param,NULL);
}
Exemplo n.º 11
0
void init_tab_lua (GtkWidget *dialog, GtkWidget *tab)
{
  if(!pref_list) return; // no option registered => don't create the tab
  char tooltip[1024];
  GtkWidget  *label, *labelev;
  GtkWidget *hbox = gtk_hbox_new(5, FALSE);
  GtkWidget *vbox1 = gtk_vbox_new(5, TRUE);
  GtkWidget *vbox2 = gtk_vbox_new(5, TRUE);
  gtk_box_pack_start(GTK_BOX(hbox), vbox1, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0);
  GtkWidget *alignment = gtk_alignment_new(0.5, 0.0, 1.0, 0.0);
  gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 20, 20, 20, 20);
  gtk_container_add(GTK_CONTAINER(alignment), hbox);
  gtk_notebook_append_page(GTK_NOTEBOOK(tab), alignment, gtk_label_new(_("lua options")));

  pref_element* cur_elt = pref_list;
  while(cur_elt)
  {
    char pref_name[1024];
    get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
    label = gtk_label_new(cur_elt->label);
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    labelev = gtk_event_box_new();
    gtk_widget_add_events(labelev, GDK_BUTTON_PRESS_MASK);
    gtk_container_add(GTK_CONTAINER(labelev), label);
    switch(cur_elt->type)
    {
      case pref_string:
        cur_elt->widget = gtk_entry_new();
        gtk_entry_set_text(GTK_ENTRY(cur_elt->widget), dt_conf_get_string(pref_name));
        g_signal_connect(G_OBJECT(cur_elt->widget), "activate", G_CALLBACK(callback_string), cur_elt);
        snprintf(tooltip, 1024, _("double click to reset to `%s'"), cur_elt->string_data.default_value);
        g_signal_connect(G_OBJECT(labelev), "button-press-event", G_CALLBACK(reset_widget_string), cur_elt);
        g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_string), cur_elt);
        break;
      case pref_bool:
        cur_elt->widget = gtk_check_button_new();
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cur_elt->widget), dt_conf_get_bool(pref_name));
        g_signal_connect(G_OBJECT(cur_elt->widget), "toggled", G_CALLBACK(callback_bool), cur_elt);
        snprintf(tooltip, 1024, _("double click to reset to `%s'"), cur_elt->bool_data.default_value?"true":"false");
        g_signal_connect(G_OBJECT(labelev), "button-press-event", G_CALLBACK(reset_widget_bool), cur_elt);
        g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_bool), cur_elt);
        break;
      case pref_int:
        cur_elt->widget = gtk_spin_button_new_with_range(cur_elt->int_data.min, cur_elt->int_data.max, 1);
        gtk_spin_button_set_digits(GTK_SPIN_BUTTON(cur_elt->widget), 0);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(cur_elt->widget), dt_conf_get_int(pref_name));
        g_signal_connect(G_OBJECT(cur_elt->widget), "value-changed", G_CALLBACK(callback_int), cur_elt);
        snprintf(tooltip, 1024, _("double click to reset to `%d'"), cur_elt->int_data.default_value);
        g_signal_connect(G_OBJECT(labelev), "button-press-event", G_CALLBACK(reset_widget_int), cur_elt);
        g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_int), cur_elt);
        break;
    }
    gtk_object_set(GTK_OBJECT(labelev),  "tooltip-text", tooltip, (char *)NULL);
    gtk_event_box_set_visible_window(GTK_EVENT_BOX(labelev), FALSE);
    gtk_object_set(GTK_OBJECT(cur_elt->widget), "tooltip-text", cur_elt->tooltip, (char *)NULL);
    gtk_box_pack_start(GTK_BOX(vbox1), labelev, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox2), cur_elt->widget, FALSE, FALSE, 0);
    cur_elt = cur_elt->next;
  }
}
Exemplo n.º 12
0
static void callback_int(GtkWidget *widget, pref_element*cur_elt )
{
  char pref_name[1024];
  get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
  dt_conf_set_int(pref_name, gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget)));
}
Exemplo n.º 13
0
static void callback_bool(GtkWidget *widget, pref_element*cur_elt )
{
  char pref_name[1024];
  get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
  dt_conf_set_bool(pref_name,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
}
Exemplo n.º 14
0
static void callback_string(GtkWidget *widget, pref_element*cur_elt )
{
  char pref_name[1024];
  get_pref_name(pref_name,1024,cur_elt->script,cur_elt->name);
  dt_conf_set_string(pref_name,gtk_entry_get_text(GTK_ENTRY(widget)));
}