Giter VIP home page Giter VIP logo

progress2's Introduction

progress2.inc

A SA:MP UI library for rendering progress bars used to visualise all manner of data from health to a countdown timer.

Library originally written by Flávio Toribio, Now maintained by Southclaws in version 2+ with new features.

Bars 1

Bars 2

Bars 3

Installation

Simply install to your project:

sampctl package install Southclaws/progress2

Include in your code and begin using the library:

#include <progress2>

Usage

Constants

  • MAX_PLAYER_BARS:
    • Defaults to the textdraw limit divided by 3.
  • INVALID_PLAYER_BAR_VALUE:
    • Invalid return value for interface functions.
  • INVALID_PLAYER_BAR_ID:
    • Invalid bar ID value.
  • BAR_DIRECTION_RIGHT:
    • Bar direction left-to-right
  • BAR_DIRECTION_LEFT:
    • Bar direction right-to-left
  • BAR_DIRECTION_UP:
    • Bar direction bottom to top
  • BAR_DIRECTION_DOWN:
    • Bar direction top to bottom
  • BAR_DIRECTION_HORIZONTAL_FROM_0
    • Bar direction left to right and starts from 0.0 in case min_value and max_value have different signs.
  • BAR_DIRECTION_VERTICAL_FROM_0
    • Bar direction down to up and starts from 0.0 in case min_value and max_value have different signs.

Functions

  • PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width = 55.5, Float:height = 3.2, colour, Float:max = 100.0, direction = BAR_DIRECTION_RIGHT):
    • Creates a progress bar for a player.
  • DestroyPlayerProgressBar(playerid, PlayerBar:barid):
    • Destroys a player's progress bar.
  • ShowPlayerProgressBar(playerid, PlayerBar:barid):
    • Shows a player's progress bar to them.
  • HidePlayerProgressBar(playerid, PlayerBar:barid):
    • Hides a player's progress bar from them.
  • IsValidPlayerProgressBar(playerid, PlayerBar:barid):
    • Returns true if the input bar ID is valid and exists.
  • GetPlayerProgressBarPos(playerid, PlayerBar:barid, &Float:x, &Float:y):
    • Returns the on-screen position of the specified progress bar.
  • SetPlayerProgressBarPos(playerid, PlayerBar:barid, Float:x, Float:y):
    • Updates the position for a progress bar and re-renders it.
  • Float:GetPlayerProgressBarWidth(playerid, PlayerBar:barid):
    • Returns the width of a progress bar.
  • SetPlayerProgressBarWidth(playerid, PlayerBar:barid, Float:width):
    • Updates the width of a progress bar and re-renders it.
  • Float:GetPlayerProgressBarHeight(playerid, PlayerBar:barid):
    • Returns the height of a progress bar.
  • SetPlayerProgressBarHeight(playerid, PlayerBar:barid, Float:height):
    • Updates the height of a progress bar and re-renders it.
  • GetPlayerProgressBarColour(playerid, PlayerBar:barid):
    • Returns the colour of a progress bar.
  • SetPlayerProgressBarColour(playerid, PlayerBar:barid, colour):
    • Sets the colour of a progress bar.
  • Float:GetPlayerProgressBarMinValue(playerid, PlayerBar:barid)
    • Returns the minumum value of a progress bar.
  • SetPlayerProgressBarMinValue(playerid, PlayerBar:barid, Float:min_value)
    • Sets the minumum value that a progress bar represents.
  • Float:GetPlayerProgressBarMaxValue(playerid, PlayerBar:barid):
    • Returns the maximum value of a progress bar.
  • SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max):
    • Sets the maximum value that a progress bar represents.
  • Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid):
    • Returns the value a progress bar represents.
  • SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value):
    • Sets the value a progress bar represents.
  • progressbar_direction:GetPlayerProgressBarDirection(playerid, PlayerBar:barid):
    • Returns the direction of a progress bar.
  • SetPlayerProgressBarDirection(playerid, PlayerBar:barid, progressbar_direction:direction):
    • Updates the direction for a progress bar and re-renders it.
  • GetPlayerProgressBarPadding(playerid, PlayerBar:barid, &Float:padding_x, &Float:padding_y)
    • Receives current padding for both dimensions.
  • SetPlayerProgressBarPadding(playerid, PlayerBar:barid, Float:padding_x, Float:padding_y)
    • Updates current padding for both dimensions.

