Skip to content

Commit

Permalink
Multiple Click() params fixes and right-click handling (#1929)
Browse files Browse the repository at this point in the history
Co-authored-by: ike709 <[email protected]>
  • Loading branch information
ike709 and ike709 authored Aug 19, 2024
1 parent a2215f7 commit 9b12503
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
9 changes: 5 additions & 4 deletions OpenDreamClient/Input/MouseInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public bool HandleViewportEvent(ScalingViewport viewport, GUIBoundKeyEventArgs a
return OnRelease(viewport, args);
}

public void HandleStatClick(string atomRef, bool isMiddle) {
public void HandleStatClick(string atomRef, bool isRight, bool isMiddle) {
bool shift = _inputManager.IsKeyDown(Keyboard.Key.Shift);
bool ctrl = _inputManager.IsKeyDown(Keyboard.Key.Control);
bool alt = _inputManager.IsKeyDown(Keyboard.Key.Alt);

RaiseNetworkEvent(new StatClickedEvent(atomRef, isMiddle, shift, ctrl, alt));
RaiseNetworkEvent(new StatClickedEvent(atomRef, isRight, isMiddle, shift, ctrl, alt));
}

private (ClientObjectReference Atom, Vector2i IconPosition)? GetAtomUnderMouse(ScalingViewport viewport, GUIBoundKeyEventArgs args) {
Expand Down Expand Up @@ -143,7 +143,7 @@ private bool OnPress(ScalingViewport viewport, GUIBoundKeyEventArgs args) {
return false;

var atom = underMouse.Value.Atom;
var clickParams = CreateClickParams(viewport, args, underMouse.Value.IconPosition);
var clickParams = CreateClickParams(viewport, args, underMouse.Value.IconPosition); // If client.show_popup_menu is disabled, this will handle sending right clicks

_selectedEntity = new(atom, args.PointerLocation, clickParams);
return true;
Expand All @@ -166,6 +166,7 @@ private bool OnRelease(ScalingViewport viewport, GUIBoundKeyEventArgs args) {
}

private ClickParams CreateClickParams(ScalingViewport viewport, GUIBoundKeyEventArgs args, Vector2i iconPos) {
bool right = args.Function == EngineKeyFunctions.UIRightClick;
bool middle = args.Function == OpenDreamKeyFunctions.MouseMiddle;
bool shift = _inputManager.IsKeyDown(Keyboard.Key.Shift);
bool ctrl = _inputManager.IsKeyDown(Keyboard.Key.Control);
Expand All @@ -176,6 +177,6 @@ private ClickParams CreateClickParams(ScalingViewport viewport, GUIBoundKeyEvent
ScreenLocation screenLoc = new ScreenLocation((int) screenLocPos.X, (int) screenLocY, 32); // TODO: icon_size other than 32

// TODO: Take icon transformations into account for iconPos
return new(screenLoc, middle, shift, ctrl, alt, iconPos.X, iconPos.Y);
return new(screenLoc, right, middle, shift, ctrl, alt, iconPos.X, iconPos.Y);
}
}
2 changes: 1 addition & 1 deletion OpenDreamClient/Interface/Controls/ControlInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void OnKeyBindDown(GUIBoundKeyEventArgs e) {
return;

e.Handle();
mouseInputSystem.HandleStatClick(_atomRef, e.Function == OpenDreamKeyFunctions.MouseMiddle);
mouseInputSystem.HandleStatClick(_atomRef, e.Function == EngineKeyFunctions.UIRightClick, e.Function == OpenDreamKeyFunctions.MouseMiddle);
}
}

Expand Down
17 changes: 16 additions & 1 deletion OpenDreamRuntime/Input/MouseInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,25 @@ private void HandleAtomClick(IAtomMouseEvent e, DreamObjectAtom atom, EntitySess

private string ConstructClickParams(ClickParams clickParams) {
NameValueCollection paramsBuilder = HttpUtility.ParseQueryString(string.Empty);
if (clickParams.Middle) paramsBuilder.Add("middle", "1");

// Handles setting left=1, right=1, or middle=1 mouse param
if (clickParams.Right) {
paramsBuilder.Add("right", "1");
paramsBuilder.Add("button", "right");
} else if (clickParams.Middle) {
paramsBuilder.Add("middle", "1");
paramsBuilder.Add("button", "middle");
} else {
paramsBuilder.Add("left", "1");
paramsBuilder.Add("button", "left");
}

// Modifier keys
if (clickParams.Shift) paramsBuilder.Add("shift", "1");
if (clickParams.Ctrl) paramsBuilder.Add("ctrl", "1");
if (clickParams.Alt) paramsBuilder.Add("alt", "1");

// Other params
paramsBuilder.Add("screen-loc", clickParams.ScreenLoc.ToString());
paramsBuilder.Add("icon-x", clickParams.IconX.ToString());
paramsBuilder.Add("icon-y", clickParams.IconY.ToString());
Expand Down
7 changes: 4 additions & 3 deletions OpenDreamShared/Input/SharedMouseInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ protected interface IAtomMouseEvent {
}

[Serializable, NetSerializable]
public struct ClickParams(ScreenLocation screenLoc, bool middle, bool shift, bool ctrl, bool alt, int iconX, int iconY) {
public struct ClickParams(ScreenLocation screenLoc, bool right, bool middle, bool shift, bool ctrl, bool alt, int iconX, int iconY) {
public ScreenLocation ScreenLoc { get; } = screenLoc;
public bool Right { get; } = right;
public bool Middle { get; } = middle;
public bool Shift { get; } = shift;
public bool Ctrl { get; } = ctrl;
Expand All @@ -37,12 +38,12 @@ public sealed class AtomDraggedEvent(ClientObjectReference srcAtom, ClientObject
}

[Serializable, NetSerializable]
public sealed class StatClickedEvent(string atomRef, bool middle, bool shift, bool ctrl, bool alt)
public sealed class StatClickedEvent(string atomRef, bool right, bool middle, bool shift, bool ctrl, bool alt)
: EntityEventArgs, IAtomMouseEvent {
public string AtomRef = atomRef; // TODO: Use ClientObjectReference

// TODO: icon-x and icon-y
// TODO: ScreenLoc doesn't appear at all in the click params
public ClickParams Params { get; } = new(new(0, 0, 32), middle, shift, ctrl, alt, 0, 0);
public ClickParams Params { get; } = new(new(0, 0, 32), right, middle, shift, ctrl, alt, 0, 0);
}
}

0 comments on commit 9b12503

Please sign in to comment.