Пример #1
0
/**************************************************************************
  Popup the yes/no dialog for inciting, since we know the cost now
**************************************************************************/
void popup_incite_dialog(struct city *pcity, int cost)
{
  char tbuf[128], buf[128];

  fc_snprintf(tbuf, ARRAY_SIZE(tbuf), PL_("Treasury contains %d gold.",
                                          "Treasury contains %d gold.",
                                          client_player()->economic.gold),
              client_player()->economic.gold);

  if (INCITE_IMPOSSIBLE_COST == cost) {
    fc_snprintf(buf, sizeof(buf), _("You can't incite a revolt in %s."),
		city_name(pcity));
    popup_message_dialog(toplevel, "diplomatnogolddialog", buf,
			 diplomat_incite_no_callback, 0, 0, NULL);
  } else if (cost <= client_player()->economic.gold) {
    fc_snprintf(buf, sizeof(buf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Incite a revolt for %d gold?\n%s",
                    "Incite a revolt for %d gold?\n%s", cost), cost, tbuf);
    diplomat_target_id = pcity->id;
    popup_message_dialog(toplevel, "diplomatrevoltdialog", buf,
                         diplomat_incite_yes_callback, 0, 0,
                         diplomat_incite_no_callback, 0, 0,
                         NULL);
  } else {
    fc_snprintf(buf, sizeof(buf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Inciting a revolt costs %d gold.\n%s",
                    "Inciting a revolt costs %d gold.\n%s", cost), cost, tbuf);
    popup_message_dialog(toplevel, "diplomatnogolddialog", buf,
                         diplomat_incite_no_callback, 0, 0,
                         NULL);
  }
}
Пример #2
0
/****************************************************************
  Popup unit bribe dialog
*****************************************************************/
void popup_bribe_dialog(struct unit *punit, int cost)
{
    GtkWidget *shell;
    char buf[1024];

    fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Treasury contains %d gold.",
                                          "Treasury contains %d gold.",
                                          client_player()->economic.gold),
                client_player()->economic.gold);

    if (cost <= client_player()->economic.gold) {
        shell = gtk_message_dialog_new(NULL, 0,
                                       GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
                                       /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                                       PL_("Bribe unit for %d gold?\n%s",
                                           "Bribe unit for %d gold?\n%s", cost), cost, buf);
        gtk_window_set_title(GTK_WINDOW(shell), _("Bribe Enemy Unit"));
        setup_dialog(shell, toplevel);
    } else {
        shell = gtk_message_dialog_new(NULL, 0,
                                       GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
                                       /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                                       PL_("Bribing the unit costs %d gold.\n%s",
                                           "Bribing the unit costs %d gold.\n%s", cost), cost, buf);
        gtk_window_set_title(GTK_WINDOW(shell), _("Traitors Demand Too Much!"));
        setup_dialog(shell, toplevel);
    }
    gtk_window_present(GTK_WINDOW(shell));

    g_signal_connect(shell, "response", G_CALLBACK(bribe_response), NULL);
}
Пример #3
0
/**************************************************************************
  Creates and popups the bribe dialog
**************************************************************************/
void popup_bribe_dialog(struct unit *punit, int cost)
{
  char tbuf[128], buf[128];

  fc_snprintf(tbuf, ARRAY_SIZE(tbuf), PL_("Treasury contains %d gold.",
                                          "Treasury contains %d gold.",
                                          client_player()->economic.gold),
              client_player()->economic.gold);

  if (cost <= client_player()->economic.gold) {
    fc_snprintf(buf, sizeof(buf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Bribe unit for %d gold?\n%s",
                    "Bribe unit for %d gold?\n%s", cost), cost, tbuf);
    popup_message_dialog(toplevel, "diplomatbribedialog", buf,
			 diplomat_bribe_yes_callback, 0, 0,
			 diplomat_bribe_no_callback, 0, 0,
			 NULL);
  } else {
    fc_snprintf(buf, sizeof(buf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Bribing the unit costs %d gold.\n%s",
                    "Bribing the unit costs %d gold.\n%s", cost), cost, tbuf);
    popup_message_dialog(toplevel, "diplomatnogolddialog", buf,
			 diplomat_bribe_no_callback, 0, 0,
			 NULL);
  }
}
Пример #4
0
/****************************************************************
Popup the yes/no dialog for inciting, since we know the cost now
*****************************************************************/
void popup_incite_dialog(struct city *pcity, int cost)
{
  GtkWidget *shell;
  char buf[1024];

  fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Treasury contains %d gold.",
                                        "Treasury contains %d gold.",
                                        client_player()->economic.gold),
              client_player()->economic.gold);

  if (INCITE_IMPOSSIBLE_COST == cost) {
    shell = gtk_message_dialog_new(NULL,
      0,
      GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
      _("You can't incite a revolt in %s."),
      city_name(pcity));
    gtk_window_set_title(GTK_WINDOW(shell), _("City can't be incited!"));
  setup_dialog(shell, toplevel);
  } else if (cost <= client_player()->economic.gold) {
    shell = gtk_message_dialog_new(NULL, 0,
      GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
      /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
      PL_("Incite a revolt for %d gold?\n%s",
          "Incite a revolt for %d gold?\n%s", cost), cost, buf);
    gtk_window_set_title(GTK_WINDOW(shell), _("Incite a Revolt!"));
    setup_dialog(shell, toplevel);
  } else {
    shell = gtk_message_dialog_new(NULL,
      0,
      GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
      /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
      PL_("Inciting a revolt costs %d gold.\n%s",
          "Inciting a revolt costs %d gold.\n%s", cost), cost, buf);
    gtk_window_set_title(GTK_WINDOW(shell), _("Traitors Demand Too Much!"));
    setup_dialog(shell, toplevel);
  }
  gtk_window_present(GTK_WINDOW(shell));
  
  g_signal_connect(shell, "response", G_CALLBACK(incite_response), NULL);
}
Пример #5
0
/**************************************************************************
...
**************************************************************************/
void unit_select_all_callback(Widget w, XtPointer client_data, 
			      XtPointer call_data)
{
  int i;

  XtSetSensitive(main_form, TRUE);
  XtDestroyWidget(unit_select_dialog_shell);
  
  for(i=0; i<unit_select_no; i++) {
    struct unit *punit = player_unit_by_number(client_player(),
                                               unit_select_ids[i]);
    if(punit) {
      unit_focus_set(punit);
    }
  }
}
Пример #6
0
/****************************************************************
popup the dialog 10% inside the main-window 
*****************************************************************/
void unit_select_dialog_popup(struct tile *ptile)
{
  int i,n,r;
  char buffer[512];
  Arg args[4];
  int nargs;
  Widget unit_select_all_command, unit_select_close_command;
  Widget firstcolumn=0,column=0;
  Pixel bg;
  struct unit *unit_list[unit_list_size(ptile->units)];

  XtSetSensitive(main_form, FALSE);

  unit_select_dialog_shell =
    I_T(XtCreatePopupShell("unitselectdialogshell", 
			   transientShellWidgetClass,
			   toplevel, NULL, 0));

  unit_select_form = XtVaCreateManagedWidget("unitselectform", 
					     formWidgetClass, 
					     unit_select_dialog_shell, NULL);

  XtVaGetValues(unit_select_form, XtNbackground, &bg, NULL);
  XSetForeground(display, fill_bg_gc, bg);

  n = MIN(MAX_SELECT_UNITS, unit_list_size(ptile->units));
  r = number_of_rows(n);

  fill_tile_unit_list(ptile, unit_list);

  for(i=0; i<n; i++) {
    struct unit *punit = unit_list[i];
    struct unit_type *punittemp=unit_type(punit);
    struct city *pcity;
    struct canvas store;
    
    if(!(i%r))  {
      nargs=0;
      if(i)  { XtSetArg(args[nargs], XtNfromHoriz, column); nargs++;}
      column = XtCreateManagedWidget("column", formWidgetClass,
				     unit_select_form,
				     args, nargs);
      if(!i) firstcolumn=column;
    }

    unit_select_ids[i]=punit->id;

    pcity = player_city_by_number(client_player(), punit->homecity);
    
    fc_snprintf(buffer, sizeof(buffer), "%s(%s)\n%s", 
	    utype_name_translation(punittemp), 
	    pcity ? city_name(pcity) : "",
	    unit_activity_text(punit));

    unit_select_pixmaps[i]=XCreatePixmap(display, XtWindow(map_canvas), 
					 tileset_full_tile_width(tileset), tileset_full_tile_height(tileset),
					 display_depth);

    XFillRectangle(display, unit_select_pixmaps[i], fill_bg_gc,
		   0, 0, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset));
    store.pixmap = unit_select_pixmaps[i];
    put_unit(punit, &store, 0, 0);

    nargs=0;
    XtSetArg(args[nargs], XtNbitmap, (XtArgVal)unit_select_pixmaps[i]);nargs++;
    XtSetArg(args[nargs], XtNsensitive, 
             can_unit_do_activity(punit, ACTIVITY_IDLE));nargs++;
    if(i%r)  {
      XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++;
    }
    unit_select_commands[i]=XtCreateManagedWidget("unitselectcommands", 
						  commandWidgetClass,
						  column, args, nargs);

    nargs=0;
    XtSetArg(args[nargs], XtNlabel, (XtArgVal)buffer); nargs++;
    XtSetArg(args[nargs], XtNfromHoriz, unit_select_commands[i]); nargs++;
    if(i%r) {
      XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++;
    }
    unit_select_labels[i]=XtCreateManagedWidget("unitselectlabels", 
						labelWidgetClass, 
						column, args, nargs);

    XtAddCallback(unit_select_commands[i],
		  XtNdestroyCallback,free_bitmap_destroy_callback, NULL);
    XtAddCallback(unit_select_commands[i],
                  XtNcallback, unit_select_callback, NULL);
  }

  unit_select_no=i;

  unit_select_close_command =
    I_L(XtVaCreateManagedWidget("unitselectclosecommand", 
				commandWidgetClass,
				unit_select_form,
				XtNfromVert, firstcolumn,
				NULL));

  unit_select_all_command =
    I_L(XtVaCreateManagedWidget("unitselectallcommand", 
				commandWidgetClass,
				unit_select_form,
				XtNfromVert, firstcolumn,
				NULL));

  XtAddCallback(unit_select_close_command, XtNcallback, unit_select_callback, NULL);
  XtAddCallback(unit_select_all_command, XtNcallback, unit_select_all_callback, NULL);

  xaw_set_relative_position(toplevel, unit_select_dialog_shell, 15, 10);
  XtPopup(unit_select_dialog_shell, XtGrabNone);
}
Пример #7
0
bool can_unit_upgrade(struct unit* punit) {
    return can_upgrade_unittype(client_player(), unit_type(punit));
}
Пример #8
0
/**************************************************************************
  Popup a dialog asking a diplomatic unit if it wishes to bribe the
  given enemy unit.
**************************************************************************/
void popup_bribe_dialog(struct unit *pUnit, int cost)
{
  struct widget *pWindow = NULL, *pBuf = NULL;
  SDL_String16 *pStr;
  struct unit *pDiplomatUnit;
  char tBuf[255], cBuf[255];
  bool exit = FALSE;
  SDL_Rect area;
  
  if (pBribe_Dlg) {
    return;
  }
    
  /* ugly hack */
  pDiplomatUnit = head_of_units_in_focus();
  
  if (!pDiplomatUnit || !is_diplomat_unit(pDiplomatUnit)) {
    return;
  }
  
  is_unit_move_blocked = TRUE;
  
  pBribe_Dlg = fc_calloc(1, sizeof(struct small_diplomat_dialog));
  pBribe_Dlg->diplomat_id = pDiplomatUnit->id;
  pBribe_Dlg->diplomat_target_id = pUnit->id;
  pBribe_Dlg->pdialog = fc_calloc(1, sizeof(struct SMALL_DLG));

  fc_snprintf(tBuf, ARRAY_SIZE(tBuf), PL_("Treasury contains %d gold.",
                                          "Treasury contains %d gold.",
                                          client_player()->economic.gold),
              client_player()->economic.gold);

  /* window */
  pStr = create_str16_from_char(_("Bribe Enemy Unit"), adj_font(12));
    
  pStr->style |= TTF_STYLE_BOLD;
  
  pWindow = create_window_skeleton(NULL, pStr, 0);
    
  pWindow->action = bribe_dlg_window_callback;
  set_wstate(pWindow, FC_WS_NORMAL);

  add_to_gui_list(ID_BRIBE_DLG_WINDOW, pWindow);
  pBribe_Dlg->pdialog->pEndWidgetList = pWindow;
  
  area = pWindow->area;
  area.w = MAX(area.w, adj_size(8));
  area.h = MAX(area.h, adj_size(2));
  
  if (cost <= client_player()->economic.gold) {
    fc_snprintf(cBuf, sizeof(cBuf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Bribe unit for %d gold?\n%s",
                    "Bribe unit for %d gold?\n%s", cost), cost, tBuf);

    create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL);
  
    add_to_gui_list(ID_LABEL, pBuf);
    
    area.w = MAX(area.w, pBuf->size.w);
    area.h += pBuf->size.h;
    
    /*------------*/
    create_active_iconlabel(pBuf, pWindow->dst, pStr,
	    _("Yes"), diplomat_bribe_yes_callback);
    pBuf->data.unit = pUnit;
    set_wstate(pBuf, FC_WS_NORMAL);
  
    add_to_gui_list(MAX_ID - pDiplomatUnit->id, pBuf);
    
    area.w = MAX(area.w, pBuf->size.w);
    area.h += pBuf->size.h;
    /* ------- */
    create_active_iconlabel(pBuf, pWindow->dst, pStr,
	    _("No") , exit_bribe_dlg_callback);
    
    set_wstate(pBuf , FC_WS_NORMAL);
    pBuf->key = SDLK_ESCAPE;
    
    add_to_gui_list(ID_LABEL, pBuf);
    
    area.w = MAX(area.w, pBuf->size.w);
    area.h += pBuf->size.h;
    
  } else {
    /* exit button */
    pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst,
                            WF_WIDGET_HAS_INFO_LABEL
                            | WF_RESTORE_BACKGROUND);
    pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"),
                                              adj_font(12));
    area.w += pBuf->size.w + adj_size(10);
    pBuf->action = exit_bribe_dlg_callback;
    set_wstate(pBuf, FC_WS_NORMAL);
    pBuf->key = SDLK_ESCAPE;
  
    add_to_gui_list(ID_BRIBE_DLG_EXIT_BUTTON, pBuf);
    exit = TRUE;
    /* --------------- */

    fc_snprintf(cBuf, sizeof(cBuf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Bribing the unit costs %d gold.\n%s",
                    "Bribing the unit costs %d gold.\n%s", cost), cost, tBuf);

    create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL);
  
    add_to_gui_list(ID_LABEL, pBuf);
    
    area.w = MAX(area.w, pBuf->size.w);
    area.h += pBuf->size.h;
    
    /*------------*/
    create_active_iconlabel(pBuf, pWindow->dst, pStr,
	    _("Traitors Demand Too Much!"), NULL);
        
    add_to_gui_list(ID_LABEL, pBuf);
    
    area.w = MAX(area.w, pBuf->size.w);
    area.h += pBuf->size.h;
  }
  pBribe_Dlg->pdialog->pBeginWidgetList = pBuf;
  
  /* setup window size and start position */

  resize_window(pWindow, NULL, NULL,
                (pWindow->size.w - pWindow->area.w) + area.w,
                (pWindow->size.h - pWindow->area.h) + area.h);
  
  area = pWindow->area;
  
  auto_center_on_focus_unit();
  put_window_near_map_tile(pWindow, pWindow->size.w, pWindow->size.h,
                           pDiplomatUnit->tile);      
  
  /* setup widget size and start position */
  pBuf = pWindow;
  
  if (exit)
  {/* exit button */
    pBuf = pBuf->prev;
    pBuf->size.x = area.x + area.w - pBuf->size.w - 1;
    pBuf->size.y = pWindow->size.y + adj_size(2);
  }
  
  pBuf = pBuf->prev;
  setup_vertical_widgets_position(1,
	area.x,
  	area.y + 1, area.w, 0,
	pBribe_Dlg->pdialog->pBeginWidgetList, pBuf);
  
  /* --------------------- */
  /* redraw */
  redraw_group(pBribe_Dlg->pdialog->pBeginWidgetList, pWindow, 0);

  widget_flush(pWindow);
}
Пример #9
0
/**************************************************************************
  Returns TRUE when a tile is available to be worked, or the city itself
  is currently working the tile (and can continue).

  See also city_can_work_tile() (common/city.[ch]).
**************************************************************************/
bool client_city_can_work_tile(const struct city *pcity,
                               const struct tile *ptile)
{
  return base_city_can_work_tile(client_player(), pcity, ptile);
}
Пример #10
0
/**************************************************************************
  Slot for selecting player/nation
**************************************************************************/
void plr_widget::nation_selected(const QItemSelection &sl,
                                 const QItemSelection &ds)
{
  QModelIndex index;
  QVariant qvar;
  QModelIndexList indexes = sl.indexes();
  struct city *pcity;
  const struct player_diplstate *state;
  struct player_research *research;
  char tbuf[256];
  QString res;
  QString sp = " ";
  QString nl = "<br>";
  struct player *pplayer;
  int a , b;
  bool added;
  bool entry_exist = false;
  struct player *me;
  Tech_type_id tech_id;

  other_player = NULL;
  intel_str.clear();
  tech_str.clear();
  ally_str.clear();
  if (indexes.isEmpty()) {
    plr->update_report();
    return;
  }
  index = indexes.at(0);
  qvar = index.data(Qt::UserRole);
  pplayer = reinterpret_cast<player *>(qvar.value<void *>());
  other_player = pplayer;
  if (pplayer->is_alive == false) {
    plr->update_report();
    return;
  }
  pcity = player_capital(pplayer);
  research = player_research_get(pplayer);

  switch (research->researching) {
  case A_UNKNOWN:
    res = _("(Unknown)");
    break;
  case A_UNSET:
    res = _("(none)");
    break;
  default:
    res = QString(advance_name_researching(pplayer))
          + sp + "(" + QString::number(research->bulbs_researched) + "/"
          + QString::number(total_bulbs_required(pplayer)) + ")";
    break;
  }
  /** Formatting rich text */
  intel_str =
    QString("<table><tr><td><b>") + _("Nation") + QString("</b></td><td>")
    + QString(nation_adjective_for_player(pplayer))
    + QString("</td><tr><td><b>") + N_("Ruler:") + QString("</b></td><td>")
    + QString(ruler_title_for_player(pplayer, tbuf, sizeof(tbuf)))
    + QString("</td></tr><tr><td><b>") + N_("Government:") 
    + QString("</b></td><td>") + QString(government_name_for_player(pplayer))
    + QString("</td></tr><tr><td><b>") + N_("Capital:")
    + QString("</b></td><td>")
    + QString(((!pcity) ? _("(unknown)") : city_name(pcity)))
    + QString("</td></tr><tr><td><b>") + N_("Gold:")
    + QString("</b></td><td>") + QString::number(pplayer->economic.gold)
    + QString("</td></tr><tr><td><b>") + N_("Tax:")
    + QString("</b></td><td>") + QString::number(pplayer->economic.tax)
    + QString("%</td></tr><tr><td><b>") + N_("Science:")
    + QString("</b></td><td>") + QString::number(pplayer->economic.science)
    + QString("%</td></tr><tr><td><b>") + N_("Luxury:")
    + QString("</b></td><td>") + QString::number(pplayer->economic.luxury)
    + QString("%</td></tr><tr><td><b>") + N_("Researching:")
    + QString("</b></td><td>") + res + QString("</td></table>");

  for (int i = 0; i < static_cast<int>(DS_LAST); i++) {
    added = false;
    if (entry_exist) {
      ally_str += "<br>";
    }
    entry_exist = false;
    players_iterate_alive(other) {
      if (other == pplayer) {
        continue;
      }
      state = player_diplstate_get(pplayer, other);
      if (static_cast<int>(state->type) == i) {
        if (added == false) {
          ally_str = ally_str  + QString("<b>")
                     + QString(diplstate_type_translated_name(
                                 static_cast<diplstate_type>(i)))
                     + ": "  + QString("</b>") + nl;
          added = true;
        }
        ally_str = ally_str + nation_plural_for_player(other) + ", ";
        entry_exist = true;
      }
    }
    players_iterate_alive_end;
    if (entry_exist) {
      ally_str.replace(ally_str.lastIndexOf(","), 1, ".");
    }
  }
  me = client_player();
  if ((player_has_embassy(me, pplayer) || client_is_global_observer())
      && me != pplayer) {
    a = 0;
    b = 0;
    techs_known = QString("<b>") + _("Techs unknown by") + sp
                  + QString(nation_adjective_for_player(pplayer)) + sp
                  + QString(_("nation")) + QString("</b> :");
    techs_unknown = QString("<b>") + _("Techs unkown by you") + sp
                    + QString("</b> :");

    advance_iterate(A_FIRST, padvance) {
      tech_id = advance_number(padvance);
      if (player_invention_state(me, tech_id) == TECH_KNOWN
          && (player_invention_state(pplayer, tech_id) == TECH_UNKNOWN)) {
        a++;
        techs_known = techs_known + QString("<i>") 
                      + advance_name_for_player(pplayer, tech_id)
                      + "," + QString("</i>") + sp;
      }
      if (player_invention_state(me, tech_id) == TECH_UNKNOWN
          && (player_invention_state(pplayer, tech_id) == TECH_KNOWN)) {
        b++;
        techs_unknown = techs_unknown + QString("<i>")
                        + advance_name_for_player(pplayer, tech_id)
                        + "," + QString("</i>") + sp;
      }
    } advance_iterate_end;