mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
runnable build
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
#include "abstractBitmapText.h"
|
||||
#include <IGUIFont.h>
|
||||
|
||||
using namespace irr::core;
|
||||
using namespace irr::video;
|
||||
using namespace irr::gui;
|
||||
using namespace game::core;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
AbstractBitmapText::AbstractBitmapText(stringw text, vector2d<s32> pos, IGUIFont *font) {
|
||||
this->text = text;
|
||||
this->pos = pos;
|
||||
this->font = font;
|
||||
color = new SColor(255, 255, 255, 255);
|
||||
}
|
||||
|
||||
AbstractBitmapText::~AbstractBitmapText() {}
|
||||
|
||||
void AbstractBitmapText::update() {
|
||||
font->draw(text, rect<s32>(pos.X, pos.Y, pos.X + 10, pos.Y + 10), *color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef ABSTRACT_BITMAP_TEXT
|
||||
#define ABSTRACT_BITMAP_TEXT
|
||||
|
||||
#include "gameManager.h"
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
class AbstractBitmapText {
|
||||
public:
|
||||
AbstractBitmapText(irr::core::stringw, irr::core::vector2d<s32>, irr::gui::IGUIFont*);
|
||||
~AbstractBitmapText();
|
||||
void update();
|
||||
inline irr::core::vector2d<s32> getPos(){return pos;}
|
||||
inline void setPos(irr::core::vector2d<s32> p){this->pos=p;}
|
||||
inline irr::video::SColor* getColor(){return color;}
|
||||
inline void setColor(irr::video::SColor *c){this->color=c;}
|
||||
inline irr::core::stringw getText(){return text;}
|
||||
inline void setText(irr::core::stringw t){this->text=t;}
|
||||
inline irr::gui::IGUIFont* getFont(){return font;}
|
||||
inline void setFont(irr::gui::IGUIFont *f){this->font=f;}
|
||||
private:
|
||||
core::GameManager *gameManager;
|
||||
irr::core::stringw text;
|
||||
irr::gui::IGUIFont *font;
|
||||
irr::core::vector2d<s32> pos;
|
||||
irr::video::SColor *color;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "abstractImage.h"
|
||||
|
||||
using namespace irr::video;
|
||||
using namespace irr::core;
|
||||
using namespace game::core;
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace gui{
|
||||
AbstractImage::AbstractImage(ITexture *image, vector2d<s32> pos, vector2d<s32> size) {
|
||||
this->image = image;
|
||||
this->pos = pos;
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
AbstractImage::~AbstractImage() {
|
||||
}
|
||||
|
||||
void AbstractImage::update() {
|
||||
irr::video::IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->draw2DImage(image, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef ABSTRACT_IMAGE
|
||||
#define ABSTRACT_IMAGE
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace gui{
|
||||
class AbstractImage {
|
||||
public:
|
||||
AbstractImage(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>);
|
||||
~AbstractImage();
|
||||
void update();
|
||||
inline irr::video::ITexture* getImage(){return image;}
|
||||
inline void setImage(irr::video::ITexture *t){this->image=t;}
|
||||
inline irr::core::vector2d<s32> getPos(){return pos;}
|
||||
inline irr::core::vector2d<s32> getSize(){return size;}
|
||||
inline void setPos(irr::core::vector2d<s32> p){this->pos=p;}
|
||||
inline void setSize(irr::core::vector2d<s32> s){this->size=s;}
|
||||
inline irr::core::stringw getPath(){return path;}
|
||||
private:
|
||||
irr::video::ITexture *image;
|
||||
irr::core::vector2d<s32> pos, size;
|
||||
irr::core::stringw path;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+3
-2
@@ -29,7 +29,7 @@ namespace game{
|
||||
class UnitButton : public vb01Gui::Button{
|
||||
public:
|
||||
UnitButton(ActiveGameState*, vb01::Vector2, vb01::Vector2, std::string, int, int);
|
||||
~UnitButton();
|
||||
~UnitButton(){}
|
||||
virtual void onClick();
|
||||
virtual void onMouseOver();
|
||||
virtual void onMouseAway();
|
||||
@@ -37,10 +37,11 @@ namespace game{
|
||||
ActiveGameState *activeState;
|
||||
int faction, unitId;
|
||||
};
|
||||
|
||||
class UnitActionButton : public vb01Gui::Button{
|
||||
public:
|
||||
UnitActionButton(content::unitData::UNIT_TYPE, vb01::Vector2, vb01::Vector2, std::string, std::string);
|
||||
~UnitActionButton();
|
||||
~UnitActionButton(){}
|
||||
virtual void onClick();
|
||||
virtual void onMouseOver();
|
||||
virtual void onMouseAway();
|
||||
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
#include "button.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
using namespace irr::core;
|
||||
using namespace irr::video;
|
||||
using namespace irr::gui;
|
||||
using namespace game::core;
|
||||
using namespace game::core;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
Button::Button() {}
|
||||
|
||||
Button::Button(vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) {
|
||||
color = new SColor(255, 200, 200, 200);
|
||||
this->name = name;
|
||||
this->pos = pos;
|
||||
this->size = size;
|
||||
this->separate = separate;
|
||||
}
|
||||
|
||||
Button::~Button() {
|
||||
delete color;
|
||||
color = nullptr;
|
||||
}
|
||||
|
||||
void Button::update() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
|
||||
|
||||
if (!imageButton) {
|
||||
driver->draw2DRectangle(*color, rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
|
||||
if (separate) {
|
||||
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp");
|
||||
font->draw(name, rect<s32>(pos.X + size.X / 4 + textXOffset, pos.Y + size.Y / 4 + textYOffset, size.X, size.Y), SColor(255, 250, 250, 250));
|
||||
}
|
||||
} else
|
||||
driver->draw2DImage(image->getImage(), pos);
|
||||
}
|
||||
|
||||
void Button::moveButton(int x, int y) {
|
||||
pos.X += x;
|
||||
pos.Y += y;
|
||||
moveText(x, y);
|
||||
}
|
||||
|
||||
void Button::moveText(int x, int y) {
|
||||
textXOffset += x;
|
||||
textYOffset += y;
|
||||
}
|
||||
|
||||
void Button::setImageButton(Image *i) {
|
||||
imageButton = true;
|
||||
image = i;
|
||||
image->setPos(pos);
|
||||
size = image->getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef BUTTON_H
|
||||
#define BUTTON_H
|
||||
|
||||
#include <irrlicht.h>
|
||||
#include <string>
|
||||
#include "abstractImage.h"
|
||||
#include "abstractBitmapText.h"
|
||||
#include "gameManager.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace game{
|
||||
namespace gui {
|
||||
class Button {
|
||||
public:
|
||||
Button();
|
||||
Button(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
|
||||
~Button();
|
||||
virtual void onClick(){}
|
||||
virtual void onMouseOver(){}
|
||||
virtual void onMouseAway(){}
|
||||
virtual void update();
|
||||
virtual void moveText(int, int);
|
||||
virtual void moveButton(int, int);
|
||||
inline void setMouseOverDone(bool m){this->mouseOverDone=m;}
|
||||
inline void setMouseAwayDone(bool m){this->mouseAwayDone=m;}
|
||||
void setImageButton(Image*);
|
||||
inline irr::core::vector2d<s32> getPos(){return pos;}
|
||||
inline irr::core::vector2d<s32> getSize(){return size;}
|
||||
inline void setPos(irr::core::vector2d<s32> p){this->pos=p;}
|
||||
inline void setSize(irr::core::vector2d<s32> s){this->size=s;}
|
||||
inline irr::video::SColor* getColor(){return color;}
|
||||
inline void setColor(irr::video::SColor *c){this->color=c;}
|
||||
inline irr::core::stringw getName(){return name;}
|
||||
inline void setName(irr::core::stringw n){this->name=n;}
|
||||
inline bool isSeparate(){return separate;}
|
||||
inline bool isImageButton(){return imageButton;}
|
||||
inline bool isMouseOverDone(){return mouseOverDone;}
|
||||
inline bool isMouseAwayDone(){return mouseAwayDone;}
|
||||
inline Image* getImage(){return image;}
|
||||
private:
|
||||
Image *image = nullptr;
|
||||
bool separate = true, imageButton = false;
|
||||
int textXOffset = 0, textYOffset = 0;
|
||||
protected:
|
||||
irr::core::stringw name;
|
||||
irr::core::vector2d<s32> pos, size;
|
||||
irr::video::SColor *color = nullptr;
|
||||
bool mouseOverDone=false,mouseAwayDone=false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
#include "checkbox.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
using namespace irr::core;
|
||||
using namespace irr::video;
|
||||
using namespace game::core;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
Checkbox::CheckboxButton::CheckboxButton(Checkbox *ch, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) :Button(pos, size, name, separate) {
|
||||
checkbox = ch;
|
||||
}
|
||||
|
||||
void Checkbox::CheckboxButton::onClick() {
|
||||
checkbox->check();
|
||||
}
|
||||
|
||||
Checkbox::Checkbox(vector2d<s32> pos){
|
||||
this->pos = pos;
|
||||
checkboxButton = new CheckboxButton(this, pos, vector2d<s32>(length,length), "CheckboxButton", false);
|
||||
}
|
||||
|
||||
Checkbox::~Checkbox() {
|
||||
|
||||
}
|
||||
|
||||
void Checkbox::update() {
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->draw2DRectangle(SColor(255, 100, 100, 100), rect<s32>(pos.X, pos.Y, pos.X + length, pos.Y + length), nullptr);
|
||||
if (checked) {
|
||||
driver->draw2DLine(pos, vector2d<s32>(pos.X + length, pos.Y + length),SColor(255,255,255,255));
|
||||
driver->draw2DLine(vector2d<s32>(pos.X,pos.Y+length), vector2d<s32>(pos.X + length, pos.Y), SColor(255, 255, 255, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef CHECKBOX_H
|
||||
#define CHECKBOX_H
|
||||
|
||||
#include "button.h"
|
||||
|
||||
namespace game{
|
||||
namespace gui {
|
||||
class Checkbox {
|
||||
public:
|
||||
Checkbox(irr::core::vector2d<s32>);
|
||||
~Checkbox();
|
||||
void update();
|
||||
virtual void check(){checked=!checked;}
|
||||
virtual bool isChecked(){return checked;}
|
||||
private:
|
||||
class CheckboxButton : public Button {
|
||||
public:
|
||||
CheckboxButton(Checkbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
|
||||
void onClick();
|
||||
private:
|
||||
Checkbox *checkbox = nullptr;
|
||||
};
|
||||
const int length=15;
|
||||
bool checked = false;
|
||||
irr::core::vector2d<s32> pos;
|
||||
CheckboxButton *checkboxButton;
|
||||
public:
|
||||
inline CheckboxButton* getCheckboxButton(){return checkboxButton;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -25,12 +25,6 @@ namespace game{
|
||||
class GameManager {
|
||||
public:
|
||||
static GameManager* getSingleton();
|
||||
inline void attachBitmapText(gui::AbstractBitmapText *a){bitmapTexts.push_back(a);}
|
||||
void detachBitmapText(gui::AbstractBitmapText*);
|
||||
void detachAllBitmapTexts();
|
||||
inline void attachImage(gui::AbstractImage *a){images.push_back(a);}
|
||||
void detachImage(gui::AbstractImage*);
|
||||
void detachAllImages();
|
||||
void update();
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
#include "listbox.h"
|
||||
#include "guiAppState.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace irr::core;
|
||||
using namespace irr::gui;
|
||||
using namespace irr::video;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
Listbox::ListboxButton::ListboxButton(Listbox *l, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void Listbox::ListboxButton::onClick() {
|
||||
if (!listbox->isOpen())
|
||||
listbox->openUp();
|
||||
else
|
||||
listbox->close();
|
||||
}
|
||||
|
||||
Listbox::ScrollingButton::ScrollingButton(vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void Listbox::ScrollingButton::onClick() {
|
||||
|
||||
}
|
||||
|
||||
Listbox::Listbox(vector2d<s32> pos, vector2d<s32> size, vector<stringw> lines, int maxDisplay, bool controlsListbox) {
|
||||
this->pos = pos;
|
||||
this->size = size;
|
||||
this->lines = lines;
|
||||
this->maxDisplay = maxDisplay;
|
||||
this->controlsListbox=controlsListbox;
|
||||
listboxButton = new ListboxButton(this, pos, size, "ListboxButton", false);
|
||||
scrollingButton = new ScrollingButton(vector2d<s32>(pos.X + size.X - 20, pos.Y + 20), vector2d<s32>(20, 20.0 * (maxDisplay - 2) / (lines.size() - maxDisplay)), "scrollingButton", false);
|
||||
}
|
||||
|
||||
Listbox::~Listbox() {}
|
||||
|
||||
void Listbox::update() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp");
|
||||
|
||||
if (open) {
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(*listboxButton->getColor(), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y * maxDisplay), nullptr);
|
||||
int mousePosX = gm->getDevice()->getCursorControl()->getPosition().X, mousePosY = gm->getDevice()->getCursorControl()->getPosition().Y;
|
||||
|
||||
for (int i = 0; i < maxDisplay; i++) {
|
||||
if (mousePosY > pos.Y + size.Y * i && mousePosY < pos.Y + size.Y * (i + 1)){
|
||||
selectedOption=scrollOffset+i;
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y + size.Y * i, pos.X + size.X - 20, pos.Y + size.Y * (i + 1)), nullptr);
|
||||
}
|
||||
else if (mousePosY < pos.Y){
|
||||
selectedOption=scrollOffset;
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y, pos.X + size.X - 20, pos.Y + size.Y), nullptr);
|
||||
}
|
||||
else if (mousePosY > pos.Y + size.Y * maxDisplay){
|
||||
selectedOption=scrollOffset+maxDisplay-1;
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y + size.Y * (maxDisplay - 1), pos.X + size.X - 20, pos.Y + size.Y * (maxDisplay + 0)), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxDisplay; i++)
|
||||
font->draw(lines[i + scrollOffset], rect<s32>(pos.X, pos.Y + size.Y*i, pos.X + size.X, pos.Y + size.Y * (i + 1)), SColor(255, 255, 255, 255));
|
||||
|
||||
if (scrollOffset > 0) {
|
||||
vector2d<s32> scrollingButtonPos = scrollingButton->getPos();
|
||||
scrollingButtonPos.Y = pos.Y + 20 + scrollingButton->getSize().Y * (scrollOffset - 1);
|
||||
scrollingButton->setPos(scrollingButtonPos);
|
||||
}
|
||||
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 150, 150, 150), rect<s32>(
|
||||
scrollingButton->getPos().X, scrollingButton->getPos().Y, scrollingButton->getPos().X + scrollingButton->getSize().X,
|
||||
scrollingButton->getPos().Y + scrollingButton->getSize().Y));
|
||||
} else {
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(*listboxButton->getColor(), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
|
||||
font->draw(lines[selectedOption], rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), SColor(255, 255, 255, 255));
|
||||
}
|
||||
}
|
||||
|
||||
void Listbox::openUp() {
|
||||
open = true;
|
||||
vector2d<s32> size = listboxButton->getSize();
|
||||
size.Y *= maxDisplay;
|
||||
listboxButton->setSize(size);
|
||||
}
|
||||
|
||||
void Listbox::close() {
|
||||
if(!controlsListbox){
|
||||
open = false;
|
||||
vector2d<s32> size = listboxButton->getSize();
|
||||
size.Y /= maxDisplay;
|
||||
listboxButton->setSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
void Listbox::scrollUp() {
|
||||
if (scrollOffset > 0)
|
||||
scrollOffset--;
|
||||
}
|
||||
|
||||
void Listbox::scrollDown() {
|
||||
if (scrollOffset < lines.size() - maxDisplay)
|
||||
scrollOffset++;
|
||||
}
|
||||
|
||||
void Listbox::appendLines(vector<stringw>& lines) {
|
||||
for (int i = 0; i < this->lines.size(); i++)
|
||||
lines.push_back(this->lines[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef LISTBOX_H
|
||||
#define LISTBOX_H
|
||||
|
||||
#include "button.h"
|
||||
|
||||
namespace game{
|
||||
namespace gui {
|
||||
class Listbox {
|
||||
public:
|
||||
Listbox(irr::core::vector2d<s32>, irr::core::vector2d<s32>, std::vector<irr::core::stringw>, int,bool=false);
|
||||
~Listbox();
|
||||
void update();
|
||||
void openUp();
|
||||
void close();
|
||||
void scrollUp();
|
||||
void scrollDown();
|
||||
inline void addLine(irr::core::stringw l){lines.push_back(l);}
|
||||
inline void changeLine(int i, irr::core::stringw l){lines[i]=l;}
|
||||
inline bool isOpen(){return open;}
|
||||
void appendLines(std::vector<irr::core::stringw>&);
|
||||
inline std::vector<irr::core::stringw> getContents(){return lines;}
|
||||
inline int getSelectedOption(){return selectedOption;}
|
||||
private:
|
||||
class ListboxButton : public Button {
|
||||
public:
|
||||
ListboxButton(Listbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
|
||||
void onClick();
|
||||
private:
|
||||
Listbox *listbox = nullptr;
|
||||
};
|
||||
class ScrollingButton : public Button {
|
||||
public:
|
||||
ScrollingButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
|
||||
void onClick();
|
||||
private:
|
||||
};
|
||||
int maxDisplay, scrollOffset = 0, selectedOption = 0;
|
||||
bool open = false,controlsListbox=false;
|
||||
std::vector<irr::core::stringw> lines;
|
||||
irr::core::vector2d<s32> pos, size;
|
||||
ListboxButton *listboxButton = nullptr;
|
||||
Button *scrollingButton = nullptr;
|
||||
public:
|
||||
inline ListboxButton* getListboxButton(){return listboxButton;}
|
||||
inline bool isControlsListbox(){return controlsListbox;}
|
||||
inline irr::core::stringw getLine(int i){return lines[i];}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -28,8 +28,10 @@ namespace game{
|
||||
}
|
||||
void OptionsButton::BackButton::onClick() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
gm->detachAllBitmapTexts();
|
||||
gm->detachAllImages();
|
||||
*/
|
||||
state->removeAllListboxes();
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllSliders();
|
||||
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#include "slider.h"
|
||||
#include "defConfigs.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace irr::core;
|
||||
using namespace irr::video;
|
||||
using namespace game::core;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
Slider::MovableSliderButton::MovableSliderButton(Slider *slider, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->slider = slider;
|
||||
}
|
||||
|
||||
void Slider::MovableSliderButton::onClick() {
|
||||
clicked = !clicked;
|
||||
}
|
||||
|
||||
void Slider::MovableSliderButton::update() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
int posX = gm->getDevice()->getCursorControl()->getPosition().X, posY = gm->getDevice()->getCursorControl()->getPosition().Y;
|
||||
|
||||
if (clicked && posY > slider->getPos().Y && posY < slider->getPos().Y + slider->getSize().Y) {
|
||||
if (posX < slider->getPos().X)
|
||||
posX = slider->getPos().X;
|
||||
else if (posX > slider->getPos().X + slider->getSize().X)
|
||||
posX = slider->getPos().X + slider->getSize().X;
|
||||
slider->setValue((((double) posX - slider->getPos().X) / slider->getSize().X) * slider->getMaxValue());
|
||||
}
|
||||
}
|
||||
|
||||
Slider::StaticSliderButton::StaticSliderButton(Slider *slider, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->slider = slider;
|
||||
}
|
||||
|
||||
void Slider::StaticSliderButton::onClick() {
|
||||
s16 buttonClickPoint = -slider->getPos().X + GameManager::getSingleton()->getDevice()->getCursorControl()->getPosition().X;
|
||||
slider->setValue(((double) buttonClickPoint / slider->getSize().X) * slider->getMaxValue());
|
||||
}
|
||||
|
||||
Slider::Slider(vector2d<s32> pos, vector2d<s32> size, double minValue, double maxValue) {
|
||||
this->pos = pos;
|
||||
this->size = size;
|
||||
this->minValue = minValue;
|
||||
this->maxValue = maxValue;
|
||||
staticSliderButton = new StaticSliderButton(this, pos, size, "StaticSliderButton", false);
|
||||
movableSliderButton = new MovableSliderButton(this, vector2d<s32>(pos.X + staticSliderButton->getSize().X / 1, pos.Y - 15), vector2d<s32>(10, 40), "MovableSliderButton", false);
|
||||
value = (maxValue - minValue) / 2;
|
||||
}
|
||||
|
||||
Slider::~Slider() {
|
||||
}
|
||||
|
||||
void Slider::update() {
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
|
||||
if (value < minValue)
|
||||
value = minValue;
|
||||
else if (value > maxValue)
|
||||
value = maxValue;
|
||||
movableSliderButton->update();
|
||||
driver->draw2DRectangle(*staticSliderButton->getColor(), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
|
||||
vector2d<s32> p = movableSliderButton->getPos(), s = movableSliderButton->getSize();
|
||||
p.X = pos.X + (double) size.X / maxValue * value;
|
||||
driver->draw2DRectangle(SColor(255, 200, 200, 200), rect<s32>(p.X, p.Y, p.X + s.X, p.Y + s.Y), nullptr);
|
||||
movableSliderButton->setPos(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef SLIDER_H
|
||||
#define SLIDER_H
|
||||
|
||||
#include<irrlicht.h>
|
||||
|
||||
#include "button.h"
|
||||
#include "textbox.h"
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
class Slider {
|
||||
public:
|
||||
Slider(irr::core::vector2d<s32>, irr::core::vector2d<s32>, double, double);
|
||||
~Slider();
|
||||
void update();
|
||||
inline void addTextbox(Textbox *t){this->textbox=t;}
|
||||
inline double getMinValue(){return minValue;}
|
||||
inline double getValue(){return value;}
|
||||
inline double getMaxValue(){return maxValue;}
|
||||
inline double getIncrement(){return increment;}
|
||||
inline void setValue(double v){this->value=v;}
|
||||
inline void setIncrement(double i){this->increment=i;}
|
||||
inline irr::core::vector2d<s32> getPos(){return pos;}
|
||||
inline irr::core::vector2d<s32> getSize(){return size;}
|
||||
inline Textbox* getTextbox(){return textbox;}
|
||||
private:
|
||||
class MovableSliderButton : public Button {
|
||||
public:
|
||||
MovableSliderButton(Slider*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
|
||||
void onClick();
|
||||
void update();
|
||||
private:
|
||||
Slider *slider;
|
||||
bool clicked = false;
|
||||
};
|
||||
class StaticSliderButton : public Button {
|
||||
public:
|
||||
StaticSliderButton(Slider*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
|
||||
void onClick();
|
||||
private:
|
||||
Slider *slider;
|
||||
};
|
||||
MovableSliderButton *movableSliderButton = nullptr;
|
||||
StaticSliderButton *staticSliderButton = nullptr;
|
||||
double minValue, value, maxValue, increment = .1;
|
||||
irr::core::vector2d<s32> pos, size;
|
||||
Textbox *textbox = nullptr;
|
||||
public:
|
||||
inline MovableSliderButton* getMovableSliderButton(){return movableSliderButton;}
|
||||
inline StaticSliderButton* getStaticSliderButton(){return staticSliderButton;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
#include "textbox.h"
|
||||
#include "defConfigs.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace irr::core;
|
||||
using namespace irr::video;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
Textbox::TextboxButton::TextboxButton(Textbox *t, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
|
||||
textbox = t;
|
||||
}
|
||||
|
||||
void Textbox::TextboxButton::onClick() {
|
||||
if (!textbox->isEnabled())
|
||||
textbox->enable();
|
||||
else
|
||||
textbox->disable();
|
||||
}
|
||||
|
||||
Textbox::Textbox(vector2d<s32> pos, vector2d<s32> size) {
|
||||
this->pos = pos;
|
||||
this->size = size;
|
||||
textboxButton = new TextboxButton(this, pos, size, "TextboxButton", false);
|
||||
font = GameManager::getSingleton()->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/bigfont.png");
|
||||
}
|
||||
|
||||
Textbox::~Textbox() {}
|
||||
|
||||
void Textbox::update() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 200, 200), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
|
||||
font->draw(entry, rect<s32>(pos.X, pos.Y - 8, pos.X + size.X, pos.Y - 8 + size.Y), SColor(255, 255, 255, 255));
|
||||
|
||||
if (enabled) {
|
||||
if (canChangeCursor()) {
|
||||
canShowCursor = !canShowCursor;
|
||||
lastBlinkTime = getTime();
|
||||
}
|
||||
if (canShowCursor)
|
||||
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 100, 100, 100), rect<s32>(pos.X + 20 * (entry.size() - cursorPosOffset), pos.Y, pos.X + 4 + 20 * (entry.size() - cursorPosOffset), pos.Y + size.Y), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void Textbox::type(wchar_t ch) {
|
||||
if (!capitalLeters)
|
||||
ch = tolower(ch);
|
||||
else
|
||||
ch = toupper(ch);
|
||||
std::vector<wchar_t> v;
|
||||
for (int i = 0; i < entry.size(); i++)
|
||||
v.push_back(entry[i]);
|
||||
v.insert(v.end() - cursorPosOffset, ch);
|
||||
entry += 0;
|
||||
for (int i = 0; i < v.size(); i++)
|
||||
entry[i] = v[i];
|
||||
}
|
||||
|
||||
void Textbox::moveCursor(bool left) {
|
||||
if (left && entry.size() - cursorPosOffset > 0)
|
||||
cursorPosOffset++;
|
||||
else if (!left && cursorPosOffset > 0)
|
||||
cursorPosOffset--;
|
||||
}
|
||||
|
||||
void Textbox::deleteCharacter() {
|
||||
if (cursorPosOffset != entry.size()) {
|
||||
std::vector<wchar_t> v;
|
||||
for (int i = 0; i < entry.size(); i++)
|
||||
v.push_back(entry[i]);
|
||||
v.erase(v.end() - 1 - cursorPosOffset);
|
||||
entry.erase(entry.size() - 1);
|
||||
for (int i = 0; i < v.size(); i++)
|
||||
entry[i] = v[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Textbox::enable() {
|
||||
enabled = true;
|
||||
lastBlinkTime = getTime();
|
||||
}
|
||||
|
||||
void Textbox::disable() {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef TEXTBOX_H
|
||||
#define TEXTBOX_H
|
||||
|
||||
#include <irrlicht.h>
|
||||
|
||||
#include "button.h"
|
||||
|
||||
namespace game{
|
||||
namespace gui {
|
||||
class Textbox {
|
||||
public:
|
||||
Textbox(irr::core::vector2d<s32>, irr::core::vector2d<s32>);
|
||||
~Textbox();
|
||||
void update();
|
||||
void enable();
|
||||
void disable();
|
||||
void type(wchar_t);
|
||||
void moveCursor(bool);
|
||||
void deleteCharacter();
|
||||
virtual irr::core::stringw getEntry(){return entry;}
|
||||
virtual void setEntry(irr::core::stringw e){this->entry=e;}
|
||||
virtual bool isEnabled(){return enabled;}
|
||||
virtual bool isCapitalLeters(){return capitalLeters;}
|
||||
virtual void setIsCapitalLeters(bool c){this->capitalLeters=c;}
|
||||
virtual void setFont(irr::gui::IGUIFont *f){this->font=f;}
|
||||
private:
|
||||
class TextboxButton : public Button {
|
||||
public:
|
||||
TextboxButton(Textbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
|
||||
void onClick();
|
||||
private:
|
||||
Textbox *textbox;
|
||||
};
|
||||
|
||||
irr::gui::IGUIFont *font;
|
||||
irr::core::vector2d<s32> pos, size;
|
||||
irr::core::stringw entry = "";
|
||||
virtual bool canChangeCursor(){return util::getTime() - lastBlinkTime > 250;}
|
||||
bool enabled, canShowCursor = false, capitalLeters = false;
|
||||
TextboxButton *textboxButton;
|
||||
s64 lastBlinkTime, cursorPosOffset = 0;
|
||||
public:
|
||||
inline TextboxButton* getTextboxButton(){return textboxButton;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -172,8 +172,8 @@ namespace game{
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void Unit::debug() {
|
||||
/*
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
driver->setMaterial(createLineMaterial());
|
||||
@@ -181,8 +181,8 @@ namespace game{
|
||||
driver->draw3DLine(pos, pos + dirVec * length, SColor(255, 0, 0, 255));
|
||||
driver->draw3DLine(pos, pos + leftVec * length, SColor(255, 255, 0, 0));
|
||||
driver->draw3DLine(pos, pos + upVec * length, SColor(255, 0, 255, 0));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void Unit::executeOrders() {
|
||||
if (orders.size() > 0) {
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace game{
|
||||
|
||||
void onClick() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
gm->detachAllBitmapTexts();
|
||||
//gm->detachAllBitmapTexts();
|
||||
state->removeButton("Back");
|
||||
// gameManager->dettachState(state);
|
||||
std::vector<string> difficulties, factions;
|
||||
@@ -77,7 +77,7 @@ namespace game{
|
||||
state->removeAllListboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
GameManager::getSingleton()->detachAllBitmapTexts();
|
||||
//GameManager::getSingleton()->detachAllBitmapTexts();
|
||||
makeTitlescreenButtons(state);
|
||||
state->removeButton("Play");
|
||||
state->removeButton("Back");
|
||||
|
||||
Reference in New Issue
Block a user