Skip to content

Commit

Permalink
Merge pull request #81 from Gaya1858/main
Browse files Browse the repository at this point in the history
Slight changes item_set to item_map in SelectAction function. We have more functionalities added to the current version of our code. (Textbox, world theme changes...)
  • Loading branch information
Gaya1858 authored Nov 20, 2023
2 parents ede27a2 + a45d06e commit e28aa2a
Show file tree
Hide file tree
Showing 28 changed files with 2,756 additions and 176 deletions.
Binary file modified assets/Ground_tiles/dirt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/walls/gray_wall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,964 changes: 1,964 additions & 0 deletions blogposts/Kanagaraj/Blog_Final.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions blogposts/Kanagaraj/DRAFT.html

Large diffs are not rendered by default.

Binary file added blogposts/Kanagaraj/images/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blogposts/Kanagaraj/images/image9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 5 additions & 10 deletions source/Interfaces/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
#include "Button.hpp"

/// Constructor
i_2D::Button::Button(std::string t, sf::Vector2f size, sf::Color bgColor, sf::Color textColor) {
if(!mfont.loadFromFile("../../assets/font/ArialNarrow7.ttf")){
std::cout << "Error loading font file" << std::endl;
}
text = std::make_unique<sf::Text>(mfont);
i_2D::Button::Button(const std::string &t, sf::Vector2f size, sf::Color bgColor,
sf::Color textColor, const sf::Font &font) {
text = std::make_unique<sf::Text>(font);

text->setString(t);
text->setFillColor(textColor);
Expand All @@ -22,11 +20,8 @@ i_2D::Button::Button(std::string t, sf::Vector2f size, sf::Color bgColor, sf::Co
/**
* @brief set the font of the button
*/
void i_2D::Button::setMFont() {
if(!mfont.loadFromFile("../../assets/font/ArialNarrow7.ttf")){
std::cout << "Error loading font file" << std::endl;
}
text = std::make_unique<sf::Text>(mfont);
void i_2D::Button::setMFont(const sf::Font &font) {
text = std::make_unique<sf::Text>(font);
}

/**
Expand Down
17 changes: 8 additions & 9 deletions source/Interfaces/Button.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* @file Button.h
* @author
*
*
* @author : Team - 3
* @date: 11/02/2023
* Button class creates a SF::Rectangle and SF::Text on top
*/

#ifndef CSE_491_BUTTON_HPP
Expand All @@ -16,30 +15,30 @@ namespace i_2D {
class Button {
private:
sf::RectangleShape button;
sf::Font mfont;
std::unique_ptr<sf::Text> text;


public:
Button(std::string t, sf::Vector2f size, sf::Color bgColor, sf::Color textColor);
Button(const std::string &t, sf::Vector2f size, sf::Color bgColor,
sf::Color textColor, const sf::Font &font);

/**
* @brief set the string of the button
*
* @param s label of the button
*/
void setString(std::string s){
void setString(const std::string &s){
text->setString(s);
}

void setMFont();
void setMFont(const sf::Font &font);

/**
* @brief set the font of the button
*
* @param font
*/
void setFont(sf::Font &font) {
void setFont(const sf::Font &font) {
text->setFont(font);
}

Expand Down
65 changes: 65 additions & 0 deletions source/Interfaces/Inventory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @author : Team - 3
* @date: 11/15/2023
* Inventory class creates an array of buttons and uses it as inventory
*/

#include "Inventory.hpp"

/**
* @brief Build an inventory window and an inventory list
*
* @param font The font used by the inventory list
*/
void i_2D::Inventory::ConstructInventory(sf::Font &font) {
mInventoryWindow = std::make_unique<sf::RectangleShape>();
mInventoryWindow->setSize({mWorldSize.x,mWorldSize.y/2});
mInventoryWindow->setFillColor(sf::Color::Black);
mInventoryWindow->setPosition(sf::Vector2f{0.f,50.f});
if(mWorldSize.x > 1800){
mCol = 5;
}else mCol = 3;
if(mWorldSize.y > 900){
mRow = 4;
}else mRow = 3;
for(int i = 0; i < mRow; i++) {
std::vector<std::unique_ptr<Button>> v1;
for (int j = 0; j < mCol; j++) {
v1.push_back(std::make_unique<Button>(
"text", sf::Vector2f{(mWorldSize.x)/mCol,(mWorldSize.y/2-50)/mRow},
sf::Color::Black, sf::Color::White, font));
v1[j]->setPosition(sf::Vector2f{j*(mWorldSize.x/mCol),
mWorldSize.y/2 + 50 + i*(mWorldSize.y/2-50)/mRow});
}
mInventoryList.push_back(std::move(v1));
}
}

/**
* @brief Draws the inventory onto the render window
*
* @param window The render window of the world
*/
void i_2D::Inventory::DrawTo(sf::RenderWindow &window) {
window.draw(*mInventoryWindow);
for(const auto &x : mInventoryList){
for(const auto &y : x){
y->drawTo(window);
}
}
}

/**
* @brief Handle the mouse move event
*
* @param window The render window of the world
*/
void i_2D::Inventory::HandleMouseMove(sf::RenderWindow &window) {
for(auto &x : mInventoryList){
for(auto &y : x){
if(y->isMouseOver(window)){
y->setBackColor(sf::Color::Magenta);
}else y->setBackColor(sf::Color::Black);
}
}
}
43 changes: 43 additions & 0 deletions source/Interfaces/Inventory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @author : Team - 3
* @date: 11/15/2023
* Inventory class creates an array of buttons and uses it as inventory
*/

#ifndef CSE_491_INVENTORY_HPP
#define CSE_491_INVENTORY_HPP

#include <SFML/Graphics.hpp>
#include "Button.hpp"
#include <vector>
#include <memory>

namespace i_2D {
/***
* @class Inventory
*
* @brief Represent the inventory of entities.
*
* An interface/visual representation of an inventory.
*/
class Inventory {
private:
/// Projected inventory screen
std::unique_ptr<sf::RectangleShape> mInventoryWindow;
/// List of items in an inventory
std::vector<std::vector<std::unique_ptr<Button>>> mInventoryList;
sf::Vector2f mWorldSize; ///< Size of the world
int mCol=0; ///< Number of columns enumerating the inventory list
int mRow=0; ///< Number of rows enumerating the inventory list

public:
explicit Inventory(const sf::Vector2f size) : mWorldSize(size) {}
void SetSize(const sf::Vector2f size) {mWorldSize = size;}
void ConstructInventory(sf::Font &font);
void DrawTo(sf::RenderWindow &window);
void HandleMouseMove(sf::RenderWindow &window);
};
}


#endif //CSE_491_INVENTORY_HPP
Loading

0 comments on commit e28aa2a

Please sign in to comment.