Skip to content
Snippets Groups Projects
Commit 0c908045 authored by dg's avatar dg
Browse files

better hex tagert

git-svn-id: http://svn.net-core.org/repos/t-engine4@5083 51575b47-30f0-44d4-a5cc-537603b46e54
parent 85340c6f
No related branches found
No related tags found
No related merge requests found
...@@ -87,6 +87,25 @@ function _M:display(dispx, dispy) ...@@ -87,6 +87,25 @@ function _M:display(dispx, dispy)
-- Do not display if not requested -- Do not display if not requested
if not self.active then return end if not self.active then return end
local display_highlight
if util.isHex() then
display_highlight = function(texture, tx, ty)
texture:toScreenHighlightHex(
self.display_x + (tx - game.level.map.mx) * self.tile_w * Map.zoom,
self.display_y + (ty - game.level.map.my + util.hexOffset(tx)) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
end
else
display_highlight = function(texture, tx, ty)
texture:toScreen(
self.display_x + (tx - game.level.map.mx) * self.tile_w * Map.zoom,
self.display_y + (ty - game.level.map.my) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
end
end
local s = self.sb local s = self.sb
local l local l
if self.target_type.source_actor.lineFOV then if self.target_type.source_actor.lineFOV then
...@@ -115,7 +134,7 @@ function _M:display(dispx, dispy) ...@@ -115,7 +134,7 @@ function _M:display(dispx, dispy)
s = self.sr s = self.sr
end end
if game.level.map:isBound(blocked_corner_x, blocked_corner_y) then if game.level.map:isBound(blocked_corner_x, blocked_corner_y) then
s:toScreen(self.display_x + (blocked_corner_x - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (blocked_corner_y - game.level.map.my + util.hexOffset(blocked_corner_x)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) display_highlight(s, blocked_corner_x, blocked_corner_y)
end end
s = self.sr s = self.sr
end end
...@@ -147,7 +166,7 @@ function _M:display(dispx, dispy) ...@@ -147,7 +166,7 @@ function _M:display(dispx, dispy)
end end
end end
end end
s:toScreen(self.display_x + (lx - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (ly - game.level.map.my + util.hexOffset(lx)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) display_highlight(s, lx, ly)
if block then if block then
s = self.sr s = self.sr
stopped = true stopped = true
...@@ -162,8 +181,8 @@ function _M:display(dispx, dispy) ...@@ -162,8 +181,8 @@ function _M:display(dispx, dispy)
s = self.sr s = self.sr
-- double the fun :-P -- double the fun :-P
if game.level.map:isBound(blocked_corner_x, blocked_corner_y) then if game.level.map:isBound(blocked_corner_x, blocked_corner_y) then
s:toScreen(self.display_x + (blocked_corner_x - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (blocked_corner_y - game.level.map.my + util.hexOffset(blocked_corner_x)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) display_highlight(s, blocked_corner_x, blocked_corner_y)
s:toScreen(self.display_x + (blocked_corner_x - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (blocked_corner_y - game.level.map.my + util.hexOffset(blocked_corner_x)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) display_highlight(s, blocked_corner_x, blocked_corner_y)
end end
end end
...@@ -182,15 +201,9 @@ function _M:display(dispx, dispy) ...@@ -182,15 +201,9 @@ function _M:display(dispx, dispy)
end, end,
function(_, px, py) function(_, px, py)
if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then
self.syg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, display_highlight(self.syg, px, py)
self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
else else
self.sg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, display_highlight(self.sg, px, py)
self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
end end
end, end,
nil) nil)
...@@ -212,15 +225,9 @@ function _M:display(dispx, dispy) ...@@ -212,15 +225,9 @@ function _M:display(dispx, dispy)
end, end,
function(_, px, py) function(_, px, py)
if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then
self.syg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, display_highlight(self.syg, px, py)
self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
else else
self.sg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, display_highlight(self.sg, px, py)
self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
end end
end, end,
nil) nil)
...@@ -241,15 +248,9 @@ function _M:display(dispx, dispy) ...@@ -241,15 +248,9 @@ function _M:display(dispx, dispy)
end, end,
function(_, px, py) function(_, px, py)
if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then
self.syg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, display_highlight(self.syg, px, py)
self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
else else
self.sg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, display_highlight(self.sg, px, py)
self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom,
self.tile_w * Map.zoom,
self.tile_h * Map.zoom)
end end
end, end,
nil) nil)
......
...@@ -1477,6 +1477,78 @@ static int sdl_texture_toscreen(lua_State *L) ...@@ -1477,6 +1477,78 @@ static int sdl_texture_toscreen(lua_State *L)
return 0; return 0;
} }
static int sdl_texture_toscreen_highlight_hex(lua_State *L)
{
GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 1);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
int w = luaL_checknumber(L, 4);
int h = luaL_checknumber(L, 5);
if (lua_isnumber(L, 6))
{
float r = luaL_checknumber(L, 6);
float g = luaL_checknumber(L, 7);
float b = luaL_checknumber(L, 8);
float a = luaL_checknumber(L, 9);
GLfloat colors[4*8] = {
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
};
glColorPointer(4, GL_FLOAT, 0, colors);
}
else
{
// A very slight gradient to give some definition to the texture
GLfloat colors[4*8] = {
0.9, 0.9, 0.9, 1,
0.9, 0.9, 0.9, 1,
1, 1, 1, 1,
1, 1, 1, 1,
0.9, 0.9, 0.9, 1,
0.8, 0.8, 0.8, 1,
0.8, 0.8, 0.8, 1,
0.9, 0.9, 0.9, 1,
};
glColorPointer(4, GL_FLOAT, 0, colors);
}
tglBindTexture(GL_TEXTURE_2D, *t);
GLfloat texcoords[2*8] = {
0, 0,
0, 1,
1, 1,
1, 0,
1, 0,
1, 0,
1, 0,
1, 0,
};
float f = x - w/6.0;
float v = 4.0*w/3.0;
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
GLfloat vertices[2*8] = {
x + 0.5*v, y + 0.5*h,
f + 0.25*v, y,
f, y + 0.5*h,
f + 0.25*v, y + h,
f + 0.75*v, y + h,
f + v, y + 0.5*h,
f + 0.75*v, y,
f + 0.25*v, y,
};
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_FAN, 0, 8);
return 0;
}
static int sdl_texture_toscreen_full(lua_State *L) static int sdl_texture_toscreen_full(lua_State *L)
{ {
GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 1); GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 1);
...@@ -2361,6 +2433,7 @@ static const struct luaL_reg sdl_texture_reg[] = ...@@ -2361,6 +2433,7 @@ static const struct luaL_reg sdl_texture_reg[] =
{"toScreen", sdl_texture_toscreen}, {"toScreen", sdl_texture_toscreen},
{"toScreenFull", sdl_texture_toscreen_full}, {"toScreenFull", sdl_texture_toscreen_full},
{"toScreenPrecise", sdl_texture_toscreen_precise}, {"toScreenPrecise", sdl_texture_toscreen_precise},
{"toScreenHighlightHex", sdl_texture_toscreen_highlight_hex},
{"makeOutline", sdl_texture_outline}, {"makeOutline", sdl_texture_outline},
{"toSurface", gl_texture_to_sdl}, {"toSurface", gl_texture_to_sdl},
{"bind", sdl_texture_bind}, {"bind", sdl_texture_bind},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment