Cosmic
New member
- Joined
- Jun 21, 2005
- RedCents
- 30¢
Someone requested a plugin that let you edit macros from within EQ ala the Notes window. I think this will fit the bill.
Zipped versions of the source+xml and dll+xml are attached for those averse to cut-n-paste.
and the UI file:
Zipped versions of the source+xml and dll+xml are attached for those averse to cut-n-paste.
Rich (BB code):
// MQ2Notepad.cpp : Defines the entry point for the DLL application.
//
//
// MQ2Notepad by Cosmic
// First release 10/20/2005
//
// known bugs:
// 1: Lines limited to 999 characters
// 2: Filesize limited to 64k
// 3: Path limited to 299 characters
// 4: exceeding any of these causes things to go boom
// 5: couldn't make horizontal scrollbars work, so words wrap. its annoying.
//
//
// Usage: (Don't forget to put the MQUI_NotepadWindow.xml in your UI directory
// /notepad dir - display current working directory
// /notepad dir <directoryname> - set current working directory
// /notepad <filename> - open file for editing
//
#include "../MQ2Plugin.h"
PreSetup("MQ2Notepad");
void SaveFile();
#define CWS_PASSWORDCHAR 0x20000
#define CWS_WANTRETURN 0x40000
class CNotepadWnd : public CCustomWnd
{
public:
CNotepadWnd():CCustomWnd("NotepadWindow")
{
SaveButton = (CButtonWnd*)GetChildItem("NPWSave"); //Save Button
NoteBox = (CTextEntryWnd*)GetChildItem("NPWInput");
NoteBox->WindowStyle|=CWS_WANTRETURN;
SetWndNotification(CNotepadWnd);
}
~CNotepadWnd()
{
}
int WndNotification(CXWnd *pWnd, unsigned int Message, void *unknown)
{
//Save Button
if (pWnd==(CXWnd*)SaveButton)
{
if (Message==XWM_LCLICK)
{
SaveFile();
}
else
DebugSpew("SaveButton message %Xh / %d",Message,Message);
}
return CSidlScreenWnd::WndNotification(pWnd,Message,unknown);
};
CButtonWnd *SaveButton;
CTextEntryWnd *NoteBox;
};
CNotepadWnd *MyWnd = 0;
char Directory[1000]={0};
char FileName[1000]={0};
void ReadWindowINI(PCSIDLWND pWindow)
{
CHAR Buffer[MAX_STRING] = {0};
pWindow->Location.top = GetPrivateProfileInt("Settings","ChatTop", 357,INIFileName);
pWindow->Location.bottom = GetPrivateProfileInt("Settings","ChatBottom", 620,INIFileName);
pWindow->Location.left = GetPrivateProfileInt("Settings","ChatLeft", 164,INIFileName);
pWindow->Location.right = GetPrivateProfileInt("Settings","ChatRight", 375,INIFileName);
pWindow->Locked = GetPrivateProfileInt("Settings","Locked", 0,INIFileName);
pWindow->Fades = GetPrivateProfileInt("Settings","Fades", 1,INIFileName);
pWindow->TimeMouseOver = GetPrivateProfileInt("Settings","Delay", 2000,INIFileName);
pWindow->FadeDuration = GetPrivateProfileInt("Settings","Duration", 500,INIFileName);
pWindow->Alpha = GetPrivateProfileInt("Settings","Alpha", 255,INIFileName);
pWindow->FadeToAlpha = GetPrivateProfileInt("Settings","FadeToAlpha", 255,INIFileName);
pWindow->BGType = GetPrivateProfileInt("Settings","BGType", 1,INIFileName);
pWindow->BGColor.R = GetPrivateProfileInt("Settings","BGTint.red", 255,INIFileName);
pWindow->BGColor.G = GetPrivateProfileInt("Settings","BGTint.green", 255,INIFileName);
pWindow->BGColor.B = GetPrivateProfileInt("Settings","BGTint.blue", 255,INIFileName);
GetPrivateProfileString("Settings","Directory","c:",Directory,999,INIFileName);
}
void WriteWindowINI(PCSIDLWND pWindow)
{
CHAR szTemp[MAX_STRING] = {0};
if (pWindow->Minimized)
{
WritePrivateProfileString("Settings","ChatTop", itoa(pWindow->OldLocation.top, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","ChatBottom", itoa(pWindow->OldLocation.bottom, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","ChatLeft", itoa(pWindow->OldLocation.left, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","ChatRight", itoa(pWindow->OldLocation.right, szTemp,10),INIFileName);
}
else
{
WritePrivateProfileString("Settings","ChatTop", itoa(pWindow->Location.top, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","ChatBottom", itoa(pWindow->Location.bottom, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","ChatLeft", itoa(pWindow->Location.left, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","ChatRight", itoa(pWindow->Location.right, szTemp,10),INIFileName);
}
WritePrivateProfileString("Settings","Locked", itoa(pWindow->Locked, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","Fades", itoa(pWindow->Fades, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","Delay", itoa(pWindow->MouseOver, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","Duration", itoa(pWindow->FadeDuration, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","Alpha", itoa(pWindow->Alpha, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","FadeToAlpha", itoa(pWindow->FadeToAlpha, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","BGType", itoa(pWindow->BGType, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","BGTint.red", itoa(pWindow->BGColor.R, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","BGTint.green", itoa(pWindow->BGColor.G, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","BGTint.blue", itoa(pWindow->BGColor.B, szTemp,10),INIFileName);
WritePrivateProfileString("Settings","Directory",Directory,INIFileName);
}
void StartEditor()
{
// Destroy old window
if (MyWnd)
{
delete MyWnd;
MyWnd=0;
}
char s[300]={0};
char filename[300];
sprintf(filename,"%s\\%s",Directory,FileName);
FILE *f;
f=fopen(filename,"r");
if (f==NULL)
{
sprintf(s,"Notepad: File not found (%s)",filename);
WriteChatColor(s,CONCOLOR_RED);
return;
}
//Build Window
DebugTry(CScreenPieceTemplate *templ=pSidlMgr->FindScreenPieceTemplate("NotepadWindow"));
if (templ)
MyWnd = new CNotepadWnd;
else
return; //God forbid
ReadWindowINI((PCSIDLWND) MyWnd);
sprintf(s,"Notepad - '%s'",FileName);
SetCXStr(&(((PCSIDLWND)MyWnd)->WindowText),s);
//Load File
char buff[64000]={0};
char line[1000]={0};
while (!feof(f))
{
if (fgets(line,999,f)!=NULL)
strcat(buff,line);
}
fclose(f);
// strip tabs
for (unsigned int i=0;i<strlen(buff);i++) if (buff=='\t') buff=' ';
SetCXStr(&(PCXSTR)MyWnd->NoteBox->InputText,buff);
}
void SaveFile()
{
char filename[300];
sprintf(filename,"%s\\%s",Directory,FileName);
char buff[64000]={0};
GetCXStr((PCXSTR)MyWnd->NoteBox->InputText,buff,63999);
FILE *f;
f=fopen(filename,"w");
if (f==NULL)
{
char s[300]={0};
sprintf(s,"Notepad: Write Error (%s)",filename);
WriteChatColor(s,CONCOLOR_RED);
return;
}
fputs(buff,f);
fclose(f);
}
void Usage(void)
{
char str[MAX_STRING] = {0};
WriteChatColor("Sytax: /notepad <filename> - edit a file",USERCOLOR_DEFAULT);
WriteChatColor("Sytax: /notepad dir <directory name> - set the directory",USERCOLOR_DEFAULT);
}
void Notepad(PSPAWNINFO pChar, PCHAR szLine)
{
char Arg1[MAX_STRING] = {0};
char Arg2[MAX_STRING] = {0};
GetArg(Arg1,szLine,1);
GetArg(Arg2,szLine,2);
if (stricmp(Arg1,"dir")==0)
{
if (strlen(Arg2)>0)
{
strcpy(Directory,Arg2);
WritePrivateProfileString("Settings","Directory",Directory,INIFileName);
}
else
{
char s[300]={0};
GetPrivateProfileString("Settings","Directory","c:",Directory,999,INIFileName);
sprintf(s,"Notepad: Current Directory '%s'",Directory);
WriteChatColor(s,USERCOLOR_DEFAULT);
}
return;
}
if (strlen(Arg1)>0)
{
GetPrivateProfileString("Settings","Directory","c:",Directory,999,INIFileName);
sprintf(FileName,"%s",Arg1);
StartEditor();
}
else
Usage();
}
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
DebugSpewAlways("Initializing MQ2Notepad");
// Add commands, MQ2Data items, hooks, etc.
AddCommand("/notepad",Notepad);
AddXMLFile("MQUI_NotepadWindow.xml");
// bmMyBenchmark=AddMQ2Benchmark("My Benchmark Name");
}
// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
DebugSpewAlways("Shutting down MQ2Notepad");
if (MyWnd)
{
WriteWindowINI((PCSIDLWND)MyWnd);
delete MyWnd;
MyWnd=0;
}
// Remove commands, MQ2Data items, hooks, etc.
// RemoveMQ2Benchmark(bmMyBenchmark);
RemoveCommand("/notepad");
RemoveXMLFile("MQUI_NotepadWindow.xml");
}
// Called once directly before shutdown of the new ui system, and also
// every time the game calls CDisplay::CleanGameUI()
PLUGIN_API VOID OnCleanUI(VOID)
{
DebugSpewAlways("MQ2Notepad::OnCleanUI()");
// destroy custom windows, etc
if (MyWnd)
{
WriteWindowINI((PCSIDLWND)MyWnd);
delete MyWnd;
MyWnd=0;
}
}
and the UI file:
Rich (BB code):
<?xml version = "1.0"?>
<XML ID = "EQInterfaceDefinitionLanguage">
<Schema xmlns = "EverQuestData" xmlns:dt = "EverQuestDataTypes"/>
<Editbox item = "NPWInput">
<ScreenID>NPWInput</ScreenID>
<DrawTemplate>WDT_Inner</DrawTemplate>
<Style_Transparent>false</Style_Transparent>
<Style_VScroll>true</Style_VScroll>
<RelativePosition>true</RelativePosition>
<AutoStretch>true</AutoStretch>
<LeftAnchorOffset>2</LeftAnchorOffset>
<TopAnchorOffset>2</TopAnchorOffset>
<RightAnchorOffset>2</RightAnchorOffset>
<BottomAnchorOffset>30</BottomAnchorOffset>
<TopAnchorToTop>true</TopAnchorToTop>
<RightAnchorToLeft>false</RightAnchorToLeft>
<BottomAnchorToTop>false</BottomAnchorToTop>
<TextColor>
<R>255</R>
<G>255</G>
<B>255</B>
</TextColor>
<Style_Border>true</Style_Border>
<Style_Multiline>true</Style_Multiline>
</Editbox>
<Button item = "NPWSave">
<ScreenID>NPWSave</ScreenID>
<!--<Font>3</Font>-->
<RelativePosition>true</RelativePosition>
<AutoStretch>true</AutoStretch>
<LeftAnchorOffset>68</LeftAnchorOffset>
<TopAnchorOffset>26</TopAnchorOffset>
<RightAnchorOffset>4</RightAnchorOffset>
<BottomAnchorOffset>2</BottomAnchorOffset>
<TopAnchorToTop>false</TopAnchorToTop>
<BottomAnchorToTop>false</BottomAnchorToTop>
<LeftAnchorToLeft>false</LeftAnchorToLeft>
<RightAnchorToLeft>false</RightAnchorToLeft>
<Style_Transparent>false</Style_Transparent>
<TooltipReference>Save this file</TooltipReference>
<Style_Checkbox>false</Style_Checkbox>
<Text>Save</Text>
<TextColor>
<R>255</R>
<G>255</G>
<B>255</B>
</TextColor>
<ButtonDrawTemplate>
<Normal>A_SmallBtnNormal</Normal>
<Pressed>A_SmallBtnPressed</Pressed>
<Flyby>A_SmallBtnFlyby</Flyby>
<Disabled>A_SmallBtnDisabled</Disabled>
<PressedFlyby>A_SmallBtnPressedFlyby</PressedFlyby>
</ButtonDrawTemplate>
</Button>
<Screen item = "NotepadWindow">
<RelativePosition>false</RelativePosition>
<Location>
<X>95</X>
<Y>280</Y>
</Location>
<Size>
<CX>421</CX>
<CY>200</CY>
</Size>
<Style_VScroll>false</Style_VScroll>
<Style_HScroll>false</Style_HScroll>
<Style_Transparent>false</Style_Transparent>
<DrawTemplate>WDT_Def2</DrawTemplate>
<Style_Titlebar>true</Style_Titlebar>
<Style_Closebox>true</Style_Closebox>
<Style_Minimizebox>true</Style_Minimizebox>
<Style_Border>true</Style_Border>
<Style_Sizable>true</Style_Sizable>
<Pieces>NPWInput</Pieces>
<Pieces>NPWSave</Pieces>
</Screen>
</XML>


