Ejemplo n.º 1
0
/******************************************************************
  Show the user the action if it is enabled.
*******************************************************************/
static void action_entry(GtkWidget *shl, enum mk_eval_result state,
                         const gchar *label, GCallback handler)
{
    switch (state) {
    case MKE_FALSE:
        /* Don't even show disabled actions */
        break;
    case MKE_UNCERTAIN:
        choice_dialog_add(shl, label, handler, NULL, TRUE);
        break;
    case MKE_TRUE:
        choice_dialog_add(shl, label, handler, NULL, FALSE);
        break;
    }
}
Ejemplo n.º 2
0
/****************************************************************
  Open new choice dialog.
*****************************************************************/
GtkWidget *popup_choice_dialog(GtkWindow *parent, const gchar *dialogname,
				const gchar *text, ...)
{
  GtkWidget *dshell;
  va_list args;
  gchar *name;

  dshell = choice_dialog_start(parent, dialogname, text);
  
  va_start(args, text);

  while ((name = va_arg(args, gchar *))) {
    GCallback handler;
    gpointer data;

    handler = va_arg(args, GCallback);
    data = va_arg(args, gpointer);

    choice_dialog_add(dshell, name, handler, data);
  }

  va_end(args);

  choice_dialog_end(dshell);

  return dshell;
}
Ejemplo n.º 3
0
/****************************************************************
 Popup new diplomat dialog.
*****************************************************************/
void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile)
{
    struct city *pcity;
    struct unit *ptunit;
    GtkWidget *shl;
    struct astring title = ASTRING_INIT, text = ASTRING_INIT;

    diplomat_target_id[ATK_CITY] = -1;
    diplomat_target_id[ATK_UNIT] = -1;

    diplomat_id = punit->id;

    astr_set(&title,
             /* TRANS: %s is a unit name, e.g., Spy */
             _("Choose Your %s's Strategy"), unit_name_translation(punit));
    astr_set(&text,
             /* TRANS: %s is a unit name, e.g., Diplomat, Spy */
             _("Your %s is waiting for your command."),
             unit_name_translation(punit));

    shl = choice_dialog_start(GTK_WINDOW(toplevel), astr_str(&title),
                              astr_str(&text));

    if ((pcity = tile_city(dest_tile))) {
        /* Spy/Diplomat acting against a city */

        diplomat_target_id[ATK_CITY] = pcity->id;

        action_entry(shl,
                     action_enabled_unit_on_city_local(
                         ACTION_ESTABLISH_EMBASSY, punit, pcity),
                     _("Establish _Embassy"),
                     (GCallback)diplomat_embassy_callback);

        action_entry(shl,
                     action_enabled_unit_on_city_local(
                         ACTION_SPY_INVESTIGATE_CITY, punit, pcity),
                     _("_Investigate City"),
                     (GCallback)diplomat_investigate_callback);

        action_entry(shl,
                     action_enabled_unit_on_city_local(ACTION_SPY_POISON,
                             punit, pcity),
                     _("_Poison City"),
                     (GCallback)spy_poison_callback);

        action_entry(shl,
                     action_enabled_unit_on_city_local(
                         ACTION_SPY_SABOTAGE_CITY, punit, pcity),
                     _("_Sabotage City"),
                     (GCallback)diplomat_sabotage_callback);

        action_entry(shl,
                     action_enabled_unit_on_city_local(
                         ACTION_SPY_TARGETED_SABOTAGE_CITY, punit, pcity),
                     _("Industrial _Sabotage"),
                     (GCallback)spy_request_sabotage_list);

        action_entry(shl,
                     action_enabled_unit_on_city_local(
                         ACTION_SPY_STEAL_TECH, punit, pcity),
                     _("Steal _Technology"),
                     (GCallback)diplomat_steal_callback);

        action_entry(shl,
                     action_enabled_unit_on_city_local(
                         ACTION_SPY_TARGETED_STEAL_TECH, punit, pcity),
                     _("Industrial espionage"),
                     (GCallback)spy_steal_popup);

        action_entry(shl,
                     action_enabled_unit_on_city_local(ACTION_SPY_INCITE_CITY,
                             punit, pcity),
                     _("Incite a _Revolt"),
                     (GCallback)diplomat_incite_callback);
    }

    if ((ptunit = unit_list_get(dest_tile->units, 0))) {
        /* Spy/Diplomat acting against a unit */

        diplomat_target_id[ATK_UNIT] = ptunit->id;

        action_entry(shl,
                     action_enabled_unit_on_unit_local(
                         ACTION_SPY_BRIBE_UNIT, punit, ptunit),
                     _("_Bribe Enemy Unit"),
                     (GCallback)diplomat_bribe_callback);

        action_entry(shl,
                     action_enabled_unit_on_unit_local(
                         ACTION_SPY_SABOTAGE_UNIT, punit, ptunit),
                     _("_Sabotage Enemy Unit"),
                     (GCallback)spy_sabotage_unit_callback);
    }

    if (diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) {
        if (pcity) {
            choice_dialog_add(shl, _("_Keep moving"),
                              (GCallback)diplomat_keep_moving_city_callback,
                              NULL, FALSE);
        } else {
            choice_dialog_add(shl, _("_Keep moving"),
                              (GCallback)diplomat_keep_moving_unit_callback,
                              NULL, FALSE);
        }
    }

    choice_dialog_add(shl, GTK_STOCK_CANCEL,
                      (GCallback)diplomat_cancel_callback, NULL, FALSE);

    choice_dialog_end(shl);

    diplomat_dialog = shl;

    choice_dialog_set_hide(shl, TRUE);
    g_signal_connect(shl, "destroy",
                     G_CALLBACK(diplomat_destroy_callback), NULL);
    g_signal_connect(shl, "delete_event",
                     G_CALLBACK(diplomat_cancel_callback), NULL);
    astr_free(&title);
    astr_free(&text);
}