forked from Mirrors/openclonk
pump: implement gui interface for selecting materials to pump
parent
ae40126dbb
commit
b9aaa2fda4
|
@ -17,6 +17,8 @@
|
|||
static const PUMP_Menu_Action_Switch_On = "on";
|
||||
static const PUMP_Menu_Action_Switch_Off = "off";
|
||||
static const PUMP_Menu_Action_Description = "description";
|
||||
static const PUMP_Menu_Action_Material_Enable = "material_on";
|
||||
static const PUMP_Menu_Action_Material_Disable = "material_off";
|
||||
|
||||
|
||||
local animation; // animation handle
|
||||
|
@ -127,7 +129,7 @@ func GetPumpMenuEntry(proplist custom_entry, symbol, string text, int priority,
|
|||
public func GetInteractionMenus(object clonk)
|
||||
{
|
||||
var menus = _inherited(clonk, ...) ?? [];
|
||||
var prod_menu =
|
||||
var control_menu =
|
||||
{
|
||||
title = "$Control$",
|
||||
entries_callback = this.GetPumpControlMenuEntries,
|
||||
|
@ -137,7 +139,18 @@ public func GetInteractionMenus(object clonk)
|
|||
BackgroundColor = RGB(0, 50, 50),
|
||||
Priority = 20
|
||||
};
|
||||
PushBack(menus, prod_menu);
|
||||
PushBack(menus, control_menu);
|
||||
var materials_menu =
|
||||
{
|
||||
title = "$PumpMaterials$",
|
||||
entries_callback = this.GetPumpMaterialsMenuEntries,
|
||||
callback = "OnPumpMaterials",
|
||||
callback_hover = "OnPumpMaterialsHover",
|
||||
callback_target = this,
|
||||
BackgroundColor = RGB(0, 50, 50),
|
||||
Priority = 25
|
||||
};
|
||||
PushBack(menus, materials_menu);
|
||||
return menus;
|
||||
}
|
||||
|
||||
|
@ -732,7 +745,7 @@ public func SetMaterialSelection(array mats)
|
|||
return;
|
||||
}
|
||||
|
||||
private func RemoveFromMaterialSeleciton(id mat)
|
||||
private func RemoveFromMaterialSelection(id mat)
|
||||
{
|
||||
return RemoveArrayValue(pump_materials, mat);
|
||||
}
|
||||
|
@ -754,6 +767,57 @@ private func IsInMaterialSelection(/* any */ mat)
|
|||
return false;
|
||||
}
|
||||
|
||||
public func GetPumpMaterialsMenuEntries(object clonk)
|
||||
{
|
||||
var menu_entries = [];
|
||||
// Add materials to the selection.
|
||||
var index = 0, def;
|
||||
while (def = GetDefinition(index++))
|
||||
{
|
||||
if (def->~IsLiquid() && def != Library_Liquid)
|
||||
{
|
||||
var act = PUMP_Menu_Action_Material_Disable;
|
||||
var status = Icon_Ok;
|
||||
var enabled = IsInMaterialSelection(def);
|
||||
if (!enabled)
|
||||
{
|
||||
act = PUMP_Menu_Action_Material_Enable;
|
||||
status = Icon_Cancel;
|
||||
}
|
||||
PushBack(menu_entries,
|
||||
{symbol = def, extra_data = act,
|
||||
custom =
|
||||
{
|
||||
Right = "2em", Bottom = "2em",
|
||||
BackgroundColor = {Std = 0, OnHover = 0x50ff0000},
|
||||
Priority = index,
|
||||
status = {Right = "1em", Top = "1em", Symbol = status},
|
||||
image = {Symbol = def}
|
||||
}}
|
||||
);
|
||||
}
|
||||
}
|
||||
return menu_entries;
|
||||
}
|
||||
|
||||
public func OnPumpMaterialsHover(id symbol, string action, desc_menu_target, menu_id)
|
||||
{
|
||||
var text = "";
|
||||
if (action == PUMP_Menu_Action_Material_Enable) text = Format("$MsgEnableMaterial$", symbol->GetLiquidType());
|
||||
else if (action == PUMP_Menu_Action_Material_Disable) text = Format("$MsgDisableMaterial$", symbol->GetLiquidType());
|
||||
else if (action == PUMP_Menu_Action_Description) text = this.Description;
|
||||
GuiUpdateText(text, menu_id, 1, desc_menu_target);
|
||||
}
|
||||
|
||||
public func OnPumpMaterials(symbol_or_object, string action, bool alt)
|
||||
{
|
||||
if (action == PUMP_Menu_Action_Material_Enable)
|
||||
AddToMaterialSelection(symbol_or_object);
|
||||
else if (action == PUMP_Menu_Action_Material_Disable)
|
||||
RemoveFromMaterialSelection(symbol_or_object);
|
||||
UpdateInteractionMenus(this.GetPumpMaterialsMenuEntries);
|
||||
}
|
||||
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
|
|
|
@ -28,4 +28,8 @@ MsgAirPipeProhibited=Die Pumpe hat bereits ein Abflussrohr, es ist kein Platz f
|
|||
MsgCreatedSource=Zuflussrohr angeschlossen.
|
||||
MsgCreatedDrain=Abflussrohr angeschlossen.
|
||||
MsgCreatedAirDrain=Luftrohr angeschlossen.
|
||||
MsgHasPipes=Die Pumpe hat schon ein Zu- und Abflussrohr.
|
||||
MsgHasPipes=Die Pumpe hat schon ein Zu- und Abflussrohr.
|
||||
|
||||
PumpMaterials=Pumpe Materialien
|
||||
MsgEnableMaterial=Schalte das Pumpen von Materiale %s ein.
|
||||
MsgDisableMaterial=Schalte das Pumpen von Materiale %s aus.
|
|
@ -28,4 +28,8 @@ MsgAirPipeProhibited=Pump already has a drain pipe and cannot take an air pipe.
|
|||
MsgCreatedSource=Connected source pipe.
|
||||
MsgCreatedDrain=Connected drain pipe.
|
||||
MsgCreatedAirDrain=Connected air pipe.
|
||||
MsgHasPipes=Pump already has a source and a drain pipe.
|
||||
MsgHasPipes=Pump already has a source and a drain pipe.
|
||||
|
||||
PumpMaterials=Pump Materials
|
||||
MsgEnableMaterial=Enable the pumping of material %s.
|
||||
MsgDisableMaterial=Disable the pumping of material %s.
|
|
@ -58,7 +58,7 @@ protected func InitializePlayer(int plr)
|
|||
|
||||
// Add test control effect.
|
||||
var effect = AddEffect("IntTestControl", nil, 100, 2);
|
||||
effect.testnr = 2;
|
||||
effect.testnr = 1;
|
||||
effect.launched = false;
|
||||
effect.plr = plr;
|
||||
return;
|
||||
|
@ -193,6 +193,7 @@ global func Test1_Completed()
|
|||
global func Test1_OnFinished()
|
||||
{
|
||||
RemoveAll(Find_Or(Find_ID(Foundry), Find_ID(Pump), Find_ID(Loam)));
|
||||
RestoreWaterLevels();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -232,7 +233,8 @@ global func Test2_Completed()
|
|||
|
||||
global func Test2_OnFinished()
|
||||
{
|
||||
RemoveAll(Find_Or(Find_ID(Foundry), Find_ID(Pump)));
|
||||
RemoveAll(Find_Or(Find_ID(Foundry), Find_ID(Pump), Find_ID(Pipe)));
|
||||
RestoreWaterLevels();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -275,6 +277,7 @@ global func Test3_Completed()
|
|||
global func Test3_OnFinished()
|
||||
{
|
||||
RemoveAll(Find_Or(Find_ID(SteamEngine), Find_ID(Pump), Find_ID(Pipe)));
|
||||
RestoreWaterLevels();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -287,7 +290,7 @@ global func RestoreWaterLevels()
|
|||
DrawMaterialQuad("Water", 144, 168, 208 + 1, 168, 208 + 1, 304, 144, 304, true);
|
||||
for (var x = 216; x <= 280; x++)
|
||||
for (var y = 24; y <= 120; y++)
|
||||
if (GetMaterial(x, y) == Material("Water"))
|
||||
if (GetMaterial(x, y) != Material("BrickSoft"))
|
||||
ClearFreeRect(x, y, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
@ -296,7 +299,7 @@ global func RemoveWater()
|
|||
{
|
||||
for (var x = 144; x <= 208 + 1; x++)
|
||||
for (var y = 168; y <= 304; y++)
|
||||
if (GetMaterial(x, y) == Material("Water"))
|
||||
if (GetMaterial(x, y) != Material("BrickSoft"))
|
||||
ClearFreeRect(x, y, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue