summaryrefslogtreecommitdiff
path: root/ship_gui.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-26 16:47:51 +0000
committerbjarni <bjarni@openttd.org>2006-09-26 16:47:51 +0000
commit40eecb339193a9c5fb100237a1a863687ea31c55 (patch)
tree381d620a928fbc6c40266c4078ae71959a878f36 /ship_gui.c
parentce5dc846587432d853c72fcd36648ec9311eabbd (diff)
downloadopenttd-40eecb339193a9c5fb100237a1a863687ea31c55.tar.xz
(svn r6513) -Codechange: unified the code to draw depot windows
This change is intended to make it easier to make depot behaviour consistent and faster to code when adding more features in the future The user interface should hopefully not be affected by this
Diffstat (limited to 'ship_gui.c')
-rw-r--r--ship_gui.c280
1 files changed, 0 insertions, 280 deletions
diff --git a/ship_gui.c b/ship_gui.c
index 6a1fcda09..c39d53d2b 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -604,286 +604,6 @@ void ShowShipViewWindow(const Vehicle *v)
}
}
-static void DrawShipDepotWindow(Window *w)
-{
- Vehicle **vl = WP(w, traindepot_d).vehicle_list;
- TileIndex tile;
- int x, y, max;
- uint16 num = WP(w, traindepot_d).engine_count;
- Depot *depot;
-
- tile = w->window_number;
-
- /* setup disabled buttons */
- w->disabled_state =
- IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 7));
-
- /* determine amount of items for scroller */
- SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
-
- /* locate the depot struct */
- depot = GetDepotByTile(tile);
- assert(depot != NULL);
-
- SetDParam(0, depot->town_index);
- DrawWindowWidgets(w);
-
- x = 2;
- y = 15;
- num = w->vscroll.pos * w->hscroll.cap;
- max = min(WP(w, traindepot_d).engine_count, num + (w->vscroll.cap * w->hscroll.cap));
-
- for (; num < max; num++) {
- const Vehicle *v = vl[num];
- DrawShipImage(v, x + 19, y, WP(w,traindepot_d).sel);
-
- SetDParam(0, v->unitnumber);
- DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
-
- DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x, y + 9);
-
- if ((x += 90) == 2 + 90 * w->hscroll.cap) {
- x = 2;
- y += 24;
- }
- }
-}
-
-static int GetVehicleFromShipDepotWndPt(const Window *w, int x, int y, Vehicle **veh)
-{
- Vehicle **vl = WP(w, traindepot_d).vehicle_list;
- uint xt,row,xm,ym;
- int pos;
-
- xt = x / 90;
- xm = x % 90;
- if (xt >= w->hscroll.cap) return 1;
-
- row = (y - 14) / 24;
- ym = (y - 14) % 24;
- if (row >= w->vscroll.cap) return 1;
-
- pos = (row + w->vscroll.pos) * w->hscroll.cap + xt;
-
- if (WP(w, traindepot_d).engine_count <= pos) return 1; // empty block, so no vehicle is selected
- *veh = vl[pos];
- if (xm >= 19) return 0; // drag vehicle
- if (ym <= 10) return -1; // show window
- return -2; // start stop
-}
-
-static void ShipDepotClick(Window *w, int x, int y)
-{
- Vehicle *v = NULL;
- int mode = GetVehicleFromShipDepotWndPt(w, x, y, &v);
-
- // share / copy orders
- if (_thd.place_mode && mode <= 0) {
- _place_clicked_vehicle = v;
- return;
- }
-
- switch (mode) {
- case 1: // invalid
- return;
-
- case 0: // start dragging of vehicle
- if (v != NULL) {
- WP(w,traindepot_d).sel = v->index;
- SetWindowDirty(w);
- SetObjectToPlaceWnd(GetVehiclePalette(v) | GetShipImage(v, DIR_W), 4, w);
- }
- break;
-
- case -1: // show info window
- ShowShipViewWindow(v);
- break;
-
- case -2: // click start/stop flag
- DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
- break;
-
- default:
- NOT_REACHED();
- }
-}
-
-/**
- * Clones a ship
- * @param *v is the original vehicle to clone
- * @param *w is the window of the depot where the clone is build
- */
-static void HandleCloneVehClick(const Vehicle *v, const Window *w)
-{
- if (v == NULL || v->type != VEH_Ship) return;
-
- DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip,
- CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)
- );
-
- ResetObjectToPlace();
-}
-
-static void ClonePlaceObj(const Window *w)
-{
- const Vehicle *v = CheckMouseOverVehicle();
-
- if (v != NULL) HandleCloneVehClick(v, w);
-}
-
-static void ShipDepotWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_CREATE:
- WP(w, traindepot_d).vehicle_list = NULL;
- WP(w, traindepot_d).engine_count = 0;
- break;
-
- case WE_PAINT:
- BuildDepotVehicleList(VEH_Ship, w->window_number, &WP(w, traindepot_d).vehicle_list, &WP(w, traindepot_d).engine_list_length, &WP(w, traindepot_d).engine_count, NULL, NULL, NULL);
- DrawShipDepotWindow(w);
- break;
-
- case WE_CLICK:
- switch (e->we.click.widget) {
- case 5: // List
- ShipDepotClick(w, e->we.click.pt.x, e->we.click.pt.y);
- break;
-
- case 7: // Build vehicle
- ResetObjectToPlace();
- ShowBuildShipWindow(w->window_number);
- break;
-
- case 8: // Clone button
- InvalidateWidget(w, 8);
- TOGGLEBIT(w->click_state, 8);
-
- if (HASBIT(w->click_state, 8)) {
- _place_clicked_vehicle = NULL;
- SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w);
- } else {
- ResetObjectToPlace();
- }
- break;
-
- case 9: ScrollMainWindowToTile(w->window_number); break;
- }
- break;
-
- case WE_PLACE_OBJ: {
- ClonePlaceObj(w);
- } break;
-
- case WE_ABORT_PLACE_OBJ: {
- CLRBIT(w->click_state, 8);
- InvalidateWidget(w, 8);
- } break;
-
- // check if a vehicle in a depot was clicked..
- case WE_MOUSELOOP: {
- const Vehicle *v = _place_clicked_vehicle;
-
- // since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
- if (v != NULL && HASBIT(w->click_state, 8)) {
- _place_clicked_vehicle = NULL;
- HandleCloneVehClick(v, w);
- }
- } break;
-
- case WE_DESTROY:
- DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
- free((void*)WP(w, traindepot_d).vehicle_list);
- break;
-
- case WE_DRAGDROP:
- switch (e->we.click.widget) {
- case 5: {
- Vehicle *v;
- VehicleID sel = WP(w,traindepot_d).sel;
-
- WP(w,traindepot_d).sel = INVALID_VEHICLE;
- SetWindowDirty(w);
-
- if (GetVehicleFromShipDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v) == 0 &&
- v != NULL &&
- sel == v->index) {
- ShowShipViewWindow(v);
- }
- } break;
-
- case 4:
- if (!HASBIT(w->disabled_state, 4) &&
- WP(w,traindepot_d).sel != INVALID_VEHICLE) {
- Vehicle *v;
-
- HandleButtonClick(w, 4);
-
- v = GetVehicle(WP(w,traindepot_d).sel);
- WP(w,traindepot_d).sel = INVALID_VEHICLE;
-
- _backup_orders_tile = v->tile;
- BackupVehicleOrders(v, _backup_orders_data);
-
- if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP)))
- _backup_orders_tile = 0;
- }
- break;
- default:
- WP(w,traindepot_d).sel = INVALID_VEHICLE;
- SetWindowDirty(w);
- }
- break;
-
- case WE_RESIZE:
- w->vscroll.cap += e->we.sizing.diff.y / 24;
- w->hscroll.cap += e->we.sizing.diff.x / 90;
- w->widget[5].data = (w->vscroll.cap << 8) + w->hscroll.cap;
- break;
- }
-}
-
-static const Widget _ship_depot_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 292, 0, 13, STR_9803_SHIP_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_LR, 14, 293, 304, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PANEL, RESIZE_LRB, 14, 270, 292, 14, 13, 0x0, STR_NULL},
-{ WWT_IMGBTN, RESIZE_LRTB, 14, 270, 292, 14, 61, 0x2A9, STR_9821_DRAG_SHIP_TO_HERE_TO_SELL},
-
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 269, 14, 61, 0x203, STR_981F_SHIPS_CLICK_ON_SHIP_FOR},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 293, 304, 14, 61, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 96, 62, 73, STR_9804_NEW_SHIPS, STR_9820_BUILD_NEW_SHIP},
-{WWT_NODISTXTBTN, RESIZE_TB, 14, 97, 194, 62, 73, STR_CLONE_SHIP, STR_CLONE_SHIP_DEPOT_INFO},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 195, 292, 62, 73, STR_00E4_LOCATION, STR_9822_CENTER_MAIN_VIEW_ON_SHIP},
-{ WWT_PANEL, RESIZE_RTB, 14, 293, 292, 62, 73, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 293, 304, 62, 73, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-static const WindowDesc _ship_depot_desc = {
- -1, -1, 305, 74,
- WC_VEHICLE_DEPOT,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
- _ship_depot_widgets,
- ShipDepotWndProc
-};
-
-void ShowShipDepotWindow(TileIndex tile)
-{
- Window *w = AllocateWindowDescFront(&_ship_depot_desc,tile);
-
- if (w != NULL) {
- w->caption_color = GetTileOwner(w->window_number);
- w->vscroll.cap = 2;
- w->hscroll.cap = 3;
- w->resize.step_width = 90;
- w->resize.step_height = 24;
- WP(w,traindepot_d).sel = INVALID_VEHICLE;
- _backup_orders_tile = 0;
- }
-}
-
-
void DrawSmallOrderListShip(const Vehicle *v, int x, int y)
{
const Order *order;