aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.cpp')
-rw-r--r--src/ui.cpp570
1 files changed, 144 insertions, 426 deletions
diff --git a/src/ui.cpp b/src/ui.cpp
index c9f91ab..731d18b 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1,12 +1,8 @@
#include <ui.hpp>
-/*
- * Create a macro to easily access SDL keypresses
-*/
-
-#define SDL_KEY e.key.keysym.sym
-
extern std::vector<menuItem> optionsMenu;
+extern Menu *currentMenu;
+extern Menu pauseMenu;
extern SDL_Window *window;
@@ -65,16 +61,9 @@ static unsigned char fontColor[4] = {255,255,255,255};
static std::vector<std::pair<std::string,vec3>> dialogOptText;
static std::string dialogBoxText;
-static vec3 merchArrowLoc[2];
+static std::vector<vec3> merchArrowLoc ( 2, vec3 { 0, 0, 0 } );
static bool typeOutDone = true;
-
-/*
- * Menu-related objects
- */
-
-extern Menu* currentMenu;
-extern Menu pauseMenu;
-
+static bool typeOutSustain = false;
static Mix_Chunk *dialogClick;
@@ -95,19 +84,7 @@ Mix_Chunk *battleStart;
Mix_Chunk *sanic;
static GLuint pageTex = 0;
-
-void Menu::gotoParent(){
- if(parent == NULL){
- currentMenu = NULL;
- config::update();
- }else{
- currentMenu = parent;
- }
-}
-
-void Menu::gotoChild(){
- currentMenu = child;
-}
+static bool pageTexReady = false;
void loadFontSize( unsigned int size, std::vector<GLuint> &tex, std::vector<FT_Info> &dat )
{
@@ -171,7 +148,7 @@ namespace ui {
*/
vec2 mouse;
- static vec2 premouse={0,0};
+ vec2 premouse={0,0};
/*
* Variety of keydown bools
@@ -209,6 +186,8 @@ namespace ui {
unsigned int fontSize;
+ void takeScreenshot(GLubyte* pixels);
+
/*
* Initialises the Freetype library, and sets a font size.
*/
@@ -264,13 +243,15 @@ namespace ui {
}
ftex = &ftex16;
ftdat = &ftdat16;
- } else if ( size == 24 ){
+ fontSize = 16;
+ } else if ( size == 24 ) {
if ( !ft24loaded ) {
loadFontSize( fontSize = size, ftex24, ftdat24 );
ft24loaded = true;
}
ftex = &ftex24;
ftdat = &ftdat24;
+ fontSize = 24;
}
}
@@ -410,6 +391,14 @@ namespace ui {
return width;
}
+ /**
+ * Prevents typeOut from typing the next string it's given.
+ */
+
+ void dontTypeOut( void ) {
+ typeOutSustain = true;
+ }
+
/*
* Draw a string in a typewriter-esque fashion. Each letter is rendered as calls are made
* to this function. Passing a different string to the function will reset the counters.
@@ -417,34 +406,30 @@ namespace ui {
std::string ret;
std::string typeOut( std::string str ) {
- static unsigned int sinc, // Acts as a delayer for the space between each character.
+ static unsigned int tadv = TICKS_PER_SEC / 12;
+ static unsigned int tickk,
linc=0, // Contains the number of letters that should be drawn.
size=0; // Contains the full size of the current string.
- /*
- * Reset values if a new string is being passed.
- */
-
- if(strncmp(ret.c_str(),str.c_str(),linc-1)){
- ret.clear(); // Zero the buffer
- size=str.size(); // Set the new target string size
- linc=0; // Reset the incrementers
- sinc=1;
- typeOutDone = false;
+ // reset values if a new string is being passed.
+ if ( !linc || ret.substr( 0, linc ) != str.substr( 0, linc ) ) {
+ tickk = tickCount + tadv;
+ ret = str.substr( 0, 1 );
+ size = str.size(); // Set the new target string size
+ linc = 1; // Reset the incrementers
+ if ( (typeOutDone = typeOutSustain) )
+ typeOutSustain = false;
}
- /*
- * Draw the next letter if necessary.
- */
-
- if(typeOutDone)
+ if ( typeOutDone )
return str;
- else if(++sinc==2){
- sinc=0;
- ret.append(str, linc, 1);
+ // Draw the next letter if necessary.
+ else if ( tickk <= tickCount ) {
+ tickk = tickCount + tadv;
+ ret += str[linc];
- if(linc<size)
+ if ( linc < size )
linc++;
else
typeOutDone = true;
@@ -519,15 +504,11 @@ namespace ui {
ret.clear();
}
-
void merchantBox(const char *name,Trade trade,const char *opt,bool passive,const char *text,...){
va_list dialogArgs;
std::unique_ptr<char[]> printfbuf (new char[512]);
dialogPassive = passive;
-
- std::cout << "Market Trading: " << trade.quantity[0] << " " << trade.item[0] << " for " << trade.quantity[1] << " " << trade.item[1] << std::endl;
-
merchTrade = trade;
// clear the buffer
@@ -575,24 +556,21 @@ namespace ui {
* Wait for a dialog box to be dismissed.
*/
- void waitForDialog(void){
- do{
- //std::thread(dialogAdvance);
- //mainLoop();
- }while(dialogBoxExists);
+ void waitForDialog ( void ) {
+ while ( dialogBoxExists );
}
- void waitForCover(void){
- do{
+
+ void waitForCover ( void ) {
+ while ( fadeIntensity < 255 )
mainLoop();
- }while(fadeIntensity < 255);
fadeIntensity = 255;
}
- void waitForNothing(unsigned int ms){
+
+ void waitForNothing ( unsigned int ms ) {
unsigned int target = millis() + ms;
- do{
- mainLoop();
- }while(millis() < target);
+ while ( millis() < target );
}
+
void importantText(const char *text,...){
va_list textArgs;
char *printfbuf;
@@ -632,11 +610,7 @@ namespace ui {
void drawPage( std::string path ) {
pageTex = Texture::loadTexture( path );
- std::cout<<"page set\n";
- }
-
- bool pageExists( void ) {
- return pageTex;
+ pageTexReady = true;
}
void draw(void){
@@ -644,11 +618,8 @@ namespace ui {
float x,y,tmp;
std::string rtext;
- if ( pageTex ) {
-
- std::cout<<"page draw\n";
-
- glEnable( GL_TEXTURE_2D);
+ if ( pageTexReady ) {
+ glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, pageTex );
glBegin( GL_QUADS );
glTexCoord2i( 0, 0 ); glVertex2i( offset.x - 300, SCREEN_HEIGHT - 100 );
@@ -656,9 +627,9 @@ namespace ui {
glTexCoord2i( 1, 1 ); glVertex2i( offset.x + 300, SCREEN_HEIGHT - 600 );
glTexCoord2i( 0, 1 ); glVertex2i( offset.x - 300, SCREEN_HEIGHT - 600 );
glEnd();
- glDisable( GL_TEXTURE_2D);
+ glDisable( GL_TEXTURE_2D );
- } else if (dialogBoxExists){
+ } else if (dialogBoxExists) {
rtext=typeOut(dialogBoxText);
@@ -677,10 +648,11 @@ namespace ui {
putStringCentered(offset.x,offset.y,rtext.c_str());
setFontSize(16);
}
- }else if(dialogMerchant){
+ }else if ( dialogMerchant ) {
x=offset.x-SCREEN_WIDTH/6;
y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
+ // draw the box border
glColor3ub(255,255,255);
glBegin(GL_LINE_STRIP);
glVertex2f(x-1 ,y+1);
@@ -690,6 +662,7 @@ namespace ui {
glVertex2f(x - 1,y+1);
glEnd();
+ // draw the box
glColor3ub(0,0,0);
glRectf(x,y,x+SCREEN_WIDTH/3,y-SCREEN_HEIGHT*.6);
@@ -757,12 +730,12 @@ namespace ui {
setFontColor(255, 255, 255);
// draw option
+ dialogOptText[i].second.y = y - SCREEN_HEIGHT / 2 - (fontSize + HLINE) * (i + 1);
tmp = putStringCentered(offset.x, dialogOptText[i].second.y, dialogOptText[i].first);
// get coordinate information on option
dialogOptText[i].second.z = offset.x + tmp;
dialogOptText[i].second.x = offset.x - tmp;
- dialogOptText[i].second.y = y - SCREEN_HEIGHT / 2 - (fontSize + HLINE) * (i + 1);
// make text yellow if the mouse hovers over the text
if(mouse.x > dialogOptText[i].second.x && mouse.x < dialogOptText[i].second.z &&
@@ -792,7 +765,7 @@ namespace ui {
glColor3ub(0,0,0);
glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
- rtext=typeOut(dialogBoxText);
+ rtext = typeOut(dialogBoxText);
putString(x+HLINE,y-fontSize-HLINE,rtext);
@@ -813,8 +786,11 @@ namespace ui {
setFontColor(255,255,255);
}
- if ( rtext != dialogBoxText )
- Mix_PlayChannel(1,dialogClick,0);
+ static unsigned int rtext_oldsize = 0;
+ if ( rtext_oldsize != rtext.size() ) {
+ if ( !isspace( rtext[(rtext_oldsize = rtext.size()) - 1] ) )
+ Mix_PlayChannel( 1, dialogClick, 0 );
+ }
}if(!fadeIntensity){
vec2 hub = {
@@ -877,331 +853,6 @@ namespace ui {
config::save();
}
- menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f){
- menuItem temp;
- temp.member = 0;
-
- temp.button.loc = l;
- temp.button.dim = d;
- temp.button.color = c;
-
- temp.button.text = t;
-
- temp.button.func = f;
-
- return temp;
- }
-
- menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t){
- menuItem temp;
- temp.member = -1;
-
- temp.button.loc = l;
- temp.button.dim = d;
- temp.button.color = c;
-
- temp.button.text = t;
-
- temp.button.func = NULL;
-
- return temp;
- }
-
- menuItem createParentButton(vec2 l, dim2 d, Color c, const char* t){
- menuItem temp;
- temp.member = -2;
-
- temp.button.loc = l;
- temp.button.dim = d;
- temp.button.color = c;
-
- temp.button.text = t;
-
- temp.button.func = NULL;
-
- return temp;
- }
-
- menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v){
- menuItem temp;
- temp.member = 1;
-
- temp.slider.loc = l;
- temp.slider.dim = d;
- temp.slider.color = c;
- temp.slider.minValue = min;
- temp.slider.maxValue = max;
-
- temp.slider.text = t;
-
- temp.slider.var = v;
-
- temp.slider.sliderLoc = *v;
-
- return temp;
- }
-
- /*
- * Draws the menu
- */
-
- void drawMenu(Menu *menu){
- setFontSize(24);
- config::update();
- SDL_Event e;
-
- mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
- mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y;
-
- //custom event polling for menu's so all other events are disregarded
- while(SDL_PollEvent(&e)){
- switch(e.type){
- case SDL_QUIT:
- gameRunning = false;
- return;
- break;
- case SDL_MOUSEMOTION:
- premouse.x=e.motion.x;
- premouse.y=e.motion.y;
- break;
- case SDL_KEYUP:
- if(SDL_KEY == SDLK_ESCAPE){
- menu->gotoParent();
- return;
- }
- break;
- default:break;
- }
- }
-
- //draw the dark transparent background
- glColor4f(0.0f, 0.0f, 0.0f, .8f);
- glRectf(offset.x-SCREEN_WIDTH/2,0,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT);
-
- //loop through all elements of the menu
- for(auto &m : menu->items){
- //if the menu is any type of button
- if(m.member == 0 || m.member == -1 || m.member == -2){
-
- //draw the button background
- glColor3f(m.button.color.red,m.button.color.green,m.button.color.blue);
- glRectf(offset.x+m.button.loc.x,
- offset.y+m.button.loc.y,
- offset.x+m.button.loc.x + m.button.dim.x,
- offset.y+m.button.loc.y + m.button.dim.y);
- //draw the button text
- putStringCentered(offset.x + m.button.loc.x + (m.button.dim.x/2),
- (offset.y + m.button.loc.y + (m.button.dim.y/2)) - ui::fontSize/2,
- m.button.text);
-
- //tests if the mouse is over the button
- if(mouse.x >= offset.x+m.button.loc.x && mouse.x <= offset.x+m.button.loc.x + m.button.dim.x){
- if(mouse.y >= offset.y+m.button.loc.y && mouse.y <= offset.y+m.button.loc.y + m.button.dim.y){
-
- //if the mouse if over the button, it draws this white outline
- glColor3f(1.0f,1.0f,1.0f);
- glBegin(GL_LINE_STRIP);
- glVertex2f(offset.x+m.button.loc.x, offset.y+m.button.loc.y);
- glVertex2f(offset.x+m.button.loc.x+m.button.dim.x, offset.y+m.button.loc.y);
- glVertex2f(offset.x+m.button.loc.x+m.button.dim.x, offset.y+m.button.loc.y+m.button.dim.y);
- glVertex2f(offset.x+m.button.loc.x, offset.y+m.button.loc.y+m.button.dim.y);
- glVertex2f(offset.x+m.button.loc.x, offset.y+m.button.loc.y);
- glEnd();
-
- //if the mouse is over the button and clicks
- if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){
- switch(m.member){
- case 0: //normal button
- m.button.func();
- break;
- case -1:
- menu->gotoChild(); //goto child menu
- break;
- case -2:
- menu->gotoParent(); //goto parent menu
- default:break;
- }
- }
- }
- }
-
- //if element is a slider
- }else if(m.member == 1){
- //combining slider text with variable amount
- char outSV[32];
- sprintf(outSV, "%s: %.1f",m.slider.text, *m.slider.var);
-
- float sliderW, sliderH;
-
- if(m.slider.dim.y > m.slider.dim.x){
- //width of the slider handle
- sliderW = m.slider.dim.x;
- sliderH = m.slider.dim.y * .05;
- //location of the slider handle
- m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.y-sliderW);
- }else{
- //width of the slider handle
- sliderW = m.slider.dim.x * .05;
- sliderH = m.slider.dim.y;
- //location of the slider handle
- m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.x-sliderW);
- }
- //draw the background of the slider
- glColor4f(m.slider.color.red,m.slider.color.green,m.slider.color.blue, .5f);
- glRectf(offset.x+m.slider.loc.x,
- offset.y+m.slider.loc.y,
- offset.x+m.slider.loc.x + m.slider.dim.x,
- offset.y+m.slider.loc.y + m.slider.dim.y);
-
- //draw the slider handle
- glColor4f(m.slider.color.red,m.slider.color.green,m.slider.color.blue, 1.0f);
- if(m.slider.dim.y > m.slider.dim.x){
- glRectf(offset.x+m.slider.loc.x,
- offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05),
- offset.x+m.slider.loc.x + sliderW,
- offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
-
- //draw the now combined slider text
- putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y*1.05)) - ui::fontSize/2, outSV);
- }else{
- glRectf(offset.x+m.slider.loc.x+m.slider.sliderLoc,
- offset.y+m.slider.loc.y,
- offset.x+m.slider.loc.x + m.slider.sliderLoc + sliderW,
- offset.y+m.slider.loc.y + sliderH);
-
- //draw the now combined slider text
- putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y/2)) - ui::fontSize/2, outSV);
- }
- //test if mouse is inside of the slider's borders
- if(mouse.x >= offset.x+m.slider.loc.x && mouse.x <= offset.x+m.slider.loc.x + m.slider.dim.x){
- if(mouse.y >= offset.y+m.slider.loc.y && mouse.y <= offset.y+m.slider.loc.y + m.slider.dim.y){
-
- //if it is we draw a white border around it
- glColor3f(1.0f,1.0f,1.0f);
- glBegin(GL_LINE_STRIP);
- glVertex2f(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y);
- glVertex2f(offset.x+m.slider.loc.x+m.slider.dim.x, offset.y+m.slider.loc.y);
- glVertex2f(offset.x+m.slider.loc.x+m.slider.dim.x, offset.y+m.slider.loc.y+m.slider.dim.y);
- glVertex2f(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y+m.slider.dim.y);
- glVertex2f(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y);
-
- if(m.slider.dim.y > m.slider.dim.x){
- //and a border around the slider handle
- glVertex2f(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05));
- glVertex2f(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05));
- glVertex2f(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
- glVertex2f(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
- glVertex2f(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05));
- }else{
- //and a border around the slider handle
- glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
- glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y);
- glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y+m.slider.dim.y);
- glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y+m.slider.dim.y);
- glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
- }
-
- glEnd();
-
- //if we are inside the slider and click it will set the slider to that point
- if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){
- //change handle location
- if(m.slider.dim.y > m.slider.dim.x){
- *m.slider.var = (((mouse.y-offset.y) - m.slider.loc.y)/m.slider.dim.y)*100;
- //draw a white box over the handle
- glColor3f(1.0f,1.0f,1.0f);
- glRectf(offset.x+m.slider.loc.x,
- offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05),
- offset.x+m.slider.loc.x + sliderW,
- offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
-
- }else{
- *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
- //draw a white box over the handle
- glColor3f(1.0f,1.0f,1.0f);
- glRectf(offset.x+m.slider.loc.x + m.slider.sliderLoc,
- offset.y+m.slider.loc.y,
- offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW),
- offset.y+m.slider.loc.y + m.slider.dim.y);
- }
- }
-
- //makes sure handle can't go below or above min and max values
- if(*m.slider.var >= m.slider.maxValue)*m.slider.var = m.slider.maxValue;
- else if(*m.slider.var <= m.slider.minValue)*m.slider.var = m.slider.minValue;
- }
- }
- }
- }
- setFontSize(16);
- }
-
- void takeScreenshot(GLubyte* pixels){
- std::vector<GLubyte> bgr (SCREEN_WIDTH * SCREEN_HEIGHT * 3, 0);
-
- for(uint x = 0; x < SCREEN_WIDTH*SCREEN_HEIGHT*3; x+=3){
- bgr[x] = pixels[x+2];
- bgr[x+1] = pixels[x+1];
- bgr[x+2] = pixels[x];
- }
-
- time_t epoch = time(NULL);
- struct tm* timen = localtime(&epoch);
-
- std::string name = "screenshots/";
- name += std::to_string(1900 + timen->tm_year) += "-";
- name += std::to_string(timen->tm_mon + 1) += "-";
- name += std::to_string(timen->tm_mday) += "_";
- name += std::to_string(timen->tm_hour) += "-";
- name += std::to_string(timen->tm_min) += "-";
- name += std::to_string(timen->tm_sec);
- name += ".bmp";
- FILE* bmp = fopen(name.c_str(), "w+");
-
- // unsigned long header_size = sizeof(BITMAPFILEHEADER) +
- // sizeof(BITMAPINFOHEADER);
-
- BITMAPFILEHEADER bmfh;
- BITMAPINFOHEADER bmih;
-
- memset(&bmfh, 0, sizeof(BITMAPFILEHEADER));
- memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
-
- bmfh.bfType = 0x4d42;
-
- bmfh.bfOffBits = 54;
- bmfh.bfSize = sizeof(BITMAPFILEHEADER) +
- sizeof(BITMAPINFOHEADER);
- bmfh.bfReserved1 = 0;
- bmfh.bfReserved2 = 0;
-
-
- bmih.biSize = sizeof(BITMAPINFOHEADER);
- bmih.biBitCount = 24;
-
- bmih.biClrImportant = 0;
- bmih.biClrUsed = 0;
-
- bmih.biCompression = 0;
-
- bmih.biWidth = SCREEN_WIDTH;
- bmih.biHeight = SCREEN_HEIGHT;
-
- bmih.biPlanes = 1;
- bmih.biSizeImage = 0;
-
- bmih.biXPelsPerMeter = 0x0ec4;
- bmih.biYPelsPerMeter = 0x0ec4;
-
- fwrite(&bmfh, 1,sizeof(BITMAPFILEHEADER),bmp);
- fwrite(&bmih, 1,sizeof(BITMAPINFOHEADER),bmp);
- fwrite(&bgr, 1,3*SCREEN_WIDTH*SCREEN_HEIGHT,bmp);
-
- delete[] pixels;
-
- fclose(bmp);
- }
-
void closeBox(){
dialogBoxExists = false;
dialogMerchant = false;
@@ -1211,16 +862,16 @@ namespace ui {
unsigned char i;
if ( pageTex ) {
- std::cout<<"rip page\n";
glDeleteTextures( 1, &pageTex );
pageTex = 0;
+ pageTexReady = false;
return;
}
- if(!typeOutDone){
+ /*if(!typeOutDone){
typeOutDone = true;
return;
- }
+ }*/
for(i=0;i<dialogOptText.size();i++){
if(mouse.x > dialogOptText[i].second.x &&
@@ -1231,10 +882,14 @@ namespace ui {
goto EXIT;
}
}
- if(dialogMerchant){
- for(i=0;i<2;i++){
+
+ if ( dialogMerchant ) {
+ for ( i = 0; i < merchArrowLoc.size(); i++ ) {
+
+ // TODO neaten this if statement
+
if(((merchArrowLoc[i].x < merchArrowLoc[i].z) ?
- (mouse.x > merchArrowLoc[i].x && mouse.x < merchArrowLoc[i].z) :
+ (mouse.x > merchArrowLoc[i].x && mouse.x < merchArrowLoc[i].z) :
(mouse.x < merchArrowLoc[i].x && mouse.x > merchArrowLoc[i].z) &&
mouse.y > merchArrowLoc[i].y - 8 && mouse.y < merchArrowLoc[i].y + 8)){
merchOptChosen = i + 1;
@@ -1288,14 +943,10 @@ EXIT:
break;
case SDL_MOUSEBUTTONUP:
-
- // right click advances dialog
- if ( ( e.button.button & SDL_BUTTON_RIGHT ) && (dialogBoxExists | pageTex) )
- dialogAdvance();
-
if ( ig ) {
ig->vel.x = (fr.x - mouse.x) / 50.0f;
ig->vel.y = (fr.y - mouse.y) / 50.0f;
+ //ig->forcedMove = true; // kills vel.x too quickly
ig = NULL;
}
break;
@@ -1303,6 +954,10 @@ EXIT:
// mouse clicks
case SDL_MOUSEBUTTONDOWN:
+ // right click advances dialog
+ if ( ( e.button.button & SDL_BUTTON_RIGHT ) && (dialogBoxExists | pageTexReady) )
+ dialogAdvance();
+
// left click uses item
if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists )
player->inv->usingi = true;
@@ -1405,8 +1060,8 @@ EXIT:
currentWorld = ((Arena *)currentWorld)->exitArena( player );
if ( tmp != currentWorld )
toggleBlackFast();
- } else if( (tmp = currentWorld->goInsideStructure( player )) != currentWorld )
- currentWorld = tmp;
+ } else if ( (tmp = currentWorld->goInsideStructure( player )) != currentWorld )
+ currentWorld = tmp;
break;
case SDLK_LSHIFT:
if(debug){
@@ -1454,7 +1109,7 @@ EXIT:
debug ^= true;
break;
case SDLK_z:
- weather = WorldWeather::Snowy;
+ weather = WorldWeather::Rain;
break;
case SDLK_i:
if ( isCurrentWorldIndoors() && Indoorp(currentWorld)->isFloorAbove( player ) ) {
@@ -1517,9 +1172,6 @@ EXIT:
static GLubyte* pixels;
pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
- //static std::thread scr;
- //scr = std::thread(takeScreenshot,pixels);
- //scr.detach();
takeScreenshot(pixels);
std::cout << "Took screenshot" << std::endl;
@@ -1543,7 +1195,7 @@ EXIT:
}
}
- // Flush preloaded AI functions if necessary
+ // Flush preloaded AI functions if necessary
if ( !dialogBoxExists && AIpreaddr.size() ) {
while ( !AIpreaddr.empty() ) {
AIpreaddr.front()->addAIFunc( AIpreload.front(), false );
@@ -1575,4 +1227,70 @@ EXIT:
Mix_PlayChannel( 1, battleStart, 0 );
}
+
+ void takeScreenshot(GLubyte* pixels){
+ std::vector<GLubyte> bgr (SCREEN_WIDTH * SCREEN_HEIGHT * 3, 0);
+
+ for(uint x = 0; x < SCREEN_WIDTH*SCREEN_HEIGHT*3; x+=3){
+ bgr[x] = pixels[x+2];
+ bgr[x+1] = pixels[x+1];
+ bgr[x+2] = pixels[x];
+ }
+
+ time_t epoch = time(NULL);
+ struct tm* timen = localtime(&epoch);
+
+ std::string name = "screenshots/";
+ name += std::to_string(1900 + timen->tm_year) += "-";
+ name += std::to_string(timen->tm_mon + 1) += "-";
+ name += std::to_string(timen->tm_mday) += "_";
+ name += std::to_string(timen->tm_hour) += "-";
+ name += std::to_string(timen->tm_min) += "-";
+ name += std::to_string(timen->tm_sec);
+ name += ".bmp";
+ FILE* bmp = fopen(name.c_str(), "w+");
+
+ // unsigned long header_size = sizeof(BITMAPFILEHEADER) +
+ // sizeof(BITMAPINFOHEADER);
+
+ BITMAPFILEHEADER bmfh;
+ BITMAPINFOHEADER bmih;
+
+ memset(&bmfh, 0, sizeof(BITMAPFILEHEADER));
+ memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
+
+ bmfh.bfType = 0x4d42;
+
+ bmfh.bfOffBits = 54;
+ bmfh.bfSize = sizeof(BITMAPFILEHEADER) +
+ sizeof(BITMAPINFOHEADER);
+ bmfh.bfReserved1 = 0;
+ bmfh.bfReserved2 = 0;
+
+
+ bmih.biSize = sizeof(BITMAPINFOHEADER);
+ bmih.biBitCount = 24;
+
+ bmih.biClrImportant = 0;
+ bmih.biClrUsed = 0;
+
+ bmih.biCompression = 0;
+
+ bmih.biWidth = SCREEN_WIDTH;
+ bmih.biHeight = SCREEN_HEIGHT;
+
+ bmih.biPlanes = 1;
+ bmih.biSizeImage = 0;
+
+ bmih.biXPelsPerMeter = 0x0ec4;
+ bmih.biYPelsPerMeter = 0x0ec4;
+
+ fwrite(&bmfh, 1,sizeof(BITMAPFILEHEADER),bmp);
+ fwrite(&bmih, 1,sizeof(BITMAPINFOHEADER),bmp);
+ fwrite(&bgr, 1,3*SCREEN_WIDTH*SCREEN_HEIGHT,bmp);
+
+ delete[] pixels;
+
+ fclose(bmp);
+ }
}