Changeset - r7195:78237834f989
[Not reviewed]
master
0 4 0
rubidium - 17 years ago 2007-07-08 00:25:05
rubidium@openttd.org
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
4 files changed with 86 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1242,7 +1242,11 @@ static void DeliverGoodsToIndustry(TileI
 

	
 
		if (HASBIT(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(callback, CBM_IND_PRODUCTION_256_TICKS)) {
 
			best->incoming_cargo_waiting[accepted_cargo_index] = min(num_pieces + best->incoming_cargo_waiting[accepted_cargo_index], 0xFFFF);
 
			if (HASBIT(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) IndustryProductionCallback(ind, 0);
 
			if (HASBIT(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) {
 
				IndustryProductionCallback(best, 0);
 
			} else {
 
				InvalidateWindow(WC_INDUSTRY_VIEW, best->index);
 
			}
 
		} else {
 
			best->produced_cargo_waiting[0] = min(best->produced_cargo_waiting[0] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][0] / 256), 0xFFFF);
 
			best->produced_cargo_waiting[1] = min(best->produced_cargo_waiting[1] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][1] / 256), 0xFFFF);
src/industry_gui.cpp
Show inline comments
 
@@ -20,6 +20,10 @@
 
#include "variables.h"
 
#include "helpers.hpp"
 
#include "cargotype.h"
 
#include "newgrf.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_industries.h"
 
#include "newgrf_text.h"
 

	
 
/* industries per climate, according to the different construction windows */
 
const byte _build_industry_types[4][12] = {
 
@@ -299,14 +303,57 @@ static void IndustryViewWndProc(Window *
 
	 * WP(w,vp2_d).data_3 is for the click pos (left or right) */
 

	
 
	switch (e->event) {
 
	case WE_CREATE: {
 
		/* Count the number of lines that we need to resize the GUI with */
 
		const IndustrySpec *ind = GetIndustrySpec(GetIndustry(w->window_number)->type);
 
		int lines = -3;
 

	
 
		if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
 
			for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) {
 
				if (j == 0) lines++;
 
				lines++;
 
			}
 
		} else if (ind->accepts_cargo[0] != CT_INVALID) {
 
			lines++;
 
		}
 

	
 
		for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) {
 
			if (j == 0) {
 
				if (ind->accepts_cargo[0] != CT_INVALID) lines++;
 
				lines++;
 
			}
 
			lines++;
 
		}
 

	
 
		if (HASBIT(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) lines += 2;
 

	
 
		for (uint j = 5; j <= 7; j++) {
 
			if (j != 5) w->widget[j].top += lines * 10;
 
			w->widget[j].bottom += lines * 10;
 
		}
 
		w->height += lines * 10;
 
	} break;
 

	
 
	case WE_PAINT: {
 
		const Industry *i = GetIndustry(w->window_number);
 
		Industry *i = GetIndustry(w->window_number);
 
		const IndustrySpec *ind = GetIndustrySpec(i->type);
 
		int y = 111;
 

	
 
		SetDParam(0, w->window_number);
 
		DrawWindowWidgets(w);
 

	
 
		if (ind->accepts_cargo[0] != CT_INVALID) {
 
		if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
 
			for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) {
 
				if (j == 0) {
 
					DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0);
 
					y += 10;
 
				}
 
				SetDParam(0, ind->accepts_cargo[j]);
 
				SetDParam(1, i->incoming_cargo_waiting[j]);
 
				DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0);
 
				y += 10;
 
			}
 
		} else if (ind->accepts_cargo[0] != CT_INVALID) {
 
			StringID str;
 

	
 
			SetDParam(0, GetCargo(ind->accepts_cargo[0])->name);
 
@@ -319,39 +366,44 @@ static void IndustryViewWndProc(Window *
 
					str = STR_4829_REQUIRES;
 
				}
 
			}
 
			DrawString(2, 107, str, 0);
 
			DrawString(2, y, str, 0);
 
			y += 10;
 
		}
 

	
 
		if (ind->produced_cargo[0] != CT_INVALID) {
 
			DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
 
		for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) {
 
			if (j == 0) {
 
				if (ind->accepts_cargo[0] != CT_INVALID) y += 10;
 
				DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0);
 
				y += 10;
 
			}
 

	
 
			SetDParam(0, ind->produced_cargo[0]);
 
			SetDParam(1, i->last_month_production[0]);
 
			SetDParam(0, ind->produced_cargo[j]);
 
			SetDParam(1, i->last_month_production[j]);
 

	
 
			SetDParam(2, i->last_month_pct_transported[0] * 100 >> 8);
 
			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 127, STR_482B_TRANSPORTED, 0);
 
			SetDParam(2, i->last_month_pct_transported[j] * 100 >> 8);
 
			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, 0);
 
			/* Let's put out those buttons.. */
 
			if (IsProductionAlterable(i)) {
 
				DrawArrowButtons(5, 127, 3, (WP(w, vp2_d).data_2 == 1) ? WP(w, vp2_d).data_3 : 0,
 
						!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
 
				DrawArrowButtons(5, y, 3, (WP(w, vp2_d).data_2 == j + 1) ? WP(w, vp2_d).data_3 : 0,
 
						!isProductionMinimum(i, j), !isProductionMaximum(i, j));
 
			}
 
			y += 10;
 
		}
 

	
 
			if (ind->produced_cargo[1] != CT_INVALID) {
 
				SetDParam(0, ind->produced_cargo[1]);
 
				SetDParam(1, i->last_month_production[1]);
 
				SetDParam(2, i->last_month_pct_transported[1] * 100 >> 8);
 
				DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
 
				/* Let's put out those buttons.. */
 
				if (IsProductionAlterable(i)) {
 
					DrawArrowButtons(5, 137, 3, (WP(w, vp2_d).data_2 == 2) ? WP(w, vp2_d).data_3 : 0,
 
						!isProductionMinimum(i, 1), !isProductionMaximum(i, 1));
 
		/* Get the extra message for the GUI */
 
		if (HASBIT(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) {
 
			uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->xy);
 
			if (callback_res != CALLBACK_FAILED) {
 
				StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
 
				if (message != STR_NULL && message != STR_UNDEFINED) {
 
					y += 10;
 
					DrawString(2, y, message, 0);
 
				}
 
			}
 
		}
 

	
 
		DrawWindowViewport(w);
 
		}
 
		break;
 
	} break;
 

	
 
	case WE_CLICK: {
 
		Industry *i;
 
@@ -366,8 +418,8 @@ static void IndustryViewWndProc(Window *
 
			if (!IsProductionAlterable(i)) return;
 

	
 
			x = e->we.click.pt.x;
 
			line = (e->we.click.pt.y - 127) / 10;
 
			if (e->we.click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) &&
 
			line = (e->we.click.pt.y - 121) / 10;
 
			if (e->we.click.pt.y >= 121 && IS_INT_INSIDE(line, 0, 2) &&
 
					GetIndustrySpec(i->type)->produced_cargo[line] != CT_INVALID) {
 
				if (IS_INT_INSIDE(x, 5, 25) ) {
 
					/* Clicked buttons, decrease or increase production */
src/lang/english.txt
Show inline comments
 
@@ -1980,6 +1980,9 @@ STR_4828_REQUIRES                       
 
STR_4829_REQUIRES                                               :{BLACK}Requires: {YELLOW}{STRING}, {STRING}, {STRING}
 
############ range for requires ends
 

	
 
STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING                      :{BLACK}Cargo waiting to be processed:
 
STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO                     :{YELLOW}{CARGO}{BLACK}
 

	
 
STR_482A_PRODUCTION_LAST_MONTH                                  :{BLACK}Production last month:
 
STR_482B_TRANSPORTED                                            :{YELLOW}{CARGO}{BLACK} ({COMMA}% transported)
 
STR_482C_CENTER_THE_MAIN_VIEW_ON                                :{BLACK}Centre the main view on industry location
src/newgrf_industries.cpp
Show inline comments
 
@@ -295,4 +295,6 @@ void IndustryProductionCallback(Industry
 

	
 
		SB(object.callback_param2, 24, 8, again);
 
	}
 

	
 
	InvalidateWindow(WC_INDUSTRY_VIEW, ind->index);
 
}
0 comments (0 inline, 0 general)