mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
tooltips
This commit is contained in:
+45
-1
@@ -1,4 +1,3 @@
|
||||
#include <solUtil.h>
|
||||
#include <soundManager.h>
|
||||
|
||||
#include <quad.h>
|
||||
@@ -60,6 +59,42 @@ namespace battleship{
|
||||
return concreteGuiManager;
|
||||
}
|
||||
|
||||
Tooltip* ConcreteGuiManager::parseTooltip(sol::table &tooltipTbl, Vector3 guiPos){
|
||||
sol::table offsetTbl = tooltipTbl["offset"], sizeTbl = tooltipTbl["size"];
|
||||
Vector3 offset = Vector3(offsetTbl["x"], offsetTbl["y"], .1);
|
||||
Vector2 size = Vector2(sizeTbl["x"], sizeTbl["y"]);
|
||||
|
||||
sol::table lineDataTbl = tooltipTbl["lines"];
|
||||
int numLines = lineDataTbl.size();
|
||||
vector<Tooltip::LineData> lines;
|
||||
|
||||
for(int i = 0; i < numLines; i++){
|
||||
vector<pair<int, string>> iconsData;
|
||||
sol::optional<sol::table> iconsTblOpt = lineDataTbl[i + 1]["icons"];
|
||||
|
||||
if(iconsTblOpt != sol::nullopt){
|
||||
sol::table iconsTbl = lineDataTbl[i + 1]["icons"];
|
||||
int numIcons = iconsTbl.size();
|
||||
|
||||
for(int j = 0; j < numIcons; j++)
|
||||
iconsData.push_back(make_pair(iconsTbl[j + 1]["charId"], iconsTbl[j + 1]["path"]));
|
||||
}
|
||||
|
||||
sol::table entryTbl = lineDataTbl[i + 1]["entry"];
|
||||
wstring entry = (wstring)entryTbl["text"];
|
||||
Vector4 color = Vector4::VEC_IJKL;
|
||||
sol::optional<sol::table> colorTblOpt = entryTbl["color"];
|
||||
|
||||
if(colorTblOpt != sol::nullopt)
|
||||
color = Vector4(entryTbl["color"]["r"], entryTbl["color"]["g"], entryTbl["color"]["b"], entryTbl["color"]["a"]);
|
||||
|
||||
lines.push_back(Tooltip::LineData(entry, color, iconsData));
|
||||
}
|
||||
|
||||
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf";
|
||||
return new Tooltip(guiPos + offset, size, lines, fontPath);
|
||||
}
|
||||
|
||||
//TODO refactor player difficulty and faction listbox selection
|
||||
//TODO remove hardcoded font path values
|
||||
//TODO use configurable map path values
|
||||
@@ -91,12 +126,21 @@ namespace battleship{
|
||||
bool texturingEnabled = true;
|
||||
}
|
||||
|
||||
Tooltip *tooltip = nullptr;
|
||||
sol::optional<sol::table> tooltipTblOpt = guiTable["tooltip"];
|
||||
|
||||
if(tooltipTblOpt != sol::nullopt){
|
||||
sol::table tbl = guiTable["tooltip"];
|
||||
tooltip = parseTooltip(tbl, pos);
|
||||
}
|
||||
|
||||
Button *button = nullptr;
|
||||
string guiScreen = "";
|
||||
|
||||
switch(type){
|
||||
case SINGLE_PLAYER:
|
||||
button = new SinglePlayerButton(pos, size, name);
|
||||
((SinglePlayerButton*)button)->setTooltip(tooltip);
|
||||
break;
|
||||
case EDITOR:
|
||||
button = new MapEditorButton(pos, size);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CONCRETE_GUI_MANAGER_H
|
||||
|
||||
#include <abstractGuiManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -71,6 +72,7 @@ namespace battleship{
|
||||
CONSOLE,
|
||||
TRADE_OFFERS
|
||||
};
|
||||
class Tooltip;
|
||||
|
||||
class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{
|
||||
public:
|
||||
@@ -99,6 +101,7 @@ namespace battleship{
|
||||
void parseLuaScript(std::string, std::string = "");
|
||||
private:
|
||||
ConcreteGuiManager();
|
||||
Tooltip* parseTooltip(sol::table&, vb01::Vector3);
|
||||
vb01Gui::Button* parseButton(int);
|
||||
vb01Gui::Listbox* parseGameObjectListbox();
|
||||
vb01Gui::Listbox* parseListbox(int);
|
||||
|
||||
+12
-9
@@ -1,8 +1,11 @@
|
||||
#include "singlePlayerButton.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "gameManager.h"
|
||||
#include "tooltip.h"
|
||||
|
||||
#include <listbox.h>
|
||||
#include <quad.h>
|
||||
#include <node.h>
|
||||
#include <text.h>
|
||||
|
||||
#include <glfw3.h>
|
||||
@@ -13,14 +16,8 @@ namespace battleship{
|
||||
using namespace vb01Gui;
|
||||
|
||||
SinglePlayerButton::SinglePlayerButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_S, true) {}
|
||||
|
||||
void SinglePlayerButton::onMouseOver(){
|
||||
setColor(Vector4(.8, .8, .8, 1));
|
||||
}
|
||||
|
||||
void SinglePlayerButton::onMouseOff(){
|
||||
setColor(Vector4(.6, .6, .6, 1));
|
||||
}
|
||||
|
||||
SinglePlayerButton::~SinglePlayerButton(){delete tooltip;}
|
||||
|
||||
void SinglePlayerButton::onClick() {
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
@@ -32,4 +29,10 @@ namespace battleship{
|
||||
|
||||
guiManager->getText("_mainPlayer")->setText(GameManager::getSingleton()->getMainPlayerName());
|
||||
}
|
||||
|
||||
void SinglePlayerButton::update() {
|
||||
setColor(mouseOver ? Vector4(.8, .8, .8, 1) : Vector4(.6, .6, .6, 1));
|
||||
|
||||
if(tooltip) tooltip->getBackground()->getNode()->setVisible(mouseOver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,17 @@
|
||||
#include <button.h>
|
||||
|
||||
namespace battleship{
|
||||
class Tooltip;
|
||||
|
||||
class SinglePlayerButton : public vb01Gui::Button {
|
||||
public:
|
||||
SinglePlayerButton(vb01::Vector3, vb01::Vector2, std::string);
|
||||
~SinglePlayerButton();
|
||||
void onClick();
|
||||
void onMouseOver();
|
||||
void onMouseOff();
|
||||
void update();
|
||||
inline void setTooltip(Tooltip *t){this->tooltip = t;}
|
||||
private:
|
||||
Tooltip *tooltip = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+69
-2
@@ -1,14 +1,81 @@
|
||||
#include "tooltip.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
#include <root.h>
|
||||
#include <text.h>
|
||||
#include <quad.h>
|
||||
#include <node.h>
|
||||
#include <material.h>
|
||||
#include <texture.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace battleship{
|
||||
Tooltip::Tooltip(Vector2 pos, string entry){
|
||||
this->pos = pos;
|
||||
Tooltip::Tooltip(Vector3 p, Vector2 s, vector<Tooltip::LineData> lineData, string fontPath) : pos(p), size(s){
|
||||
Root *root = Root::getSingleton();
|
||||
Material *bgMat = new Material(root->getLibPath() + "gui");
|
||||
bgMat->addBoolUniform("texturingEnabled", false);
|
||||
bgMat->addVec4Uniform("diffuseColor", Vector4(.5, .5, .5, .5));
|
||||
|
||||
background = new Quad(Vector3(s.x, s.y, 0), false);
|
||||
background->setMaterial(bgMat);
|
||||
|
||||
Node *bgNode = new Node(p);
|
||||
bgNode->attachMesh(background);
|
||||
root->getGuiNode()->attachChild(bgNode);
|
||||
|
||||
string basePath = GameManager::getSingleton()->getPath();
|
||||
string iconBasePath = basePath + "Textures/Icons/";
|
||||
|
||||
for(int i = 0; i < lineData.size(); i++){
|
||||
LineData &ld = lineData[i];
|
||||
|
||||
Material *textMat = new Material(root->getLibPath() + "text");
|
||||
textMat->addBoolUniform("texturingEnabled", false);
|
||||
textMat->addVec4Uniform("diffuseColor", ld.textColor);
|
||||
|
||||
float scale = .2;
|
||||
|
||||
Vector3 offset = Vector3(0, 20 * (i + 1), .01);
|
||||
Text *text = new Text(fontPath, ld.entryText);
|
||||
text->setMaterial(textMat);
|
||||
Node *textNode = new Node(pos + offset - Vector3(0, 3, 0), Quaternion::QUAT_W, scale * Vector3::VEC_IJK);
|
||||
textNode->addText(text);
|
||||
bgNode->attachChild(textNode);
|
||||
|
||||
for(pair<int, string> &iconData: ld.iconsData){
|
||||
Vector3 iconOffset = offset;
|
||||
wstring entry = text->getText();
|
||||
|
||||
for(int j = 0; j < iconData.first; j++){
|
||||
Text::Glyph *glyph = text->getGlyph(entry[j]);
|
||||
iconOffset.x += scale * (glyph->advance >> 6);
|
||||
}
|
||||
|
||||
entry.insert(iconData.first, L" ");
|
||||
text->setText(entry);
|
||||
|
||||
Material *iconMat = new Material(root->getLibPath() + "gui");
|
||||
iconMat->addBoolUniform("texturingEnabled", true);
|
||||
string ip[]{iconBasePath + iconData.second};
|
||||
Texture *t = new Texture(ip, 1, false);
|
||||
iconMat->addTexUniform("textures[0]", t, false);
|
||||
|
||||
Vector2 iconSize = 20 * Vector2::VEC_IJ;
|
||||
Quad *rect = new Quad(Vector3(iconSize.x, iconSize.y, 0), false);
|
||||
rect->setMaterial(iconMat);
|
||||
Node *rectNode = new Node(iconOffset - Vector3(0, iconSize.y, 0));
|
||||
rectNode->attachMesh(rect);
|
||||
bgNode->attachChild(rectNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Tooltip::~Tooltip(){
|
||||
Node *node = background->getNode();
|
||||
Root::getSingleton()->getGuiNode()->dettachChild(node);
|
||||
delete node;
|
||||
}
|
||||
|
||||
void Tooltip::update(){
|
||||
|
||||
@@ -1,16 +1,36 @@
|
||||
#ifndef TOOLTIP_H
|
||||
#define TOOLTIP_H
|
||||
|
||||
#include <text.h>
|
||||
#include <vector.h>
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
|
||||
namespace vb01{
|
||||
class Quad;
|
||||
class Text;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Tooltip{
|
||||
public:
|
||||
Tooltip(vb01::Vector2, std::string);
|
||||
struct LineData{
|
||||
std::wstring entryText;
|
||||
vb01::Vector4 textColor;
|
||||
std::vector<std::pair<int, std::string>> iconsData;
|
||||
|
||||
LineData(std::wstring et, vb01::Vector4 tc, std::vector<std::pair<int, std::string>> id) : entryText(et), textColor(tc), iconsData(id){};
|
||||
};
|
||||
|
||||
Tooltip(vb01::Vector3, vb01::Vector2, std::vector<LineData>, std::string);
|
||||
~Tooltip();
|
||||
void update();
|
||||
inline vb01::Quad* getBackground(){return background;}
|
||||
private:
|
||||
vb01::Vector2 pos;
|
||||
vb01::Vector3 pos;
|
||||
vb01::Vector2 size;
|
||||
vb01::Quad *background = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user