Allow shift-clicking on borrow/repay money buttons to enter amount
This commit is contained in:
@@ -266,8 +266,8 @@ static const NWidgetPart _nested_company_finances_widgets[] = {
|
|||||||
EndContainer(),
|
EndContainer(),
|
||||||
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_BUTTONS),
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_BUTTONS),
|
||||||
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
||||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INCREASE_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_BORROW_BUTTON, STR_FINANCES_BORROW_TOOLTIP),
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INCREASE_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_BORROW_BUTTON, STR_NULL),
|
||||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_REPAY_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_REPAY_BUTTON, STR_FINANCES_REPAY_TOOLTIP),
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_REPAY_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_REPAY_BUTTON, STR_NULL),
|
||||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INFRASTRUCTURE), SetFill(1, 0), SetDataTip(STR_FINANCES_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP),
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INFRASTRUCTURE), SetFill(1, 0), SetDataTip(STR_FINANCES_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
@@ -277,6 +277,7 @@ static const NWidgetPart _nested_company_finances_widgets[] = {
|
|||||||
struct CompanyFinancesWindow : Window {
|
struct CompanyFinancesWindow : Window {
|
||||||
Money max_money; ///< The approximate maximum amount of money a company has had over the lifetime of this window
|
Money max_money; ///< The approximate maximum amount of money a company has had over the lifetime of this window
|
||||||
bool small; ///< Window is toggled to 'small'.
|
bool small; ///< Window is toggled to 'small'.
|
||||||
|
int query_widget; ///< The widget associated with the current text query input.
|
||||||
|
|
||||||
CompanyFinancesWindow(WindowDesc *desc, CompanyID company) : Window(desc)
|
CompanyFinancesWindow(WindowDesc *desc, CompanyID company) : Window(desc)
|
||||||
{
|
{
|
||||||
@@ -444,11 +445,23 @@ struct CompanyFinancesWindow : Window {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_CF_INCREASE_LOAN: // increase loan
|
case WID_CF_INCREASE_LOAN: // increase loan
|
||||||
DoCommandP(0, 0, _ctrl_pressed, CMD_INCREASE_LOAN | CMD_MSG(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY));
|
if (_shift_pressed) {
|
||||||
|
this->query_widget = WID_CF_INCREASE_LOAN;
|
||||||
|
SetDParam(0, 0);
|
||||||
|
ShowQueryString(STR_JUST_INT, STR_FINANCES_BORROW_QUERY_CAPT, 20, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
|
||||||
|
} else {
|
||||||
|
DoCommandP(0, 0, _ctrl_pressed, CMD_INCREASE_LOAN | CMD_MSG(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_CF_REPAY_LOAN: // repay loan
|
case WID_CF_REPAY_LOAN: // repay loan
|
||||||
DoCommandP(0, 0, _ctrl_pressed, CMD_DECREASE_LOAN | CMD_MSG(STR_ERROR_CAN_T_REPAY_LOAN));
|
if (_shift_pressed) {
|
||||||
|
this->query_widget = WID_CF_REPAY_LOAN;
|
||||||
|
SetDParam(0, 0);
|
||||||
|
ShowQueryString(STR_JUST_INT, STR_FINANCES_REPAY_QUERY_CAPT, 20, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
|
||||||
|
} else {
|
||||||
|
DoCommandP(0, 0, _ctrl_pressed, CMD_DECREASE_LOAN | CMD_MSG(STR_ERROR_CAN_T_REPAY_LOAN));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_CF_INFRASTRUCTURE: // show infrastructure details
|
case WID_CF_INFRASTRUCTURE: // show infrastructure details
|
||||||
@@ -457,6 +470,24 @@ struct CompanyFinancesWindow : Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnQueryTextFinished(char *str) override
|
||||||
|
{
|
||||||
|
/* Was 'cancel' pressed or nothing entered? */
|
||||||
|
if (str == nullptr || StrEmpty(str)) return;
|
||||||
|
|
||||||
|
if (this->query_widget == WID_CF_INCREASE_LOAN) {
|
||||||
|
const Company *c = Company::Get((CompanyID)this->window_number);
|
||||||
|
Money amount = std::min<Money>(strtoull(str, nullptr, 10) / _currency->rate, _economy.max_loan - c->current_loan);
|
||||||
|
amount = LOAN_INTERVAL * CeilDivT<Money>(amount, LOAN_INTERVAL);
|
||||||
|
DoCommandP(0, amount >> 32, (amount & 0xFFFFFFFC) | 2, CMD_INCREASE_LOAN | CMD_MSG(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY));
|
||||||
|
} else if (this->query_widget == WID_CF_REPAY_LOAN) {
|
||||||
|
const Company *c = Company::Get((CompanyID)this->window_number);
|
||||||
|
Money amount = std::min<Money>(strtoull(str, nullptr, 10) / _currency->rate, c->current_loan);
|
||||||
|
amount = LOAN_INTERVAL * CeilDivT<Money>(amount, LOAN_INTERVAL);
|
||||||
|
DoCommandP(0, amount >> 32, (amount & 0xFFFFFFFC) | 2, CMD_DECREASE_LOAN | CMD_MSG(STR_ERROR_CAN_T_REPAY_LOAN));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OnHundredthTick() override
|
void OnHundredthTick() override
|
||||||
{
|
{
|
||||||
const Company *c = Company::Get((CompanyID)this->window_number);
|
const Company *c = Company::Get((CompanyID)this->window_number);
|
||||||
@@ -466,6 +497,26 @@ struct CompanyFinancesWindow : Window {
|
|||||||
this->ReInit();
|
this->ReInit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond)
|
||||||
|
{
|
||||||
|
switch (widget) {
|
||||||
|
case WID_CF_INCREASE_LOAN: {
|
||||||
|
uint64 arg = STR_FINANCES_BORROW_TOOLTIP;
|
||||||
|
GuiShowTooltips(this, STR_FINANCES_BORROW_TOOLTIP_EXTRA, 1, &arg, close_cond);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WID_CF_REPAY_LOAN: {
|
||||||
|
uint64 arg = STR_FINANCES_REPAY_TOOLTIP;
|
||||||
|
GuiShowTooltips(this, STR_FINANCES_REPAY_TOOLTIP_EXTRA, 1, &arg, close_cond);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static WindowDesc _company_finances_desc(
|
static WindowDesc _company_finances_desc(
|
||||||
|
@@ -4190,6 +4190,10 @@ STR_FINANCES_BORROW_BUTTON :{BLACK}Borrow {
|
|||||||
STR_FINANCES_BORROW_TOOLTIP :{BLACK}Increase size of loan. Ctrl+Click borrows as much as possible
|
STR_FINANCES_BORROW_TOOLTIP :{BLACK}Increase size of loan. Ctrl+Click borrows as much as possible
|
||||||
STR_FINANCES_REPAY_BUTTON :{BLACK}Repay {CURRENCY_LONG}
|
STR_FINANCES_REPAY_BUTTON :{BLACK}Repay {CURRENCY_LONG}
|
||||||
STR_FINANCES_REPAY_TOOLTIP :{BLACK}Repay part of loan. Ctrl+Click repays as much loan as possible
|
STR_FINANCES_REPAY_TOOLTIP :{BLACK}Repay part of loan. Ctrl+Click repays as much loan as possible
|
||||||
|
STR_FINANCES_BORROW_TOOLTIP_EXTRA :{BLACK}{STRING}. Shift+Click to enter an amount to borrow
|
||||||
|
STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING}. Shift+Click to enter an amount to repay
|
||||||
|
STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}Enter the amount of money to borrow
|
||||||
|
STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Enter the amount of money to repay
|
||||||
STR_FINANCES_INFRASTRUCTURE_BUTTON :{BLACK}Infrastructure
|
STR_FINANCES_INFRASTRUCTURE_BUTTON :{BLACK}Infrastructure
|
||||||
|
|
||||||
# Company view
|
# Company view
|
||||||
|
Reference in New Issue
Block a user