implement *Mouse*Wheel1Up/Down for player controls

implement mouse wheel viewport zoom as async PlayerControl
Sven Eberhardt 2009-12-31 18:20:45 +01:00
parent 8b4006da08
commit 23a206ccdd
8 changed files with 50 additions and 12 deletions

View File

@ -333,6 +333,20 @@
Identifier=Test
GUIName=Test
GUIDesc=Test
# Viewport Zoom
[ControlDef]
Identifier=ZoomIn
GUIName=Zoom in
GUIDesc=Increase viewport zoom
Action=ZoomIn
[ControlDef]
Identifier=ZoomOut
GUIName=Zoom out
GUIDesc=Decrease viewport zoom
Action=ZoomOut
[ControlSets]
@ -598,6 +612,16 @@
Key=S,GameMouse1ButtonRight
Priority=150
Control=DropAlt
[Assignment]
Key=Mouse1Wheel1Up
Priority=100
Control=ZoomIn
[Assignment]
Key=Mouse1Wheel1Down
Priority=100
Control=ZoomOut
[ControlSet]
Name=Gamepad1

View File

@ -54,6 +54,8 @@ void C4PlayerControlDef::CompileFunc(StdCompiler *pComp)
{ "MenuUp", CDA_MenuUp },
{ "MenuRight", CDA_MenuRight },
{ "MenuDown", CDA_MenuDown },
{ "ZoomIn", CDA_ZoomIn },
{ "ZoomOut", CDA_ZoomOut },
{ NULL, CDA_None } };
pComp->Value(mkNamingAdapt(mkEnumAdapt<Actions, int32_t>(eAction, ActionNames), "Action", CDA_Script));
pComp->NameEnd();
@ -819,6 +821,7 @@ bool C4PlayerControl::ExecuteControlAction(int32_t iControl, C4PlayerControlDef:
{
// get affected player
C4Player *pPlr = NULL;
C4Viewport *pVP;
if (iPlr > -1)
{
pPlr = ::Players.Get(iPlr);
@ -839,6 +842,9 @@ bool C4PlayerControl::ExecuteControlAction(int32_t iControl, C4PlayerControlDef:
case C4PlayerControlDef::CDA_MenuUp: if (!pPlr || !pPlr->Menu.IsActive() || fUp) return false; pPlr->Menu.Control(COM_MenuUp ,0); return true; // navigate
case C4PlayerControlDef::CDA_MenuRight: if (!pPlr || !pPlr->Menu.IsActive() || fUp) return false; pPlr->Menu.Control(COM_MenuRight,0); return true; // navigate
case C4PlayerControlDef::CDA_MenuDown: if (!pPlr || !pPlr->Menu.IsActive() || fUp) return false; pPlr->Menu.Control(COM_MenuDown ,0); return true; // navigate
case C4PlayerControlDef::CDA_ZoomIn: if (!pPlr || !(pVP = GraphicsSystem.GetViewport(iPlr))) return false; pVP->ChangeZoom(C4GFX_ZoomStep); return true; // viewport zoom
case C4PlayerControlDef::CDA_ZoomOut: if (!pPlr || !(pVP = GraphicsSystem.GetViewport(iPlr))) return false; pVP->ChangeZoom(1.0f/C4GFX_ZoomStep); return true; // viewport zoom
//unknown action
default: return false;
@ -946,7 +952,7 @@ void C4PlayerControl::AddKeyBinding(const C4KeyCodeEx &key, bool fHoldKey, int32
C4CustomKey::PRIO_PlrControl));
}
bool C4PlayerControl::DoMouseInput(uint8_t mouse_id, int32_t mouseevent, float game_x, float game_y, float gui_x, float gui_y, bool is_ctrl_down, bool is_shift_down, bool is_alt_down)
bool C4PlayerControl::DoMouseInput(uint8_t mouse_id, int32_t mouseevent, float game_x, float game_y, float gui_x, float gui_y, bool is_ctrl_down, bool is_shift_down, bool is_alt_down, int wheel_dir)
{
// convert moueevent to key code
uint8_t mouseevent_code;
@ -961,9 +967,11 @@ bool C4PlayerControl::DoMouseInput(uint8_t mouse_id, int32_t mouseevent, float g
case C4MC_Button_RightDown: mouseevent_code = KEY_MOUSE_ButtonRight; break;
case C4MC_Button_LeftDouble: mouseevent_code = KEY_MOUSE_ButtonLeftDouble; break;
case C4MC_Button_RightDouble: mouseevent_code = KEY_MOUSE_ButtonRightDouble; break;
case C4MC_Button_Wheel: mouseevent_code = KEY_MOUSE_ButtonMiddleDouble; break;
case C4MC_Button_MiddleUp: is_down = false; // nobreak
case C4MC_Button_MiddleDown: mouseevent_code = KEY_MOUSE_ButtonMiddle; break;
case C4MC_Button_Wheel:
if (!wheel_dir) return false;
mouseevent_code = (wheel_dir > 0) ? KEY_MOUSE_Wheel1Up : KEY_MOUSE_Wheel1Down; break;
default: assert(false); return false;
}
// compose keycode

View File

@ -45,6 +45,7 @@ class C4PlayerControlDef
CDA_Script, // default: Script callback
CDA_Menu, // open player menu (async)
CDA_MenuOK, CDA_MenuCancel, CDA_MenuLeft, CDA_MenuUp, CDA_MenuRight, CDA_MenuDown, // player menu controls (async)
CDA_ZoomIn, CDA_ZoomOut, // player viewport control (async)
};
private:
Actions eAction;
@ -352,7 +353,7 @@ class C4PlayerControl
void Execute();
// mouse input
bool DoMouseInput(uint8_t mouse_id, int32_t mouseevent, float game_x, float game_y, float gui_x, float gui_y, bool is_ctrl_down, bool is_shift_down, bool is_alt_down);
bool DoMouseInput(uint8_t mouse_id, int32_t mouseevent, float game_x, float game_y, float gui_x, float gui_y, bool is_ctrl_down, bool is_shift_down, bool is_alt_down, int wheel_dir);
// control enable/disable
bool SetControlDisabled(int ctrl, bool is_disabled) { return Sync.SetControlDisabled(ctrl, is_disabled); }

View File

@ -421,7 +421,7 @@ bool C4Shape::ContactCheck(int32_t cx, int32_t cy)
}
return ContactCount;
return !!ContactCount;
}
int32_t C4Shape::GetVertexX(int32_t iVertex)

