diff --git a/gui/trafficlight_info.cc b/gui/trafficlight_info.cc index 3765eec02..bef251de6 100644 --- a/gui/trafficlight_info.cc +++ b/gui/trafficlight_info.cc @@ -19,7 +19,7 @@ trafficlight_info_t::trafficlight_info_t(roadsign_t* s) : obj_infowin_t(s), ampel(s) { - ns.set_pos( scr_coord(10,get_windowsize().h-40) ); + ns.set_pos( scr_coord(10,get_windowsize().h-85) ); ns.set_size( scr_size(52, D_EDIT_HEIGHT) ); ns.set_limits( 1, 255 ); ns.set_value( s->get_ticks_ns() ); @@ -27,7 +27,7 @@ trafficlight_info_t::trafficlight_info_t(roadsign_t* s) : ns.add_listener( this ); add_component( &ns ); - ow.set_pos( scr_coord(66,get_windowsize().h-40) ); + ow.set_pos( scr_coord(66,get_windowsize().h-85) ); ow.set_size( scr_size(52, D_EDIT_HEIGHT) ); ow.set_limits( 1, 255 ); ow.set_value( s->get_ticks_ow() ); @@ -35,13 +35,34 @@ trafficlight_info_t::trafficlight_info_t(roadsign_t* s) : ow.add_listener( this ); add_component( &ow ); - offset.set_pos( scr_coord(122,get_windowsize().h-40) ); + offset.set_pos( scr_coord(122,get_windowsize().h-85) ); offset.set_size( scr_size(52, D_EDIT_HEIGHT) ); offset.set_limits( 0, 255 ); offset.set_value( s->get_ticks_offset() ); offset.wrap_mode( false ); offset.add_listener( this ); add_component( &offset ); + + // direction_buttons + const char* direction_texts[4] = {"nord","ost","sued","west"}; + for(uint8 i=0; i<4; i++) { + // left side + direction_buttons[i].init( button_t::square_state, "", scr_coord(30,get_windowsize().h-25-LINESPACE*(4-i)), scr_size(D_BUTTON_HEIGHT,D_BUTTON_HEIGHT) ); + + // right side + direction_buttons[i+4].init( button_t::square_state, "", scr_coord(90,get_windowsize().h-25-LINESPACE*(4-i)), scr_size(D_BUTTON_HEIGHT,D_BUTTON_HEIGHT) ); + + // center labels + direction_labels[i].init( direction_texts[i], scr_coord(40,get_windowsize().h-25-LINESPACE*(4-i))); + direction_labels[i].set_size( scr_size(50, D_LABEL_HEIGHT) ); + direction_labels[i].set_align(gui_label_t::align_t::centered); + add_component( &direction_labels[i] ); + } + for(uint8 i=0; i<8; i++) { + direction_buttons[i].add_listener( this ); + direction_buttons[i].pressed = ((ampel->get_open_direction())&(1<set_default_param( param ); welt->set_tool( tool_t::simple_tool[TOOL_CHANGE_TRAFFIC_LIGHT], welt->get_active_player() ); } + else { + // maybe this event is caused by the direction buttons. + + uint8 dir = ampel->get_open_direction(); + for(uint8 i=0; i<8; i++) { + if(komp == &direction_buttons[i]) { + dir ^= 1 << i; + } + } + // set open_direction + sprintf( param, "%s,3,%i", ampel->get_pos().get_str(), dir ); + tool_t::simple_tool[TOOL_CHANGE_TRAFFIC_LIGHT]->set_default_param( param ); + welt->set_tool( tool_t::simple_tool[TOOL_CHANGE_TRAFFIC_LIGHT], welt->get_active_player() ); + for(uint8 i=0; i<8; i++) { + direction_buttons[i].pressed = ((ampel->get_open_direction())&(1<get_ticks_ns() ); ow.set_value( ampel->get_ticks_ow() ); offset.set_value( ampel->get_ticks_offset() ); + for(uint8 i=0; i<8; i++) { + direction_buttons[i].pressed = ((ampel->get_open_direction())&(1< east-west set_owner( player ); if( desc->is_private_way() ) { // init ownership of private ways @@ -202,8 +203,7 @@ void roadsign_t::info(cbuffer_t & buf) const buf.printf("%s%u\n", translator::translate("\ndirection:"), dir); if( automatic ) { buf.append(translator::translate("\nSet phases:")); - buf.append("\n"); - buf.append("\n"); + buf.append("\n\n\n\n\n\n"); } } } @@ -470,10 +470,10 @@ sync_result roadsign_t::sync_step(uint32 /*delta_t*/) // change every ~32s uint32 ticks = ((welt->get_ticks()>>10)+ticks_offset) % (ticks_ns+ticks_ow); - uint8 new_state = (ticks >= ticks_ns) ^ (welt->get_settings().get_rotation() & 1); + uint8 new_state = (ticks >= ticks_ns); if(state!=new_state) { state = new_state; - dir = (new_state==0) ? ribi_t::northsouth : ribi_t::eastwest; + dir = (new_state==0) ? open_direction&0x0F : (open_direction>>4)&0x0F; calc_image(); } } @@ -486,10 +486,9 @@ void roadsign_t::rotate90() // only meaningful for traffic lights obj_t::rotate90(); if(automatic && !desc->is_private_way()) { - state = (state+1)&1; - uint8 temp = ticks_ns; - ticks_ns = ticks_ow; - ticks_ow = temp; + uint8 first_dir = ribi_t::rotate90(open_direction&0x0F); + uint8 second_dir = ribi_t::rotate90((open_direction>>4)&0x0F); + open_direction = first_dir + (second_dir << 4); trafficlight_info_t *const trafficlight_win = dynamic_cast( win_get_magic( (ptrdiff_t)this ) ); if( trafficlight_win ) { @@ -553,6 +552,12 @@ void roadsign_t::rdwr(loadsave_t *file) } } + if( file->get_version()>=120006 ) { + file->rdwr_byte(open_direction); + } else if( file->is_loading() ) { + open_direction = 0xA5; + } + dummy = state; file->rdwr_byte(dummy); state = dummy; diff --git a/obj/roadsign.h b/obj/roadsign.h index 951f28a46..7471c1849 100644 --- a/obj/roadsign.h +++ b/obj/roadsign.h @@ -37,6 +37,7 @@ protected: uint8 ticks_ns; uint8 ticks_ow; uint8 ticks_offset; + uint8 open_direction; sint8 after_yoffset, after_xoffset; @@ -112,6 +113,9 @@ public: uint8 get_ticks_offset() const { return ticks_offset; } void set_ticks_offset(uint8 offset) { ticks_offset = offset; } + uint8 get_open_direction() const { return open_direction; } + void set_open_direction(uint8 dir) { open_direction = dir; } + inline void set_image( image_id b ) { image = b; } image_id get_image() const { return image; } diff --git a/simtool.cc b/simtool.cc index 20ae588ba..be1af91f7 100644 --- a/simtool.cc +++ b/simtool.cc @@ -7332,6 +7332,9 @@ bool tool_change_traffic_light_t::init( player_t *player ) else if( ns == 2 ) { rs->set_ticks_offset( (uint8)ticks ); } + else if( ns == 3 ) { + rs->set_open_direction( (uint8)ticks ); + } // update the window if( rs->get_desc()->is_traffic_light() ) { trafficlight_info_t* trafficlight_win = (trafficlight_info_t*)win_get_magic((ptrdiff_t)rs); diff --git a/simversion.h b/simversion.h index 604790dfc..d4a626c6f 100644 --- a/simversion.h +++ b/simversion.h @@ -17,8 +17,8 @@ // Beware: SAVEGAME minor is often ahead of version minor when there were patches. // ==> These have no direct connection at all! -#define SIM_SAVE_MINOR 5 -#define SIM_SERVER_MINOR 6 +#define SIM_SAVE_MINOR 6 +#define SIM_SERVER_MINOR 7 // NOTE: increment before next release to enable save/load of new features #define MAKEOBJ_VERSION "60.0"