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

targetting cursor

window title
better tooltips


git-svn-id: http://svn.net-core.org/repos/t-engine4@42 51575b47-30f0-44d4-a5cc-537603b46e54
parent 5556d44b
No related branches found
No related tags found
No related merge requests found
game/data/gfx/target_cursor.png

221 B

......@@ -49,6 +49,10 @@ end
function _M:tick()
end
--- Called by the engine when the user tries to close the window
function _M:onQuit()
end
--- Registers a dialog to display
function _M:registerDialog(d)
table.insert(self.dialogs, d)
......
......@@ -9,6 +9,8 @@ function _M:init(map, source_actor)
self.tile_w, self.tile_h = map.tile_w, map.tile_h
self.active = false
self.cursor = core.display.loadImage(engine.Tiles.prefix.."target_cursor.png")
self.sr = core.display.newSurface(map.tile_w, map.tile_h)
self.sr:alpha(125)
self.sr:erase(255, 0, 0)
......@@ -17,7 +19,13 @@ function _M:init(map, source_actor)
self.sb:erase(0, 0, 255)
self.source_actor = source_actor
self.target = {x=self.source_actor.x, y=self.source_actor.y}
-- Setup the tracking target table
-- Notice its values are set to weak references, this has no effects on the number for x and y
-- but it means if the entity field is set to an entity, when it disappears this link wont prevent
-- the garbage collection
self.target = {x=self.source_actor.x, y=self.source_actor.y, entity=nil}
setmetatable(self.target, {__mode='v'})
end
function _M:display()
......@@ -37,6 +45,7 @@ function _M:display()
s:toScreen(self.display_x + lx * self.tile_w, self.display_y + ly * self.tile_h)
lx, ly = l()
end
self.cursor:toScreen(self.display_x + self.target.x * self.tile_w, self.display_y + self.target.y * self.tile_h)
end
function _M:setActive(v)
......
......@@ -2,6 +2,8 @@ require "engine.class"
module(..., package.seeall, class.make)
tiles = engine.Tiles.new(16, 16)
function _M:init(fontname, fontsize, color, bgcolor)
self.color = color or {255,255,255}
self.bgcolor = bgcolor or {0,0,0}
......@@ -13,6 +15,14 @@ end
function _M:set(str, ...)
self.text = str:format(...):splitLines(300, self.font)
self.w, self.h = 0, 0
for i, l in ipairs(self.text) do
local w, h = self.font:size(l)
if w > self.w then self.w = w end
self.h = self.h + self.font_h
end
self.w = self.w + 8
self.h = self.h + 8
self.changed = true
end
......@@ -21,13 +31,27 @@ function _M:display()
if not self.changed then return self.surface end
self.changed = false
self.surface = core.display.newSurface(300, self.font_h * #self.text)
self.surface = core.display.newSurface(self.w, self.h)
self.surface:alpha(200)
-- Erase and the display the map
-- Erase and the display the tooltip
self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3])
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_7.png"), 0, 0)
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_9.png"), self.w - 8, 0)
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_1.png"), 0, self.h - 8)
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_3.png"), self.w - 8, self.h - 8)
for i = 8, self.w - 9 do
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), i, 0)
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), i, self.h - 3)
end
for i = 8, self.h - 9 do
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), 0, i)
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), self.w - 3, i)
end
for i, l in ipairs(self.text) do
self.surface:drawColorString(self.font, self.text[i], 0, (i-1) * self.font_h, self.color[1], self.color[2], self.color[3])
self.surface:drawColorString(self.font, self.text[i], 4, 4 + (i-1) * self.font_h, self.color[1], self.color[2], self.color[3])
end
return self.surface
end
......@@ -29,6 +29,8 @@ if mod_def then
if not mod.name or not mod.short_name or not mod.version or not mod.starter then os.exit() end
core.display.setWindowTitle(mod.name)
engine.Tiles.prefix = "/data/gfx/"
game = dofile("/"..mod.starter:gsub("%.", "/")..".lua")
game:run()
......
......@@ -72,29 +72,33 @@ function _M:display()
self.log:display():toScreen(self.log.display_x, self.log.display_y)
if self.level and self.level.map then
-- Display the map and compute FOV for the player if needed
if self.level.map.changed then
self.level.map:fov(self.player.x, self.player.y, 20)
self.level.map:fovLite(self.player.x, self.player.y, 4)
end
local s = self.level.map:display()
if s then
s:toScreen(self.level.map.display_x, self.level.map.display_y)
end
self.level.map:display():toScreen(self.level.map.display_x, self.level.map.display_y)
-- DIsplay the targetting system if active
self.target:display()
-- Display a tooltip if available
local mx, my = core.mouse.get()
local tmx, tmy = math.floor(mx / self.level.map.tile_w), math.floor(my / self.level.map.tile_h)
local tt = self.level.map:checkAllEntities(tmx, tmy, "tooltip")
if tt then
if tt and self.level.map.seens(tmx, tmy) then
self.tooltip:set(tt)
local t = self.tooltip:display()
mx = mx - self.tooltip.w
my = my - self.tooltip.h
if mx < 0 then mx = 0 end
if my < 0 then my = 0 end
if t then t:toScreen(mx, my) end
end
if self.old_tmx ~= tmx or self.old_tmy ~= tmy then
self.target.target.x, self.target.target.y = tmx, tmy
end
self.old_tmx, self.old_tmy = tmx, tmy
self.target:display()
end
engine.GameTurnBased.display(self)
......@@ -201,7 +205,7 @@ function _M:setupCommands()
end,
-- Exit the game
[{"_x","ctrl"}] = function()
self:registerDialog(QuitDialog.new())
self:onQuit()
end,
-- Targeting movement
......@@ -243,3 +247,11 @@ function _M:setupMouse()
if button == "wheeldown" then self.log:scrollUp(-1) end
end)
end
--- Ask if we realy want to close, if so, save the game first
function _M:onQuit()
if not self.quit_dialog then
self.quit_dialog = QuitDialog.new()
self:registerDialog(self.quit_dialog)
end
end
......@@ -6,7 +6,7 @@ return {
level = 1, exp_worth = 1,
life = 20,
mana = 1000,
energy = { mod=0.8 },
energy = { mod=0.5 },
has_blood = true,
stats = { str=15, dex=8, mag=12, },
combat = { dam=8, atk=10, apr=2, def=4, armor=6},
......
......@@ -11,6 +11,7 @@ function _M:init()
end,
__DEFAULT = function()
game:unregisterDialog(self)
game.quit_dialog = false
end,
}
end
......
name = "Tales of Middle Earth: 4th Age"
name = "Tales of Middle Earth: The Fourth Age"
short_name = "tome"
author = { "DarkGod", "darkgod@t-o-m-e.net" }
description = [[
......
......@@ -445,6 +445,13 @@ static int sdl_surface_alpha(lua_State *L)
return 0;
}
static int sdl_set_window_title(lua_State *L)
{
const char *title = luaL_checkstring(L, 1);
SDL_WM_SetCaption(title, NULL);
return 0;
}
static const struct luaL_reg displaylib[] =
{
{"fullscreen", sdl_fullscreen},
......@@ -452,6 +459,7 @@ static const struct luaL_reg displaylib[] =
{"newFont", sdl_new_font},
{"newSurface", sdl_new_surface},
{"loadImage", sdl_load_image},
{"setWindowTitle", sdl_set_window_title},
{NULL, NULL},
};
......
......@@ -59,6 +59,23 @@ typedef struct {
Uint32 color;
} MainStateData;
int event_filter(const SDL_Event *event)
{
// Do not allow the user to close without asking the game to know about it
if (event->type == SDL_QUIT && (current_game != LUA_NOREF))
{
lua_rawgeti(L, LUA_REGISTRYINDEX, current_game);
lua_pushstring(L, "onQuit");
lua_gettable(L, -2);
lua_remove(L, -2);
lua_rawgeti(L, LUA_REGISTRYINDEX, current_game);
docall(L, 1, 0);
return 0;
}
return 1;
}
void on_event(SDL_Event *event)
{
switch (event->type) {
......@@ -232,6 +249,9 @@ int main(int argc, char *argv[])
luaL_loadfile(L, "/engine/init.lua");
docall(L, 0, 0);
// Filter events, to catch the quit event
SDL_SetEventFilter(event_filter);
bool done = FALSE;
SDL_Event event;
while ( !done )
......
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