Added function SetFullGameName to LUA scripts - use name for WM icon and title

- On Unix load icon from /usr/share/pixmaps/
 - On Windows load icon from exe file from previous image argv[0]
This commit is contained in:
Pali Rohár 2010-07-11 12:36:30 +02:00
parent 0cb00b273b
commit 545b0c4526
4 changed files with 80 additions and 1 deletions

View file

@ -41,6 +41,8 @@
<li>Fixed saving campaign game - multiline lua strings and lua triggers (from Pali Rohar)
<li>Added option print debug output to console on Windows (from Pali Rohar)
<li>Added function PlayMovie to LUA scripts - play movies from game (from Pali Rohar)
<li>Added command line params -O and -o for force using OpenGL (from Pali Rohar)
<li>Added function SetFullGameName to LUA scripts - use name for WM icon and title (from Pali Rohar)
<li>Added support for 64bit Windows version (from Pali Rohar)
<li>Added new NSIS Installer for Windows (from Pali Rohar)
<li>Added support for more graphics resolutions (from Pali Rohar)

View file

@ -242,6 +242,7 @@ extern const char NameLine[];
extern std::string UserDirectory; /// Directory containing user settings and data
extern std::string StratagusLibPath; /// Location of stratagus data
extern std::string GameName; /// Name of the game
extern std::string FullGameName; /// Full Name of the game
extern std::string ClickMissile; /// Missile to show when you click
extern std::string DamageMissile; /// Missile to show damage caused

View file

@ -83,6 +83,7 @@ lua_State *Lua; /// Structure to work with lua files.
std::string CclStartFile; /// CCL start file
std::string UserDirectory;
std::string GameName;
std::string FullGameName;
int CclInConfigFile; /// True while config file parsing
bool SaveGameLoading; /// If a Saved Game is Loading
std::string CurrentLuaFile; /// Lua file currently being interpreted
@ -1928,6 +1929,21 @@ static int CclSetGameName(lua_State *l)
return 0;
}
static int CclSetFullGameName(lua_State *l)
{
int args;
args = lua_gettop(l);
if (args > 1 || (args == 1 && (!lua_isnil(l, 1) && !lua_isstring(l, 1)))) {
LuaError(l, "incorrect argument");
}
if (args == 1 && !lua_isnil(l, 1)) {
FullGameName = lua_tostring(l, 1);
}
return 0;
}
/**
** Set the video sync speed
**
@ -2381,6 +2397,7 @@ void InitCcl(void)
lua_register(Lua, "ListFilesInDirectory", CclListFilesInDirectory);
lua_register(Lua, "ListDirsInDirectory", CclListDirsInDirectory);
lua_register(Lua, "SetGameName", CclSetGameName);
lua_register(Lua, "SetFullGameName", CclSetFullGameName);
lua_register(Lua, "SetVideoSyncSpeed", CclSetVideoSyncSpeed);
lua_register(Lua, "SetLocalPlayerName", CclSetLocalPlayerName);
lua_register(Lua, "GetLocalPlayerName", CclGetLocalPlayerName);

View file

@ -51,6 +51,7 @@
#ifndef _MSC_VER
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include "SDL.h"
@ -67,6 +68,7 @@
#ifdef USE_WIN32
#include "net_lowlevel.h"
#include "SDL_syswm.h"
#endif
#if defined(USE_WIN32) && defined(NO_STDIO_REDIRECT)
@ -459,8 +461,65 @@ void InitVideoSdl(void)
signal(SIGSEGV, CleanExit);
signal(SIGABRT, CleanExit);
#endif
if (FullGameName.empty())
FullGameName = "Stratagus";
// Set WindowManager Title
SDL_WM_SetCaption("Stratagus", "Stratagus");
SDL_WM_SetCaption(FullGameName.c_str(), FullGameName.c_str());
#ifndef USE_WIN32
SDL_Surface * icon = NULL;
CGraphic * g = NULL;
struct stat st;
char buf[1024];
sprintf(buf, "/usr/share/pixmaps/%s.png", FullGameName.c_str());
if (stat(buf, &st) == 0) {
g = CGraphic::New(buf);
g->Load();
icon = g->Surface;
}
if (!icon) {
FullGameName[0] = tolower(FullGameName[0]);
sprintf(buf, "/usr/share/pixmaps/%s.png", FullGameName.c_str());
if (stat(buf, &st) == 0) {
if (g)
CGraphic::Free(g);
g = CGraphic::New(buf);
g->Load();
icon = g->Surface;
}
}
if (icon)
SDL_WM_SetIcon(icon, 0);
if (g)
CGraphic::Free(g);
#else
int argc = 0;
LPWSTR * argv = NULL;
HWND hwnd = NULL;
HICON hicon = NULL;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (SDL_GetWMInfo(&info))
hwnd = info.window;
if (hwnd)
hicon = ExtractIcon(GetModuleHandle(NULL), argv[0], 0);
if (hicon) {
SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon);
SetClassLong(hwnd, GCL_HICON, (LONG)hicon);
DestroyIcon(hicon);
}
#endif
}
// Initialize the display