Add a submerge value to items, to control submerge amount
It defaults to 0, which is no submersion.
This commit is contained in:
parent
13c3235a68
commit
3127178e17
9 changed files with 45 additions and 10 deletions
|
@ -24,6 +24,7 @@ local function add_overlay(x, y, cfg)
|
|||
team_name = cfg.team_name,
|
||||
filter_team = cfg.filter_team,
|
||||
visible_in_fog = cfg.visible_in_fog,
|
||||
submerge = cfg.submerge,
|
||||
redraw = cfg.redraw,
|
||||
name = cfg.name,
|
||||
z_order = cfg.z_order,
|
||||
|
@ -60,6 +61,7 @@ end
|
|||
---@field team_name string
|
||||
---@field filter_team WML
|
||||
---@field visible_in_fog boolean
|
||||
---@field submerge number
|
||||
---@field redraw boolean
|
||||
---@field name string
|
||||
---@field z_order integer
|
||||
|
@ -82,6 +84,7 @@ function wesnoth.interface.get_items(x, y)
|
|||
team_name = cfg.team_name,
|
||||
filter_team = cfg.filter_team,
|
||||
visible_in_fog = cfg.visible_in_fog,
|
||||
submerge = cfg.submerge,
|
||||
redraw = cfg.redraw,
|
||||
name = cfg.name,
|
||||
z_order = cfg.z_order,
|
||||
|
|
|
@ -749,6 +749,7 @@
|
|||
{SIMPLE_KEY name string}
|
||||
# Override some supertag keys to allow variable substitutions
|
||||
{DEFAULT_KEY visible_in_fog s_bool yes}
|
||||
{SIMPLE_KEY submerge s_real}
|
||||
{FILTER_TAG "filter_side" side ()}
|
||||
[/tag]
|
||||
[tag]
|
||||
|
|
|
@ -462,6 +462,7 @@
|
|||
{SIMPLE_KEY halo string}
|
||||
{SIMPLE_KEY team_name string}
|
||||
{DEFAULT_KEY visible_in_fog bool yes}
|
||||
{SIMPLE_KEY submerge real}
|
||||
[/tag]
|
||||
[tag]
|
||||
name="time"
|
||||
|
|
|
@ -139,7 +139,7 @@ void display::parse_team_overlays()
|
|||
}
|
||||
|
||||
|
||||
void display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo, const std::string& team_name, const std::string& item_id, bool visible_under_fog, float z_order)
|
||||
void display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo, const std::string& team_name, const std::string& item_id, bool visible_under_fog, float submerge, float z_order)
|
||||
{
|
||||
halo::handle halo_handle;
|
||||
if(halo != "") {
|
||||
|
@ -149,7 +149,7 @@ void display::add_overlay(const map_location& loc, const std::string& img, const
|
|||
|
||||
std::vector<overlay>& overlays = get_overlays()[loc];
|
||||
auto it = std::find_if(overlays.begin(), overlays.end(), [z_order](const overlay& ov) { return ov.z_order > z_order; });
|
||||
overlays.emplace(it, img, halo, halo_handle, team_name, item_id, visible_under_fog, z_order);
|
||||
overlays.emplace(it, img, halo, halo_handle, team_name, item_id, visible_under_fog, submerge, z_order);
|
||||
}
|
||||
|
||||
void display::remove_overlay(const map_location& loc)
|
||||
|
@ -1516,8 +1516,16 @@ void display::draw_text_in_hex(const map_location& loc,
|
|||
static void add_submerge_ipf_mod(
|
||||
std::string& image_path,
|
||||
int image_height,
|
||||
double submersion_amount)
|
||||
double submersion_amount,
|
||||
int shift = 0)
|
||||
{
|
||||
// We may also want to shift the position so that the waterline matches.
|
||||
// Note: This currently has blending problems (see the note on sdl_blit),
|
||||
// but if that blending problem is fixed it should work.
|
||||
if (shift) {
|
||||
image_path = "misc/blank-hex.png~BLIT(" + image_path;
|
||||
}
|
||||
|
||||
// general formula for submerge alpha:
|
||||
// if (y > WATERLINE)
|
||||
// then min(max(alpha_mod, 0), 1) * alpha
|
||||
|
@ -1542,6 +1550,13 @@ static void add_submerge_ipf_mod(
|
|||
// but that's not available below SDL 2.0.18.
|
||||
// Alternately it could also be done fairly easily using shaders,
|
||||
// if a graphics system supporting them (such as openGL) is moved to.
|
||||
|
||||
if (shift) {
|
||||
// Finish the shifting blit. This assumes a hex-sized image.
|
||||
image_path += ",0,";
|
||||
image_path += std::to_string(shift);
|
||||
image_path += ')';
|
||||
}
|
||||
}
|
||||
|
||||
void display::render_image(int x, int y, const display::drawing_layer drawing_layer,
|
||||
|
@ -2814,10 +2829,17 @@ void display::draw_hex(const map_location& loc)
|
|||
{
|
||||
point isize = image::get_size(ov.image, image::HEXED);
|
||||
std::string ipf = ov.image;
|
||||
add_submerge_ipf_mod(ipf, isize.y, submerge);
|
||||
const texture tex = ov.image.find("~NO_TOD_SHIFT()") == std::string::npos ?
|
||||
image::get_lighted_texture(ipf, lt) :
|
||||
image::get_texture(ipf, image::HEXED);
|
||||
if(ov.submerge) {
|
||||
// Adjust submerge appropriately
|
||||
double sub = submerge * ov.submerge;
|
||||
// Shift the image so the waterline remains static.
|
||||
// This is so that units swimming there look okay.
|
||||
int shift = isize.y * (sub - submerge);
|
||||
add_submerge_ipf_mod(ipf, isize.y, sub, shift);
|
||||
}
|
||||
const texture tex = ov.image.find("~NO_TOD_SHIFT()") == std::string::npos
|
||||
? image::get_lighted_texture(ipf, lt)
|
||||
: image::get_texture(ipf, image::HEXED);
|
||||
drawing_buffer_add(LAYER_TERRAIN_BG, loc, dest, tex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public:
|
|||
*/
|
||||
void add_overlay(const map_location& loc, const std::string& image,
|
||||
const std::string& halo="", const std::string& team_name="",const std::string& item_id="",
|
||||
bool visible_under_fog = true, float z_order = 0);
|
||||
bool visible_under_fog = true, float submerge = 0.0f, float z_order = 0);
|
||||
|
||||
/** remove_overlay will remove all overlays on a tile. */
|
||||
void remove_overlay(const map_location& loc);
|
||||
|
|
|
@ -52,7 +52,7 @@ std::unique_ptr<editor_action> mouse_action_item::click_left(editor_display& dis
|
|||
}
|
||||
|
||||
const overlay& item = item_palette_.selected_fg_item();
|
||||
disp.add_overlay(start_hex_, item.image, item.halo, "", "", true);
|
||||
disp.add_overlay(start_hex_, item.image, item.halo, "", "", item.visible_in_fog, item.submerge);
|
||||
|
||||
click_ = true;
|
||||
return nullptr;
|
||||
|
|
|
@ -513,6 +513,9 @@ config map_context::to_config()
|
|||
item["name"].write_if_not_empty(o.name);
|
||||
item["team_name"].write_if_not_empty(o.team_name);
|
||||
item["halo"].write_if_not_empty(o.halo);
|
||||
if(o.submerge) {
|
||||
item["submerge"] = o.submerge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ struct overlay
|
|||
const std::string& overlay_team_name,
|
||||
const std::string& item_id,
|
||||
const bool fogged,
|
||||
float submerge,
|
||||
float item_z_order = 0)
|
||||
: image(img)
|
||||
, halo(halo_img)
|
||||
|
@ -33,6 +34,7 @@ struct overlay
|
|||
, id(item_id)
|
||||
, halo_handle(handle)
|
||||
, visible_in_fog(fogged)
|
||||
, submerge(submerge)
|
||||
, z_order(item_z_order)
|
||||
{}
|
||||
|
||||
|
@ -45,6 +47,7 @@ struct overlay
|
|||
, id(cfg["id"])
|
||||
, halo_handle()
|
||||
, visible_in_fog(cfg["visible_in_fog"].to_bool())
|
||||
, submerge(cfg["submerge"].to_double(0))
|
||||
, z_order(cfg["z_order"].to_double(0))
|
||||
{
|
||||
}
|
||||
|
@ -57,6 +60,7 @@ struct overlay
|
|||
|
||||
halo::handle halo_handle;
|
||||
bool visible_in_fog;
|
||||
float submerge;
|
||||
float z_order;
|
||||
|
||||
};
|
||||
|
|
|
@ -3645,7 +3645,8 @@ int game_lua_kernel::intf_add_tile_overlay(lua_State *L)
|
|||
|
||||
if (game_display_) {
|
||||
game_display_->add_overlay(loc, cfg["image"], cfg["halo"],
|
||||
team_name, cfg["name"], cfg["visible_in_fog"].to_bool(true), cfg["z_order"].to_double(0));
|
||||
team_name, cfg["name"], cfg["visible_in_fog"].to_bool(true),
|
||||
cfg["submerge"].to_double(0), cfg["z_order"].to_double(0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue