From bc9697ab3a0e332d46027b8bb8c05f3b86850efe Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Sat, 3 Jan 2015 15:32:06 +0100 Subject: [PATCH] worked on making the order of items in the interaction menu and action bar more consistent; changed some minor things --- .../ControllerActionBar.ocd/Script.c | 24 +++++++++++-------- .../ObjectInteractionMenu.ocd/Script.c | 8 ++++++- .../Libraries.ocd/ClonkControl.ocd/Script.c | 24 ++++++++++++------- .../Libraries.ocd/Producer.ocd/Script.c | 5 ++-- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c index fbc81a0bb..f4fcf49ca 100644 --- a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c @@ -128,7 +128,8 @@ public func FxIntSearchInteractionObjectsTimer(object target, effect, int time) // only update if we see any changes var old_actionbar_items = actionbar_items; actionbar_items = target->GetInteractableObjects(); - + PrepareAndSortNewActionBarItems(GetCursor(GetOwner())); + // determine if update is necessary var do_update = GetLength(actionbar_items) != GetLength(old_actionbar_items); if (!do_update) @@ -160,15 +161,21 @@ public func FxIntSearchInteractionObjectsTimer(object target, effect, int time) return 1; } +func IsActionInfoSelected(action_info, crew) +{ + return (action_info.actiontype == ACTIONTYPE_VEHICLE && crew->GetProcedure() == "PUSH" && crew->GetActionTarget() == action_info.interaction_object) + || (action_info.actiontype == ACTIONTYPE_STRUCTURE && crew->Contained() == action_info.interaction_object) + || (action_info.actiontype == ACTIONTYPE_INVENTORY); +} + func UpdateActionBarDisplay() { + var crew = GetCursor(GetOwner()); // clean up old first // the action bar is always completely re-created when an update is detected var current_bar = actionbar_items; CloseActionBarGui(); actionbar_items = current_bar; - SortActionBar(); - var menu = { @@ -177,8 +184,6 @@ func UpdateActionBarDisplay() Top = "50%", Bottom = Format("50%%%s", ToEmString(GUI_Controller_ActionBar_IconSize)) }; - var crew = GetCursor(GetOwner()); - var button_number = 0; var all_buttons_count = GetLength(actionbar_items); for (var action_info in actionbar_items) @@ -212,9 +217,7 @@ func UpdateActionBarDisplay() OnMouseOut = GuiAction_SetTag("Std"), }; - var selected = (action_info.actiontype == ACTIONTYPE_VEHICLE && crew->GetProcedure() == "PUSH" && crew->GetActionTarget() == action_info.interaction_object) - || (action_info.actiontype == ACTIONTYPE_STRUCTURE && crew->Contained() == action_info.interaction_object) - || (action_info.actiontype == ACTIONTYPE_INVENTORY); + var selected = IsActionInfoSelected(action_info, crew); var graphics_name = nil; var graphics_id = nil, tooltip = nil; @@ -307,17 +310,18 @@ func CreateNewActionButton(int priority, object interaction_object, int actionty PushBack(actionbar_items, button_info); } -func SortActionBar() +func PrepareAndSortNewActionBarItems(object crew) { RemoveHoles(actionbar_items); + // sort correctly for priority var len = GetLength(actionbar_items); for (var c = 0; c < len; ++c) { var min = nil; for (var i = c; i < len; ++i) { - if (min == nil || actionbar_items[min].priority < actionbar_items[i].priority) + if (min == nil || actionbar_items[min].priority > actionbar_items[i].priority) min = i; } var temp = actionbar_items[min]; diff --git a/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c index 123ae5c2e..d5ecfddd1 100644 --- a/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c @@ -73,6 +73,10 @@ func Destruction() if (menu && menu.menu_object) menu.menu_object->RemoveObject(); } + // remove all remaining contained dummy objects to prevent script warnings about objects in removed containers + var i = ContentsCount(), obj = nil; + while (obj = Contents(--i)) + obj->RemoveObject(false); } // used as a static function @@ -101,7 +105,6 @@ func FxIntCheckObjectsStart(target, effect, temp) func FxIntCheckObjectsTimer(target, effect, timer) { var new_objects = FindObjects(Find_AtPoint(target->GetX(), target->GetY()), Find_Or(Find_Category(C4D_Vehicle), Find_Category(C4D_Structure), Find_Func("IsContainer"), Find_Func("IsClonk"))); - if (new_objects == current_objects) return; UpdateObjects(new_objects); @@ -286,10 +289,13 @@ func CreateSideBar(int slot) background_color = RGBa(255, 255, 0, 10); symbol = Icon_Menu_RectangleBrightRounded; } + var priority = 10000 - obj.Plane; + if (obj == cursor) priority = 1; var entry = { Right = em_size, Bottom = em_size, Symbol = symbol, + Priority = priority, Style = GUI_TextBottom | GUI_TextHCenter, BackgroundColor = background_color, OnMouseIn = GuiAction_SetTag("OnHover"), diff --git a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c index a784f61b4..3a9f05470 100644 --- a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c @@ -146,15 +146,15 @@ protected func OnActionChanged(string oldaction) /** Returns additional interactions the clonk possesses as an array of function pointers. Returned Proplist contains: Fn = Name of the function to call - Object = object to call the function in. Will also be displayed on the interaction-button - Description = a description of what the interaction does + Object = Object to call the function in. Will also be displayed on the interaction-button + Description = A description of what the interaction does IconID = ID of the definition that contains the icon (like GetInteractionMetaInfo) - IconName = Namo of the graphic for teh icon (like GetInteractionMetaInfo) - [Priority] = Where to sort in in the interaction-list. 0=front, 1=after script, 2=after vehicles, >=3=at the end, nil equals 3 + IconName = Name of the graphic for the icon (like GetInteractionMetaInfo) + Priority = Where to sort in in the interaction-list. 0=front, 10=after script, 20=after vehicles, 30=after structures, nil means no preverence */ public func GetExtraInteractions() { - var functions = CreateArray(); + var functions = _inherited(...) ?? []; // flipping construction-preview var effect; @@ -213,7 +213,7 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re // look for minimum priority var best = nil; for (var info in interaction_objects) - if (best == nil || (info.priority > best.priority)) best = info; + if (best == nil || (info.priority < best.priority)) best = info; if (best) { ExecuteInteraction(best); @@ -1188,7 +1188,7 @@ func GetInteractableObjects() PushBack(possible_interactions, { interaction_object = interactable, - priority = 50, + priority = 9, interaction_index = j, extra_data = nil, actiontype = ACTIONTYPE_SCRIPT @@ -1199,10 +1199,14 @@ func GetInteractableObjects() // can be grabbed? (vehicles/chests..) if (interactable->GetOCF() & OCF_Grab) { + var priority = 19; + // high priority if already grabbed + if (GetActionTarget() == interactable) priority = 0; + PushBack(possible_interactions, { interaction_object = interactable, - priority = 40, + priority = priority, interaction_index = nil, extra_data = nil, actiontype = ACTIONTYPE_VEHICLE @@ -1213,10 +1217,12 @@ func GetInteractableObjects() // can be entered? if (interactable->GetOCF() & OCF_Entrance && (!can_only_use_container || interactable == Contained())) { + var priority = 29; + if (Contained() == interactable) priority = 0; PushBack(possible_interactions, { interaction_object = interactable, - priority = 30, + priority = priority, interaction_index = nil, extra_data = nil, actiontype = ACTIONTYPE_STRUCTURE diff --git a/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c index 19204e119..053342c51 100644 --- a/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c @@ -41,7 +41,8 @@ protected func Initialize() // All producers are accessible. public func IsContainer() { return true; } -public func IsInteractable() { return GetCon() >= 100; } +// not per-se interactable via [Space]; interaction happens via the interaction menu +public func IsInteractable() { return false; } public func GetConsumerPriority() { return 50; } @@ -74,7 +75,7 @@ public func OnProductHover(symbol, extra_data, desc_menu_target, menu_id) { var new_box = { - Text = symbol.Description, + Text = Format("%s:|%s", symbol.Name, symbol.Description,), requirements = { Top = "100% - 2em",