diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index 5f0b4a85d5..21122143fe 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -1659,9 +1659,9 @@ function removeFromProductionQueue(entity, id) } // Called by unit selection buttons -function changePrimarySelectionGroup(templateName) +function changePrimarySelectionGroup(templateName, deselectGroup) { - if (Engine.HotkeyIsPressed("session.deselectgroup")) + if (Engine.HotkeyIsPressed("session.deselectgroup") || deselectGroup) g_Selection.makePrimarySelection(templateName, true); else g_Selection.makePrimarySelection(templateName, false); diff --git a/binaries/data/mods/public/gui/session/unit_commands.js b/binaries/data/mods/public/gui/session/unit_commands.js index 8bf50cd2cf..1cd04e89b4 100644 --- a/binaries/data/mods/public/gui/session/unit_commands.js +++ b/binaries/data/mods/public/gui/session/unit_commands.js @@ -534,6 +534,12 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, playerState, items, c // Items can have a callback element that overrides the normal caller-supplied callback function. button.onpress = (function(e){ return function() { e.callback ? e.callback(e) : callback(e) } })(item); + if(guiName == SELECTION) + { + button.onpressright = (function(e){return function() {callback(e, true) } })(item); + button.onpress = (function(e){ return function() {callback(e, false) } })(item); + } + if (guiName == RESEARCH) { if (item.pair) @@ -973,7 +979,7 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s if (selection.length > 1) setupUnitPanel(SELECTION, usedPanels, entState, playerState, g_Selection.groups.getTemplateNames(), - function (entType) { changePrimarySelectionGroup(entType); } ); + function (entType, rightPressed) { changePrimarySelectionGroup(entType, rightPressed); } ); var commands = getEntityCommandsList(entState); if (commands.length) diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h index 42224f2505..a380cd8f26 100644 --- a/source/gui/GUIbase.h +++ b/source/gui/GUIbase.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2012 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -93,7 +93,9 @@ enum EGUIMessageType GUIM_MOUSE_MOTION, GUIM_LOAD, // Called when an object is added to the GUI. GUIM_GOT_FOCUS, - GUIM_LOST_FOCUS + GUIM_LOST_FOCUS, + GUIM_PRESSED_MOUSE_RIGHT, + GUIM_DOUBLE_PRESSED_MOUSE_RIGHT }; /** diff --git a/source/gui/IGUIButtonBehavior.cpp b/source/gui/IGUIButtonBehavior.cpp index 2113e74ecb..0cb7f2f5d9 100644 --- a/source/gui/IGUIButtonBehavior.cpp +++ b/source/gui/IGUIButtonBehavior.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2012 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -48,7 +48,50 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message) break; m_Pressed = true; - } break; + } + break; + + case GUIM_MOUSE_DBLCLICK_RIGHT: + case GUIM_MOUSE_RELEASE_RIGHT: + { + bool enabled; + GUI::GetSetting(this, "enabled", enabled); + + if (!enabled) + break; + + if (m_PressedRight) + { + m_PressedRight = false; + if (Message.type == GUIM_MOUSE_RELEASE_RIGHT) + { + // Button was right-clicked + SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright"); + } + else + { + // Button was clicked a second time. We can't tell if the button + // expects to receive doublepress events or just a second press + // event, so send both of them (and assume the extra unwanted press + // is harmless on buttons that expect doublepress) + SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright"); + SendEvent(GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, "doublepressright"); + } + } + } + break; + + case GUIM_MOUSE_PRESS_RIGHT: + { + bool enabled; + GUI::GetSetting(this, "enabled", enabled); + + if (!enabled) + break; + + m_PressedRight = true; + } + break; case GUIM_MOUSE_DBLCLICK_LEFT: case GUIM_MOUSE_RELEASE_LEFT: @@ -77,7 +120,8 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message) SendEvent(GUIM_DOUBLE_PRESSED, "doublepress"); } } - } break; + } + break; default: break; diff --git a/source/gui/IGUIButtonBehavior.h b/source/gui/IGUIButtonBehavior.h index 09152bc31b..a7701c40d5 100644 --- a/source/gui/IGUIButtonBehavior.h +++ b/source/gui/IGUIButtonBehavior.h @@ -115,6 +115,7 @@ protected: // Notify the gui that we aren't hovered anymore UpdateMouseOver(NULL); m_Pressed = false; + m_PressedRight = false; } /** @@ -125,6 +126,7 @@ protected: * this lets us know we are done with step one (clicking). */ bool m_Pressed; + bool m_PressedRight; }; #endif