Internal

  • _RenderBar(playerid, barid):
    • Renders a valid bar on-screen using it's current properties. Called on creation and whenever position, width or height are updated.

Hooked

  • OnScriptInit:
    • When y_iterate is used, initialises iterators.
  • OnPlayerDisconnect:
    • To automatically destroy bars when a player disconnects.

Testing

To test, simply run the package:

sampctl package run

And connect to localhost:7777 to test.

progress2's People

Contributors

michaelbelgium avatar muthax avatar mysy00 avatar nathanramli avatar pt-player avatar samp-pinch avatar southclaws avatar victormacielghost avatar zbyss avatar ze8h avatar zorono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

progress2's Issues

Incorrect OnPlayerDisconnect() code

When a player disconnects any PlayerBars are destroyed

for(new i; i < MAX_PLAYER_BARS; i++)
DestroyPlayerProgressBar(playerid, PlayerBar:i);

This is not needed since

  • Player textdraws automatically delete
  • Creating a new playerbar resets all values (Technically you should never even need to reset the values)

Suggested change:
for(new i; i < MAX_PLAYER_BARS; i++)
PlayerBar:i = INVALID_PLAYER_BAR_ID;

And remove variable resetting from DestroyPlayerProgressBar()

One more issue if(!IsPlayerConnected(playerid)) should not be needed except for in the CreatePlayerProgressBar() function the IsValidPlayerProgressBar() will suffice since a player that is not connected would never have a valid bar id.

Gradient and leveled bars

Two suggestions:

  1. Gradient bars. Function that gives input of up to 10 colors and each color's level. You will make the gradient where each color is full at its level.
  2. Leveled bars. Same as the first suggestion, but the color just switches at once.

Issue with hidden playerbars

For some reason, when the progressbar is hidden, this if statement returns false when it should be true. And my common sense says this should work also when playerbars are hidden (cuz I have a toggle command to display or hide the progressbar)

if(GetPlayerProgressBarValue(playerid,Player_Token[playerid][b_Level]) >= GetPlayerProgressBarMaxValue(playerid,Player_Token[playerid][b_Level]))

EDIT; ok - this issue is in 2.0.3, I updated to the latest in case already
EDIT2: ok, no it might be because of SetPlayerProgressBarValue that displays the progressbar when it's hidden
EDIT3: well i can fix it in my code by doing this before the if statement
SetPlayerProgressBarValue(playerid,Player_Token[playerid][b_Level],Player_Token[playerid][b_LevelVal]); if(!Player[playerid][Toggle][4]) HidePlayerProgressBar(playerid, Player_Token[playerid][b_Level]);

Instead of
if(Player[playerid][Toggle][4]) SetPlayerProgressBarValue(playerid,Player_Token[playerid][b_Level],Player_Token[playerid][b_LevelVal]);

So after all idk the point of this issue, Or maybe you can add bool:pbar_hidden in E_BAR_DATA and work from there on - If you're bored you can do it or so :p Your choice if u want to do it

Gammix Project Merge

Hello dude, Good job and thanks for sharing your efforts....
but unfortunately i am still not intersted in y_iterate/y_hooks as it requires too many libs from YSI(y_remote,y_core,_y_cgen,y_hooks...) which takes a size on my server(big AMX file) and slows down my server so it'd be great if you merged gammix's fork with yours(https://github.com/Agneese-Saini/SA-MP/blob/master/pawno/include/progress.inc) as it doesn't require YSI and includes too many new features as an optional version of your project for those who aren't interested in YSI like me... Thanks for your patience and i wish to agree.

Write from-the-middle bar style

Suggested by @Pottus, a bar that starts in the middle and expands to the edges. Maybe an inverse version too that just renders the background bar in front and expands that instead.

Rewrite bar rendering

Bar rendering should be abstracted to another function where the position can also be altered. Then write the from-the-middle bar style that adjusts the position using this function.

File or Function is not found 0.3.DL

Hi, the function CreatePlayerProgressBar have a problem with 0.3.DL, i can't run my server.. When i comment only this function, it's Okay. issue for this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.