From db53603396cc0ef275f74ce50876b5f2845bf141 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Sun, 26 Feb 2012 16:19:52 +0100 Subject: [PATCH] Hotkeys select the item at release now Holding hotkey + left/right mouse button selects it into the corresponding hand --- .../HUD.ocd/Controller.ocd/Script.c | 10 + .../Libraries.ocd/ClonkControl.ocd/Script.c | 67 +++++- .../Libraries.ocd/HUDAdapter.ocd/Script.c | 14 ++ planet/System.ocg/PlayerControls.txt | 190 +++++++++++++++++- 4 files changed, 268 insertions(+), 13 deletions(-) diff --git a/planet/Objects.ocd/HUD.ocd/Controller.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Controller.ocd/Script.c index 754290427..4b81edba0 100644 --- a/planet/Objects.ocd/HUD.ocd/Controller.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Controller.ocd/Script.c @@ -639,6 +639,16 @@ public func OnHandSelectionChange(int old, int new, int handslot) OnSlotObjectChanged(handslot); } +protected func OnInventoryHotkeyPress(int slot) +{ + backpack[slot]->OnMouseOver(GetOwner()); +} + +protected func OnInventoryHotkeyRelease(int slot) +{ + backpack[slot]->OnMouseOut(GetOwner()); +} + // call from HUDAdapter (Clonk) public func OnSlotObjectChanged(int slot) { diff --git a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c index 00def402d..55ba67846 100644 --- a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c @@ -45,6 +45,8 @@ local force_collection; local inventory; local use_objects; +local handslot_choice_pending; + /* Item limit */ private func HandObjects() { return 2; } @@ -86,6 +88,8 @@ public func SetHandItemPos(int hand, int inv) this->~OnSlotFull(hand); else this->~OnSlotEmpty(hand); + + handslot_choice_pending = false; } /* Returns the position in the inventory of the ith use item */ @@ -487,6 +491,14 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re if (!this) return false; + if(ctrl == CON_InteractionBar) + { + if(!release); + // todo: show action bar + else; + // todo: hide action bar + } + //Log(Format("%d, %d, %s, strength: %d, repeat: %v, release: %v", x,y,GetPlayerControlName(ctrl), strength, repeat, release),this); // Backpack menu @@ -610,6 +622,37 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re return true; } + // this wall of text is called when 1-0 is beeing held, and left or right mouse button is pressed. + var hand = 0; + hot = 0; + if (ctrl == CON_Hotkey0Select) hot = 10; + if (ctrl == CON_Hotkey1Select) hot = 1; + if (ctrl == CON_Hotkey2Select) hot = 2; + if (ctrl == CON_Hotkey3Select) hot = 3; + if (ctrl == CON_Hotkey4Select) hot = 4; + if (ctrl == CON_Hotkey5Select) hot = 5; + if (ctrl == CON_Hotkey6Select) hot = 6; + if (ctrl == CON_Hotkey7Select) hot = 7; + if (ctrl == CON_Hotkey8Select) hot = 8; + if (ctrl == CON_Hotkey9Select) hot = 9; + if (ctrl == CON_Hotkey0SelectAlt) {hot = 10; hand=1; } + if (ctrl == CON_Hotkey1SelectAlt) {hot = 1; hand=1; } + if (ctrl == CON_Hotkey2SelectAlt) {hot = 2; hand=1; } + if (ctrl == CON_Hotkey3SelectAlt) {hot = 3; hand=1; } + if (ctrl == CON_Hotkey4SelectAlt) {hot = 4; hand=1; } + if (ctrl == CON_Hotkey5SelectAlt) {hot = 5; hand=1; } + if (ctrl == CON_Hotkey6SelectAlt) {hot = 6; hand=1; } + if (ctrl == CON_Hotkey7SelectAlt) {hot = 7; hand=1; } + if (ctrl == CON_Hotkey8SelectAlt) {hot = 8; hand=1; } + if (ctrl == CON_Hotkey9SelectAlt) {hot = 9; hand=1; } + + if(hot > 0 && hot <= MaxContentsCount()) + { + SetHandItemPos(hand, hot-1); + this->~OnInventoryHotkeyRelease(hot-1); + return true; + } + // inventory hot = 0; if (ctrl == CON_Hotkey0) hot = 10; @@ -623,13 +666,33 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re if (ctrl == CON_Hotkey8) hot = 8; if (ctrl == CON_Hotkey9) hot = 9; + // only the last-pressed key is taken into consideration. + // if 2 hotkeys are held, the earlier one is beeing treated as released if (hot > 0 && hot <= MaxContentsCount()) { - SetHandItemPos(0, hot-1); + // if released, we chose, if not chosen already + if(release) + { + if(handslot_choice_pending == hot) + { + SetHandItemPos(0, hot-1); + this->~OnInventoryHotkeyRelease(hot-1); + } + } + // else we just highlight + else + { + if(handslot_choice_pending) + { + this->~OnInventoryHotkeyRelease(handslot_choice_pending-1); + } + handslot_choice_pending = hot; + this->~OnInventoryHotkeyPress(hot-1); + } + return true; } - var proc = GetProcedure(); // cancel usage diff --git a/planet/Objects.ocd/Libraries.ocd/HUDAdapter.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/HUDAdapter.ocd/Script.c index d90838298..e05bfc7bb 100644 --- a/planet/Objects.ocd/Libraries.ocd/HUDAdapter.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/HUDAdapter.ocd/Script.c @@ -156,6 +156,20 @@ protected func OnHandSelectionChange(int old, int new, int handslot) return _inherited(old, new, handslot, ...); } +protected func OnInventoryHotkeyPress(int slot) +{ + if (HUDcontroller) + HUDcontroller->OnInventoryHotkeyPress(slot); + return _inherited(slot, ...); +} + +protected func OnInventoryHotkeyRelease(int slot) +{ + if (HUDcontroller) + HUDcontroller->OnInventoryHotkeyRelease(slot); + return _inherited(slot, ...); +} + // when two items switch place protected func OnInventoryChange(int old, int new) { diff --git a/planet/System.ocg/PlayerControls.txt b/planet/System.ocg/PlayerControls.txt index 029cb8f19..b158aaef9 100644 --- a/planet/System.ocg/PlayerControls.txt +++ b/planet/System.ocg/PlayerControls.txt @@ -173,43 +173,103 @@ [ControlDef] Identifier=Hotkey1 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey2 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey3 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey4 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey5 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey6 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey7 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey8 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey9 - SendCursorPos=1 + Hold=1 [ControlDef] Identifier=Hotkey0 - SendCursorPos=1 + Hold=1 + + [ControlDef] + Identifier=Hotkey1Select + + [ControlDef] + Identifier=Hotkey1SelectAlt + + [ControlDef] + Identifier=Hotkey2Select + + [ControlDef] + Identifier=Hotkey2SelectAlt + + [ControlDef] + Identifier=Hotkey3Select + + [ControlDef] + Identifier=Hotkey3SelectAlt + + [ControlDef] + Identifier=Hotkey4Select + + [ControlDef] + Identifier=Hotkey4SelectAlt + + [ControlDef] + Identifier=Hotkey5Select + + [ControlDef] + Identifier=Hotkey5SelectAlt + + [ControlDef] + Identifier=Hotkey6Select + + [ControlDef] + Identifier=Hotkey6SelectAlt + + [ControlDef] + Identifier=Hotkey7Select + + [ControlDef] + Identifier=Hotkey7SelectAlt + + [ControlDef] + Identifier=Hotkey8Select + + [ControlDef] + Identifier=Hotkey8SelectAlt + + [ControlDef] + Identifier=Hotkey9Select + + [ControlDef] + Identifier=Hotkey9SelectAlt + + [ControlDef] + Identifier=Hotkey0Select + + [ControlDef] + Identifier=Hotkey0SelectAlt # Controlling (contents, vehicles, structures) @@ -295,6 +355,10 @@ GUIDesc=Interact with object in landscape SendCursorPos=1 + [ControlDef] + Identifier=InteractionBar + Hold=1 + [ControlDef] Identifier=Enter GUIName=Enter @@ -307,7 +371,6 @@ GUIDesc=Exit the building - # Interaction Hotkeys (lower bar) [ControlDef] @@ -1200,6 +1263,106 @@ Key=0 Control=Hotkey0 + [Assignment] + Key=Hotkey1,Mouse1ButtonLeft + Control=Hotkey1Select + Priority=200 + + [Assignment] + Key=Hotkey1,Mouse1ButtonRight + Control=Hotkey1SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey2,Mouse1ButtonLeft + Control=Hotkey2Select + Priority=200 + + [Assignment] + Key=Hotkey2,Mouse1ButtonRight + Control=Hotkey2SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey3,Mouse1ButtonLeft + Control=Hotkey3Select + Priority=200 + + [Assignment] + Key=Hotkey3,Mouse1ButtonRight + Control=Hotkey3SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey4,Mouse1ButtonLeft + Control=Hotkey4Select + Priority=200 + + [Assignment] + Key=Hotkey4,Mouse1ButtonRight + Control=Hotkey4SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey5,Mouse1ButtonLeft + Control=Hotkey5Select + Priority=200 + + [Assignment] + Key=Hotkey5,Mouse1ButtonRight + Control=Hotkey5SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey6,Mouse1ButtonLeft + Control=Hotkey6Select + Priority=200 + + [Assignment] + Key=Hotkey6,Mouse1ButtonRight + Control=Hotkey6SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey7,Mouse1ButtonLeft + Control=Hotkey7Select + Priority=200 + + [Assignment] + Key=Hotkey7,Mouse1ButtonRight + Control=Hotkey7SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey8,Mouse1ButtonLeft + Control=Hotkey8Select + Priority=200 + + [Assignment] + Key=Hotkey8,Mouse1ButtonRight + Control=Hotkey8SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey9,Mouse1ButtonLeft + Control=Hotkey9Select + Priority=200 + + [Assignment] + Key=Hotkey9,Mouse1ButtonRight + Control=Hotkey9SelectAlt + Priority=200 + + [Assignment] + Key=Hotkey0,Mouse1ButtonLeft + Control=Hotkey0Select + Priority=200 + + [Assignment] + Key=Hotkey0,Mouse1ButtonRight + Control=Hotkey0SelectAlt + Priority=200 + [Assignment] Key=Shift+Hotkey1 Control=InteractionHotkey1 @@ -1287,6 +1450,11 @@ [ControlSet] Name=* + # Interaction-Bar + [Assignment] + Key=L + Control=InteractionBar + # Collect [Assignment]