EchoesOfFate
A game for our COMP315 Project
 
Loading...
Searching...
No Matches
InventoryState Class Reference

Forward declaration to avoid circular dependency. More...

#include <InventoryState.h>

Public Member Functions

 InventoryState ()
 Please note this is a Very old version of the options Needs to work with the new audio manager class.
 
void setupButton (sf::Text &button, const std::string &label, float x, float y)
 sets up the buttons
 
void setupInventory (sf::Sprite &img, const sf::Texture &texture, float x, float y, float size)
 sets the texture and position of a sprite, and scales it
 
void setPlayerInventory (Player *ply, std::vector< sf::Texture > *textures, std::vector< sf::Sprite > *sprites, std::vector< std::string > *filepaths)
 
void handleClick (sf::RenderWindow &window)
 handles the clicks
 
void draw (sf::RenderWindow &window)
 
void toggleSound ()
 
bool isSoundOn () const
 
void setMusicReference (sf::Music &music)
 
void setMenuReference (PauseMenuState *menuPtr)
 

Public Attributes

PauseMenuStatemenu
 New function to set menu reference.
 

Detailed Description

Forward declaration to avoid circular dependency.

Constructor & Destructor Documentation

◆ InventoryState()

InventoryState::InventoryState ( )

Please note this is a Very old version of the options Needs to work with the new audio manager class.


Include SceneClass to access music

Load the font

Set up buttons for sound and back navigation

Start with sound off

define size of a single slot

Member Function Documentation

◆ draw()

void InventoryState::draw ( sf::RenderWindow & window)

Draw the sound button

Draw the back button

sf::VideoMode desktop = sf::VideoMode::getDesktopMode(); unsigned int width = desktop.width; int slots = (width - 400) / slotSize - 2; int size = std::min((int)imgs.size(), (begin * slots + MAX_VERT * slots)*2);

◆ handleClick()

void InventoryState::handleClick ( sf::RenderWindow & window)

handles the clicks

loops through the amount of valid sprites in imgs

checks if sprite has a position

checks if mouse is in the bounds of any of the sprites in imgs

checks if waiting for a second valid click, i.e. first time clicked an image

records position

tells program not waiting for second click anymore, next click will be second click

swaps items

set player inv to updated inv

sets sprite textures again

tells prog, next click is first click

clears window

redraws

Toggle sound when sound button is clicked

Return to the main menu when the back button is clicked

Switch back to main menu

increases start position if down key pressed, begin used for scroll bar

dec start pos

◆ isSoundOn()

bool InventoryState::isSoundOn ( ) const

◆ setMenuReference()

void InventoryState::setMenuReference ( PauseMenuState * menuPtr)

◆ setMusicReference()

void InventoryState::setMusicReference ( sf::Music & music)

Set the music reference

◆ setPlayerInventory()

void InventoryState::setPlayerInventory ( Player * ply,
std::vector< sf::Texture > * textures,
std::vector< sf::Sprite > * sprites,
std::vector< std::string > * filepaths )

take in references to player, textures, sprites, filepaths(for checking which texture to assign)

set the global pointers so we can call this function elsewhere in this class

checks if player has been created

loads player locally

gets player inventory

checks if player has items in their inventory

inits vertical offset

develops amount of slots needed based on your screen size

global loads blank sprites

locally loads texture file paths, parallel to texture objects

inits index used to locate correct texture in texture vector

loops through twice the size of the inventory, 1 for the slot image, 1 for the sprite(item) image

checks if we are not on the first level in our grid

checks if we reached the slot amount

increments y offset

loops though paths

checks if path matches item's image path

tells index which path is the right image path

sets sprite at imgs[i] to the correct location with the correct texture and adds a slot image srpite to the locations after

◆ setupButton()

void InventoryState::setupButton ( sf::Text & button,
const std::string & label,
float x,
float y )

sets up the buttons

◆ setupInventory()

void InventoryState::setupInventory ( sf::Sprite & img,
const sf::Texture & texture,
float x,
float y,
float size )

sets the texture and position of a sprite, and scales it

◆ toggleSound()

void InventoryState::toggleSound ( )

Full volume

Set the music volume to 100

Mute

Set the music volume to 0 (mute it)

Member Data Documentation

◆ menu

PauseMenuState* InventoryState::menu

New function to set menu reference.


The documentation for this class was generated from the following files: