From 68bb07f162b5d7fa58de1d5f5fa5f6c03243464a Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 27 Dec 2018 17:45:32 +0100 Subject: [PATCH] Allow more options for customization in the resource selection icons --- .../ResourceSelection.ocd/Script.c | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/ResourceSelection.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/ResourceSelection.ocd/Script.c index b3eef268e..b90d781f7 100755 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/ResourceSelection.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/ResourceSelection.ocd/Script.c @@ -108,16 +108,24 @@ public func GetResourceSelectionMenuEntries(object clonk) && this->IsResourceSelectionParent(resource, nil)) // Ignore those with parent resource, because they will be added/removed together with the parent { var enabled = IsInResourceSelection(resource); - var action, status; + var action; if (enabled) { action = RESOURCE_SELECT_Menu_Action_Resource_Disable; - status = Icon_Ok; } else { action = RESOURCE_SELECT_Menu_Action_Resource_Enable; - status = Icon_Cancel; + } + var icon = this->GetResourceSelectionIcon(resource, enabled), icon_type, icon_gfx; + if (GetType(icon) == C4V_C4Object || GetType(icon) == C4V_Def) + { + icon_type = icon; + } + else if (icon) + { + icon_type = icon.Symbol; + icon_gfx = icon.GraphicsName; } PushBack(menu_entries, {symbol = resource, extra_data = action, @@ -126,8 +134,8 @@ public func GetResourceSelectionMenuEntries(object clonk) Right = "2em", Bottom = "2em", BackgroundColor = {Std = 0, OnHover = 0x50ff0000}, Priority = index, - status = {Right = "1em", Top = "1em", Symbol = status}, - image = {Symbol = resource} + image = {Priority = 1, Symbol = resource}, + icon = {Priority = 2, Right = "1em", Top = "1em", Symbol = icon_type, GraphicsName = icon_gfx}, }} ); } @@ -196,3 +204,27 @@ func InitResourceSelection() return; */ } + +/** + Defines how the icons for selection are displayed, + in the lower left corner. + + By default, the enabled icon is a green check mark, + the disabled icon is a red cross mark. + + Return values can be either: + - ID: for an icon + - Object: for an object + - Proplist: {Symbol, GraphicsName}, as in usual script GUIs + */ +func GetResourceSelectionIcon(id resource, bool enabled) +{ + if (enabled) + { + return Icon_Ok; + } + else + { + return Icon_Cancel; + } +}