Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "base/internal/ui/reflexcore"
- mat_weapons =
- {
- userData = {};
- };
- registerWidget("mat_weapons");
- function mat_weapons:initialize()
- self.userData = loadUserData();
- CheckSetDefaultValue(self, "userData", "table", {});
- CheckSetDefaultValue(self.userData, "alpha1", "number", 255);
- CheckSetDefaultValue(self.userData, "alpha2", "number", 255);
- end
- function mat_weapons:drawOptions(x, y)
- local u = self.userData;
- uiLabel("Transparency (white boxes)", x, y);
- u.alpha1 = uiEditBox(u.alpha1, x+230, y, 80);
- y = y + 40;
- uiLabel("Transparency (black boxes)", x, y);
- u.alpha2 = uiEditBox(u.alpha2, x+230, y, 80);
- y = y + 40;
- saveUserData(u);
- end
- function draw_box(x, y, w, h, r, color, stroke, strokeColor)
- nvgBeginPath();
- nvgRoundedRect(x, y, w, h, r);
- nvgFillColor(color);
- nvgFill();
- if stroke then
- nvgStrokeWidth(2);
- nvgStrokeColor(strokeColor);
- nvgStroke();
- end
- end
- function draw_weapon(x_Icon, y_Icon, x_Ammo, y_Ammo, icon, color, size, fontColor, ammo)
- -- icon
- local x = 0.38;
- nvgFillColor(Color(100,100,100,255));
- nvgSvg(icon, x_Icon+0.5, y_Icon+0.5, size * x);
- nvgFillColor(color);
- nvgSvg(icon, x_Icon, y_Icon, size * x);
- -- ammo
- nvgFontSize(size * 1.1);
- --nvgFontFace("TitilliumWeb-Bold");
- nvgTextAlign(NVG_ALIGN_CENTER, NVG_ALIGN_MIDDLE);
- nvgFontBlur(0);
- nvgFillColor(fontColor);
- nvgText(x_Ammo, y_Ammo, ammo);
- end
- function mat_weapons:draw()
- if not shouldShowHUD() then return end;
- -- info
- local player = getPlayer();
- local alpha1 = self.userData.alpha1;
- local alpha2 = self.userData.alpha2;
- local numWeapons = 9; -- axe, bg, sg, pg, gl, rl, ic, br, stake?
- local numCarried = 0;
- local selectedShown = false;
- for weaponIndex = 3, numWeapons-1 do
- local weapon = player.weapons[weaponIndex];
- if weapon.pickedup then
- numCarried = numCarried + 1;
- end
- if weaponIndex == player.weaponIndexSelected then
- selectedShown = true;
- end
- end
- -- style
- local roundness = 0;
- local color_Box = Color(0,0,0,alpha2);
- local color_BoxSelected = Color(255,255,255,alpha1);
- local stroke = false;
- local color_BoxStroke = Color(0,0,0,alpha2);
- local color_BoxStrokeSelected = Color(255,255,255,alpha1);
- local color_Font = Color(255,255,255,255);
- local color_FontSelected = Color(0,0,0,255);
- -- weapon box
- local height_Box = 30;
- local width_IconBox = height_Box;
- local width_AmmoBox = 40;
- local width_Box = width_IconBox + width_AmmoBox;
- local space = 10;
- local scale = 1.8;
- -- weapon rack
- local width_Rack = (numCarried - 1) * (width_Box + space) + scale * width_Box;
- local offset_y = height_Box / 2;
- if selectedShown then
- offset_y = (height_Box * scale) / 2;
- end
- -- draw
- local xpos = -width_Rack / 2;
- for i = 3, numWeapons-1 do
- local weapon = player.weapons[i];
- local color = weapon.color;
- if weapon.pickedup then
- -- box
- local x = xpos;
- local y = -height_Box / 2;
- local w = width_Box;
- local h = height_Box;
- local c = color_Box;
- local s = color_BoxStroke;
- if i == player.weaponIndexSelected then
- y = -(height_Box * scale) / 2;
- w = w * scale;
- h = h * scale;
- c = color_BoxSelected;
- s = color_BoxStrokeSelected;
- end
- -- icon/ammo
- local x_Icon = x + width_IconBox / 2;
- local y_Icon = y + height_Box / 2;
- local x_Ammo = x + width_IconBox + width_AmmoBox / 2;
- local y_Ammo = y + height_Box / 2;
- local icon = "internal/ui/icons/weapon"..i;
- local size = width_IconBox;
- local fontColor = color_Font;
- if i == player.weaponIndexSelected then
- size = size * scale;
- x_Icon = x + scale * width_IconBox / 2;
- y_Icon = y + scale * height_Box / 2;
- x_Ammo = x + scale * width_IconBox + scale * width_AmmoBox / 2;
- y_Ammo = y + scale * height_Box / 2;
- fontColor = color_FontSelected;
- end
- -- ammo color
- local ammoMax = weapon.maxAmmo;
- local ammoLow = weapon.lowAmmoWarning;
- local colorTop = Color(fontColor.r, fontColor.g, fontColor.b);
- local colorMid = Color(255,176,14);
- local colorLow = Color(236,0,0);
- if i == player.weaponIndexSelected then
- colorTop = Color(c.r, c.g, c.b, 255);
- end
- local ammoColor = Color(colorTop.r, colorTop.g, colorTop.b, 255);
- if weapon.ammo > ammoLow then
- local a = (weapon.ammo - ammoLow) / (ammoMax - ammoLow);
- ammoColor.r = a * colorTop.r + (1-a) * colorMid.r;
- ammoColor.g = a * colorTop.g + (1-a) * colorMid.g;
- ammoColor.b = a * colorTop.b + (1-a) * colorMid.b;
- else
- local a = weapon.ammo / ammoLow;
- ammoColor.r = a * colorMid.r + (1-a) * colorLow.r;
- ammoColor.g = a * colorMid.g + (1-a) * colorLow.g;
- ammoColor.b = a * colorMid.b + (1-a) * colorLow.b;
- end
- if i == player.weaponIndexSelected then
- ammoColor.a = alpha1;
- c = ammoColor;
- else
- fontColor = ammoColor;
- end
- -- draw
- draw_box(x, y, w, h, roundness, c, stroke, s);
- draw_weapon(x_Icon, y_Icon, x_Ammo, y_Ammo, icon, color, size, fontColor, weapon.ammo);
- xpos = xpos + w + space;
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement