123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- #include "pch.h"
- //////////////////////////////////////////////////////////////////////////////
- //
- // Logon Popup
- //
- //////////////////////////////////////////////////////////////////////////////
- class LogonPopup :
- public IPopup,
- public EventTargetContainer<LogonPopup>,
- public TEvent<ZString>::Sink
- {
- private:
- TRef<Pane> m_ppane;
- TRef<ButtonPane> m_pbuttonLogon;
- TRef<ButtonPane> m_pbuttonAbort;
- TRef<ButtonPane> m_pbuttonSignUp;
- TRef<ButtonPane> m_pbuttonCDKey;
- TRef<ButtonPane> m_pbuttonSavePassword;
- TRef<EditPane> m_peditName;
- TRef<EditPane> m_peditPassword;
- TRef<Pane> m_ppanePassword;
- TRef<LogonSite> m_psite;
- TRef<IKeyboardInput> m_pfocus;
- LogonType m_lt;
- public:
- LogonPopup(Modeler* pmodeler, LogonSite* psite, LogonType lt,
- LPCSTR szPrompt, LPCSTR szName, LPCSTR szPW, BOOL fRememberPW) :
- m_psite(psite),
- m_lt(lt)
- {
- enum LogonNameType { lntCallsign, lntZone, lntPassport } logonNameType;
- if (lt == LogonLAN)
- logonNameType = lntCallsign;
- else if (trekClient.GetCfgInfo().bUsePassport)
- logonNameType = lntPassport;
- else
- logonNameType = lntZone;
- TRef<INameSpace> pnsLogonData = pmodeler->CreateNameSpace("logondata", pmodeler->GetNameSpace("gamepanes"));
- pnsLogonData->AddMember("promptText", new ModifiableString(szPrompt));
- pnsLogonData->AddMember("Callsign", new ModifiableNumber((float)lntCallsign));
- pnsLogonData->AddMember("ZoneID", new ModifiableNumber((float)lntZone));
- pnsLogonData->AddMember("PassportID", new ModifiableNumber((float)lntPassport));
- pnsLogonData->AddMember("logonNameType", new ModifiableNumber((float)logonNameType));
- TRef<INameSpace> pns = pmodeler->GetNameSpace("logon");
- CastTo(m_ppane, pns->FindMember("popup"));
- CastTo(m_pbuttonLogon, pns->FindMember("logonButtonPane"));
- AddEventTarget(OnButtonLogon, m_pbuttonLogon->GetEventSource());
- CastTo(m_pbuttonAbort, pns->FindMember("abortButtonPane"));
- AddEventTarget(OnButtonAbort, m_pbuttonAbort->GetEventSource());
- CastTo(m_pbuttonSignUp, pns->FindMember("signUpButtonPane"));
- AddEventTarget(OnButtonSignUp, m_pbuttonSignUp->GetEventSource());
- CastTo(m_pbuttonCDKey, pns->FindMember("cdKeyButtonPane"));
- AddEventTarget(OnButtonCDKey, m_pbuttonCDKey->GetEventSource());
- CastTo(m_peditName, (Pane*)pns->FindMember("nameEditPane" ));
- AddEventTarget(OnNameClick, m_peditName->GetClickEvent());
- CastTo(m_pbuttonSavePassword, pns->FindMember("savePasswordButtonPane"));
- CastTo(m_ppanePassword, pns->FindMember("passwordPane"));
- CastTo(m_peditPassword, (Pane*)pns->FindMember("passwordEditPane"));
- AddEventTarget(OnPasswordClick, m_peditPassword->GetClickEvent());
- m_peditPassword->SetType(EditPane::Password);
- m_peditPassword->SetString(ZString());
- m_peditName->SetString(ZString());
- // !!! disable logon button if name is empty
- // Get defaults
- if (LogonLAN == lt)
- {
- m_ppanePassword->SetHidden(true);
- m_pbuttonSavePassword->SetHidden(true);
- m_pbuttonCDKey->SetHidden(true);
- m_pbuttonSignUp->SetHidden(true);
- }
- else
- {
- m_peditPassword->SetString(szPW);
- m_pbuttonSavePassword->SetChecked(!!fRememberPW);
- }
- m_peditName->SetString(szName);
- m_peditName->SetMaxLength((LogonLAN != lt && trekClient.GetCfgInfo().bUsePassport)
- ? (c_cbPassportName - 1)
- : (c_cbName - 1)
- );
- if (m_peditName->GetString().IsEmpty()) {
- SetFocus(m_peditName);
- } else {
- SetFocus(m_peditPassword);
- }
- pmodeler->UnloadNameSpace(pns);
- }
- bool OnButtonLogon()
- {
- // Make sure that they have entered a CD Key
- if (g_bAskForCDKey && trekClient.GetCDKey().IsEmpty())
- {
- TRef<IPopup> ppopupCDKey = CreateCDKeyPopup();
- GetWindow()->GetPopupContainer()->OpenPopup(ppopupCDKey, false);
- }
- else
- {
- //
- // Grab info from the controls
- //
- ZString strName = m_peditName->GetString();
- ZString strPassword = m_peditPassword->GetString();
- bool fRememberPW = m_pbuttonSavePassword->GetChecked();
- if (strName[0] != ' ' && strName[0] != '\0') // give 'em a msg box?
- {
- //
- // Close
- //
- TRef<LogonPopup> pthis = this;
- ClosePopup(NULL);
- //
- // Tell the site
- //
- m_psite->OnLogon(strName, strPassword, fRememberPW);
- }
- }
- return true;
- }
- bool OnButtonAbort()
- {
- m_psite->OnAbort();
- ClosePopup(NULL);
- return true;
- }
- bool OnButtonSignUp()
- {
- GetWindow()->ShowWebPage("http://www.zone.com/allegiance/minilaunch1.asp");
- return true;
- }
- bool OnButtonCDKey()
- {
- TRef<IPopup> ppopupCDKey = CreateCDKeyPopup();
- GetWindow()->GetPopupContainer()->OpenPopup(ppopupCDKey, false);
- return true;
- }
- void SetFocus(IKeyboardInput* pfocus)
- {
- if (m_pfocus) {
- m_pfocus->SetFocusState(false);
- }
- m_pfocus = pfocus;
- m_pfocus->SetFocusState(true);
- }
- bool OnEvent(TEvent<ZString>::Source* psource, ZString str)
- {
- m_pbuttonLogon->SetEnabled(!str.IsEmpty());
- return true;
- }
- bool OnNameClick()
- {
- SetFocus(m_peditName);
- return true;
- }
- bool OnPasswordClick()
- {
- SetFocus(m_peditPassword);
- return true;
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- // IPopup Methods
- //
- //////////////////////////////////////////////////////////////////////////////
- void SetContainer(IPopupContainer* pcontainer)
- {
- IPopup::SetContainer(pcontainer);
- if (g_bQuickstart || g_bReloaded)
- {
- g_bReloaded = false; // we do this just once
- OnButtonLogon();
- }
- }
- Pane* GetPane()
- {
- return m_ppane;
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- // IKeyboardInput Methods
- //
- //////////////////////////////////////////////////////////////////////////////
- bool OnKey(IInputProvider* pprovider, const KeyState& ks, bool& fForceTranslate)
- {
- if (ks.bDown)
- {
- if (ks.vk == VK_RETURN)
- {
- if (m_pbuttonLogon->GetEnabled())
- {
- OnButtonLogon();
- }
- else
- {
- OnButtonAbort();
- }
- return true;
- }
- else if (ks.vk == VK_ESCAPE)
- {
- OnButtonAbort();
- return true;
- }
- else if (ks.vk == VK_TAB)
- {
- if (m_pfocus == m_peditName
- && (LogonAllegianceZone == m_lt || LogonFreeZone == m_lt))
- {
- SetFocus(m_peditPassword);
- } else
- {
- SetFocus(m_peditName);
- }
- return true;
- }
- }
- return m_pfocus->OnKey(pprovider, ks, fForceTranslate);
- }
- bool OnChar(IInputProvider* pprovider, const KeyState& ks)
- {
- return m_pfocus->OnChar(pprovider, ks);
- }
- };
- //////////////////////////////////////////////////////////////////////////////
- //
- // Constructor
- //
- //////////////////////////////////////////////////////////////////////////////
- TRef<IPopup> CreateLogonPopup(Modeler* pmodeler, LogonSite* psite, LogonType lt, LPCSTR szPrompt, LPCSTR szName, LPCSTR szPW, BOOL fRememberPW)
- {
- return new LogonPopup(pmodeler, psite, lt, szPrompt, szName, szPW, fRememberPW);
- }
|