/
b_main.cpp
160 lines (137 loc) · 5.69 KB
/
b_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/** @file b_main.cpp Event and device state bindings system.
*
* @todo Pretty much everything in this file belongs in InputSystem.
*
* @authors Copyright © 2009-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2007-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program 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. This program 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 this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#include "de_platform.h" // stricmp macro, etc...
#include "ui/b_main.h"
#include <cctype>
#include <cmath>
#include <doomsday/console/exec.h>
#include <doomsday/console/cmd.h>
#include <doomsday/console/var.h>
#include "dd_main.h"
#include "dd_def.h"
#include "clientapp.h"
#include "ui/commandbinding.h"
#include "ui/bindcontext.h"
#include "ui/playerimpulse.h"
#include "ui/inputdevice.h"
#include "ui/inputdeviceaxiscontrol.h"
#include "ui/ui_main.h"
using namespace de;
/**
* Binding context fallback for the "global" context.
*
* @param ddev Event being processed.
*
* @return @c true if the event was eaten and can be processed by the rest of the
* binding context stack.
*/
static int globalContextFallback(ddevent_t const *ddev)
{
if(App_GameLoaded())
{
event_t ev;
if(InputSystem::convertEvent(ddev, &ev))
{
// The game's normal responder only returns true if the bindings can't
// be used (like when chatting). Note that if the event is eaten here,
// the rest of the bindings contexts won't get a chance to process the
// event.
if(gx.Responder && gx.Responder(&ev))
{
return true;
}
}
}
return false;
}
/// @note Called once on init.
void B_Init()
{
InputSystem &isys = ClientApp::inputSystem();
// In dedicated mode we have fewer binding contexts available.
// The contexts are defined in reverse order, with the context of lowest
// priority defined first.
isys.newContext(DEFAULT_BINDING_CONTEXT_NAME);
// Game contexts.
/// @todo Game binding context setup obviously belong to the game plugin, so shouldn't be here.
isys.newContext("map");
isys.newContext("map-freepan");
isys.newContext("finale"); // uses a fallback responder to handle script events
isys.newContext("menu")->acquireAll();
isys.newContext("gameui");
isys.newContext("shortcut");
isys.newContext("chat")->acquire(IDEV_KEYBOARD);
isys.newContext("message")->acquireAll();
// Binding context for the console.
BindContext *bc = isys.newContext(CONSOLE_BINDING_CONTEXT_NAME);
bc->protect(); // Only we can (de)activate.
bc->acquire(IDEV_KEYBOARD); // Console takes over all keyboard events.
// UI doesn't let anything past it.
isys.newContext(UI_BINDING_CONTEXT_NAME)->acquireAll();
// Top-level context that is always active and overrides every other context.
// To be used only for system-level functionality.
bc = isys.newContext(GLOBAL_BINDING_CONTEXT_NAME);
bc->protect();
bc->setDDFallbackResponder(globalContextFallback);
bc->activate();
/*
B_BindCommand("joy-hat-angle3", "print {angle 3}");
B_BindCommand("joy-hat-center", "print center");
B_BindCommand("game:key-m-press", "print hello");
B_BindCommand("key-codex20-up", "print {space released}");
B_BindCommand("key-up-down + key-shift + key-ctrl", "print \"shifted and controlled up\"");
B_BindCommand("key-up-down + key-shift", "print \"shifted up\"");
B_BindCommand("mouse-left", "print mbpress");
B_BindCommand("mouse-right-up", "print \"right mb released\"");
B_BindCommand("joy-x-neg1.0 + key-ctrl-up", "print \"joy x negative without ctrl\"");
B_BindCommand("joy-x- within 0.1 + joy-y-pos1", "print \"joy x centered\"");
B_BindCommand("joy-x-pos1.0", "print \"joy x positive\"");
B_BindCommand("joy-x-neg1.0", "print \"joy x negative\"");
B_BindCommand("joy-z-pos1.0", "print \"joy z positive\"");
B_BindCommand("joy-z-neg1.0", "print \"joy z negative\"");
B_BindCommand("joy-w-pos1.0", "print \"joy w positive\"");
B_BindCommand("joy-w-neg1.0", "print \"joy w negative\"");
*/
/*B_BindControl("turn", "key-left-staged-inverse");
B_BindControl("turn", "key-right-staged");
B_BindControl("turn", "mouse-x");
B_BindControl("turn", "joy-x + key-shift-up + joy-hat-center + key-code123-down");
*/
// Bind all the defaults for the engine only.
B_BindDefaults();
isys.initialContextActivations();
}
void B_BindDefaults()
{
InputSystem &isys = ClientApp::inputSystem();
// Engine's highest priority context: opening control panel, opening the console.
isys.bindCommand("global:key-f11-down + key-alt-down", "releasemouse");
isys.bindCommand("global:key-f11-down", "togglefullscreen");
isys.bindCommand("global:key-tilde-down + key-shift-up", "taskbar");
// Console bindings (when open).
isys.bindCommand("console:key-tilde-down + key-shift-up", "taskbar"); // without this, key would be entered into command line
// Bias editor.
}
void B_BindGameDefaults()
{
if(!App_GameLoaded()) return;
Con_Executef(CMDS_DDAY, false, "defaultgamebindings");
}