1. import ui
  2. import snd
  3. import systemSetting
  4. import net
  5. import chat
  6. import app
  7. import localeInfo
  8. import constInfo
  9. import chrmgr
  10. import player
  11. import uiPrivateShopBuilder
  12. import interfaceModule
  13. import background
  14. blockMode = 0
  15. viewChatMode = 0
  16. class OptionDialog(ui.ScriptWindow):
  17. def __init__(self):
  18. ui.ScriptWindow.__init__(self)
  19. self.__Initialize()
  20. self.__Load()
  21. self.RefreshViewChat()
  22. self.RefreshAlwaysShowName()
  23. self.RefreshShowDamage()
  24. self.RefreshShowSalesText()
  25. self.arayuzmod()
  26. def __del__(self):
  27. ui.ScriptWindow.__del__(self)
  28. print " -------------------------------------- DELETE GAME OPTION DIALOG"
  29. def __Initialize(self):
  30. self.kargordumabi = []
  31. self.titleBar = 0
  32. self.nameColorModeButtonList = []
  33. self.viewTargetBoardButtonList = []
  34. self.pvpModeButtonDict = {}
  35. self.blockButtonList = []
  36. self.viewChatButtonList = []
  37. self.alwaysShowNameButtonList = []
  38. self.showDamageButtonList = []
  39. self.showsalesTextButtonList = []
  40. self.arayuzButtonList = []
  41. def Destroy(self):
  42. self.ClearDictionary()
  43. self.__Initialize()
  44. print " -------------------------------------- DESTROY GAME OPTION DIALOG"
  45. def __Load_LoadScript(self, fileName):
  46. try:
  47. pyScriptLoader = ui.PythonScriptLoader()
  48. pyScriptLoader.LoadScriptFile(self, fileName)
  49. except:
  50. import exception
  51. exception.Abort("OptionDialog.__Load_LoadScript")
  52. def __Load_BindObject(self):
  53. try:
  54. GetObject = self.GetChild
  55. self.titleBar = GetObject("titlebar")
  56. self.nameColorModeButtonList.append(GetObject("name_color_normal"))
  57. self.nameColorModeButtonList.append(GetObject("name_color_empire"))
  58. self.viewTargetBoardButtonList.append(GetObject("target_board_no_view"))
  59. self.viewTargetBoardButtonList.append(GetObject("target_board_view"))
  60. self.pvpModeButtonDict[player.PK_MODE_PEACE] = GetObject("pvp_peace")
  61. self.pvpModeButtonDict[player.PK_MODE_REVENGE] = GetObject("pvp_revenge")
  62. self.pvpModeButtonDict[player.PK_MODE_GUILD] = GetObject("pvp_guild")
  63. self.pvpModeButtonDict[player.PK_MODE_FREE] = GetObject("pvp_free")
  64. self.blockButtonList.append(GetObject("block_exchange_button"))
  65. self.blockButtonList.append(GetObject("block_party_button"))
  66. self.blockButtonList.append(GetObject("block_guild_button"))
  67. self.blockButtonList.append(GetObject("block_whisper_button"))
  68. self.blockButtonList.append(GetObject("block_friend_button"))
  69. self.blockButtonList.append(GetObject("block_party_request_button"))
  70. self.viewChatButtonList.append(GetObject("view_chat_on_button"))
  71. self.viewChatButtonList.append(GetObject("view_chat_off_button"))
  72. self.alwaysShowNameButtonList.append(GetObject("always_show_name_on_button"))
  73. self.alwaysShowNameButtonList.append(GetObject("always_show_name_off_button"))
  74. self.showDamageButtonList.append(GetObject("show_damage_on_button"))
  75. self.showDamageButtonList.append(GetObject("show_damage_off_button"))
  76. self.arayuzButtonList.append(GetObject("arayuz_on_button"))
  77. self.arayuzButtonList.append(GetObject("arayuz_off_button"))
  78. self.showsalesTextButtonList.append(GetObject("salestext_on_button"))
  79. self.showsalesTextButtonList.append(GetObject("salestext_off_button"))
  80. self.kargordumabi.append(GetObject("snow_aktif"))
  81. self.kargordumabi.append(GetObject("snow_pasif"))
  82. self.ctrlShopNamesRange = GetObject("salestext_range_controller")
  83. except:
  84. import exception
  85. exception.Abort("OptionDialog.__Load_BindObject")
  86. def __Load(self):
  87. self.__Load_LoadScript("uiscript/gameoptiondialog.py")
  88. self.__Load_BindObject()
  89. self.SetCenterPosition()
  90. self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close))
  91. self.nameColorModeButtonList[0].SAFE_SetEvent(self.__OnClickNameColorModeNormalButton)
  92. self.nameColorModeButtonList[1].SAFE_SetEvent(self.__OnClickNameColorModeEmpireButton)
  93. self.viewTargetBoardButtonList[0].SAFE_SetEvent(self.__OnClickTargetBoardViewButton)
  94. self.viewTargetBoardButtonList[1].SAFE_SetEvent(self.__OnClickTargetBoardNoViewButton)
  95. self.pvpModeButtonDict[player.PK_MODE_PEACE].SAFE_SetEvent(self.__OnClickPvPModePeaceButton)
  96. self.pvpModeButtonDict[player.PK_MODE_REVENGE].SAFE_SetEvent(self.__OnClickPvPModeRevengeButton)
  97. self.pvpModeButtonDict[player.PK_MODE_GUILD].SAFE_SetEvent(self.__OnClickPvPModeGuildButton)
  98. self.pvpModeButtonDict[player.PK_MODE_FREE].SAFE_SetEvent(self.__OnClickPvPModeFreeButton)
  99. self.blockButtonList[0].SetToggleUpEvent(self.__OnClickBlockExchangeButton)
  100. self.blockButtonList[1].SetToggleUpEvent(self.__OnClickBlockPartyButton)
  101. self.blockButtonList[2].SetToggleUpEvent(self.__OnClickBlockGuildButton)
  102. self.blockButtonList[3].SetToggleUpEvent(self.__OnClickBlockWhisperButton)
  103. self.blockButtonList[4].SetToggleUpEvent(self.__OnClickBlockFriendButton)
  104. self.blockButtonList[5].SetToggleUpEvent(self.__OnClickBlockPartyRequest)
  105. self.blockButtonList[0].SetToggleDownEvent(self.__OnClickBlockExchangeButton)
  106. self.blockButtonList[1].SetToggleDownEvent(self.__OnClickBlockPartyButton)
  107. self.blockButtonList[2].SetToggleDownEvent(self.__OnClickBlockGuildButton)
  108. self.blockButtonList[3].SetToggleDownEvent(self.__OnClickBlockWhisperButton)
  109. self.blockButtonList[4].SetToggleDownEvent(self.__OnClickBlockFriendButton)
  110. self.blockButtonList[5].SetToggleDownEvent(self.__OnClickBlockPartyRequest)
  111. self.viewChatButtonList[0].SAFE_SetEvent(self.__OnClickViewChatOnButton)
  112. self.viewChatButtonList[1].SAFE_SetEvent(self.__OnClickViewChatOffButton)
  113. self.alwaysShowNameButtonList[0].SAFE_SetEvent(self.__OnClickAlwaysShowNameOnButton)
  114. self.alwaysShowNameButtonList[1].SAFE_SetEvent(self.__OnClickAlwaysShowNameOffButton)
  115. self.arayuzButtonList[0].SAFE_SetEvent(self.arayuzac)
  116. self.arayuzButtonList[1].SAFE_SetEvent(self.arayuzkapa)
  117. self.showDamageButtonList[0].SAFE_SetEvent(self.__OnClickShowDamageOnButton)
  118. self.showDamageButtonList[1].SAFE_SetEvent(self.__OnClickShowDamageOffButton)
  119. self.showsalesTextButtonList[0].SAFE_SetEvent(self.__OnClickSalesTextOnButton)
  120. self.showsalesTextButtonList[1].SAFE_SetEvent(self.__OnClickSalesTextOffButton)
  121. self.kargordumabi[0].SAFE_SetEvent(self.__SnowAktif)
  122. self.kargordumabi[1].SAFE_SetEvent(self.__SnowPasif)
  123. self.__ClickRadioButton(self.nameColorModeButtonList, constInfo.GET_CHRNAME_COLOR_INDEX())
  124. self.__ClickRadioButton(self.viewTargetBoardButtonList, constInfo.GET_VIEW_OTHER_EMPIRE_PLAYER_TARGET_BOARD())
  125. self.__SetPeacePKMode()
  126. self.ctrlShopNamesRange.SetSliderPos(float(uiPrivateShopBuilder.GetShopNamesRange()))
  127. self.ctrlShopNamesRange.SetEvent(ui.__mem_func__(self.OnChangeShopNamesRange))
  128. def __SnowAktif(self):
  129. systemSetting.SetSnowTexturesMode(TRUE)
  130. self.Yenilebeni()
  131. if background.GetCurrentMapName():
  132. snow_maps = [
  133. "metin2_map_a1",
  134. "metin2_map_b1",
  135. "metin2_map_c1"
  136. ]
  137. snow_maps_textures = {
  138. "metin2_map_a1" : "textureset\metin2_a1_snow.txt",
  139. "metin2_map_b1" : "textureset\metin2_b1_snow.txt",
  140. "metin2_map_c1" : "textureset\metin2_c1_snow.txt", }
  141. if str(background.GetCurrentMapName()) in snow_maps:
  142. background.TextureChange(snow_maps_textures[str(background.GetCurrentMapName())])
  143. def __SnowPasif(self):
  144. systemSetting.SetSnowTexturesMode(FALSE)
  145. self.Yenilebeni()
  146. if background.GetCurrentMapName():
  147. snow_maps = [
  148. "metin2_map_a1",
  149. "metin2_map_b1",
  150. "metin2_map_c1"
  151. ]
  152. snow_maps_textures = {
  153. "metin2_map_a1" : "textureset\metin2_a1.txt",
  154. "metin2_map_b1" : "textureset\metin2_b1.txt",
  155. "metin2_map_c1" : "textureset\metin2_c1.txt", }
  156. if str(background.GetCurrentMapName()) in snow_maps:
  157. background.TextureChange(snow_maps_textures[str(background.GetCurrentMapName())])
  158. def Yenilebeni(self):
  159. if systemSetting.IsSnowTexturesMode():
  160. self.kargordumabi[0].Down()
  161. self.kargordumabi[1].SetUp()
  162. else:
  163. self.kargordumabi[0].SetUp()
  164. self.kargordumabi[1].Down()
  165. def OnChangeShopNamesRange(self):
  166. pos = self.ctrlShopNamesRange.GetSliderPos()
  167. uiPrivateShopBuilder.SetShopNamesRange(pos)
  168. if systemSetting.IsShowSalesText():
  169. uiPrivateShopBuilder.UpdateADBoard()
  170. def __ClickRadioButton(self, buttonList, buttonIndex):
  171. try:
  172. selButton=buttonList[buttonIndex]
  173. except IndexError:
  174. return
  175. for eachButton in buttonList:
  176. eachButton.SetUp()
  177. selButton.Down()
  178. def __SetNameColorMode(self, index):
  179. constInfo.SET_CHRNAME_COLOR_INDEX(index)
  180. self.__ClickRadioButton(self.nameColorModeButtonList, index)
  181. def __SetTargetBoardViewMode(self, flag):
  182. constInfo.SET_VIEW_OTHER_EMPIRE_PLAYER_TARGET_BOARD(flag)
  183. self.__ClickRadioButton(self.viewTargetBoardButtonList, flag)
  184. def __OnClickNameColorModeNormalButton(self):
  185. self.__SetNameColorMode(0)
  186. def __OnClickNameColorModeEmpireButton(self):
  187. self.__SetNameColorMode(1)
  188. def __OnClickTargetBoardViewButton(self):
  189. self.__SetTargetBoardViewMode(0)
  190. def __OnClickTargetBoardNoViewButton(self):
  191. self.__SetTargetBoardViewMode(1)
  192. def __OnClickCameraModeShortButton(self):
  193. self.__SetCameraMode(0)
  194. def __OnClickCameraModeLongButton(self):
  195. self.__SetCameraMode(1)
  196. def __OnClickFogModeLevel0Button(self):
  197. self.__SetFogLevel(0)
  198. def __OnClickFogModeLevel1Button(self):
  199. self.__SetFogLevel(1)
  200. def __OnClickFogModeLevel2Button(self):
  201. self.__SetFogLevel(2)
  202. def __OnClickBlockExchangeButton(self):
  203. self.RefreshBlock()
  204. global blockMode
  205. net.SendChatPacket("/setblockmode " + str(blockMode ^ player.BLOCK_EXCHANGE))
  206. def __OnClickBlockPartyButton(self):
  207. self.RefreshBlock()
  208. global blockMode
  209. net.SendChatPacket("/setblockmode " + str(blockMode ^ player.BLOCK_PARTY))
  210. def __OnClickBlockGuildButton(self):
  211. self.RefreshBlock()
  212. global blockMode
  213. net.SendChatPacket("/setblockmode " + str(blockMode ^ player.BLOCK_GUILD))
  214. def __OnClickBlockWhisperButton(self):
  215. self.RefreshBlock()
  216. global blockMode
  217. net.SendChatPacket("/setblockmode " + str(blockMode ^ player.BLOCK_WHISPER))
  218. def __OnClickBlockFriendButton(self):
  219. self.RefreshBlock()
  220. global blockMode
  221. net.SendChatPacket("/setblockmode " + str(blockMode ^ player.BLOCK_FRIEND))
  222. def __OnClickBlockPartyRequest(self):
  223. self.RefreshBlock()
  224. global blockMode
  225. net.SendChatPacket("/setblockmode " + str(blockMode ^ player.BLOCK_PARTY_REQUEST))
  226. def __OnClickViewChatOnButton(self):
  227. global viewChatMode
  228. viewChatMode = 1
  229. systemSetting.SetViewChatFlag(viewChatMode)
  230. self.RefreshViewChat()
  231. def __OnClickViewChatOffButton(self):
  232. global viewChatMode
  233. viewChatMode = 0
  234. systemSetting.SetViewChatFlag(viewChatMode)
  235. self.RefreshViewChat()
  236. def __OnClickAlwaysShowNameOnButton(self):
  237. systemSetting.SetAlwaysShowNameFlag(True)
  238. self.RefreshAlwaysShowName()
  239. def __OnClickAlwaysShowNameOffButton(self):
  240. systemSetting.SetAlwaysShowNameFlag(False)
  241. self.RefreshAlwaysShowName()
  242. def __OnClickShowDamageOnButton(self):
  243. systemSetting.SetShowDamageFlag(True)
  244. self.RefreshShowDamage()
  245. def __OnClickShowDamageOffButton(self):
  246. systemSetting.SetShowDamageFlag(False)
  247. self.RefreshShowDamage()
  248. def __OnClickSalesTextOnButton(self):
  249. systemSetting.SetShowSalesTextFlag(True)
  250. self.RefreshShowSalesText()
  251. uiPrivateShopBuilder.UpdateADBoard()
  252. def __OnClickSalesTextOffButton(self):
  253. systemSetting.SetShowSalesTextFlag(False)
  254. self.RefreshShowSalesText()
  255. def __CheckPvPProtectedLevelPlayer(self):
  256. if player.GetStatus(player.LEVEL)<constInfo.PVPMODE_PROTECTED_LEVEL:
  257. self.__SetPeacePKMode()
  258. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OPTION_PVPMODE_PROTECT % (constInfo.PVPMODE_PROTECTED_LEVEL))
  259. return 1
  260. return 0
  261. def __SetPKMode(self, mode):
  262. for btn in self.pvpModeButtonDict.values():
  263. btn.SetUp()
  264. if self.pvpModeButtonDict.has_key(mode):
  265. self.pvpModeButtonDict[mode].Down()
  266. def __SetPeacePKMode(self):
  267. self.__SetPKMode(player.PK_MODE_PEACE)
  268. def __RefreshPVPButtonList(self):
  269. self.__SetPKMode(player.GetPKMode())
  270. def __OnClickPvPModePeaceButton(self):
  271. if self.__CheckPvPProtectedLevelPlayer():
  272. return
  273. self.__RefreshPVPButtonList()
  274. if constInfo.PVPMODE_ENABLE:
  275. net.SendChatPacket("/pkmode 0", chat.CHAT_TYPE_TALKING)
  276. else:
  277. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OPTION_PVPMODE_NOT_SUPPORT)
  278. def __OnClickPvPModeRevengeButton(self):
  279. if self.__CheckPvPProtectedLevelPlayer():
  280. return
  281. self.__RefreshPVPButtonList()
  282. if constInfo.PVPMODE_ENABLE:
  283. net.SendChatPacket("/pkmode 1", chat.CHAT_TYPE_TALKING)
  284. else:
  285. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OPTION_PVPMODE_NOT_SUPPORT)
  286. def __OnClickPvPModeFreeButton(self):
  287. if self.__CheckPvPProtectedLevelPlayer():
  288. return
  289. self.__RefreshPVPButtonList()
  290. if constInfo.PVPMODE_ENABLE:
  291. net.SendChatPacket("/pkmode 2", chat.CHAT_TYPE_TALKING)
  292. else:
  293. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OPTION_PVPMODE_NOT_SUPPORT)
  294. def __OnClickPvPModeGuildButton(self):
  295. if self.__CheckPvPProtectedLevelPlayer():
  296. return
  297. self.__RefreshPVPButtonList()
  298. if 0 == player.GetGuildID():
  299. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OPTION_PVPMODE_CANNOT_SET_GUILD_MODE)
  300. return
  301. if constInfo.PVPMODE_ENABLE:
  302. net.SendChatPacket("/pkmode 4", chat.CHAT_TYPE_TALKING)
  303. else:
  304. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OPTION_PVPMODE_NOT_SUPPORT)
  305. def OnChangePKMode(self):
  306. self.__RefreshPVPButtonList()
  307. def OnCloseInputDialog(self):
  308. self.inputDialog.Close()
  309. self.inputDialog = None
  310. return True
  311. def OnCloseQuestionDialog(self):
  312. self.questionDialog.Close()
  313. self.questionDialog = None
  314. return True
  315. def OnPressEscapeKey(self):
  316. self.Close()
  317. return True
  318. def RefreshBlock(self):
  319. global blockMode
  320. for i in xrange(len(self.blockButtonList)):
  321. if 0 != (blockMode & (1 << i)):
  322. self.blockButtonList[i].Down()
  323. else:
  324. self.blockButtonList[i].SetUp()
  325. def RefreshViewChat(self):
  326. if systemSetting.IsViewChat():
  327. self.viewChatButtonList[0].Down()
  328. self.viewChatButtonList[1].SetUp()
  329. else:
  330. self.viewChatButtonList[0].SetUp()
  331. self.viewChatButtonList[1].Down()
  332. def RefreshAlwaysShowName(self):
  333. if systemSetting.IsAlwaysShowName():
  334. self.alwaysShowNameButtonList[0].Down()
  335. self.alwaysShowNameButtonList[1].SetUp()
  336. else:
  337. self.alwaysShowNameButtonList[0].SetUp()
  338. self.alwaysShowNameButtonList[1].Down()
  339. def arayuzac(self):
  340. constInfo.arayuz_mod = 0
  341. self.arayuzmod()
  342. def arayuzkapa(self):
  343. constInfo.arayuz_mod = 1
  344. self.arayuzmod()
  345. def arayuzmod(self):
  346. if constInfo.arayuz_mod == 0:
  347. self.arayuzButtonList[0].Down()
  348. self.arayuzButtonList[1].SetUp()
  349. else:
  350. self.arayuzButtonList[0].SetUp()
  351. self.arayuzButtonList[1].Down()
  352. def RefreshShowDamage(self):
  353. if systemSetting.IsShowDamage():
  354. self.showDamageButtonList[0].Down()
  355. self.showDamageButtonList[1].SetUp()
  356. else:
  357. self.showDamageButtonList[0].SetUp()
  358. self.showDamageButtonList[1].Down()
  359. def RefreshShowSalesText(self):
  360. if systemSetting.IsShowSalesText():
  361. self.showsalesTextButtonList[0].Down()
  362. self.showsalesTextButtonList[1].SetUp()
  363. else:
  364. self.showsalesTextButtonList[0].SetUp()
  365. self.showsalesTextButtonList[1].Down()
  366. def OnBlockMode(self, mode):
  367. global blockMode
  368. blockMode = mode
  369. self.RefreshBlock()
  370. def Show(self):
  371. self.RefreshBlock()
  372. ui.ScriptWindow.Show(self)
  373. def Close(self):
  374. self.Hide()