1
0
forked from 0ad/0ad

Make session GUI visible and usable when playtesting from Atlas.

Fix Atlas icon on non-Windows.
Remove some nonexistent-hotkey config.

This was SVN commit r7602.
This commit is contained in:
Ykkrosh 2010-06-02 00:36:21 +00:00
parent ffe9241cd3
commit 23ab6dad38
11 changed files with 286 additions and 35 deletions

View File

@ -105,8 +105,6 @@ hotkey.camera.zoom.wheel.in = WheelUp ; Zoom camera in (wheel speed).
hotkey.camera.zoom.wheel.out = WheelDown ; Zoom camera out (wheel speed).
hotkey.camera.rotate = "Ctrl+MouseMiddle" ; Rotate view by moving mouse, maintaining the
; absolute position of the camera
hotkey.camera.rotate.left = "Q" ;
hotkey.camera.rotate.right = "E" ;
hotkey.camera.rotate.keyboard = "Shift" ;
hotkey.camera.rotate.abouttarget = "MouseLeft+MouseRight" ; Rotate view by moving mouse, maintaining the
; world coordinates of the centre of the viewport

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -6,7 +6,10 @@ function setupSimTest(window)
function play(newSpeed)
{
if (state == 'inactive')
{
Atlas.Message.SimStateSave('default');
Atlas.Message.GuiSwitchPage('page_session_new.xml');
}
Atlas.Message.SimPlay(newSpeed);
state = 'playing';
speed = newSpeed;
@ -15,8 +18,12 @@ function setupSimTest(window)
function reset()
{
if (state == 'playing')
{
Atlas.Message.SimStateRestore('default');
Atlas.Message.GuiSwitchPage('page_atlas.xml');
}
Atlas.Message.SimPlay(0);
Atlas.Message.SimStateRestore('default');
state = 'inactive';
speed = 0;
updateEnableStatus();

View File

@ -338,11 +338,6 @@ static void MainControllerInit()
{
// add additional input handlers only needed by this controller:
// gui_handler needs to be registered after (i.e. called before!) the
// hotkey handler so that input boxes can be typed in without
// setting off hotkeys.
in_add_handler(gui_handler);
// must be registered after gui_handler. Should mayhap even be last.
in_add_handler(MainInputHandler);
}

View File

@ -442,17 +442,6 @@ static void InitVfs(const CmdLineArgs& args)
static void InitPs(bool setup_gui, const CStrW& gui_page)
{
if (!setup_gui)
{
// We do actually need *some* kind of GUI loaded, so use the
// (currently empty) Atlas one
g_GUI->SwitchPage(L"page_atlas.xml", JSVAL_VOID);
return;
}
// The things here aren't strictly GUI, but they're unnecessary when in Atlas
// because the game doesn't draw any text or handle keys or anything
{
// console
TIMER(L"ps_console");
@ -479,6 +468,14 @@ static void InitPs(bool setup_gui, const CStrW& gui_page)
LoadHotkeys();
}
if (!setup_gui)
{
// We do actually need *some* kind of GUI loaded, so use the
// (currently empty) Atlas one
g_GUI->SwitchPage(L"page_atlas.xml", JSVAL_VOID);
return;
}
// GUI uses VFS, so this must come after VFS init.
g_GUI->SwitchPage(gui_page, JSVAL_VOID);
@ -520,6 +517,11 @@ static void InitInput()
in_add_handler(HotkeyInputHandler);
in_add_handler(GlobalsInputHandler);
// gui_handler needs to be registered after (i.e. called before!) the
// hotkey handler so that input boxes can be typed in without
// setting off hotkeys.
in_add_handler(gui_handler);
}

View File

@ -0,0 +1,104 @@
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "KeyMap.h"
#include "SDL/SDL_keysym.h"
int GetSDLKeyFromWxKeyCode(int wxkey)
{
// wx gives uppercase letters, SDL expects lowercase
if (wxkey >= 'A' && wxkey <= 'Z')
return wxkey + 'a' - 'A';
if (wxkey < 256)
return wxkey;
switch (wxkey)
{
case WXK_NUMPAD0: return SDLK_KP0;
case WXK_NUMPAD1: return SDLK_KP1;
case WXK_NUMPAD2: return SDLK_KP2;
case WXK_NUMPAD3: return SDLK_KP3;
case WXK_NUMPAD4: return SDLK_KP4;
case WXK_NUMPAD5: return SDLK_KP5;
case WXK_NUMPAD6: return SDLK_KP6;
case WXK_NUMPAD7: return SDLK_KP7;
case WXK_NUMPAD8: return SDLK_KP8;
case WXK_NUMPAD9: return SDLK_KP9;
case WXK_NUMPAD_DECIMAL: return SDLK_KP_PERIOD;
case WXK_NUMPAD_DIVIDE: return SDLK_KP_DIVIDE;
case WXK_NUMPAD_MULTIPLY: return SDLK_KP_MULTIPLY;
case WXK_NUMPAD_SUBTRACT: return SDLK_KP_MINUS;
case WXK_NUMPAD_ADD: return SDLK_KP_PLUS;
case WXK_NUMPAD_ENTER: return SDLK_KP_ENTER;
case WXK_NUMPAD_EQUAL: return SDLK_KP_EQUALS;
case WXK_UP: return SDLK_UP;
case WXK_DOWN: return SDLK_DOWN;
case WXK_RIGHT: return SDLK_RIGHT;
case WXK_LEFT: return SDLK_LEFT;
case WXK_INSERT: return SDLK_INSERT;
case WXK_HOME: return SDLK_HOME;
case WXK_END: return SDLK_END;
case WXK_PAGEUP: return SDLK_PAGEUP;
case WXK_PAGEDOWN: return SDLK_PAGEDOWN;
case WXK_F1: return SDLK_F1;
case WXK_F2: return SDLK_F2;
case WXK_F3: return SDLK_F3;
case WXK_F4: return SDLK_F4;
case WXK_F5: return SDLK_F5;
case WXK_F6: return SDLK_F6;
case WXK_F7: return SDLK_F7;
case WXK_F8: return SDLK_F8;
case WXK_F9: return SDLK_F9;
case WXK_F10: return SDLK_F10;
case WXK_F11: return SDLK_F11;
case WXK_F12: return SDLK_F12;
case WXK_F13: return SDLK_F13;
case WXK_F14: return SDLK_F14;
case WXK_F15: return SDLK_F15;
case WXK_NUMLOCK: return SDLK_NUMLOCK;
// case WXK_: return SDLK_CAPSLOCK;
case WXK_SCROLL: return SDLK_SCROLLOCK;
case WXK_SHIFT: return SDLK_RSHIFT;
// case WXK_: return SDLK_LSHIFT;
case WXK_CONTROL: return SDLK_RCTRL;
// case WXK_: return SDLK_LCTRL;
case WXK_ALT: return SDLK_RALT;
// case WXK_: return SDLK_LALT;
// case WXK_: return SDLK_RMETA;
// case WXK_: return SDLK_LMETA;
// case WXK_: return SDLK_LSUPER;
// case WXK_: return SDLK_RSUPER;
// case WXK_: return SDLK_MODE;
// case WXK_: return SDLK_COMPOSE;
case WXK_HELP: return SDLK_HELP;
case WXK_PRINT: return SDLK_PRINT;
// case WXK_: return SDLK_SYSREQ;
// case WXK_: return SDLK_BREAK;
case WXK_MENU: return SDLK_MENU;
// case WXK_: return SDLK_POWER;
// case WXK_: return SDLK_EURO;
// case WXK_: return SDLK_UNDO;
}
return 0;
}

View File

@ -0,0 +1,23 @@
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEYMAP_INCLUDED
#define KEYMAP_INCLUDED
extern int GetSDLKeyFromWxKeyCode(int wxkey);
#endif // KEYMAP_INCLUDED

View File

@ -39,6 +39,8 @@
#include "AtlasScript/ScriptInterface.h"
#include "Misc/KeyMap.h"
#include "Tools/Common/Tools.h"
#include "Tools/Common/Brushes.h"
#include "Tools/Common/MiscState.h"
@ -100,13 +102,13 @@ private:
if (wxGetKeyState(WXK_DOWN)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::BACKWARDS, speed));
if (wxGetKeyState((wxKeyCode)']')) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::CLOCKWISE, speed));
if (wxGetKeyState((wxKeyCode)'[')) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::ANTICLOCKWISE, speed));
return false;
}
else
{
POST_MESSAGE(ScrollConstant, (eRenderView::GAME, dir, enable ? speed : 0.0f));
return true;
}
return true;
}
void OnKeyDown(wxKeyEvent& evt)
@ -121,6 +123,10 @@ private:
if (KeyScroll(evt, true))
return;
// Slight hack: Only pass 'special' keys; normal keys will generate a translated Char event instead
if (evt.GetKeyCode() >= 256)
POST_MESSAGE(GuiKeyEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey(), true));
evt.Skip();
}
@ -132,6 +138,10 @@ private:
if (KeyScroll(evt, false))
return;
// Slight hack: Only pass 'special' keys; normal keys will generate a translated Char event instead
if (evt.GetKeyCode() >= 256)
POST_MESSAGE(GuiKeyEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey(), false));
evt.Skip();
}
@ -159,13 +169,15 @@ private:
if (dir)
{
float speed = 16.f;
if (wxGetKeyState(WXK_SHIFT))
speed *= 4.f;
float speed = 16.f * ScenarioEditor::GetSpeedModifier();
POST_MESSAGE(SmoothZoom, (eRenderView::GAME, speed*dir));
}
else
{
POST_MESSAGE(GuiCharEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey()));
evt.Skip();
}
}
virtual void HandleMouseEvent(wxMouseEvent& evt)
@ -230,6 +242,13 @@ private:
}
}
}
if (evt.ButtonDown())
POST_MESSAGE(GuiMouseButtonEvent, (evt.GetButton(), true, evt.GetPosition()));
else if (evt.ButtonUp())
POST_MESSAGE(GuiMouseButtonEvent, (evt.GetButton(), false, evt.GetPosition()));
else if (evt.GetEventType() == wxEVT_MOTION)
POST_MESSAGE(GuiMouseMotionEvent, (evt.GetPosition()));
}
enum { NONE, SCROLL, ROTATEAROUND };
@ -345,7 +364,16 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac
SetOpenFilename(_T(""));
SetIcon(wxIcon(_T("ICON_ScenarioEditor")));
#if defined(__WXMSW__)
SetIcon(wxIcon(_T("ICON_ScenarioEditor"))); // load from atlas.rc
#else
{
const wxString relativePath (_T("tools/atlas/icons/ScenarioEditor.ico"));
wxFileName filename (relativePath, wxPATH_UNIX);
filename.MakeAbsolute(Datafile::GetDataDirectory());
SetIcon(wxIcon(filename.GetFullPath()));
}
#endif
wxToolTip::Enable(true);

