Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[modified] Pickup menu overhaul #2276

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Entities/Characters/Knight/KnightCommon.as
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ const string[] bombNames = { "Bomb",
"Water Bomb"
};

const string[] bombIcons = { "$Bomb$",
"$WaterBomb$"
const string[] bombIcons = { "$BombIcon$",
"$WaterBombIcon$"
};

const string[] bombTypeNames = { "mat_bombs",
Expand Down
129 changes: 48 additions & 81 deletions Entities/Common/Controls/StandardPickup.as
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,7 @@ void onInit(CBlob@ this)
WheelMenu@ menu = get_wheel_menu("pickup");
if (menu.entries.length == 0)
{
menu.option_notice = "Pickup";

// knight stuff
menu.add_entry(PickupWheelMenuEntry("Keg", "$keg$", "keg"));

const PickupWheelOption[] bomb_options = {PickupWheelOption("bomb", 1), PickupWheelOption("mat_bombs", 0)};
menu.add_entry(PickupWheelMenuEntry("Bomb", "$mat_bombs$", bomb_options, Vec2f(0, -8.0f)));

const PickupWheelOption[] waterbomb_options = {PickupWheelOption("waterbomb", 1), PickupWheelOption("mat_waterbombs", 0)};
menu.add_entry(PickupWheelMenuEntry("Water Bomb", "$mat_waterbombs$", waterbomb_options, Vec2f(0, -6.0f)));

menu.add_entry(PickupWheelMenuEntry("Mine", "$mine$", "mine"));

// archer stuff
menu.add_entry(PickupWheelMenuEntry("Arrows", "$mat_arrows$", "mat_arrows", Vec2f(0, -8.0f)));
menu.add_entry(PickupWheelMenuEntry("Water Arrows", "$mat_waterarrows$", "mat_waterarrows", Vec2f(0, 2.0f)));
menu.add_entry(PickupWheelMenuEntry("Fire Arrows", "$mat_firearrows$", "mat_firearrows", Vec2f(0, -6.0f)));
menu.add_entry(PickupWheelMenuEntry("Bomb Arrows", "$mat_bombarrows$", "mat_bombarrows"));

// builder stuff
menu.add_entry(PickupWheelMenuEntry("Gold", "$mat_gold$", "mat_gold", Vec2f(0, -6.0f)));
menu.add_entry(PickupWheelMenuEntry("Stone", "$mat_stone$", "mat_stone", Vec2f(0, -6.0f)));
menu.add_entry(PickupWheelMenuEntry("Wood", "$mat_wood$", "mat_wood", Vec2f(0, -6.0f)));
menu.add_entry(PickupWheelMenuEntry("Drill", "$drill$", "drill", Vec2f(-16.0f, 0.0f)));
menu.add_entry(PickupWheelMenuEntry("Saw", "$saw$", "saw", Vec2f(-16.0f, -16.0f)));
menu.add_entry(PickupWheelMenuEntry("Trampoline", "$trampoline$", "trampoline", Vec2f(-16.0f, -8.0f)));
menu.add_entry(PickupWheelMenuEntry("Boulder", "$boulder$", "boulder"));
menu.add_entry(PickupWheelMenuEntry("Sponge", "$sponge$", "sponge", Vec2f(0, 8.0f)));
menu.add_entry(PickupWheelMenuEntry("Seed", "$seed$", "seed", Vec2f(8.0f, 8.0f)));

// misc
menu.add_entry(PickupWheelMenuEntry("Log", "$log$", "log"));
const PickupWheelOption[] food_options = {
PickupWheelOption("food"),
PickupWheelOption("heart"),
PickupWheelOption("fishy"),
PickupWheelOption("grain"),
PickupWheelOption("steak"),
PickupWheelOption("egg")
};
menu.add_entry(PickupWheelMenuEntry("Food", "$food$", food_options));
menu.add_entry(PickupWheelMenuEntry("Ballista Ammo", "$mat_bolts$", "mat_bolts"));
menu.add_entry(PickupWheelMenuEntry("Crate", "$crate$", "crate", Vec2f(-16.0f, 0)));
menu.add_entry(PickupWheelMenuEntry("Bucket", "$filled_bucket$", "bucket"));
menu.option_notice = getTranslatedString("Pickup");
}
}

Expand All @@ -82,10 +39,12 @@ void onTick(CBlob@ this)
CControls@ controls = getControls();

// drop / pickup / throw
if (controls.ActionKeyPressed(AK_PICKUP_MODIFIER))
if (controls.ActionKeyPressed(AK_PICKUP_MODIFIER) && this.isKeyPressed(key_pickup))
{
closest_netids.clear();

WheelMenu@ menu = get_wheel_menu("pickup");
if (this.isKeyPressed(key_pickup) && menu !is get_active_wheel_menu())
if (menu !is get_active_wheel_menu())
{
set_active_wheel_menu(@menu);
}
Expand All @@ -95,29 +54,47 @@ void onTick(CBlob@ this)
CBlob@[] available;
FillAvailable(this, available);

for (uint i = 0; i < menu.entries.length; i++)
const u8 pickup_wheel_size = 20;
WheelMenuEntry@[] entries;
for (u32 i = 0; i < pickup_wheel_size; i++)
{
PickupWheelMenuEntry@ entry = cast<PickupWheelMenuEntry>(menu.entries[i]);
PickupWheelMenuEntry entry;
entry.disabled = true;

for (uint j = 0; j < available.length; j++)
entries.push_back(entry);
}

string[] names;
for (u16 i = 0; i < available.length; i++)
{
CBlob@ item = available[i];
const string name = item.getName();
if (names.find(name) != -1) continue;

Vec2f dim = item.inventoryFrameDimension;
const f32 offset_x = Maths::Clamp(16 - dim.x, -dim.x, dim.x);
const f32 offset_y = Maths::Clamp(16 - dim.y, -dim.y, dim.y);
const string inventory_name = item.getInventoryName();
const string icon = GUI::hasIconName("$"+inventory_name+"$") ? "$"+inventory_name+"$" : "$"+name+"$";
PickupWheelMenuEntry entry(name, getTranslatedString(inventory_name), icon, Vec2f(offset_x, offset_y));
names.push_back(name);

const u32 index = name.getHash() % pickup_wheel_size;
for (u32 p = 0; p < pickup_wheel_size; p++)
{
string bname = available[j].getName();
for (uint k = 0; k < entry.options.length; k++)
{
if (entry.options[k].name == bname)
{
entry.disabled = false;
break;
}
}

if (!entry.disabled)
const u32 probe = (index + p) % pickup_wheel_size;
if (entries[probe].disabled)
{
@entries[probe] = @entry;
break;
}
}
}

if (entries != menu.entries)
{
menu.entries = entries;
menu.update();
}
}
else if (this.isKeyJustPressed(key_pickup))
{
Expand Down Expand Up @@ -167,34 +144,24 @@ void onTick(CBlob@ this)
CBlob@[] blobsInRadius;
if (getMap().getBlobsInRadius(this.getPosition(), this.getRadius() + 50.0f, @blobsInRadius))
{
uint highestPriority = 0;
float closestScore = 600.0f;
CBlob@ closest;

for (uint i = 0; i < blobsInRadius.length; i++)
{
CBlob@ b = blobsInRadius[i];
if (b.getName() != selected.name) continue;

string bname = b.getName();
for (uint j = 0; j < selected.options.length; j++)
{
PickupWheelOption@ selectedOption = @selected.options[j];
if (bname != selectedOption.name) continue;

if (!canBlobBePickedUp(this, b)) break;

float maxDist = Maths::Max(this.getRadius() + b.getRadius() + 20.0f, 36.0f);
float dist = (this.getPosition() - b.getPosition()).Length();
float factor = dist / maxDist;
if (!canBlobBePickedUp(this, b)) continue;

float score = getPriorityPickupScale(this, b, factor);

if (score < closestScore || selectedOption.priority > highestPriority)
{
highestPriority = selectedOption.priority;
closestScore = score;
@closest = @b;
}
const f32 maxDist = Maths::Max(this.getRadius() + b.getRadius() + 20.0f, 36.0f);
const f32 dist = (this.getPosition() - b.getPosition()).Length();
const f32 factor = dist / maxDist;
const f32 score = getPriorityPickupScale(this, b, factor);
if (score < closestScore)
{
closestScore = score;
@closest = @b;
}
}

Expand Down
54 changes: 18 additions & 36 deletions Entities/Common/GUI/WheelMenuCommon.as
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class WheelMenuEntry
float angle_min, angle_max;
Vec2f position;
bool hovered;
bool disabled = false;

SColor get_color()
{
Expand All @@ -60,6 +61,11 @@ class WheelMenuEntry
{
GUI::DrawTextCentered(visible_name, position, get_color());
}

bool opEquals(WheelMenuEntry@ other)
{
return this.name == other.name;
}
};

class IconWheelMenuEntry : WheelMenuEntry
Expand Down Expand Up @@ -89,53 +95,23 @@ class IconWheelMenuEntry : WheelMenuEntry
}
};

class PickupWheelOption
{
string name;

// If two options are available with a different priority, regardless of score, we pick the one with the highest priority.
uint priority;

PickupWheelOption(const string&in p_name, uint p_priority = 0)
{
name = p_name;
priority = p_priority;
}
};

class PickupWheelMenuEntry : WheelMenuEntry
{
// Visual parameters
string icon_name;
float scale;
bool disabled;
PickupWheelOption[] options;
Vec2f offset;

PickupWheelMenuEntry(const string&in p_name, const string&in p_icon_name, const string&in p_option, Vec2f p_offset = Vec2f(0, 0))
{
this = PickupWheelMenuEntry(p_name, p_icon_name, PickupWheelOption[](1, PickupWheelOption(p_option)), p_offset);
}

PickupWheelMenuEntry(const string&in p_name, const string&in p_icon_name, PickupWheelOption[] p_options, Vec2f p_offset = Vec2f(0, 0))
PickupWheelMenuEntry(const string&in p_name, const string&in p_visible_name, const string&in p_icon_name, Vec2f p_offset = Vec2f(0, 0))
{
super(p_name);
visible_name = p_name;
visible_name = p_visible_name;
icon_name = p_icon_name;
options = p_options;
scale = 1.0f;
disabled = false;
offset = p_offset;
item_distance = 0.25f; // override
}

void render() override
{
if (disabled)
{
return;
}

GUI::DrawIcon(
"InteractionIconsBackground.png",
0,
Expand All @@ -147,7 +123,7 @@ class PickupWheelMenuEntry : WheelMenuEntry
GUI::DrawIconByName(
icon_name,
position + offset - Vec2f(16, 16),
scale
1.0f
);
}
};
Expand Down Expand Up @@ -207,7 +183,10 @@ class WheelMenu
// ignore cursor at center of the screen
if (is_cursor_in_range(cursor, WheelMenu::hover_distance))
{
@hovered = get_entry_from_position(cursor);
WheelMenuEntry@ entry = get_entry_from_position(cursor);
if (entry !is null && entry.disabled) return;

@hovered = entry;

if (previously_hovered !is hovered)
{
Expand Down Expand Up @@ -309,8 +288,11 @@ class WheelMenu

for (int i = 0; i < entries.length; ++i)
{
entries[i].hovered = (entries[i] is hovered);
entries[i].render();
WheelMenuEntry@ entry = entries[i];
if (entry.disabled) continue;

entry.hovered = entry is hovered;
entry.render();
}
}

Expand Down
6 changes: 3 additions & 3 deletions Rules/CommonScripts/BasicHelps.as
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
void onInit(CRules@ this)
{
// knight
AddIconToken("$Bomb$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 0);
AddIconToken("$WaterBomb$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 2);
AddIconToken("$BombIcon$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 0);
AddIconToken("$WaterBombIcon$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 2);
AddIconToken("$Satchel$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 3);
AddIconToken("$Keg$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 4);
AddIconToken("$KegIcon$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 4);
AddIconToken("$Help_Bomb1$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 30);
AddIconToken("$Help_Bomb2$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 31);
AddIconToken("$Swap$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 7);
Expand Down