Skip to content

Commit

Permalink
ADD: (falconne) hide only objects around cursor
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@4958 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Nov 25, 2011
1 parent 40ef435 commit 8f20be9
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 15 deletions.
10 changes: 9 additions & 1 deletion dataobj/umgebung.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ bool umgebung_t::night_shift;
bool umgebung_t::hide_with_transparency;
bool umgebung_t::hide_trees;
uint8 umgebung_t::hide_buildings;
bool umgebung_t::hide_under_cursor;
uint16 umgebung_t::cursor_hide_range;
bool umgebung_t::use_transparency_station_coverage;
uint8 umgebung_t::station_coverage_show;
sint32 umgebung_t::show_names;
Expand Down Expand Up @@ -120,6 +122,8 @@ void umgebung_t::init()
hide_with_transparency = true;
hide_trees = false;
hide_buildings = umgebung_t::NOT_HIDE;
hide_under_cursor = false;
cursor_hide_range = 5;

/* station stuff */
use_transparency_station_coverage = true;
Expand Down Expand Up @@ -300,7 +304,6 @@ void umgebung_t::rdwr(loadsave_t *file)
file->rdwr_bool( add_player_name_to_message );
file->rdwr_short( window_snap_distance );
}

else if( file->is_loading() ) {
// did not know about chat message, so we enable it
message_flags[0] |= (1 << message_t::chat); // ticker
Expand All @@ -310,5 +313,10 @@ void umgebung_t::rdwr(loadsave_t *file)

}

if( file->get_version()>=111001 ) {
file->rdwr_bool( hide_under_cursor );
file->rdwr_short( cursor_hide_range );
}

// server settings are not saved, since the are server specific and could be different on different servers on the save computers
}
10 changes: 10 additions & 0 deletions dataobj/umgebung.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ class umgebung_t
*/
static bool hide_trees;

/**
* When set, buildings and trees under mouse cursor will be hidden
*/
static bool hide_under_cursor;

/**
* Range of tiles from current cursor position to hide
*/
static uint16 cursor_hide_range;

/**
* Namen (Städte, Haltestellen) anzeigen? (0 .. 3)
* lable type 4..7
Expand Down
36 changes: 28 additions & 8 deletions gui/colors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
#define USE_TRANSPARENCY (SEPERATE1+4)
#define HIDE_TREES (USE_TRANSPARENCY+13)
#define HIDE_CITY_HOUSES (HIDE_TREES+13)
#define HIDE_UNDER_CURSOR (HIDE_CITY_HOUSES+13)
#define CURSOR_HIDE_RANGE (HIDE_UNDER_CURSOR)

#define SEPERATE2 (HIDE_CITY_HOUSES+13)
#define SEPERATE2 (CURSOR_HIDE_RANGE+13)

#define USE_TRANSPARENCY_STATIONS (SEPERATE2+4)
#define SHOW_STATION_COVERAGE (USE_TRANSPARENCY_STATIONS+13)
Expand Down Expand Up @@ -93,6 +95,13 @@ gui_frame_t( translator::translate("Helligk. u. Farben") )
scrollspeed.set_limits( 1, 9 );
scrollspeed.add_listener(this);

// range to hide under mouse cursor
cursor_hide_range.set_pos( koord(RIGHT_WIDTH-10-45,CURSOR_HIDE_RANGE) );
cursor_hide_range.set_groesse( koord( 45, BUTTON_HEIGHT-1 ) );
cursor_hide_range.set_value(umgebung_t::cursor_hide_range);
cursor_hide_range.set_limits( 0, 10 );
cursor_hide_range.add_listener(this);

// traffic density
traffic_density.set_pos( koord(RIGHT_WIDTH-10-45,DENS_TRAFFIC) );
traffic_density.set_groesse( koord( 45, BUTTON_HEIGHT-1 ) );
Expand Down Expand Up @@ -156,9 +165,6 @@ gui_frame_t( translator::translate("Helligk. u. Farben") )
buttons[18].set_pos( koord(10,SHOW_STATION_SIGNS) );
buttons[18].set_typ(button_t::arrowright);
buttons[18].set_tooltip("show station names");
/* buttons[18].set_text("show station names");
buttons[18].pressed = umgebung_t::show_names&1;
*/

