src/bridge_gui.cpp
changeset 6530 c43fa965e8ae
parent 6443 b8f06d8eb7be
child 6720 35756db7e577
child 7439 0c0e2945c890
child 9903 dc85aaa556ae
equal deleted inserted replaced
6529:c53737959606 6530:c43fa965e8ae
    39 }
    39 }
    40 
    40 
    41 static void BuildBridgeWndProc(Window *w, WindowEvent *e)
    41 static void BuildBridgeWndProc(Window *w, WindowEvent *e)
    42 {
    42 {
    43 	switch (e->event) {
    43 	switch (e->event) {
    44 	case WE_PAINT: {
    44 		case WE_PAINT:
    45 		uint i;
    45 			DrawWindowWidgets(w);
    46 
    46 
    47 		DrawWindowWidgets(w);
    47 			for (uint i = 0; i < 4 && i + w->vscroll.pos < _bridgedata.count; i++) {
       
    48 				const Bridge *b = &_bridge[_bridgedata.indexes[i + w->vscroll.pos]];
    48 
    49 
    49 		for (i = 0; i < 4 && i + w->vscroll.pos < _bridgedata.count; i++) {
    50 				SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]);
    50 			const Bridge *b = &_bridge[_bridgedata.indexes[i + w->vscroll.pos]];
    51 				SetDParam(1, b->speed * 10 / 16);
       
    52 				SetDParam(0, b->material);
       
    53 				DrawSprite(b->sprite, b->pal, 3, 15 + i * 22);
    51 
    54 
    52 			SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]);
    55 				DrawString(44, 15 + i * 22 , STR_500D, 0);
    53 			SetDParam(1, b->speed * 10 / 16);
    56 			}
    54 			SetDParam(0, b->material);
    57 			break;
    55 			DrawSprite(b->sprite, b->pal, 3, 15 + i * 22);
       
    56 
    58 
    57 			DrawString(44, 15 + i * 22 , STR_500D, 0);
    59 		case WE_KEYPRESS: {
    58 		}
    60 			uint i = e->we.keypress.keycode - '1';
    59 	} break;
    61 			if (i < 9 && i < _bridgedata.count) {
       
    62 				e->we.keypress.cont = false;
       
    63 				BuildBridge(w, i);
       
    64 			}
    60 
    65 
    61 	case WE_KEYPRESS: {
    66 			break;
    62 		uint i = e->we.keypress.keycode - '1';
       
    63 		if (i < 9 && i < _bridgedata.count) {
       
    64 			e->we.keypress.cont = false;
       
    65 			BuildBridge(w, i);
       
    66 		}
    67 		}
    67 
    68 
    68 		break;
    69 		case WE_CLICK:
    69 	}
    70 			if (e->we.click.widget == 2) {
    70 
    71 				uint ind = ((int)e->we.click.pt.y - 14) / 22;
    71 	case WE_CLICK:
    72 				if (ind < 4 && (ind += w->vscroll.pos) < _bridgedata.count)
    72 		if (e->we.click.widget == 2) {
    73 					BuildBridge(w, ind);
    73 			uint ind = ((int)e->we.click.pt.y - 14) / 22;
    74 			}
    74 			if (ind < 4 && (ind += w->vscroll.pos) < _bridgedata.count)
    75 			break;
    75 				BuildBridge(w, ind);
       
    76 		}
       
    77 		break;
       
    78 	}
    76 	}
    79 }
    77 }
    80 
    78 
    81 static const Widget _build_bridge_widgets[] = {
    79 static const Widget _build_bridge_widgets[] = {
    82 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
    80 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
   132 
   130 
   133 	if (CmdFailed(ret)) {
   131 	if (CmdFailed(ret)) {
   134 		errmsg = _error_message;
   132 		errmsg = _error_message;
   135 	} else {
   133 	} else {
   136 		// check which bridges can be built
   134 		// check which bridges can be built
   137 		int bridge_len;         // length of the middle parts of the bridge
       
   138 		int tot_bridgedata_len; // total length of bridge
       
   139 
       
   140 		// get absolute bridge length
   135 		// get absolute bridge length
   141 		bridge_len = GetBridgeLength(start, end);
   136 		// length of the middle parts of the bridge
   142 		tot_bridgedata_len = bridge_len + 2;
   137 		int bridge_len = GetBridgeLength(start, end);
       
   138 		// total length of bridge
       
   139 		int tot_bridgedata_len = bridge_len + 2;
   143 
   140 
   144 		tot_bridgedata_len = CalcBridgeLenCostFactor(tot_bridgedata_len);
   141 		tot_bridgedata_len = CalcBridgeLenCostFactor(tot_bridgedata_len);
   145 
   142 
   146 		for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) { // loop for all bridgetypes
   143 		for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) { // loop for all bridgetypes
   147 			if (CheckBridge_Stuff(bridge_type, bridge_len)) {
   144 			if (CheckBridge_Stuff(bridge_type, bridge_len)) {