adapted flagpole to the interaction menu; moved some frequent checks (completion/hostility) to the interaction menu; the flag is no longer static back

Controls
David Dormagen 2015-03-01 11:20:33 +01:00
parent f169640713
commit 6466c6d45b
7 changed files with 112 additions and 65 deletions

View File

@ -341,6 +341,19 @@ func CreateMainMenu(object obj, int slot)
container.Left = ToEmString(InteractionMenu_SideBarSize);
container.Right = "100%";
}
// Do virtually nothing if the building is not ready to be interacted with. This can be caused by several things.
var error_message = nil;
if (obj->GetCon() < 100) error_message = Format("$MsgNotFullyConstructed$", obj->GetName());
else if (Hostile(cursor->GetOwner(), obj->GetOwner())) error_message = Format("$MsgHostile$", obj->GetName(), GetTaggedPlayerName(obj->GetOwner()));
if (error_message)
{
container.Style = GUI_TextVCenter | GUI_TextHCenter;
container.Text = error_message;
return container;
}
var menus = obj->~GetInteractionMenus(cursor) ?? [];
// get all interaction info from the object and put it into a menu
// contents first
@ -470,7 +483,7 @@ func OnMenuEntrySelected(proplist menu_info, int entry_index, int player)
var callback_target;
if (!(callback_target = info.menu.callback_target)) return;
var result = callback_target->Call(info.menu.callback, info.entry.symbol, info.entry.extra_data);
var result = callback_target->Call(info.menu.callback, info.entry.symbol, info.entry.extra_data, cursor);
// todo: trigger refresh for special value of result
}

View File

@ -1,4 +1,7 @@
Name=Objektinteraktionsmenü
Description=Kümmert sich um die Spielerinteraktion mit Gebäuden, Fahrzeugen etc.
Contents=Inventar
Contents=Inventar
MsgNotFullyConstructed=%s ist noch nicht fertig gebaut.|Im Moment sind keine Interaktionen möglich.
MsgHostile=%s gehört deinem Feind %s.|Es sind keine Interaktionen möglich.

View File

@ -2,3 +2,6 @@ Name=ObjectInteractionMenu
Description=Handles the inventory exchange and general interaction between the player and buildings, vehicles etc.
Contents=Inventory
MsgNotFullyConstructed=%s is not fully constructed yet.|There are no interactions possible at this point.
MsgHostile=%s belongs to your enemy %s.|No interactions are possible.

View File

@ -122,22 +122,18 @@ public func GetProductionMenuEntries()
public func GetInteractionMenus(object clonk)
{
var menus = _inherited() ?? [];
// only open the menus if ready
if (GetCon() >= 100)
var prod_menu =
{
var prod_menu =
{
title = "$Production$",
entries_callback = this.GetProductionMenuEntries,
callback = "OnProductSelection",
callback_hover = "OnProductHover",
callback_target = this,
BackgroundColor = RGB(0, 0, 50),
Priority = 20
};
PushBack(menus, prod_menu);
}
title = "$Production$",
entries_callback = this.GetProductionMenuEntries,
callback = "OnProductSelection",
callback_hover = "OnProductHover",
callback_target = this,
BackgroundColor = RGB(0, 0, 50),
Priority = 20
};
PushBack(menus, prod_menu);
return menus;
}

View File

