|
@@ -370,76 +370,71 @@ public:
|
|
|
/* Get the additional purchase info text, if it has not already been queried. */
|
|
|
str = STR_NULL;
|
|
|
if (HasBit(indsp->callback_mask, CBM_IND_FUND_MORE_TEXT)) {
|
|
|
uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, NULL, this->selected_type, INVALID_TILE);
|
|
|
if (callback_res != CALLBACK_FAILED) { // Did it fail?
|
|
|
str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Draw the Additional purchase text, provided by newgrf callback, if any.
|
|
|
* Otherwhise, will print Nothing */
|
|
|
if (str != STR_NULL && str != STR_UNDEFINED) {
|
|
|
SetDParam(0, str);
|
|
|
DrawStringMultiLine(left, right, y, bottom, STR_JUST_STRING);
|
|
|
}
|
|
|
} break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
this->DrawWidgets();
|
|
|
}
|
|
|
|
|
|
virtual void OnDoubleClick(Point pt, int widget)
|
|
|
{
|
|
|
if (widget != DPIW_MATRIX_WIDGET) return;
|
|
|
this->OnClick(pt, DPIW_FUND_WIDGET);
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
case DPIW_MATRIX_WIDGET: {
|
|
|
const IndustrySpec *indsp;
|
|
|
int y = (pt.y - this->GetWidget<NWidgetBase>(DPIW_MATRIX_WIDGET)->pos_y) / this->resize.step_height + this->vscroll.GetPosition();
|
|
|
|
|
|
if (y >= 0 && y < count) { // Is it within the boundaries of available data?
|
|
|
this->selected_index = y;
|
|
|
this->selected_type = this->index[y];
|
|
|
indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
|
|
if ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != NULL && indsp->IsRawIndustry()) ||
|
|
|
this->selected_type == INVALID_INDUSTRYTYPE) {
|
|
|
/* Reset the button state if going to prospecting or "build many industries" */
|
|
|
this->RaiseButtons();
|
|
|
ResetObjectToPlace();
|
|
|
}
|
|
|
|
|
|
this->SetWidgetDisabledState(DPIW_FUND_WIDGET, !this->enabled[this->selected_index]);
|
|
|
if (this->enabled[this->selected_index] && click_count > 1) this->OnClick(pt, DPIW_FUND_WIDGET, 1);
|
|
|
}
|
|
|
} break;
|
|
|
|
|
|
case DPIW_FUND_WIDGET: {
|
|
|
if (this->selected_type == INVALID_INDUSTRYTYPE) {
|
|
|
this->HandleButtonClick(DPIW_FUND_WIDGET);
|
|
|
|
|
|
if (Town::GetNumItems() == 0) {
|
|
|
ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_INDUSTRIES, STR_ERROR_MUST_FOUND_TOWN_FIRST, 0, 0);
|
|
|
} else {
|
|
|
extern void GenerateIndustries();
|
|
|
_generating_world = true;
|
|
|
GenerateIndustries();
|
|
|
_generating_world = false;
|
|
|
}
|
|
|
} else if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
|
|
|
DoCommandP(0, this->selected_type, InteractiveRandom(), CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
|
|
|
this->HandleButtonClick(DPIW_FUND_WIDGET);
|
|
|
} else {
|
|
|
HandlePlacePushButton(this, DPIW_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT, NULL);
|
|
|
}
|
|
|
} break;
|
|
|
}
|
|
|
}
|
|
@@ -682,49 +677,49 @@ public:
|
|
|
y += WD_PAR_VSEP_WIDE;
|
|
|
|
|
|
PrepareTextRefStackUsage(6);
|
|
|
/* Use all the available space left from where we stand up to the
|
|
|
* end of the window. We ALSO enlarge the window if needed, so we
|
|
|
* can 'go' wild with the bottom of the window. */
|
|
|
y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, message);
|
|
|
StopTextRefStackUsage();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return y + WD_FRAMERECT_BOTTOM;
|
|
|
}
|
|
|
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
{
|
|
|
if (widget== IVW_CAPTION) SetDParam(0, this->window_number);
|
|
|
}
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
{
|
|
|
if (widget == IVW_INFO) size->height = this->info_height;
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
{
|
|
|
Industry *i;
|
|
|
|
|
|
switch (widget) {
|
|
|
case IVW_INFO: {
|
|
|
i = Industry::Get(this->window_number);
|
|
|
|
|
|
/* We should work if needed.. */
|
|
|
if (!IsProductionAlterable(i)) return;
|
|
|
uint x = pt.x;
|
|
|
int line = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
|
|
|
if (pt.y >= this->production_offset_y && IsInsideMM(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
|
|
|
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
|
|
|
uint left = nwi->pos_x + WD_FRAMETEXT_LEFT;
|
|
|
uint right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
|
|
|
if (IsInsideMM(x, left, left + 20) ) {
|
|
|
/* Clicked buttons, decrease or increase production */
|
|
|
if (x < left + 10) {
|
|
|
if (IsProductionMinimum(i, line)) return;
|
|
|
i->production_rate[line] = max(i->production_rate[line] / 2, 0);
|
|
|
} else {
|
|
|
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
|
|
|
int new_prod = i->production_rate[line] == 0 ? 1 : i->production_rate[line] * 2;
|
|
|
if (IsProductionMaximum(i, line)) return;
|
|
@@ -1084,49 +1079,49 @@ public:
|
|
|
for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
|
|
|
d = maxdim(d, GetStringBoundingBox(IndustryDirectoryWindow::sorter_names[i]));
|
|
|
}
|
|
|
d.width += padding.width;
|
|
|
d.height += padding.height;
|
|
|
*size = maxdim(*size, d);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case IDW_INDUSTRY_LIST: {
|
|
|
Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
|
|
|
for (uint i = 0; i < this->industries.Length(); i++) {
|
|
|
d = maxdim(d, GetStringBoundingBox(this->GetIndustryString(this->industries[i])));
|
|
|
}
|
|
|
resize->height = d.height;
|
|
|
d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
|
d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
*size = maxdim(*size, d);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
case IDW_DROPDOWN_ORDER:
|
|
|
this->industries.ToggleSortOrder();
|
|
|
this->SetDirty();
|
|
|
break;
|
|
|
|
|
|
case IDW_DROPDOWN_CRITERIA:
|
|
|
ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), IDW_DROPDOWN_CRITERIA, 0, 0);
|
|
|
break;
|
|
|
|
|
|
case IDW_INDUSTRY_LIST: {
|
|
|
int y = (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height;
|
|
|
uint16 p;
|
|
|
|
|
|
if (!IsInsideMM(y, 0, this->vscroll.GetCapacity())) return;
|
|
|
p = y + this->vscroll.GetPosition();
|
|
|
if (p < this->industries.Length()) {
|
|
|
if (_ctrl_pressed) {
|
|
|
ShowExtraViewPortWindow(this->industries[p]->location.tile);
|
|
|
} else {
|
|
|
ScrollMainWindowToTile(this->industries[p]->location.tile);
|
|
|
}
|
|
|
}
|