Bug #2508 » 0004-sdl-Keep-diplomacy-gold-limit-in-step-with-players-g-main.patch
| client/gui-sdl2/diplodlg.c | ||
|---|---|---|
|
{
|
||
|
int amount;
|
||
|
struct diplomacy_dialog *pdialog;
|
||
|
struct player *giver = player_by_number(pwidget->data.cont->id0);
|
||
|
if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
|
||
|
pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
|
||
| ... | ... | |
|
if (pwidget->string_utf8->text != NULL) {
|
||
|
sscanf(pwidget->string_utf8->text, "%d", &amount);
|
||
|
if (amount > pwidget->data.cont->value) {
|
||
|
if (amount > giver->economic.gold) {
|
||
|
/* Max player gold */
|
||
|
amount = pwidget->data.cont->value;
|
||
|
amount = giver->economic.gold;
|
||
|
}
|
||
|
} else {
|
||
| ... | ... | |
|
/* ---------------------------- */
|
||
|
if (clause_enabled(CLAUSE_GOLD) && pplayer0->economic.gold > 0) {
|
||
|
cont->value = pplayer0->economic.gold;
|
||
|
if (clause_enabled(CLAUSE_GOLD)) {
|
||
|
fc_snprintf(cbuf, sizeof(cbuf), _("Gold(max %d)"), pplayer0->economic.gold);
|
||
|
buf = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
|
||
|
cbuf, FONTO_ATTENTION,
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Show the player's gold in the gold label of a panel of theirs.
|
||
|
Return whether the label changed.
|
||
|
**************************************************************************/
|
||
|
static bool update_gold_label(struct advanced_dialog *panel,
|
||
|
struct player *pplayer)
|
||
|
{
|
||
|
struct widget *buf = panel->end_widget_list;
|
||
|
char cbuf[128];
|
||
|
if (buf->data.cont->id0 != player_number(pplayer)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
/* The label is the widget before the gold edit. */
|
||
|
do {
|
||
|
buf = buf->prev;
|
||
|
if (buf->action == gold_callback) {
|
||
|
buf = buf->next;
|
||
|
fc_snprintf(cbuf, sizeof(cbuf), _("Gold(max %d)"),
|
||
|
pplayer->economic.gold);
|
||
|
if (strcmp(buf->string_utf8->text, cbuf) == 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
copy_chars_to_utf8_str(buf->string_utf8, cbuf);
|
||
|
widget_redraw(buf);
|
||
|
widget_mark_dirty(buf);
|
||
|
return TRUE;
|
||
|
}
|
||
|
} while (buf != panel->begin_widget_list);
|
||
|
return FALSE;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Player's gold may have changed.
|
||
|
**************************************************************************/
|
||
|
void update_diplomacy_gold(struct player *pplayer)
|
||
|
{
|
||
|
/* PORTME */
|
||
|
bool changed = FALSE;
|
||
|
dialog_list_iterate(dialog_list, pdialog) {
|
||
|
changed |= update_gold_label(pdialog->poffers, pplayer);
|
||
|
changed |= update_gold_label(pdialog->pwants, pplayer);
|
||
|
} dialog_list_iterate_end;
|
||
|
if (changed) {
|
||
|
flush_dirty();
|
||
|
}
|
||
|
}
|
||
| client/gui-sdl3/diplodlg.c | ||
|---|---|---|
|
{
|
||
|
int amount;
|
||
|
struct diplomacy_dialog *pdialog;
|
||
|
struct player *giver = player_by_number(pwidget->data.cont->id0);
|
||
|
if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
|
||
|
pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
|
||
| ... | ... | |
|
if (pwidget->string_utf8->text != NULL) {
|
||
|
sscanf(pwidget->string_utf8->text, "%d", &amount);
|
||
|
if (amount > pwidget->data.cont->value) {
|
||
|
if (amount > giver->economic.gold) {
|
||
|
/* Max player gold */
|
||
|
amount = pwidget->data.cont->value;
|
||
|
amount = giver->economic.gold;
|
||
|
}
|
||
|
} else {
|
||
| ... | ... | |
|
/* ---------------------------- */
|
||
|
if (clause_enabled(CLAUSE_GOLD) && pplayer0->economic.gold > 0) {
|
||
|
cont->value = pplayer0->economic.gold;
|
||
|
if (clause_enabled(CLAUSE_GOLD)) {
|
||
|
fc_snprintf(cbuf, sizeof(cbuf), _("Gold(max %d)"), pplayer0->economic.gold);
|
||
|
buf = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
|
||
|
cbuf, FONTO_ATTENTION,
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Show the player's gold in the gold label of a panel of theirs.
|
||
|
Return whether the label changed.
|
||
|
**************************************************************************/
|
||
|
static bool update_gold_label(struct advanced_dialog *panel,
|
||
|
struct player *pplayer)
|
||
|
{
|
||
|
struct widget *buf = panel->end_widget_list;
|
||
|
char cbuf[128];
|
||
|
if (buf->data.cont->id0 != player_number(pplayer)) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
/* The label is the widget before the gold edit. */
|
||
|
do {
|
||
|
buf = buf->prev;
|
||
|
if (buf->action == gold_callback) {
|
||
|
buf = buf->next;
|
||
|
fc_snprintf(cbuf, sizeof(cbuf), _("Gold(max %d)"),
|
||
|
pplayer->economic.gold);
|
||
|
if (strcmp(buf->string_utf8->text, cbuf) == 0) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
copy_chars_to_utf8_str(buf->string_utf8, cbuf);
|
||
|
widget_redraw(buf);
|
||
|
widget_mark_dirty(buf);
|
||
|
return TRUE;
|
||
|
}
|
||
|
} while (buf != panel->begin_widget_list);
|
||
|
return FALSE;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Player's gold may have changed.
|
||
|
**************************************************************************/
|
||
|
void update_diplomacy_gold(struct player *pplayer)
|
||
|
{
|
||
|
/* PORTME */
|
||
|
bool changed = FALSE;
|
||
|
dialog_list_iterate(dialog_list, pdialog) {
|
||
|
changed |= update_gold_label(pdialog->poffers, pplayer);
|
||
|
changed |= update_gold_label(pdialog->pwants, pplayer);
|
||
|
} dialog_list_iterate_end;
|
||
|
if (changed) {
|
||
|
flush_dirty();
|
||
|
}
|
||
|
}
|
||