View File

@ -28,6 +28,7 @@
#include "InputProcessor.h"
#include "gui/GUIManager.h"
#include "lib/app_hooks.h"
#include "lib/external_libraries/sdl.h"
#include "lib/timer.h"
@ -228,6 +229,14 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
ReloadChangedFiles();
// Pump SDL events (e.g. hotkeys)
SDL_Event_ ev;
while (SDL_PollEvent(&ev.ev))
in_dispatch_event(&ev);
if (g_GUI)
g_GUI->TickObjects();
state.view->Update(state.frameLength);
state.view->Render();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,17 +20,19 @@
#include "MessageHandler.h"
#include "../MessagePasserImpl.h"
#include "ps/GameSetup/Config.h"
#include "ps/Util.h"
#include "ps/Game.h"
#include "graphics/GameView.h"
#include "graphics/CinemaTrack.h"
#include "lib/sysdep/cpu.h"
#include "renderer/Renderer.h"
#include "ps/GameSetup/GameSetup.h"
#include "../GameLoop.h"
#include "../View.h"
#include "graphics/CinemaTrack.h"
#include "graphics/GameView.h"
#include "gui/GUIManager.h"
#include "lib/external_libraries/sdl.h"
#include "lib/sysdep/cpu.h"
#include "maths/MathUtil.h"
#include "ps/Game.h"
#include "ps/Util.h"
#include "ps/GameSetup/Config.h"
#include "ps/GameSetup/GameSetup.h"
#include "renderer/Renderer.h"
extern void (*Atlas_GLSwapBuffers)(void* context);
@ -146,5 +148,61 @@ MESSAGEHANDLER(JavaScript)
g_ScriptingHost.ExecuteScript(*msg->command, L"Atlas");
}
MESSAGEHANDLER(GuiSwitchPage)
{
g_GUI->SwitchPage(*msg->page, CScriptVal());
}
MESSAGEHANDLER(GuiMouseButtonEvent)
{
SDL_Event_ ev = { { 0 } };
ev.ev.type = msg->pressed ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
ev.ev.button.button = msg->button;
ev.ev.button.state = msg->pressed ? SDL_PRESSED : SDL_RELEASED;
float x, y;
msg->pos->GetScreenSpace(x, y);
ev.ev.button.x = (u16)clamp((int)x, 0, g_xres);
ev.ev.button.y = (u16)clamp((int)y, 0, g_yres);
in_dispatch_event(&ev);
}
MESSAGEHANDLER(GuiMouseMotionEvent)
{
SDL_Event_ ev = { { 0 } };
ev.ev.type = SDL_MOUSEMOTION;
float x, y;
msg->pos->GetScreenSpace(x, y);
ev.ev.motion.x = (u16)clamp((int)x, 0, g_xres);
ev.ev.motion.y = (u16)clamp((int)y, 0, g_yres);
in_dispatch_event(&ev);
}
MESSAGEHANDLER(GuiKeyEvent)
{
SDL_Event_ ev = { { 0 } };
ev.ev.type = msg->pressed ? SDL_KEYDOWN : SDL_KEYUP;
ev.ev.key.state = msg->pressed ? SDL_PRESSED : SDL_RELEASED;
ev.ev.key.keysym.sym = (SDLKey)(int)msg->sdlkey;
ev.ev.key.keysym.unicode = msg->unichar;
in_dispatch_event(&ev);
}
MESSAGEHANDLER(GuiCharEvent)
{
// wxWidgets has special Char events but SDL doesn't, so convert it to
// a keydown+keyup sequence. (We do the conversion here instead of on
// the wx side to avoid nondeterministic behaviour caused by async messaging.)
SDL_Event_ ev = { { 0 } };
ev.ev.type = SDL_KEYDOWN;
ev.ev.key.state = SDL_PRESSED;
ev.ev.key.keysym.sym = (SDLKey)(int)msg->sdlkey;
ev.ev.key.keysym.unicode = msg->unichar;
in_dispatch_event(&ev);
ev.ev.type = SDL_KEYUP;
ev.ev.key.state = SDL_RELEASED;
in_dispatch_event(&ev);
}
}

View File

@ -65,6 +65,33 @@ MESSAGE(JavaScript,
//////////////////////////////////////////////////////////////////////////
MESSAGE(GuiSwitchPage,
((std::wstring, page))
);
MESSAGE(GuiMouseButtonEvent,
((int, button))
((bool, pressed))
((Position, pos))
);
MESSAGE(GuiMouseMotionEvent,
((Position, pos))
);
MESSAGE(GuiKeyEvent,
((int, sdlkey)) // SDLKey code
((int, unichar)) // Unicode character
((bool, pressed))
);
MESSAGE(GuiCharEvent,
((int, sdlkey))
((int, unichar))
);
//////////////////////////////////////////////////////////////////////////
MESSAGE(SimStateSave,
((std::wstring, label)) // named slot to store saved data
);