@ -3,11 +3,25 @@
#include Library_Structure
#include Library_Flag
#include Library_GoldSeller
#include Library_Base // Needed for DuBuy...
#include Library_Base // Needed for DoBuy...
local ActMap = {
Fly = {
Prototype = Action,
Name = "Fly",
Procedure = DFA_FLOAT,
NextAction = "Hold",
},
};
protected func Initialize()
{
SetCategory(C4D_StaticBack);
// The flag is not supposed to be moved ever, ever.
// But setting the category to StaticBack would mess with other things that rely on recognizing buildings by category.
// no: SetCategory(C4D_StaticBack);
// Thus the flag can now fly.
SetAction("Fly");
SetComDir(COMD_Stop);
return _inherited(...);
}
@ -21,44 +35,69 @@ public func NoConstructionFlip() { return true; }
/*-- Interaction --*/
public func IsInteractable(object clonk)
{
if (!ObjectCount(Find_ID(Rule_BuyAtFlagpole))) return false;
if (GetCon() < 100) return false;
return !Hostile(GetOwner(), clonk->GetOwner());
}
public func GetInteractionMetaInfo(object clonk)
public func GetInteractionMenus(object clonk)
{
return { Description = "$MsgBuy$", IconName = nil, IconID = Library_Base };
var menus = _inherited() ?? [];
// only open the menus if ready
if (ObjectCount(Find_ID(Rule_BuyAtFlagpole)))
{
var buy_menu =
{
title = "$MsgBuy$",
entries_callback = this.GetBuyMenuEntries,
callback = "OnBuyMenuSelection",
callback_target = this,
BackgroundColor = RGB(50, 50, 0),
Priority = 20
};
PushBack(menus, buy_menu);
}
return menus;
}
public func Interact(object clonk)
public func GetBuyMenuEntries(object clonk)
{
var menu;
// default design of a control menu item
var custom_entry =
{
Right = "8em", Bottom = "4em",
BackgroundColor = {Std = 0, OnHover = 0x50ff0000},
image = {Right = "4em", Style = GUI_TextBottom | GUI_TextRight},
price = {Left = "4em", Priority = 3}
};
var wealth = GetWealth(GetOwner()); // Note that the flag owner pays for everything atm.
var menu_entries = [];
var i = 0, item, amount;
while (item = GetBaseMaterial(GetOwner(), nil, i++))
{
amount = GetBaseMaterial(GetOwner(), item);
// Add even if amount==0
if (!menu) menu = clonk->CreateRingMenu(Flagpole, this);
if (!menu) return false;
menu->AddItem(item, amount, nil);
var entry =
{
Prototype = custom_entry,
image = {Prototype = custom_entry.image},
price = {Prototype = custom_entry.price}
};
entry.image.Symbol = item;
entry.image.Text = Format("%dx", amount);
var value = GetBuyValue(item);
entry.price.Text = Format("<c ffff00>%d$</c>", value);
entry.Priority = 1000 * value + i; // Order by value and then by BaseMaterial index.
if (value > wealth) // If the player can't afford it, the item (except for the price) is overlayed by a greyish color.
{
entry.overlay = {Priority = 2, BackgroundColor = RGBa(50, 50, 50, 150)};
}
PushBack(menu_entries, {symbol = item, extra_data = nil, custom = entry});
}
if (!menu) return false;
menu->Show();
return true;
return menu_entries;
}
public func Selected(object menu, proplist menu_item, bool alt)
public func OnBuyMenuSelection(id def, extra_data, object clonk)
{
// Safety
var clonk = menu->GetMenuObject();
if (!clonk || !IsInteractable(clonk)) return;
var def = menu_item->GetSymbol();
if (!def) return;
// Buy
DoBuy(def, clonk->GetController(), GetOwner(), clonk, alt);
DoBuy(def, clonk->GetController(), GetOwner(), clonk);
// Excess objects exit flag (can't get them out...)
var i = ContentsCount();
var obj;
@ -74,10 +113,7 @@ public func Selected(object menu, proplist menu_item, bool alt)
obj.Entrance = this.BuyItem_Entrance;
}
}
// Update available count
menu_item->SetAmount(GetBaseMaterial(GetOwner(), def));
menu->Show();
return true;
UpdateInteractionMenus(this.GetBuyMenuEntries);
}
// newly bought items do not fade out unless collected

View File

@ -1,3 +1,3 @@
Name=Flagpole
Description=Marks your reign, where you are able to buy items in buildings.
MsgBuy=Buy stuff
MsgBuy=Buy Stuff

View File

@ -156,22 +156,18 @@ public func GetPumpControlMenuEntries(object clonk)
public func GetInteractionMenus(object clonk)
{
var menus = _inherited() ?? [];
// only open the menus if ready
if (GetCon() >= 100)
{
var prod_menu =
{
title = "$Control$",
entries_callback = this.GetPumpControlMenuEntries,
callback = "OnPumpControl",
callback_hover = "OnPumpControlHover",
callback_target = this,
BackgroundColor = RGB(0, 50, 50),
Priority = 20
};
PushBack(menus, prod_menu);
}
var menus = _inherited() ?? [];
var prod_menu =
{
title = "$Control$",
entries_callback = this.GetPumpControlMenuEntries,
callback = "OnPumpControl",
callback_hover = "OnPumpControlHover",
callback_target = this,
BackgroundColor = RGB(0, 50, 50),
Priority = 20
};
PushBack(menus, prod_menu);
return menus;
}