rail_gui.c
changeset 1738 dfa8f078450a
parent 1656 7860b81e4311
child 1781 5e2fef482637
equal deleted inserted replaced
1737:919bb66d2588 1738:dfa8f078450a
    11 #include "sound.h"
    11 #include "sound.h"
    12 #include "command.h"
    12 #include "command.h"
    13 #include "vehicle.h"
    13 #include "vehicle.h"
    14 #include "station.h"
    14 #include "station.h"
    15 #include "waypoint.h"
    15 #include "waypoint.h"
       
    16 #include "debug.h"
    16 
    17 
    17 static uint _cur_railtype;
    18 static uint _cur_railtype;
    18 static bool _remove_button_clicked;
    19 static bool _remove_button_clicked;
    19 static byte _build_depot_direction;
    20 static byte _build_depot_direction;
    20 static byte _waypoint_count=1;
    21 static byte _waypoint_count=1;
   254 
   255 
   255 static void BuildRailClick_Waypoint(Window *w)
   256 static void BuildRailClick_Waypoint(Window *w)
   256 {
   257 {
   257 	_waypoint_count = GetCustomStationsCount(STAT_CLASS_WAYP);
   258 	_waypoint_count = GetCustomStationsCount(STAT_CLASS_WAYP);
   258 	if (HandlePlacePushButton(w, 11, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Waypoint)
   259 	if (HandlePlacePushButton(w, 11, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Waypoint)
   259 	    && _waypoint_count > 1)
   260 	    && _waypoint_count > 0)
   260 		ShowBuildWaypointPicker();
   261 		ShowBuildWaypointPicker();
   261 }
   262 }
   262 
   263 
   263 static void BuildRailClick_Station(Window *w)
   264 static void BuildRailClick_Station(Window *w)
   264 {
   265 {
   857 }
   858 }
   858 
   859 
   859 
   860 
   860 static void BuildWaypointWndProc(Window *w, WindowEvent *e)
   861 static void BuildWaypointWndProc(Window *w, WindowEvent *e)
   861 {
   862 {
   862 	switch(e->event) {
   863 	switch (e->event) {
   863 	case WE_PAINT: {
   864 	case WE_PAINT: {
   864 		int r;
   865 		w->click_state = (1 << 3) << (_cur_waypoint_type - w->hscroll.pos);
   865 
       
   866 		w->click_state = (1 << 3) << _cur_waypoint_type;
       
   867 		DrawWindowWidgets(w);
   866 		DrawWindowWidgets(w);
   868 
   867 
   869 		r = 4*w->hscroll.pos;
   868 		if(w->hscroll.pos + 0 <= _waypoint_count) DrawWaypointSprite(2,   25, w->hscroll.pos + 0, _cur_railtype);
   870 		if(r+0<=_waypoint_count) DrawWaypointSprite(2,   25, r + 0, _cur_railtype);
   869 		if(w->hscroll.pos + 1 <= _waypoint_count) DrawWaypointSprite(70,  25, w->hscroll.pos + 1, _cur_railtype);
   871 		if(r+1<=_waypoint_count) DrawWaypointSprite(70,  25, r + 1, _cur_railtype);
   870 		if(w->hscroll.pos + 2 <= _waypoint_count) DrawWaypointSprite(138, 25, w->hscroll.pos + 2, _cur_railtype);
   872 		if(r+2<=_waypoint_count) DrawWaypointSprite(138, 25, r + 2, _cur_railtype);
   871 		if(w->hscroll.pos + 3 <= _waypoint_count) DrawWaypointSprite(206, 25, w->hscroll.pos + 3, _cur_railtype);
   873 		if(r+3<=_waypoint_count) DrawWaypointSprite(206, 25, r + 3, _cur_railtype);
   872 		if(w->hscroll.pos + 4 <= _waypoint_count) DrawWaypointSprite(274, 25, w->hscroll.pos + 4, _cur_railtype);
   874 		if(r+4<=_waypoint_count) DrawWaypointSprite(274, 25, r + 4, _cur_railtype);
   873 		break;
   875 		break;
   874 	}
   876 		}
       
   877 	case WE_CLICK: {
   875 	case WE_CLICK: {
   878 		switch(e->click.widget) {
   876 		switch (e->click.widget) {
   879 		case 0:
   877 		case 3: case 4: case 5: case 6: case 7:
   880 			ResetObjectToPlace();
   878 			_cur_waypoint_type = e->click.widget - 3 + w->hscroll.pos;
   881 			break;
       
   882 		case 3:
       
   883 		case 4:
       
   884 		case 5:
       
   885 		case 6:
       
   886 		case 7:
       
   887 			_cur_waypoint_type = e->click.widget - 3;
       
   888 			SndPlayFx(SND_15_BEEP);
   879 			SndPlayFx(SND_15_BEEP);
   889 			SetWindowDirty(w);
   880 			SetWindowDirty(w);
   890 			break;
   881 			break;
   891 		}
   882 		}
   892 		break;
   883 		break;
   893 	}
   884 	}
   894 
   885 
   895 	case WE_MOUSELOOP:
   886 	case WE_MOUSELOOP:
   896 		if (WP(w,def_d).close)
   887 		if (WP(w,def_d).close)
   897 			DeleteWindow(w);
   888 			DeleteWindow(w);
   898 		return;
   889 		break;
   899 
   890 
   900 	case WE_DESTROY:
   891 	case WE_DESTROY:
   901 		ResetObjectToPlace();
   892 		if (!WP(w,def_d).close)
       
   893 			ResetObjectToPlace();
   902 		break;
   894 		break;
   903 	}
   895 	}
   904 }
   896 }
   905 
   897 
   906 static const Widget _build_waypoint_widgets[] = {
   898 static const Widget _build_waypoint_widgets[] = {
   928 
   920 
   929 static void ShowBuildWaypointPicker(void)
   921 static void ShowBuildWaypointPicker(void)
   930 {
   922 {
   931 	Window *w = AllocateWindowDesc(&_build_waypoint_desc);
   923 	Window *w = AllocateWindowDesc(&_build_waypoint_desc);
   932 	w->hscroll.cap = 5;
   924 	w->hscroll.cap = 5;
   933 	w->hscroll.count = (uint) (_waypoint_count+4) / 5;
   925 	w->hscroll.count = _waypoint_count + 1;
   934 }
   926 }
   935 
   927 
   936 
   928 
   937 void InitializeRailGui(void)
   929 void InitializeRailGui(void)
   938 {
   930 {