Skip to content

Commit

Permalink
Merge pull request #60471 from mlange-42/toggle-iso-height
Browse files Browse the repository at this point in the history
Retractable "3D" sprites for walls etc.
  • Loading branch information
dseguin authored Sep 1, 2022
2 parents 5870131 + 60b6874 commit 3bb8e1e
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ std::string action_ident( action_id act )
return "toggle_auto_foraging";
case ACTION_TOGGLE_AUTO_PICKUP:
return "toggle_auto_pickup";
case ACTION_DISPLAY_ISO_WALLS:
return "toggle_iso_walls";
case ACTION_ACTIONMENU:
return "action_menu";
case ACTION_ITEMACTION:
Expand Down Expand Up @@ -896,6 +898,7 @@ action_id handle_action_menu()
#if defined(TILES)
REGISTER_ACTION( ACTION_TOGGLE_PIXEL_MINIMAP );
REGISTER_ACTION( ACTION_RELOAD_TILESET );
REGISTER_ACTION( ACTION_DISPLAY_ISO_WALLS );
#endif // TILES
REGISTER_ACTION( ACTION_TOGGLE_PANEL_ADM );
REGISTER_ACTION( ACTION_DISPLAY_SCENT );
Expand Down
2 changes: 2 additions & 0 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ enum action_id : int {
ACTION_DISPLAY_RADIATION,
/** Toggle transparency map */
ACTION_DISPLAY_TRANSPARENCY,
/** Toggle retracted ISO walls */
ACTION_DISPLAY_ISO_WALLS,
/** Toggle reachability zones map */
ACTION_DISPLAY_REACHABILITY_ZONES,
ACTION_DISPLAY_NPC_ATTACK_POTENTIAL,
Expand Down
1 change: 1 addition & 0 deletions src/cached_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bool log_from_top;
int message_ttl;
int message_cooldown;
bool test_mode;
bool tile_retracted;
bool use_tiles;
bool use_far_tiles;
bool use_tiles_overmap;
Expand Down
1 change: 1 addition & 0 deletions src/cached_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern bool keycode_mode;
extern bool log_from_top;
extern int message_ttl;
extern int message_cooldown;
extern bool tile_retracted;
extern bool use_tiles;
extern bool use_far_tiles;
extern bool use_tiles_overmap;
Expand Down
12 changes: 10 additions & 2 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ void tileset_cache::loader::load_internal( const JsonObject &config,
// Now load the tile definitions for the loaded tileset image.
sprite_offset.x = tile_part_def.get_int( "sprite_offset_x", 0 );
sprite_offset.y = tile_part_def.get_int( "sprite_offset_y", 0 );
sprite_offset_retracted.x = tile_part_def.get_int( "sprite_offset_x_retracted", sprite_offset.x );
sprite_offset_retracted.y = tile_part_def.get_int( "sprite_offset_y_retracted", sprite_offset.y );
// First load the tileset image to get the number of available tiles.
dbg( D_INFO ) << "Attempting to Load Tileset file " << tileset_image_path;
load_tileset( tileset_image_path, pump_events );
Expand All @@ -806,6 +808,7 @@ void tileset_cache::loader::load_internal( const JsonObject &config,
sprite_width = ts.tile_width;
sprite_height = ts.tile_height;
sprite_offset = point_zero;
sprite_offset_retracted = point_zero;
R = -1;
G = -1;
B = -1;
Expand Down Expand Up @@ -993,6 +996,7 @@ void tileset_cache::loader::load_ascii_set( const JsonObject &entry )
const std::string id = get_ascii_tile_id( ascii_char, FG, -1 );
tile_type curr_tile;
curr_tile.offset = sprite_offset;
curr_tile.offset_retracted = sprite_offset_retracted;
auto &sprites = *curr_tile.fg.add( std::vector<int>( {index_in_image + offset} ), 1 );
switch( ascii_char ) {
// box bottom/top side (horizontal line)
Expand Down Expand Up @@ -1070,6 +1074,7 @@ void tileset_cache::loader::load_tilejson_from_file( const JsonObject &config )
for( const std::string &t_id : ids ) {
tile_type &curr_tile = load_tile( entry, t_id );
curr_tile.offset = sprite_offset;
curr_tile.offset_retracted = sprite_offset_retracted;
bool t_multi = entry.get_bool( "multitile", false );
bool t_rota = entry.get_bool( "rotates", t_multi );
int t_h3d = entry.get_int( "height_3d", 0 );
Expand All @@ -1080,6 +1085,7 @@ void tileset_cache::loader::load_tilejson_from_file( const JsonObject &config )
const std::string m_id = str_cat( t_id, "_", s_id );
tile_type &curr_subtile = load_tile( subentry, m_id );
curr_subtile.offset = sprite_offset;
curr_tile.offset_retracted = sprite_offset_retracted;
curr_subtile.rotates = true;
curr_subtile.height_3d = t_h3d;
curr_subtile.animated = subentry.get_bool( "animated", false );
Expand Down Expand Up @@ -2481,9 +2487,11 @@ bool cata_tiles::draw_sprite_at(
int height = 0;
std::tie( width, height ) = sprite_tex->dimension();

const point &offset = tile_retracted ? tile.offset_retracted : tile.offset;

SDL_Rect destination;
destination.x = p.x + tile.offset.x * tile_width / tileset_ptr->get_tile_width();
destination.y = p.y + ( tile.offset.y - height_3d ) *
destination.x = p.x + offset.x * tile_width / tileset_ptr->get_tile_width();
destination.y = p.y + ( offset.y - height_3d ) *
tile_width / tileset_ptr->get_tile_width();
destination.w = width * tile_width / tileset_ptr->get_tile_width();
destination.h = height * tile_height / tileset_ptr->get_tile_height();
Expand Down
2 changes: 2 additions & 0 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct tile_type {
bool animated = false;
int height_3d = 0;
point offset = point_zero;
point offset_retracted = point_zero;

std::vector<std::string> available_subtiles;
};
Expand Down Expand Up @@ -238,6 +239,7 @@ class tileset_cache::loader
const SDL_Renderer_Ptr &renderer;

point sprite_offset;
point sprite_offset_retracted;

int sprite_width = 0;
int sprite_height = 0;
Expand Down
1 change: 1 addition & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,7 @@ input_context get_default_mode_input_context()
ctxt.register_action( "toggle_auto_foraging" );
ctxt.register_action( "toggle_auto_pickup" );
ctxt.register_action( "toggle_thief_mode" );
ctxt.register_action( "toggle_iso_walls" );
ctxt.register_action( "diary" );
ctxt.register_action( "action_menu" );
ctxt.register_action( "main_menu" );
Expand Down
5 changes: 5 additions & 0 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,11 @@ bool game::do_regular_action( action_id &act, avatar &player_character,
handle_debug_mode();
break;

case ACTION_DISPLAY_ISO_WALLS:
get_options().get_option( "RETRACT_ISO_WALLS" ).setNext();
get_options().save();
break;

case ACTION_ZOOM_IN:
zoom_in();
mark_main_ui_adaptor_resize();
Expand Down
6 changes: 6 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,11 @@ void options_manager::add_options_debug()
0, OVERMAP_LAYERS, 4
);

add( "RETRACT_ISO_WALLS", "debug", to_translation( "Draw walls retracted in ISO tile-sets" ),
to_translation( "If true, will draw ISO wall tiles retracted/lowered." ),
false
);

get_option( "FOV_3D_Z_RANGE" ).setPrerequisite( "FOV_3D" );
}

Expand Down Expand Up @@ -3522,6 +3527,7 @@ static void update_options_cache()
// cache to global due to heavy usage.
trigdist = ::get_option<bool>( "CIRCLEDIST" );
use_tiles = ::get_option<bool>( "USE_TILES" );
tile_retracted = ::get_option<bool>( "RETRACT_ISO_WALLS" );
// if the tilesets are identical don't duplicate
use_far_tiles = ::get_option<bool>( "USE_DISTANT_TILES" ) ||
get_option<std::string>( "TILES" ) == get_option<std::string>( "DISTANT_TILES" );
Expand Down
19 changes: 19 additions & 0 deletions tools/gfx_tools/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ def create_tile_entries_for_unused(
FALLBACK['sprite_height'] = sheet.sprite_height
FALLBACK['sprite_offset_x'] = sheet.offset_x
FALLBACK['sprite_offset_y'] = sheet.offset_y
if sheet.offset_x_retracted != sheet.offset_x \
or sheet.offset_y_retracted != sheet.offset_y:
FALLBACK['sprite_offset_x_retracted'] = \
sheet.offset_x_retracted
FALLBACK['sprite_offset_y_retracted'] = \
sheet.offset_y_retracted
continue
if sheet.is_filler and not main_finished:
create_tile_entries_for_unused(
Expand All @@ -417,6 +423,12 @@ def create_tile_entries_for_unused(
sheet_conf['sprite_height'] = sheet.sprite_height
sheet_conf['sprite_offset_x'] = sheet.offset_x
sheet_conf['sprite_offset_y'] = sheet.offset_y
if sheet.offset_x_retracted != sheet.offset_x \
or sheet.offset_y_retracted != sheet.offset_y:
sheet_conf['sprite_offset_x_retracted'] = \
sheet.offset_x_retracted
sheet_conf['sprite_offset_y_retracted'] = \
sheet.offset_y_retracted

sheet_conf['tiles'] = sheet_entries

Expand Down Expand Up @@ -497,6 +509,10 @@ def __init__(
'sprite_height', tileset.sprite_height)
self.offset_x = specs.get('sprite_offset_x', 0)
self.offset_y = specs.get('sprite_offset_y', 0)
self.offset_x_retracted = \
specs.get('sprite_offset_x_retracted', self.offset_x)
self.offset_y_retracted = \
specs.get('sprite_offset_y_retracted', self.offset_y)

self.sprites_across = specs.get('sprites_across', 16)
self.exclude = specs.get('exclude', tuple())
Expand Down Expand Up @@ -526,6 +542,9 @@ def is_standard(self) -> bool:
'''
if self.offset_x or self.offset_y:
return False
if self.offset_x_retracted != self.offset_x \
or self.offset_y_retracted != self.offset_y:
return False
if self.sprite_width != self.tileset.sprite_width:
return False
if self.sprite_height != self.tileset.sprite_height:
Expand Down
19 changes: 18 additions & 1 deletion tools/gfx_tools/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ def __init__(self, tilesheet_data, refs):
"sprite_width", refs.default_width)
self.sprite_offset_x = tilesheet_data.get("sprite_offset_x", 0)
self.sprite_offset_y = tilesheet_data.get("sprite_offset_y", 0)
self.sprite_offset_x_retracted = tilesheet_data.get(
"sprite_offset_x_retracted",
self.sprite_offset_x
)
self.sprite_offset_y_retracted = tilesheet_data.get(
"sprite_offset_y_retracted",
self.sprite_offset_y
)
self.write_dim = self.sprite_width != refs.default_width
self.write_dim |= self.sprite_height != refs.default_height
self.write_dim |= self.sprite_offset_x or self.sprite_offset_y
self.write_dim |= \
self.sprite_offset_x_retracted or self.sprite_offset_y_retracted
self.ts_pathname = refs.tileset_pathname + "/" + self.ts_filename
self.ts_image = Vips.Image.pngload(self.ts_pathname)
self.ts_width = self.ts_image.width
Expand Down Expand Up @@ -222,6 +232,13 @@ def summarize(self, tile_info, refs):
ts_tile_info["sprite_offset_y"] = self.sprite_offset_y
ts_tile_info["sprite_width"] = self.sprite_width
ts_tile_info["sprite_height"] = self.sprite_height
if self.sprite_offset_x_retracted != self.sprite_offset_x \
or self.sprite_offset_y_retracted \
!= self.sprite_offset_y:
ts_tile_info["sprite_offset_x_retracted"] = \
self.sprite_offset_x_retracted
ts_tile_info["sprite_offset_y_retracted"] = \
self.sprite_offset_y_retracted
#print("{}: {}".format(
# self.ts_filename, json.dumps(ts_tile_info, indent=2)))
tile_info.append({self.ts_filename: ts_tile_info})
Expand Down Expand Up @@ -346,7 +363,7 @@ def get_all_data(self, tileset_dirname, delete_pathname):
self.delete_pngnums.append(i)

with open(tileset_confname, encoding="utf-8") as conf_file:
return(json.load(conf_file))
return json.load(conf_file)

def add_pngnum_to_tsfilepath(self, pngnum):
if not isinstance(pngnum, int):
Expand Down

0 comments on commit 3bb8e1e

Please sign in to comment.