buttons[19].set_pos( koord(10,SHOW_STATION_GOODS) );
buttons[19].set_typ(button_t::square_state);
Expand All @@ -175,9 +181,14 @@ gui_frame_t( translator::translate("Helligk. u. Farben") )
buttons[1].set_pos( koord(RIGHT_WIDTH-10-10,CONVOI_TOOLTIPS) );
buttons[1].set_typ(button_t::arrowright);

//Hide buildings and trees under mouse cursor
buttons[21].set_pos( koord(10,HIDE_UNDER_CURSOR) );
buttons[21].set_typ( button_t::square_state );
buttons[21].set_text( "Smart hide objects" );
buttons[21].set_tooltip( "hide objects under cursor" );

for(int i=0; i<COLORS_MAX_BUTTONS; i++ ) {
buttons[i].add_listener(this);
// add_komponente( buttons+i );
}

// add buttons for sensible keyboard tab order
Expand All @@ -191,6 +202,8 @@ gui_frame_t( translator::translate("Helligk. u. Farben") )
add_komponente( &scrollspeed );
add_komponente( buttons+10 );
add_komponente( buttons+11 );
add_komponente( buttons+21);
add_komponente( &cursor_hide_range );
add_komponente( buttons+12 );
add_komponente( buttons+13 );
add_komponente( buttons+14 );
Expand All @@ -209,7 +222,6 @@ gui_frame_t( translator::translate("Helligk. u. Farben") )
// add_komponente( buttons+4 );
// add_komponente( buttons+5 );


