Skip to content

Commit ae165af

Browse files
author
Nate Fries
committed
* Added readable/writeable window for items.
* Now always shows player and tiles immediately surrounding him.
1 parent 9d3e470 commit ae165af

10 files changed

+52
-3
lines changed

console.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,12 @@ void Console::dumpText()
578578
}
579579
fclose(f);
580580
}
581+
int Console::getHeight()
582+
{
583+
// TODO (nfries88): use this to adjust the starting height for paintConsole and getConsoleEntryAt;
584+
//
585+
int height = 0;
586+
for (std::vector<ConsoleEntry>::reverse_iterator it=m_content.rbegin(); it!=m_content.rend(); it++) {
587+
height += (*it).getHeight();
588+
}
589+
}

console.h

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class Console {
133133
ConsoleEntry* getConsoleEntryAt(float relx, float rely);
134134
void clearEntries();
135135
void dumpText();
136+
137+
int getHeight();
136138
private:
137139
std::vector <ConsoleEntry> m_content;
138140
std::string m_speakername;

gamecontent/item.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Item : public Thing, public ItemUI
4747
// items with 0x06 property?
4848
bool isAlwaysUsed() const { return m_it->alwaysUsed; }
4949

50+
bool isWriteable() const { return m_it->writeable; }
51+
5052
const ObjectType* getObjectType() const {return m_it;}
5153

5254
virtual uint32_t getOrder() const {return getAlwaysOnTopLevel();}

gm_gameworld.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ void pnlInventory_t::onClick_Options(glictPos* relmousepos, glictContainer* call
114114
/*gameclass->msgBox(gettext("This functionality is not yet finished"),"TODO");*/
115115
}
116116

117+
void winReadable_t::onClose(glictPos* pos, glictContainer* caller){
118+
// TODO
119+
winReadable_t* win = (winReadable_t*)caller->GetCustomData();
120+
GM_Gameworld* gameclass = (GM_Gameworld*)g_game;
121+
win->window.SetVisible(false);
122+
if(win->dispItem->isWriteable()){
123+
gameclass->m_protocol->sendTextWindow(win->windowID, win->txtText.GetCaption());
124+
}
125+
}
126+
117127
GM_Gameworld::GM_Gameworld() : pnlMap(&m_automap)
118128
{
119129
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Starting gameworld...\n");
@@ -247,6 +257,9 @@ GM_Gameworld::GM_Gameworld() : pnlMap(&m_automap)
247257
desktop.AddObject(&winMove.window);
248258
winMove.window.SetVisible(false);
249259

260+
desktop.AddObject(&winReadable.window);
261+
winReadable.window.SetVisible(false);
262+
250263
desktop.AddObject(&pnlConsoleContainer);
251264
//pnlConsoleContainer.SetBGActiveness(false);
252265

@@ -1613,6 +1626,15 @@ void GM_Gameworld::closeTradeWindow()
16131626
#endif
16141627
}
16151628

1629+
void GM_Gameworld::onOpenItemText(int windowId, int itemid, int maxTextLenght,
1630+
const std::string& text, const std::string& lastChange,
1631+
const std::string& lastChangeDate)
1632+
{
1633+
// rest of stuff; todo
1634+
winReadable.open(itemid, windowId, text, lastChange, lastChangeDate);
1635+
centerWindow(&winReadable.window);
1636+
}
1637+
16161638
void GM_Gameworld::onUpdatePlayerCash(uint32_t newcash) {
16171639
winShop.setCash(newcash);
16181640
}

gm_gameworld.h

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "ui/minimap.h"
3636
#include "ui/exitwarning.h"
3737
#include "ui/deathnotification.h"
38+
#include "ui/uireadable.h"
3839
#include "stackpanel.h"
3940
#include "automap.h"
4041
#include "statusmsg.h"
@@ -91,6 +92,9 @@ class GM_Gameworld : public GameModeOptions {
9192
void closeShopWindow();
9293
void openTradeWindow(bool ack);
9394
void closeTradeWindow();
95+
void onOpenItemText(int windowId, int itemid, int maxTextLenght,
96+
const std::string& text, const std::string& lastChange,
97+
const std::string& lastChangeDate);
9498
void openOutfitWindow(const Outfit_t& current, const std::list<AvailOutfit_t>& available);
9599
void onTileUpdate(const Position& pos);
96100
void openDeathWindow();
@@ -180,6 +184,7 @@ class GM_Gameworld : public GameModeOptions {
180184
std::vector<winContainer_t*> containers;
181185

182186
winItemMove_t winMove;
187+
winReadable_t winReadable;
183188

184189
exitWarning_t m_exitWarningWindow;
185190
deathNotice_t m_deathNotice;
@@ -235,6 +240,7 @@ class GM_Gameworld : public GameModeOptions {
235240
friend class winVIP_t;
236241
friend class winAddVIP_t;
237242
friend class winChangeVIP_t;
243+
friend class winReadable_t;
238244

239245
MapUI m_mapui;
240246

mapui.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,9 @@ void MapUI::renderMap()
525525
}
526526

527527
if(options.showlighteffects){
528-
if(lightmap[((pos.y * m_vpw) + pos.x)].alpha >= 100) fillLightCircle(pos.x, pos.y, 2, initColor);
528+
if((player != NULL) && !(player->getLightLevel())){
529+
fillLightCircle(m_vpw/2, m_vph/2, 2, initColor);
530+
}
529531
g_engine->drawLightmap(lightmap, options.showlighteffects, m_vpw, m_vph, m_scale);
530532
}
531533

net/protocolgame.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ bool ProtocolGame::parseSelfAppear(NetworkMessage& msg)
295295
GlobalVariables::clear();
296296
Inventory::getInstance().clear();
297297
Map::getInstance().clear();
298+
Creatures::getInstance().addCreature(ourID);
298299
//TODO. reset chats
299300

300301
GlobalVariables::setPlayerID(ourID);

objects.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ObjectType::ObjectType(uint16_t _id)
6363
useable = false;
6464
rune = false;
6565
readable = false;
66+
writeable = false;
6667
fluidContainer = false;
6768
splash = false;
6869
blockSolid = false;
@@ -362,6 +363,7 @@ bool Objects::load780plus(const char* filename)
362363
break;
363364
case 0x09: //Writtable/Readable Objectss
364365
oType->readable = true;
366+
oType->writeable = true;
365367
yatc_fread(&read_short2, sizeof(read_short2), 1, fp); //maximum size of text entry TODO (ivucica#3#) store this data
366368
ECORR16(read_short);
367369
break;

objects.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ObjectType
8989
bool useable;
9090
bool rune;
9191
bool readable;
92+
bool writeable;
9293
bool fluidContainer;
9394
bool splash;
9495
bool blockSolid;

sprite.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ void Sprite::loadSurfaceFromFile(const std::string& filename, int index) {
370370

371371
fgetc(f); // number of colors; ignore
372372
fgetc(f); // always 0
373-
yatc_fread(&read_short, sizeof(read_short), 1, f); // color planes, whatever those are
373+
uint16_t colorplanes;
374+
yatc_fread(&colorplanes, sizeof(colorplanes), 1, f); // color planes, whatever those are
375+
if(colorplanes == 0) colorplanes = 1;
374376

375377
uint16_t bbp;
376378
yatc_fread(&bbp, sizeof(bbp), 1, f); // bits per pixel
@@ -389,7 +391,7 @@ void Sprite::loadSurfaceFromFile(const std::string& filename, int index) {
389391
}
390392
yatc_fread(pixels, 1, size, f); // pixel data
391393

392-
m_image = SDL_CreateRGBSurfaceFrom(pixels, width, height, bbp, 1, rmask, gmask, bmask, amask);
394+
m_image = SDL_CreateRGBSurfaceFrom(pixels, width, height, bbp * colorplanes, 1, rmask, gmask, bmask, amask);
393395
delete [] pixels;
394396

395397
if(!m_image){ // out of memory or SDL failure

0 commit comments

Comments
 (0)