From 989289faddc4b1f7dee97defb7d80e6d1cea0465 Mon Sep 17 00:00:00 2001 From: darkvater Date: Sun, 14 Nov 2004 11:04:59 +0000 Subject: [PATCH] (svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky. --- functions.h | 1 + lang/czech.txt | 3 ++ lang/english.txt | 3 ++ rail_cmd.c | 29 ++++++++++++++++ rail_gui.c | 87 ++++++++++++++++++++++++++++++++++++++++++++---- station.h | 5 +-- 6 files changed, 119 insertions(+), 9 deletions(-) diff --git a/functions.h b/functions.h index d960390cdf..7d5f2094eb 100644 --- a/functions.h +++ b/functions.h @@ -66,6 +66,7 @@ void StationPickerDrawSprite(int x, int y, int railtype, int image); /* track_land.c */ void DrawTrainDepotSprite(int x, int y, int image, int railtype); +void DrawCheckpointSprite(int x, int y, int image); /* road_land.c */ void DrawRoadDepotSprite(int x, int y, int image); diff --git a/lang/czech.txt b/lang/czech.txt index 29d7f6539d..df4cf8c651 100644 --- a/lang/czech.txt +++ b/lang/czech.txt @@ -1083,6 +1083,9 @@ STR_CHECKPOINTNAME_CITY :Kontrolni bod {TOWN} STR_CHECKPOINTNAME_CITY_SERIAL :Kontrolni bod {TOWN} #{COMMA16} STR_LANDINFO_CHECKPOINT :Kontrolni bod +STR_CHECKPOINT :{WHITE}Kontrolní bod +STR_CHECKPOINT_GRAPHICS_TIP :{BLACK}Vyber typ kontrolního bodu + STR_CHECKPOINT_VIEWPORT :{WHITE}{CHECKPOINT} STR_CHECKPOINT_VIEWPORT_TINY :{TINYFONT}{WHITE}{CHECKPOINT} STR_CHECKPOINT_RAW :{CHECKPOINT} diff --git a/lang/english.txt b/lang/english.txt index 91f246f384..e6434ee295 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -1083,6 +1083,9 @@ STR_CHECKPOINTNAME_CITY :Checkpoint {TOWN} STR_CHECKPOINTNAME_CITY_SERIAL :Checkpoint {TOWN} #{COMMA16} STR_LANDINFO_CHECKPOINT :Checkpoint +STR_CHECKPOINT :{WHITE}Checkpoint +STR_CHECKPOINT_GRAPHICS_TIP :{BLACK}Select checkpoint type + STR_CHECKPOINT_VIEWPORT :{WHITE}{CHECKPOINT} STR_CHECKPOINT_VIEWPORT_TINY :{TINYFONT}{WHITE}{CHECKPOINT} STR_CHECKPOINT_RAW :{CHECKPOINT} diff --git a/rail_cmd.c b/rail_cmd.c index 5a79829bef..67b7812d32 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -1620,6 +1620,35 @@ void DrawTrainDepotSprite(int x, int y, int image, int railtype) } } +void DrawCheckpointSprite(int x, int y, int stat_id) +{ + // TODO: We should use supersets with cargo-id FF, if available. --pasky + DrawTileSprites *cust = GetCustomStation('WAYP', stat_id); + DrawTileSeqStruct const *seq; + uint32 ormod, img; + + assert(cust); + + // emulate station tile - open with building + // add 1 to get the other direction + cust = &cust[2]; + + ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)); + + x += 33; + y += 17; + + img = cust->ground_sprite; + if (img & 0x8000) img = (img & 0x7FFF); + DrawSprite(img, x, y); + + foreach_draw_tile_seq(seq, cust->seq) { + Point pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z); + DrawSprite((seq->image&0x3FFF) | ormod, x + pt.x, y + pt.y); + } +} + + #define NUM_SSD_ENTRY 256 #define NUM_SSD_STACK 32 diff --git a/rail_gui.c b/rail_gui.c index cf106f57f3..7a16a13226 100644 --- a/rail_gui.c +++ b/rail_gui.c @@ -8,10 +8,13 @@ #include "sound.h" #include "command.h" #include "vehicle.h" +#include "station.h" static uint _cur_railtype; static bool _remove_button_clicked; static byte _build_depot_direction; +static byte _checkpoint_count; +static byte _cur_checkpoint_type; struct { byte orientation; @@ -23,6 +26,7 @@ struct { static void HandleStationPlacement(uint start, uint end); static void ShowBuildTrainDepotPicker(); +static void ShowBuildCheckpointPicker(); static void ShowStationBuilder(); typedef void OnButtonClick(Window *w); @@ -114,12 +118,7 @@ static void PlaceRail_Depot(uint tile) static void PlaceRail_Checkpoint(uint tile) { if (!_remove_button_clicked) { - /* TODO: We need a graphics selector. In the meantime we use the first - * custom station ID which works ok with newstats.grf (if you add it - * to openttd.cfg you want custom checkpoints) and if you don't have - * any custom station graphics it will fall back to the railstation - * sprites anyway. --pasky */ - DoCommandP(tile, 0x100, 0, CcPlaySound1E, CMD_BUILD_TRAIN_CHECKPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_CHECKPOINT)); + DoCommandP(tile, _checkpoint_count > 0 ? (0x100 + _cur_checkpoint_type) : 0, 0, CcPlaySound1E, CMD_BUILD_TRAIN_CHECKPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_CHECKPOINT)); } else { DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_CHECKPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_CHECKPOINT)); } @@ -308,7 +307,10 @@ static void BuildRailClick_Sign(Window *w) static void BuildRailClick_Checkpoint(Window *w) { - HandlePlacePushButton(w, 18, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Checkpoint); + _checkpoint_count = GetCustomStationsCount('WAYP'); + if (HandlePlacePushButton(w, 18, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Checkpoint) + && _checkpoint_count > 1) + ShowBuildCheckpointPicker(); } static void BuildRailClick_Convert(Window *w) @@ -1052,6 +1054,77 @@ static void ShowBuildTrainDepotPicker() AllocateWindowDesc(&_build_depot_desc); } + +static void BuildCheckpointWndProc(Window *w, WindowEvent *e) +{ + switch(e->event) { + case WE_PAINT: { + int r; + + w->click_state = (1 << 3) << _cur_checkpoint_type; + DrawWindowWidgets(w); + + r = 4*w->hscroll.pos; + if(r+0<=_checkpoint_count) DrawCheckpointSprite(2, 25, r + 0); + if(r+1<=_checkpoint_count) DrawCheckpointSprite(70, 25, r + 1); + if(r+2<=_checkpoint_count) DrawCheckpointSprite(138, 25, r + 2); + if(r+3<=_checkpoint_count) DrawCheckpointSprite(206, 25, r + 3); + break; + } + case WE_CLICK: { + switch(e->click.widget) { + case 0: + ResetObjectToPlace(); + break; + case 3: + case 4: + case 5: + case 6: + _cur_checkpoint_type = e->click.widget - 3; + SndPlayFx(0x13); + SetWindowDirty(w); + break; + } + break; + } + + case WE_MOUSELOOP: + if (WP(w,def_d).close) + DeleteWindow(w); + return; + } +} + +static const Widget _build_checkpoint_widgets[] = { +{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, +{ WWT_CAPTION, 7, 11, 275, 0, 13, STR_CHECKPOINT,STR_018C_WINDOW_TITLE_DRAG_THIS}, +{ WWT_PANEL, 7, 0, 275, 14, 91, 0x0, 0}, + +{ WWT_PANEL, 7, 3, 68, 17, 76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP}, +{ WWT_PANEL, 7, 71, 136, 17, 76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP}, +{ WWT_PANEL, 7, 139, 204, 17, 76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP}, +{ WWT_PANEL, 7, 207, 272, 17, 76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP}, + +{ WWT_HSCROLLBAR, 7, 1, 275, 80, 91, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, +{ WWT_LAST}, +}; + +static const WindowDesc _build_checkpoint_desc = { + -1,-1, 276, 92, + WC_BUILD_DEPOT,WC_BUILD_TOOLBAR, + WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, + _build_checkpoint_widgets, + BuildCheckpointWndProc +}; + +static void ShowBuildCheckpointPicker() +{ + Window *w = AllocateWindowDesc(&_build_checkpoint_desc); + w->hscroll.cap = 1; + w->hscroll.count = (uint) (_checkpoint_count+3) / 4; +} + + void InitializeRailGui() { _build_depot_direction = 3; diff --git a/station.h b/station.h index 10271785f0..826e209610 100644 --- a/station.h +++ b/station.h @@ -42,11 +42,12 @@ struct Station { // trainstation width/height byte trainst_w, trainst_h; - byte stat_id, class_id; + byte class_id; // custom graphics station class + byte stat_id; // custom graphics station id in the @class_id class uint16 build_date; //uint16 airport_flags; - uint32 airport_flags; + uint32 airport_flags; uint16 index; VehicleID last_vehicle;