set_resizemode(gui_frame_t::horizonal_resize);
set_min_windowsize( koord(RIGHT_WIDTH, BOTTOM) );
set_fenstergroesse( koord(RIGHT_WIDTH, BOTTOM) );
Expand All @@ -224,6 +236,7 @@ void color_gui_t::set_fenstergroesse(koord groesse)
brightness.set_pos( koord(w-10-40,BRIGHTNESS) );
scrollspeed.set_pos( koord(w-10-40,SCROLL_SPEED) );
traffic_density.set_pos( koord(w-10-45,DENS_TRAFFIC) );
cursor_hide_range.set_pos( koord(w-10-45,CURSOR_HIDE_RANGE) );
buttons[1].set_pos( koord(w-10-10,CONVOI_TOOLTIPS) );
buttons[13].set_pos( koord(w-10-10,HIDE_CITY_HOUSES) );
}
Expand All @@ -245,6 +258,8 @@ bool color_gui_t::action_triggered( gui_action_creator_t *komp, value_t v)
}
} else if(&scrollspeed==komp) {
umgebung_t::scroll_multi = buttons[6].pressed ? -v.i : v.i;
} else if (&cursor_hide_range==komp) {
umgebung_t::cursor_hide_range = cursor_hide_range.get_value();
} else if((buttons+0)==komp) {
umgebung_t::show_vehicle_states = (umgebung_t::show_vehicle_states+2)%3;
} else if((buttons+1)==komp) {
Expand Down Expand Up @@ -310,6 +325,12 @@ bool color_gui_t::action_triggered( gui_action_creator_t *komp, value_t v)
welt->update_map();
// renew toolbar
werkzeug_t::update_toolbars(welt);
} else if((buttons+21)==komp) {
// see simwerkz.cc::wkz_hide_under_cursor_t::init
umgebung_t::hide_under_cursor = !umgebung_t::hide_under_cursor && umgebung_t::cursor_hide_range>0;
buttons[21].pressed = umgebung_t::hide_under_cursor;
// renew toolbar
werkzeug_t::update_toolbars(welt);
} else if (komp == &inp_underground_level) {
if(grund_t::underground_mode==grund_t::ugm_level) {
grund_t::underground_level = inp_underground_level.get_value();
Expand All @@ -322,8 +343,6 @@ bool color_gui_t::action_triggered( gui_action_creator_t *komp, value_t v)
}




void color_gui_t::zeichnen(koord pos, koord gr)
{
const int x = pos.x;
Expand All @@ -334,6 +353,7 @@ void color_gui_t::zeichnen(koord pos, koord gr)
buttons[ 7].pressed = welt->get_settings().get_show_pax();
buttons[ 8].pressed = welt->get_settings().get_random_pedestrians();
buttons[11].pressed = umgebung_t::hide_trees;
buttons[21].pressed = umgebung_t::hide_under_cursor;
buttons[15].pressed = umgebung_t::station_coverage_show;
buttons[16].pressed = grund_t::underground_mode == grund_t::ugm_all;
buttons[17].pressed = grund_t::show_grid;
Expand Down
4 changes: 2 additions & 2 deletions gui/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "components/gui_button.h"
#include "components/gui_numberinput.h"

#define COLORS_MAX_BUTTONS (21)
#define COLORS_MAX_BUTTONS (22)

class karte_t;

Expand All @@ -18,7 +18,7 @@ class color_gui_t : public gui_frame_t, private action_listener_t
private:
karte_t *welt;
button_t buttons[COLORS_MAX_BUTTONS];
gui_numberinput_t brightness, scrollspeed, traffic_density, inp_underground_level;
gui_numberinput_t brightness, scrollspeed, traffic_density, inp_underground_level, cursor_hide_range;

public:
color_gui_t(karte_t *welt);
Expand Down
1 change: 1 addition & 0 deletions simmenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ werkzeug_t *create_simple_tool(int toolnr)
case WKZ_ADD_MESSAGE_TOOL: tool = new wkz_add_message_t(); break;
case WKZ_TOGGLE_RESERVATION:tool = new wkz_toggle_reservation_t(); break;
case WKZ_VIEW_OWNER: tool = new wkz_view_owner_t(); break;
case WKZ_HIDE_UNDER_CURSOR: tool = new wkz_hide_under_cursor_t(); break;
default: dbg->error("create_simple_tool()","cannot satisfy request for simple_tool[%i]!",toolnr);
return NULL;
}
Expand Down
1 change: 1 addition & 0 deletions simmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum {
WKZ_ADD_MESSAGE_TOOL,
WKZ_TOGGLE_RESERVATION,
WKZ_VIEW_OWNER,
WKZ_HIDE_UNDER_CURSOR,
SIMPLE_TOOL_COUNT,
SIMPLE_TOOL = 0x2000
};
Expand Down
3 changes: 3 additions & 0 deletions simutrans/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
FIX: CJK description of houses correctly breaking
ADD: configure modes of transport for AIs
FIX: better tree offsets on tiles, should give less errors with trees on roads, in water etc
ADD: read (when with addon loadin) also ~/Simutrans/pakxyz/config.simuconf.tab
ADD: (falconne) hide only objects around cursor


Release of 111.0 (r4911 on 1-Nov-2011):

Expand Down
30 changes: 26 additions & 4 deletions simview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ void karte_ansicht_t::display(bool force_dirty)
// gr->get_disp_height() == min(gr->get_hoehe(), hmax_ground)
const sint8 hmax_ground = (grund_t::underground_mode==grund_t::ugm_level) ? grund_t::underground_level : 127;


// lower limit for y: display correctly water/outside graphics at upper border of screen
int y_min = (-const_y_off + 4*tile_raster_scale_y( min(hmax_ground,welt->get_grundwasser())*TILE_HEIGHT_STEP/Z_TILE_STEP, IMG_SIZE )
+ 4*(menu_height -IMG_SIZE) -IMG_SIZE/2-1) / IMG_SIZE;

// prepare for selectively display
const koord cursor_pos = welt->get_zeiger() ? welt->get_zeiger()->get_pos().get_2d() : koord(-1000,-1000);
const bool saved_grid = grund_t::show_grid;
const bool saved_hide_trees = umgebung_t::hide_trees;
const uint8 saved_hide_buildings = umgebung_t::hide_buildings;

// first display ground
DBG_DEBUG4("karte_ansicht_t::display", "display ground");
int y;
Expand All @@ -131,11 +136,16 @@ void karte_ansicht_t::display(bool force_dirty)
const sint16 xpos = x*(IMG_SIZE/2) + const_x_off;

if(xpos+IMG_SIZE>0 && xpos<disp_width) {
if (grund_t const* const kb = welt->lookup_kartenboden(koord(i, j))) {
const koord pos(i,j);
if (grund_t const* const kb = welt->lookup_kartenboden(pos)) {
const sint16 yypos = ypos - tile_raster_scale_y(min(kb->get_hoehe(), hmax_ground) * TILE_HEIGHT_STEP / Z_TILE_STEP, IMG_SIZE);
if(yypos-IMG_SIZE<disp_height && yypos+IMG_SIZE>menu_height) {
if( umgebung_t::hide_under_cursor && koord_distance(pos,cursor_pos)<=umgebung_t::cursor_hide_range ) {
grund_t::show_grid = true;
}
kb->display_if_visible(xpos, yypos, IMG_SIZE);
plotted = true;
grund_t::show_grid = saved_grid;
}
}
else {
Expand All @@ -153,9 +163,10 @@ void karte_ansicht_t::display(bool force_dirty)
}
}

DBG_DEBUG4("karte_ansicht_t::display", "display things");

// and then things (and other ground)
// especially necessary for vehicles
DBG_DEBUG4("karte_ansicht_t::display", "display things");
for(y=y_min; y<dpy_height+4*4; y++) {

const sint16 ypos = y*(IMG_SIZE/4) + const_y_off;
Expand All @@ -167,7 +178,8 @@ void karte_ansicht_t::display(bool force_dirty)
const int xpos = x*(IMG_SIZE/2) + const_x_off;

if(xpos+IMG_SIZE>0 && xpos<disp_width) {
const planquadrat_t *plan=welt->lookup(koord(i,j));
const koord pos(i,j);
const planquadrat_t *plan=welt->lookup(pos);
if(plan && plan->get_kartenboden()) {
const grund_t *gr = plan->get_kartenboden();
// minimum height: ground height for overground,
Expand Down Expand Up @@ -196,7 +208,17 @@ void karte_ansicht_t::display(bool force_dirty)
} */
sint16 yypos = ypos - tile_raster_scale_y( min(gr->get_hoehe(),hmax_ground)*TILE_HEIGHT_STEP/Z_TILE_STEP, IMG_SIZE);
if(yypos-IMG_SIZE*3<disp_height && yypos+IMG_SIZE>menu_height) {

if( umgebung_t::hide_under_cursor && koord_distance(pos,cursor_pos)<=umgebung_t::cursor_hide_range ) {
// If the corresponding setting is on, then hide trees and buildings under mouse cursor
umgebung_t::hide_trees = true;
umgebung_t::hide_buildings = umgebung_t::ALL_HIDDEN_BUIDLING;
}

plan->display_dinge(xpos, yypos, IMG_SIZE, true, hmin, hmax);

umgebung_t::hide_trees = saved_hide_trees;
umgebung_t::hide_buildings = saved_hide_buildings;
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions simwerkz.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,21 @@ class wkz_view_owner_t : public werkzeug_t {
virtual bool is_work_network_save() const { return true; }
};

class wkz_hide_under_cursor_t : public werkzeug_t {
public:
wkz_hide_under_cursor_t() : werkzeug_t() { id = WKZ_HIDE_UNDER_CURSOR | SIMPLE_TOOL; }
const char *get_tooltip(const spieler_t *) const { return translator::translate("hide objects under cursor"); }
bool is_selected(const karte_t *) const { return umgebung_t::hide_under_cursor; }
bool init( karte_t *welt, spieler_t * ) {
umgebung_t::hide_under_cursor = !umgebung_t::hide_under_cursor && umgebung_t::cursor_hide_range>0;
welt->set_dirty();
return false;
}
bool exit( karte_t *w, spieler_t *s ) { return init(w,s); }
virtual bool is_init_network_save() const { return true; }
virtual bool is_work_network_save() const { return true; }
};

/******************************** Internal tools ***********/
/* internal simple tools needed for networksynchronisation */
class wkz_traffic_level_t : public werkzeug_t {
Expand Down

0 comments on commit 8f20be9

Please sign in to comment.