From 5f25baa058d3854b883958ff68871faeba04d4c7 Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Wed, 20 Jan 2016 10:36:50 +0100 Subject: [PATCH] producers: show progress of current product (#1549) This is solved via another entry in the production menu (below the products), which is updated by an effect, that is being told the menu ID/target by the interaction menu through a callback. This setup allows for very intrusive changes to the interaction menu with only few lines of code! --- .../Structures.ocd/Producer.ocd/Script.c | 57 ++++++++++++++++++- .../Producer.ocd/StringTblDE.txt | 1 + .../Producer.ocd/StringTblUS.txt | 1 + 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c index 5c377311c..9c927cf56 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c @@ -112,14 +112,28 @@ public func GetProductionMenuEntries(object clonk) PushBack(menu_entries, {symbol = product, extra_data = nil, custom = entry}); } - // At the bottom of the menu, we add some helpful information about the additional features. + // Below the symbols, we leave some space for a progress bar to indicate the current product progress. var entry = { - Style = GUI_TextBottom, - Bottom = "2em", BackgroundColor = RGBa(0, 0, 0, 100), + Bottom = "1em", BackgroundColor = RGBa(0, 0, 0, 50), + Priority = 999998, + bar = + { + BackgroundColor = RGBa(200, 200, 200, 100), + Right = "0%" + } + }; + var updating_effect = AddEffect("IntUpgradeProductProgressBar", this, 1, 2, this); + PushBack(menu_entries, {symbol = nil, extra_data = nil, custom = entry, fx = updating_effect}); + // At the bottom of the menu, we add some helpful information about the additional features. + entry = + { + Style = GUI_TextBottom | GUI_FitChildren, + Bottom = "1em", BackgroundColor = RGBa(0, 0, 0, 100), Priority = 999999, Text = Format("%s + $Click$: $InfiniteProduction$", GetPlayerControlAssignment(clonk->GetOwner(), CON_ModifierMenu1, true)) }; + PushBack(menu_entries, {symbol = nil, extra_data = nil, custom = entry}); return menu_entries; } @@ -180,6 +194,43 @@ private func GetCostString(int amount, bool available) return Format("%dx", amount); } +public func FxIntUpgradeProductProgressBarOnMenuOpened(object target, effect fx, int main_ID, int entry_ID, proplist menu_target) +{ + fx.main_ID = main_ID; + fx.entry_ID = entry_ID; + fx.menu_target = menu_target; + // Force update on first 'Timer' call. + fx.is_showing = true; + EffectCall(target, fx, "Timer"); +} + +public func FxIntUpgradeProductProgressBarTimer(object target, effect fx, int time) +{ + if (fx.menu_target == nil) return FX_OK; + // Find (new?) production effect if not already given. + if (fx.production_effect == nil) + { + fx.production_effect = GetEffect("ProcessProduction", this); + if (fx.production_effect == nil) + { + if (fx.is_showing) + { + fx.is_showing = false; + GuiUpdate({Text = "$Producing$: -", bar = {Right = "0%"}}, fx.main_ID, fx.entry_ID, fx.menu_target); + } + return FX_OK; + } + } + + fx.is_showing = true; + var max = ProductionTime(fx.production_effect.Product); + var current = Min(max, fx.production_effect.Duration); + var percent = 1000 * current / max; + var percent_string = Format("%d.%d%%", percent / 10, percent % 10); + GuiUpdate({Text = Format("$Producing$: %s", fx.production_effect.Product->GetName()), bar = {Right = percent_string}}, fx.main_ID, fx.entry_ID, fx.menu_target); + return FX_OK; +} + /*-- Production properties --*/ // This function may be overloaded by the actual producer. diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblDE.txt b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblDE.txt index 081d061d3..e4b0037e9 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblDE.txt +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblDE.txt @@ -1,4 +1,5 @@ Production=Produktion +Producing=Produziert QueueRemove=Eins weniger produzieren. InfiniteProduction=Endlosproduktion Click=Klick diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblUS.txt b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblUS.txt index 5bac20a67..5e6d918d9 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblUS.txt +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/StringTblUS.txt @@ -1,4 +1,5 @@ Production=Production +Producing=Producing QueueRemove=Produce one less. InfiniteProduction=Infinite production Click=Click