View File

@ -387,7 +387,8 @@ C4KeyCode C4KeyCodeEx::String2KeyCode(const StdStrBuf &sName)
while (isdigit(*key_str)) ++key_str;
// check for known mouse events (e.g. Mouse1Move or GameMouse1Wheel)
if (!stricmp(key_str, "Move")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Move, is_gamemouse_key);
if (!stricmp(key_str, "Wheel1")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Wheel1, is_gamemouse_key);
if (!stricmp(key_str, "Wheel1Up")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Wheel1Up, is_gamemouse_key);
if (!stricmp(key_str, "Wheel1Down")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Wheel1Down, is_gamemouse_key);
if (SEqualNoCase(key_str, "Button", 6)) // e.g. Mouse1ButtonLeft or GameMouse1ButtonRightDouble
{
// check for known mouse button events
@ -486,7 +487,8 @@ StdStrBuf C4KeyCodeEx::KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool
switch (mouse_event)
{
case KEY_MOUSE_Move: return FormatString("%s%dMove", mouse_is_game_str, mouse_id);
case KEY_MOUSE_Wheel1: return FormatString("%s%dWheel1", mouse_is_game_str, mouse_id);
case KEY_MOUSE_Wheel1Up: return FormatString("%s%dWheel1Up", mouse_is_game_str, mouse_id);
case KEY_MOUSE_Wheel1Down: return FormatString("%s%dWheel1Down", mouse_is_game_str, mouse_id);
case KEY_MOUSE_ButtonLeft: return FormatString("%s%dLeft", mouse_is_game_str, mouse_id);
case KEY_MOUSE_ButtonRight: return FormatString("%s%dRight", mouse_is_game_str, mouse_id);
case KEY_MOUSE_ButtonMiddle: return FormatString("%s%dMiddle", mouse_is_game_str, mouse_id);

View File

@ -88,7 +88,8 @@ const C4KeyCode KEY_Default = 0, // no key
KEY_MOUSE_ButtonRightDouble = KEY_MOUSE_Button1Double + 1,
KEY_MOUSE_ButtonMiddleDouble= KEY_MOUSE_Button1Double + 2,
KEY_MOUSE_ButtonMaxDouble = KEY_MOUSE_Button1Double + 0x1f, // max number of supported mouse buttons
KEY_MOUSE_Wheel1 = 0x40, // mouse control: wheel up/down
KEY_MOUSE_Wheel1Up = 0x40, // mouse control: wheel up
KEY_MOUSE_Wheel1Down = 0x41, // mouse control: wheel down
KEY_MOUSE_GameMask = 0x80; // if set, contorl is sent in game coordinates
inline uint8_t KEY_JOY_Button(uint8_t idx) { return KEY_JOY_Button1+idx; }

View File

@ -361,7 +361,9 @@ void C4MouseControl::Move(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyFl
{
if (pPlayer->ControlSet->IsMouseControlAssigned(iButton))
{
pPlayer->Control.DoMouseInput(0 /* only 1 mouse supported so far */, iButton, GameX, GameY, GuiX, GuiY, ControlDown, ShiftDown, Application.IsAltDown());
int wheel_dir = 0;
if (iButton == C4MC_Button_Wheel) wheel_dir = (short)(dwKeyFlags >> 16);
pPlayer->Control.DoMouseInput(0 /* only 1 mouse supported so far */, iButton, GameX, GameY, GuiX, GuiY, ControlDown, ShiftDown, Application.IsAltDown(), wheel_dir);
}
}
}
@ -374,7 +376,7 @@ void C4MouseControl::DoMoveInput()
if (!(pPlayer=::Players.Get(Player))) return;
if (!pPlayer->ControlSet) return;
if (!pPlayer->ControlSet->IsMouseControlAssigned(C4MC_Button_None)) return;
pPlayer->Control.DoMouseInput(0 /* only 1 mouse supported so far */, C4MC_Button_None, GameX, GameY, GuiX, GuiY, ControlDown, ShiftDown, Application.IsAltDown());
pPlayer->Control.DoMouseInput(0 /* only 1 mouse supported so far */, C4MC_Button_None, GameX, GameY, GuiX, GuiY, ControlDown, ShiftDown, Application.IsAltDown(), 0);
}
void C4MouseControl::Draw(C4TargetFacet &cgo, const ZoomData &GameZoom)
@ -876,8 +878,8 @@ void C4MouseControl::Wheel(DWORD dwFlags)
// Normal wheel: control zoom
if(!ControlDown)
{
if(iDelta > 0) Viewport->ChangeZoom(C4GFX_ZoomStep);
if(iDelta < 0) Viewport->ChangeZoom(1.0f/C4GFX_ZoomStep);
//if(iDelta > 0) Viewport->ChangeZoom(C4GFX_ZoomStep);
//if(iDelta < 0) Viewport->ChangeZoom(1.0f/C4GFX_ZoomStep);
}
// Ctrl + Wheel: pass to player control (might be used for inventory or such)
else

View File

@ -386,7 +386,7 @@ std::string C4AulScript::Translate(const std::string &text) const
if (cursor->stringTable)
return cursor->stringTable->Translate(text);
}
catch (C4LangStringTable::NoSuchTranslation &e)
catch (C4LangStringTable::NoSuchTranslation &)
{
// Ignore, soldier on
}