1/*
2 * LegacyClonk
3 *
4 * Copyright (c) RedWolf Design
5 * Copyright (c) 2008, Sven2
6 * Copyright (c) 2017-2020, The LegacyClonk Team and contributors
7 *
8 * Distributed under the terms of the ISC license; see accompanying file
9 * "COPYING" for details.
10 *
11 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12 * See accompanying file "TRADEMARK" for details.
13 *
14 * To redistribute this file separately, substitute the full license texts
15 * for the above references.
16 */
17
18// Menus attached to objects; script created or internal
19// These menus are shown to players if the target object is the current cursor
20
21#pragma once
22
23#include "C4DeletionTrackable.h"
24#include "C4Menu.h"
25
26enum
27{
28 C4MN_None = 0,
29 C4MN_Construction = 1,
30 /*C4MN_Bridge = 2, obsolete, now reserved */
31 C4MN_Take = 3,
32 C4MN_Buy = 4,
33 C4MN_Sell = 5,
34 C4MN_Activate = 6,
35 /*C4MN_Hostility = 7, now defined in C4MainMenu*/
36 /*C4MN_Surrender = 8, obsolete, now reserved*/
37 /*C4MN_Put = 9, obsolete, now reserved*/
38 /*C4MN_Magic = 10, obsolete, now reserved*/
39 /*C4MN_Main = 12, now defined in C4MainMenu*/
40 C4MN_Get = 13,
41 C4MN_Context = 14,
42 C4MN_Info = 15,
43 /*C4MN_TeamSelection = 16, now defined in C4MainMenu */
44 /*C4MN_TeamSwitch = 17, now defined in C4MainMenu */
45 C4MN_Contents = 18
46};
47
48class C4ObjectMenu : public C4Menu, private C4DeletionTrackable
49{
50public:
51 C4ObjectMenu();
52 ~C4ObjectMenu();
53
54 virtual void Default() override;
55
56 enum CallbackType { CB_None = 0, CB_Object, CB_Scenario };
57
58protected:
59 C4Object *Object;
60 C4Object *ParentObject;
61 C4Object *RefillObject;
62 C4Object **ClearObjectPtr{nullptr};
63 int32_t RefillObjectContentsCount;
64 CallbackType eCallbackType;
65 bool UserMenu; // set for script created menus; user menus do CloseQuery and MenuSelection callbacks
66 bool CloseQuerying; // recursion check for close query callback
67
68 void LocalInit(C4Object *pObject, bool fUserMenu);
69
70public:
71 void SetRefillObject(C4Object *pObj);
72 void ClearPointers(C4Object *pObj);
73 bool Init(C4FacetExSurface &fctSymbol, const char *szEmpty, C4Object *pObject, int32_t iExtra = C4MN_Extra_None, int32_t iExtraData = 0, int32_t iId = 0, int32_t iStyle = C4MN_Style_Normal, bool fUserMenu = false);
74 void Execute();
75
76 virtual C4Object *GetParentObject() override;
77 bool IsCloseQuerying() const { return !!CloseQuerying; }
78
79protected:
80 virtual bool MenuCommand(const char *szCommand, bool fIsCloseCommand) override;
81
82 virtual bool DoRefillInternal(bool &rfRefilled) override;
83 virtual void OnSelectionChanged(int32_t iNewSelection) override; // do object callbacks if selection changed in user menus
84 virtual bool IsCloseDenied() override; // do MenuQueryCancel-callbacks for user menus
85 virtual bool IsReadOnly() override; // determine whether the menu is just viewed by an observer, and should not issue any calls
86 virtual void OnUserSelectItem(int32_t Player, int32_t iIndex) override;
87 virtual void OnUserEnter(int32_t Player, int32_t iIndex, bool fRight) override;
88 virtual void OnUserClose() override;
89 virtual int32_t GetControllingPlayer() override;
90
91private:
92 int32_t AddContextFunctions(C4Object *pTarget, bool fCountOnly = false);
93};
94