示例#1
0
void b_open_autowin( )
{
	int y, yi, w, h, mpos;
	int btn_w;
	
	w = 650;
	h = 200;
	yi = 30;
	mpos = 120;
	
	if ( autowin == 0 )
	{
		bounds_t *b = new_bounds( -1, -1, w, h );
		layout_t *lt;
		
		autowin = window_widget_create( bersirc->mainwin, b, cWindowModalDialog | cWindowCenterParent );
		window_set_icon( autowin, b_icon( "bersirc" ) );
		window_set_title( autowin, lang_phrase_quick( "autoconnectwin" ) );
		object_addhandler( autowin, "destroy", b_autowin_killed );
		object_addhandler( autowin, "closing", b_autowin_closing );
		
		lt = layout_create( autowin, "[][_<|list|<][][{25}<|btnadd|<|btnedit|<|btndelete|<|btncancel|<][]", *b, 10, 10 );
		
		y = 10;
		
		autowin_servlist = listview_widget_create( autowin, lt_bounds(lt,"list"), 3, 0,
				"", cListViewTypeCheckBox,
				lang_phrase_quick( "serveraddy" ), cListViewTypeText,
				lang_phrase_quick( "channels" ), cListViewTypeText
			 );
		
		btn_w = ((w-20-20)/4);
		
		btnadd = button_widget_create_with_label( autowin, lt_bounds(lt,"btnadd"), 0, lang_phrase_quick( "addserver" ) );
		btnedit = button_widget_create_with_label( autowin, lt_bounds(lt,"btnedit"), 0, lang_phrase_quick( "editserver" ) );
		btndelete = button_widget_create_with_label( autowin, lt_bounds(lt,"btndelete"), 0, lang_phrase_quick( "deleteserver" ) );
		btncancel = button_widget_create_with_label( autowin, lt_bounds(lt,"btncancel"), 0, lang_phrase_quick( "close" ) );
		
		// no edit or delete until selected
		widget_disable( OBJECT( btndelete ) );
		widget_disable( OBJECT( btnedit ) );
		
		object_addhandler( autowin_servlist, "selected", b_autowin_serversel );
		object_addhandler( btnadd, "pushed", b_autowin_add );
		object_addhandler( btnedit, "pushed", b_autowin_edit );
		object_addhandler( btndelete, "pushed", b_autowin_delete );
		object_addhandler( btncancel, "pushed", b_autowin_close );
		
		window_show( autowin );
		
		b_autowin_gui_init( );
	}
	else
	{
		widget_focus( OBJECT( autowin ) );
	}
}
示例#2
0
void
widget_select (Widget * w)
{
    WDialog *h;

    if (!widget_get_options (w, WOP_SELECTABLE))
        return;

    h = w->owner;
    if (h != NULL)
    {
        if (widget_get_options (w, WOP_TOP_SELECT))
        {
            GList *l;

            l = dlg_find (h, w);
            widget_reorder (l, TRUE);
        }

        widget_focus (w);
    }
}
示例#3
0
void create_autoeditwin( list_item_t *item )
{
	int w, h, btn_w;
	char *srv_title, *chan_title, *srv_text, *chn_text;
	int text_w, c;
	object_t *aew_lbl_server, *aew_lbl_channels;
	layout_t *lt;
	bounds_t *b;
	char lt_str[512];
	int enable = 1;
	
	aew_edit_item = item;
	
	w = 400;
	h = 150;
	btn_w = (w-20-(10*(2-1))) / 2;
	
	b = new_bounds( -1, -1, w, h );
	autoeditwin = window_widget_create( bersirc->mainwin, b, cWindowModalDialog | cWindowCenterParent );
	window_set_icon( autoeditwin, b_icon("bersirc") );
	window_set_title( autoeditwin, lang_phrase_quick( (item==0?"addserver_t":"editserver_t") ) );
	object_addhandler( autoeditwin, "destroy", b_autoeditwin_killed );
	
	// input
	
	srv_title = lang_phrase_quick( "serveraddy_inp" );
	chan_title = lang_phrase_quick( "channels_inp" );
	
	srv_text = "";
	chn_text = "";
	
	if ( item != 0 )
	{
		int *ip = item->data[0];
		enable = *ip;
		srv_text = item->data[1];
		chn_text = item->data[2];
	}
	
	text_w = widget_font_string_width( bersirc->mainwin, srv_title, strlen( srv_title ) );
	c = widget_font_string_width( bersirc->mainwin, chan_title, strlen( chan_title ) );
	if ( c > text_w )
		text_w = c;
	
	sprintf( lt_str, "[][{25}<|(%d)lblserver|<|txtserver|<][][{25}<|(%d)lblchannels|<|txtchannels|<]"
					 "[][{25}<|enabled|<][][{25}<|btnsave|<|btncancel|<]", text_w, text_w );
	lt = layout_create( autoeditwin, lt_str, *b, 10, 10 );
	
	aew_lbl_server = label_widget_create_with_text( autoeditwin, lt_bounds(lt,"lblserver"), 0, srv_title );
	aew_txt_server = textbox_widget_create( autoeditwin, lt_bounds(lt,"txtserver"), 0 );
	textbox_set_text( aew_txt_server, srv_text );
	
	aew_lbl_channels = label_widget_create_with_text( autoeditwin, lt_bounds(lt,"lblchannels"), 0, chan_title );
	aew_txt_channels = textbox_widget_create( autoeditwin, lt_bounds(lt,"txtchannels"), 0 );
	textbox_set_text( aew_txt_channels, chn_text );
	
	object_addhandler( autoeditwin, "dialog_ok", b_autoeditwin_save );
	object_addhandler( aew_txt_server, "changed", b_autoeditwin_txtchanged );
	
	widget_focus( aew_txt_server );
	
	aew_cbx_enabled = checkbox_widget_create_with_label( autoeditwin, lt_bounds(lt,"enabled"), 0, lang_phrase_quick( "autoitemenable" ) );
	checkbox_set_checked( aew_cbx_enabled, enable );
	
	// buttons
	
	aw_btnsave = button_widget_create_with_label( autoeditwin, lt_bounds(lt,"btnsave"), 0, lang_phrase_quick( "save" ) );
	aw_btncancel = button_widget_create_with_label( autoeditwin, lt_bounds(lt,"btncancel"), 0, lang_phrase_quick( "cancel" ) );
	
	object_addhandler( aw_btnsave, "pushed", b_autoeditwin_save );
	object_addhandler( aw_btncancel, "pushed", b_autoeditwin_close );
	
	if ( item == 0 )
		widget_disable( OBJECT( aw_btnsave ) );
	
	window_show( autoeditwin );
}
void widget_new_trait_info_window(trait_t trait, bool enable_controls)
{
  struct trait * traitdata;
  
  traitdata = trait_get(trait);
  if(traitdata != NULL)
    {
      char buf[128];
      struct widget * window;

      snprintf(buf, sizeof buf, "%s: %s", gettext("Trait"), trait_get_name(trait));
      window = widget_new_window(widget_root(), 420, 200, buf);
      assert(window != NULL);
      if(window != NULL)
        {
          int y;

          widget_set_modal(window);
          widget_set_image_pointer(window, "raw_image", gfx_image(traitdata->image_id));
          widget_set_widget_pointer(window, "previously_selected_object", widget_focus());

          y = 40 + font_height();

          char ** description;
          char fn[1024];
          
          snprintf(fn, sizeof fn, "data/trait-%s", traitdata->filename);
          description = read_localized_text_file(get_data_filename(fn));
          if(description != NULL)
            {
              for(int i = 0; description[i] != NULL; i++)
                {
                  widget_new_text(window, 10, y, description[i]);
                  free(description[i]);
                  y += font_height();
                }
              free(description);
            }

          y += font_height() * 2;

          struct widget * prev;
          
          prev = NULL;
          if(enable_controls)
            {
              if(traits_get_active() & trait)
                {
                  struct widget * t;

                  t = widget_new_text(window, 10, y, gettext("You have this trait."));
                  if(traits_get_active() & TRAIT_RECYCLER)
                    {
                      struct widget * b;

                      snprintf(buf + 1, (sizeof buf) - 1, gettext("Recycle for %lu"), (long unsigned) traitdata->cost * 90 / 100);
                      buf[0] = ' '; snprintf(buf + strlen(buf), sizeof buf - strlen(buf), " "); /* Pad with spaces */
                      b = widget_new_button(window, widget_x(t) + widget_width(t) + 10, y, buf);
                      widget_set_on_release(b, on_recycle_trait_clicked);
                      widget_set_ulong(b, "trait", trait);
                      y += widget_height(b);
                      prev = b;
                    }
                  y += font_height();

                  if(trait == TRAIT_EDIT)
                    {
                      struct widget * b;

                      y += font_height();
                      snprintf(buf, sizeof buf, " %s ", gettext("Edit cave"));
                      b = widget_new_button(window, 0, y, buf);
                      widget_set_on_release(b, on_edit_trait_clicked);
                      widget_center_horizontally(b);
                      y += widget_height(b);
                      if(prev != NULL)
                        widget_set_navigation_updown(prev, b);
                      prev = b;
                    }
              
                  y += font_height();
                }
              else if(traits_get_available() & trait)
                {
                  struct widget * t;
                  
                  t = widget_new_text(window, 10, y, gettext("You don't have this trait."));
                  if(traits_get_score() >= traitdata->cost)
                    {
                      struct widget * b;

                      snprintf(buf, sizeof buf, " %s ", gettext("Buy"));
                      b = widget_new_button(window, widget_x(t) + widget_width(t) + 10, y, buf);
                      widget_set_on_release(b, on_buy_trait_clicked);
                      widget_set_ulong(b, "trait", trait);
                      if(prev != NULL)
                        widget_set_navigation_updown(prev, b);
                      prev = b;
                    }
                  y += font_height();
                  
                  widget_new_text(window, 10, y, gettext("Cost:"));
                  snprintf(buf, sizeof buf, "%u", (unsigned int) traitdata->cost);
                  widget_new_text(window, 100, y, buf);
                  y += font_height();
                  
                  widget_new_text(window, 10, y, gettext("You have:"));
                  snprintf(buf, sizeof buf, "%u", (unsigned int) traits_get_score());
                  if( ! (traits_get_active() & trait) )
                    if(traits_get_score() < traitdata->cost)
                      snprintf(buf + strlen(buf), sizeof buf - strlen(buf), gettext(" [need %u more]"), (unsigned int) (traitdata->cost - traits_get_score()));
                  widget_new_text(window, 100, y, buf);
                  y += font_height();
                }
              else
                {
                  unsigned int level;
                  
                  level = traitdata->cave_level;
                  if(level == 0)
                    level = get_cave_level_count(traitdata->cave_name);
                  snprintf(buf, sizeof buf, gettext("Level required: %u"), level);
                  widget_new_text(window, 10, y, buf);
                  y += font_height();
                }

              y += font_height();
            }

          struct widget * closebutton;

          snprintf(buf, sizeof buf, "  %s  ", gettext("Close"));
          closebutton = widget_new_button(window, 0, y, buf);
          widget_set_x(closebutton, (widget_width(window) - widget_width(closebutton)) / 2);
          widget_set_focus(closebutton);
          y += widget_height(closebutton);
          if(prev != NULL)
            widget_set_navigation_updown(prev, closebutton);


          widget_resize_to_fit_children(window);
          widget_set_width(window, widget_width(window) + 10);
          widget_set_height(window, widget_height(window) + 10);
          widget_center(window);

          ui_wait_for_window_close(window, closebutton);
        }
    }
}